Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shard fork choice rule #1773

Merged
merged 29 commits into from
Jun 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dab5a93
wip shard fork choice rule
hwwhww Apr 28, 2020
cddf9cf
Refactor
hwwhww Apr 30, 2020
8fafb6a
Make `ShardStore` an independent object
hwwhww May 1, 2020
fca1bbc
Remove `get_filtered_shard_block_tree`
hwwhww May 1, 2020
79b1b4b
Add `(shard, shard_root)` to `LatestMessage`
hwwhww May 1, 2020
870ad8b
Fix test
hwwhww May 29, 2020
63de59d
Merge branch 'dev' into hwwhww/shard_fork_choice_3
hwwhww May 29, 2020
142ba17
PR review from Danny
hwwhww Jun 2, 2020
5c5cedd
Apply PR feedback from Danny and Terence
hwwhww Jun 3, 2020
58e75c2
Merge branch 'dev' into hwwhww/shard_fork_choice
hwwhww Jun 3, 2020
e1981a7
`head_shard_root` -> `shard_head_root`
hwwhww Jun 3, 2020
d344521
Bugfix: should set `shard` for empty proposal
hwwhww Jun 3, 2020
26aae40
Use epoch of the shard_block.slot for generating seed
hwwhww Jun 3, 2020
c9a53b8
WIP test case
hwwhww Jun 3, 2020
727353c
Verify shard_block.slot fits the expected offset_slots
hwwhww Jun 4, 2020
f8597d2
Add `get_pendings_shard_blocks`
hwwhww Jun 4, 2020
ab42eee
Update shard fork choice rule to be able to handle mainnet config
hwwhww Jun 4, 2020
6f9c290
Add TODO flag of latest message
hwwhww Jun 4, 2020
a154d0c
Fix typo
hwwhww Jun 4, 2020
2d4788f
Fix `verify_shard_block_message`
hwwhww Jun 5, 2020
2afa315
clean leftover
hwwhww Jun 5, 2020
a71c0a5
Per #1704 discussion, remove `on_time_slot`: the given `beacon_state`
hwwhww Jun 5, 2020
a4cc189
Apply PR feedback from Danny
hwwhww Jun 5, 2020
4355057
PR feedback from Terence: fix `get_shard_latest_attesting_balance`
hwwhww Jun 8, 2020
7e67aae
Rename `build_shard_transitions_till_slot` to `get_shard_transitions`
hwwhww Jun 8, 2020
e03a970
PR feedback from danny: simplify `verify_shard_block_message` params
hwwhww Jun 8, 2020
9b3f45d
Merge pull request #1875 from ethereum/hwwhww/shard_fork_choice_part2
hwwhww Jun 8, 2020
3b749d7
Merge branch 'dev' into hwwhww/shard_fork_choice
hwwhww Jun 8, 2020
2d895e9
PR feedback from danny
hwwhww Jun 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions specs/phase1/shard-fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def get_shard_latest_attesting_balance(store: Store, shard_store: ShardStore, ro
return Gwei(sum(
state.validators[i].effective_balance for i in active_indices
if (
i in store.latest_messages and get_shard_ancestor(
i in store.latest_messages and
hwwhww marked this conversation as resolved.
Show resolved Hide resolved
store.latest_messages[i].shard == shard_store.shard and
djrtwo marked this conversation as resolved.
Show resolved Hide resolved
get_shard_ancestor(
store, shard_store, store.latest_messages[i].root, shard_store.blocks[root].slot
hwwhww marked this conversation as resolved.
Show resolved Hide resolved
) == root
)
Expand All @@ -71,12 +73,18 @@ def get_shard_latest_attesting_balance(store: Store, shard_store: ShardStore, ro
```python
def get_shard_head(store: Store, shard_store: ShardStore) -> Root:
# Execute the LMD-GHOST fork choice
shard_blocks = shard_store.blocks
hwwhww marked this conversation as resolved.
Show resolved Hide resolved
head_beacon_root = get_head(store)
head_shard_root = store.block_states[head_beacon_root].shard_states[shard_store.shard].latest_block_root
head_shard_state = store.block_states[head_beacon_root].shard_states[shard_store.shard]
head_shard_root = head_shard_state.latest_block_root
while True:
# Find the valid child block roots
children = [
root for root in shard_store.blocks.keys()
if shard_store.blocks[root].shard_parent_root == head_shard_root
if (
shard_blocks[root].shard_parent_root == head_shard_root
and shard_blocks[root].slot > head_shard_state.slot
)
]
if len(children) == 0:
return head_shard_root
Expand Down Expand Up @@ -116,14 +124,15 @@ def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: Si
assert shard_block.beacon_parent_root in store.block_states
beacon_state = store.block_states[shard_block.beacon_parent_root]

# 3. Check that block is later than the finalized epoch slot (optimization to reduce calls to get_ancestor)
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
assert shard_block.slot > finalized_slot
# 3. Check that block is later than the finalized shard state slot (optimization to reduce calls to get_ancestor)
finalized_beacon_state = store.block_states[store.finalized_checkpoint.root]
finalized_shard_state = finalized_beacon_state.shard_states[shard]
assert shard_block.slot > finalized_shard_state.slot

# 4. Check block is a descendant of the finalized block at the checkpoint finalized slot
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
assert (
shard_block.beacon_parent_root == store.finalized_checkpoint.root
or get_ancestor(store, shard_block.beacon_parent_root, finalized_slot) == store.finalized_checkpoint.root
get_ancestor(store, shard_block.beacon_parent_root, finalized_slot) == store.finalized_checkpoint.root
)

# Add new block to the store
Expand Down