fix gethead tests

This commit is contained in:
Danny Ryan 2019-06-25 14:42:37 -06:00
parent 228195d89d
commit c64289677f
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
2 changed files with 19 additions and 9 deletions

View File

@ -64,6 +64,16 @@ class Checkpoint(object):
root: Hash
```
#### `LatestMessage`
```python
@dataclass(eq=True, frozen=True)
class LatestMessage(object):
epoch: Epoch
root: Hash
```
#### `Store`
```python
@ -75,7 +85,7 @@ class Store(object):
blocks: Dict[Hash, BeaconBlock] = field(default_factory=dict)
block_states: Dict[Hash, BeaconState] = field(default_factory=dict)
checkpoint_states: Dict[Checkpoint, BeaconState] = field(default_factory=dict)
latest_targets: Dict[ValidatorIndex, Checkpoint] = field(default_factory=dict)
latest_messages: Dict[ValidatorIndex, LatestMessage] = field(default_factory=dict)
```
#### `get_genesis_store`
@ -113,8 +123,8 @@ def get_latest_attesting_balance(store: Store, root: Hash) -> Gwei:
active_indices = get_active_validator_indices(state, get_current_epoch(state))
return Gwei(sum(
state.validators[i].effective_balance for i in active_indices
if (i in store.latest_targets and
get_ancestor(store, store.latest_targets[i].root, store.blocks[root].slot) == root)
if (i in store.latest_messages and
get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root)
))
```
@ -207,8 +217,8 @@ def on_attestation(store: Store, attestation: Attestation) -> None:
indexed_attestation = convert_to_indexed(target_state, attestation)
validate_indexed_attestation(target_state, indexed_attestation)
# Update latest targets
# Update latest messages
for i in indexed_attestation.custody_bit_0_indices + indexed_attestation.custody_bit_1_indices:
if i not in store.latest_targets or target.epoch > store.latest_targets[i].epoch:
store.latest_targets[i] = target
if i not in store.latest_messages or target.epoch > store.latest_messages[i].epoch:
store.latest_messages[i] = LatestMessage(epoch=target.epoch, root=attestation.data.beacon_block_root)
```

View File

@ -17,10 +17,10 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
indexed_attestation = spec.convert_to_indexed(state, attestation)
spec.on_attestation(store, attestation)
assert (
store.latest_targets[indexed_attestation.custody_bit_0_indices[0]] ==
spec.Checkpoint(
store.latest_messages[indexed_attestation.custody_bit_0_indices[0]] ==
spec.LatestMessage(
epoch=attestation.data.target_epoch,
root=attestation.data.target_root,
root=attestation.data.beacon_block_root,
)
)