Skip to content

Commit

Permalink
fix gethead tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Jun 25, 2019
1 parent 228195d commit 3a54e25
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions specs/core/0_fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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)
))
```

Expand Down Expand Up @@ -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)
```

0 comments on commit 3a54e25

Please sign in to comment.