mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-26 01:05:15 +00:00
merge in fork choice. tests pass
This commit is contained in:
parent
bacd4b1e89
commit
b8c0985e60
@ -1337,13 +1337,14 @@ def process_justification_and_finalization(state: BeaconState) -> None:
|
|||||||
state, get_matching_target_attestations(state, previous_epoch)
|
state, get_matching_target_attestations(state, previous_epoch)
|
||||||
)
|
)
|
||||||
if previous_epoch_matching_target_balance * 3 >= get_total_active_balance(state) * 2:
|
if previous_epoch_matching_target_balance * 3 >= get_total_active_balance(state) * 2:
|
||||||
state.current_justified_checkpoint = Checkpoint(previous_epoch, get_block_root(state, previous_epoch))
|
state.current_justified_checkpoint = Checkpoint(epoch=previous_epoch,
|
||||||
|
root=get_block_root(state, previous_epoch))
|
||||||
state.justification_bitfield |= (1 << 1)
|
state.justification_bitfield |= (1 << 1)
|
||||||
current_epoch_matching_target_balance = get_attesting_balance(
|
current_epoch_matching_target_balance = get_attesting_balance(
|
||||||
state, get_matching_target_attestations(state, current_epoch)
|
state, get_matching_target_attestations(state, current_epoch)
|
||||||
)
|
)
|
||||||
if current_epoch_matching_target_balance * 3 >= get_total_active_balance(state) * 2:
|
if current_epoch_matching_target_balance * 3 >= get_total_active_balance(state) * 2:
|
||||||
state.current_justified_checkpoint = Checkpoint(current_epoch, get_block_root(state, current_epoch))
|
state.current_justified_checkpoint = Checkpoint(epoch=current_epoch, root=get_block_root(state, current_epoch))
|
||||||
state.justification_bitfield |= (1 << 0)
|
state.justification_bitfield |= (1 << 0)
|
||||||
|
|
||||||
# Process finalizations
|
# Process finalizations
|
||||||
|
@ -55,15 +55,6 @@ The head block root associated with a `store` is defined as `get_head(store)`. A
|
|||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
|
||||||
#### `Checkpoint`
|
|
||||||
|
|
||||||
```python
|
|
||||||
@dataclass(eq=True, frozen=True)
|
|
||||||
class Checkpoint(object):
|
|
||||||
epoch: Epoch
|
|
||||||
root: Hash
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `Store`
|
#### `Store`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -84,8 +75,8 @@ class Store(object):
|
|||||||
def get_genesis_store(genesis_state: BeaconState) -> Store:
|
def get_genesis_store(genesis_state: BeaconState) -> Store:
|
||||||
genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))
|
genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))
|
||||||
root = signing_root(genesis_block)
|
root = signing_root(genesis_block)
|
||||||
justified_checkpoint = Checkpoint(GENESIS_EPOCH, root)
|
justified_checkpoint = Checkpoint(epoch=GENESIS_EPOCH, root=root)
|
||||||
finalized_checkpoint = Checkpoint(GENESIS_EPOCH, root)
|
finalized_checkpoint = Checkpoint(epoch=GENESIS_EPOCH, root=root)
|
||||||
return Store(
|
return Store(
|
||||||
time=genesis_state.genesis_time,
|
time=genesis_state.genesis_time,
|
||||||
justified_checkpoint=justified_checkpoint,
|
justified_checkpoint=justified_checkpoint,
|
||||||
@ -168,21 +159,21 @@ def on_block(store: Store, block: BeaconBlock) -> None:
|
|||||||
store.block_states[signing_root(block)] = state
|
store.block_states[signing_root(block)] = state
|
||||||
|
|
||||||
# Update justified checkpoint
|
# Update justified checkpoint
|
||||||
if state.current_justified_epoch > store.justified_checkpoint.epoch:
|
if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
|
||||||
store.justified_checkpoint = Checkpoint(state.current_justified_epoch, state.current_justified_root)
|
store.justified_checkpoint = state.current_justified_checkpoint
|
||||||
elif state.previous_justified_epoch > store.justified_checkpoint.epoch:
|
elif state.previous_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
|
||||||
store.justified_checkpoint = Checkpoint(state.previous_justified_epoch, state.previous_justified_root)
|
store.justified_checkpoint = state.previous_justified_checkpoint
|
||||||
|
|
||||||
# Update finalized checkpoint
|
# Update finalized checkpoint
|
||||||
if state.finalized_epoch > state.finalized_epoch:
|
if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch:
|
||||||
store.finalized_checkpoint = Checkpoint(state.finalized_epoch, state.finalized_root)
|
store.finalized_checkpoint = state.finalized_checkpoint
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `on_attestation`
|
#### `on_attestation`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def on_attestation(store: Store, attestation: Attestation) -> None:
|
def on_attestation(store: Store, attestation: Attestation) -> None:
|
||||||
target = Checkpoint(attestation.data.target_epoch, attestation.data.target_root)
|
target = attestation.data.target
|
||||||
|
|
||||||
# Cannot calculate the current shuffling if have not seen the target
|
# Cannot calculate the current shuffling if have not seen the target
|
||||||
assert target.root in store.blocks
|
assert target.root in store.blocks
|
||||||
|
@ -21,8 +21,8 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
|
|||||||
assert (
|
assert (
|
||||||
store.latest_targets[indexed_attestation.custody_bit_0_indices[0]] ==
|
store.latest_targets[indexed_attestation.custody_bit_0_indices[0]] ==
|
||||||
spec.Checkpoint(
|
spec.Checkpoint(
|
||||||
epoch=attestation.data.target_epoch,
|
epoch=attestation.data.target.epoch,
|
||||||
root=attestation.data.target_root,
|
root=attestation.data.target.root,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user