straightforward light client edits
This commit is contained in:
parent
b2d25f7454
commit
3b7c02514b
|
@ -66,15 +66,28 @@ This is a standalone beacon chain patch adding light client support via sync com
|
||||||
|
|
||||||
### Extended containers
|
### Extended containers
|
||||||
|
|
||||||
#### `BeaconBlockBody`
|
*Note*: Extended SSZ containers inherit all fields from the parent in the original
|
||||||
|
order and append any additional fields to the end.
|
||||||
|
|
||||||
|
#### `BeaconBlock`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class BeaconBlockBody(phase0.BeaconBlockBody):
|
class BeaconBlock(phase0.BeaconBlock):
|
||||||
# Sync committee aggregate signature
|
# Sync committee aggregate signature
|
||||||
sync_committee_bits: Bitvector[SYNC_COMMITTEE_SIZE]
|
sync_committee_bits: Bitvector[SYNC_COMMITTEE_SIZE]
|
||||||
sync_committee_signature: BLSSignature
|
sync_committee_signature: BLSSignature
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `BeaconBlockHeader`
|
||||||
|
|
||||||
|
```python
|
||||||
|
class BeaconBlockHeader(phase0.BeaconBlockHeader):
|
||||||
|
# Sync committee aggregate signature
|
||||||
|
sync_committee_bits: Bitvector[SYNC_COMMITTEE_SIZE]
|
||||||
|
sync_committee_signature: BLSSignature
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### `BeaconState`
|
#### `BeaconState`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -105,6 +118,7 @@ def get_sync_committee_indices(state: BeaconState, epoch: Epoch) -> Sequence[Val
|
||||||
"""
|
"""
|
||||||
Return the sync committee indices for a given state and epoch.
|
Return the sync committee indices for a given state and epoch.
|
||||||
"""
|
"""
|
||||||
|
MAX_RANDOM_BYTE = 2**8 - 1
|
||||||
base_epoch = Epoch((max(epoch // EPOCHS_PER_SYNC_COMMITTEE_PERIOD, 1) - 1) * EPOCHS_PER_SYNC_COMMITTEE_PERIOD)
|
base_epoch = Epoch((max(epoch // EPOCHS_PER_SYNC_COMMITTEE_PERIOD, 1) - 1) * EPOCHS_PER_SYNC_COMMITTEE_PERIOD)
|
||||||
active_validator_indices = get_active_validator_indices(state, base_epoch)
|
active_validator_indices = get_active_validator_indices(state, base_epoch)
|
||||||
active_validator_count = uint64(len(active_validator_indices))
|
active_validator_count = uint64(len(active_validator_indices))
|
||||||
|
@ -143,21 +157,22 @@ def get_sync_committee(state: BeaconState, epoch: Epoch) -> SyncCommittee:
|
||||||
```python
|
```python
|
||||||
def process_block(state: BeaconState, block: BeaconBlock) -> None:
|
def process_block(state: BeaconState, block: BeaconBlock) -> None:
|
||||||
phase0.process_block(state, block)
|
phase0.process_block(state, block)
|
||||||
process_sync_committee(state, block.body)
|
process_sync_committee(state, block)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Sync committee processing
|
#### Sync committee processing
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_sync_committee(state: BeaconState, body: BeaconBlockBody) -> None:
|
def process_sync_committee(state: BeaconState, block: BeaconBlock) -> None:
|
||||||
# Verify sync committee aggregate signature signing over the previous slot block root
|
# Verify sync committee aggregate signature signing over the previous slot block root
|
||||||
previous_slot = max(state.slot, Slot(1)) - Slot(1)
|
previous_slot = Slot(max(state.slot, 1) - 1)
|
||||||
committee_indices = get_sync_committee_indices(state, get_current_epoch(state))
|
committee_indices = get_sync_committee_indices(state, get_current_epoch(state))
|
||||||
participant_indices = [committee_indices[i] for i in range(len(committee_indices)) if body.sync_committee_bits[i]]
|
participant_indices = [index for index, bit in zip(committee_indices, body.sync_committee_bits) if bit]
|
||||||
participant_pubkeys = [state.validators[participant_index].pubkey for participant_index in participant_indices]
|
committee_pubkeys = state.current_sync_committee.pubkeys
|
||||||
|
participant_pubkeys = [pubkey for pubkey, bit in zip(committee_pubkeys, body.sync_committee_bits) if bit]
|
||||||
domain = get_domain(state, DOMAIN_SYNC_COMMITTEE, compute_epoch_at_slot(previous_slot))
|
domain = get_domain(state, DOMAIN_SYNC_COMMITTEE, compute_epoch_at_slot(previous_slot))
|
||||||
signing_root = compute_signing_root(get_block_root_at_slot(state, previous_slot), domain)
|
signing_root = compute_signing_root(get_block_root_at_slot(state, previous_slot), domain)
|
||||||
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, body.sync_committee_signature)
|
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, block.sync_committee_signature)
|
||||||
|
|
||||||
# Reward sync committee participants
|
# Reward sync committee participants
|
||||||
participant_rewards = Gwei(0)
|
participant_rewards = Gwei(0)
|
||||||
|
|
|
@ -28,9 +28,13 @@
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Eth2 is designed to be light client friendly for constrained environments to access Eth2 with reasonable satefy and liveness. Such environments include resource-constrained devices (e.g. phones for trust-minimised wallets) and metered VMs (e.g. blockchain VMs for cross-chain bridges).
|
Eth2 is designed to be light client friendly for constrained environments to
|
||||||
|
access Eth2 with reasonable safety and liveness.
|
||||||
|
Such environments include resource-constrained devices (e.g. phones for trust-minimised wallets)
|
||||||
|
and metered VMs (e.g. blockchain VMs for cross-chain bridges).
|
||||||
|
|
||||||
This document suggests a minimal light client design for the beacon chain that uses sync committees introduced in [this beacon chain extension](./beacon-chain.md).
|
This document suggests a minimal light client design for the beacon chain that
|
||||||
|
uses sync committees introduced in [this beacon chain extension](./beacon-chain.md).
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue