fix gethead tests
This commit is contained in:
parent
228195d89d
commit
c64289677f
|
@ -64,6 +64,16 @@ class Checkpoint(object):
|
||||||
root: Hash
|
root: Hash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `LatestMessage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
@dataclass(eq=True, frozen=True)
|
||||||
|
class LatestMessage(object):
|
||||||
|
epoch: Epoch
|
||||||
|
root: Hash
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### `Store`
|
#### `Store`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -75,7 +85,7 @@ class Store(object):
|
||||||
blocks: Dict[Hash, BeaconBlock] = field(default_factory=dict)
|
blocks: Dict[Hash, BeaconBlock] = field(default_factory=dict)
|
||||||
block_states: Dict[Hash, BeaconState] = field(default_factory=dict)
|
block_states: Dict[Hash, BeaconState] = field(default_factory=dict)
|
||||||
checkpoint_states: Dict[Checkpoint, 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`
|
#### `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))
|
active_indices = get_active_validator_indices(state, get_current_epoch(state))
|
||||||
return Gwei(sum(
|
return Gwei(sum(
|
||||||
state.validators[i].effective_balance for i in active_indices
|
state.validators[i].effective_balance for i in active_indices
|
||||||
if (i in store.latest_targets and
|
if (i in store.latest_messages and
|
||||||
get_ancestor(store, store.latest_targets[i].root, store.blocks[root].slot) == root)
|
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)
|
indexed_attestation = convert_to_indexed(target_state, attestation)
|
||||||
validate_indexed_attestation(target_state, indexed_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:
|
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:
|
if i not in store.latest_messages or target.epoch > store.latest_messages[i].epoch:
|
||||||
store.latest_targets[i] = target
|
store.latest_messages[i] = LatestMessage(epoch=target.epoch, root=attestation.data.beacon_block_root)
|
||||||
```
|
```
|
||||||
|
|
|
@ -17,10 +17,10 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
|
||||||
indexed_attestation = spec.convert_to_indexed(state, attestation)
|
indexed_attestation = spec.convert_to_indexed(state, attestation)
|
||||||
spec.on_attestation(store, attestation)
|
spec.on_attestation(store, attestation)
|
||||||
assert (
|
assert (
|
||||||
store.latest_targets[indexed_attestation.custody_bit_0_indices[0]] ==
|
store.latest_messages[indexed_attestation.custody_bit_0_indices[0]] ==
|
||||||
spec.Checkpoint(
|
spec.LatestMessage(
|
||||||
epoch=attestation.data.target_epoch,
|
epoch=attestation.data.target_epoch,
|
||||||
root=attestation.data.target_root,
|
root=attestation.data.beacon_block_root,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue