merge in fork choice. tests pass

This commit is contained in:
Danny Ryan 2019-06-24 21:43:05 -06:00
parent bacd4b1e89
commit b8c0985e60
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
4 changed files with 17 additions and 25 deletions

View File

@ -1337,13 +1337,14 @@ def process_justification_and_finalization(state: BeaconState) -> None:
state, get_matching_target_attestations(state, previous_epoch)
)
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)
current_epoch_matching_target_balance = get_attesting_balance(
state, get_matching_target_attestations(state, current_epoch)
)
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)
# Process finalizations

View File

@ -55,15 +55,6 @@ The head block root associated with a `store` is defined as `get_head(store)`. A
### Helpers
#### `Checkpoint`
```python
@dataclass(eq=True, frozen=True)
class Checkpoint(object):
epoch: Epoch
root: Hash
```
#### `Store`
```python
@ -84,8 +75,8 @@ class Store(object):
def get_genesis_store(genesis_state: BeaconState) -> Store:
genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))
root = signing_root(genesis_block)
justified_checkpoint = Checkpoint(GENESIS_EPOCH, root)
finalized_checkpoint = Checkpoint(GENESIS_EPOCH, root)
justified_checkpoint = Checkpoint(epoch=GENESIS_EPOCH, root=root)
finalized_checkpoint = Checkpoint(epoch=GENESIS_EPOCH, root=root)
return Store(
time=genesis_state.genesis_time,
justified_checkpoint=justified_checkpoint,
@ -168,21 +159,21 @@ def on_block(store: Store, block: BeaconBlock) -> None:
store.block_states[signing_root(block)] = state
# Update justified checkpoint
if state.current_justified_epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = Checkpoint(state.current_justified_epoch, state.current_justified_root)
elif state.previous_justified_epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = Checkpoint(state.previous_justified_epoch, state.previous_justified_root)
if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = state.current_justified_checkpoint
elif state.previous_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = state.previous_justified_checkpoint
# Update finalized checkpoint
if state.finalized_epoch > state.finalized_epoch:
store.finalized_checkpoint = Checkpoint(state.finalized_epoch, state.finalized_root)
if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch:
store.finalized_checkpoint = state.finalized_checkpoint
```
#### `on_attestation`
```python
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
assert target.root in store.blocks

View File

@ -21,8 +21,8 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
assert (
store.latest_targets[indexed_attestation.custody_bit_0_indices[0]] ==
spec.Checkpoint(
epoch=attestation.data.target_epoch,
root=attestation.data.target_root,
epoch=attestation.data.target.epoch,
root=attestation.data.target.root,
)
)