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

Fix shard fork choice #1970

Merged
merged 10 commits into from
Jul 29, 2020
Merged

Fix shard fork choice #1970

merged 10 commits into from
Jul 29, 2020

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Jul 15, 2020

Issue

The shard chain fork choice logic should be separate from different shards. (#1768 D.1)

How did I fix it

  1. fork-choice and shard-fork-choice:
    1. Create ShardLatestMessage dataclass to store the latest message of per shard.
    2. Add latest_messages: Dict[ValidatorIndex, ShardLatestMessage] field to ShardStore.
    3. Store schema update.
      • Since we have to access ShardStore in on_attestation but I also want to avoid overhaul the existing function APIs and test cases. This PR move shard_stores: Dict[Shard, ShardStore] to be one of the fields of Store.
    4. Use shard latest_message to calculate the shard latest attesting balance.
  2. setup.py: handle the dataclass classes dependencies.

hwwhww added 4 commits July 14, 2020 17:41
1. Add `ShardLatestMessage` dataclass
2. To make it compatible with phase 0 tests and APIs, add `Store.shard_stores: Dict[Shard, ShardStore]`
3. Update `get_forkchoice_store` and `update_latest_messages`
@@ -145,9 +142,9 @@ def get_pending_shard_blocks(store: Store, shard_store: ShardStore) -> Sequence[
#### `on_shard_block`

```python
def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: SignedShardBlock) -> None:
def on_shard_block(store: Store, shard: Shard, signed_shard_block: SignedShardBlock) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should delete assert shard_block.shard == shard and simplify arguments to

def on_shard_block(store: Store, signed_shard_block: SignedShardBlock) -> None:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed
We should just derive the shard directly from the shard_block and use the appropriate shard_store from the store

@hwwhww
Copy link
Contributor Author

hwwhww commented Jul 20, 2020

The BLS-enabled tests require #1973.

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @terencechain. otherwise, PR looks good!

@@ -145,9 +142,9 @@ def get_pending_shard_blocks(store: Store, shard_store: ShardStore) -> Sequence[
#### `on_shard_block`

```python
def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: SignedShardBlock) -> None:
def on_shard_block(store: Store, shard: Shard, signed_shard_block: SignedShardBlock) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed
We should just derive the shard directly from the shard_block and use the appropriate shard_store from the store

@djrtwo
Copy link
Contributor

djrtwo commented Jul 28, 2020

looks good other than merge conflict

@djrtwo
Copy link
Contributor

djrtwo commented Jul 29, 2020

This is still marked draft.
Any blockers for un-drafting and merging @hwwhww ?

@hwwhww
Copy link
Contributor Author

hwwhww commented Jul 29, 2020

The test would not pass if BLS flag is enabled, so kinda depending on #1980 under the surface.

@djrtwo
Copy link
Contributor

djrtwo commented Jul 29, 2020

#1980 merged

@hwwhww hwwhww marked this pull request as ready for review July 29, 2020 15:59
@hwwhww hwwhww merged commit a609320 into dev Jul 29, 2020
@hwwhww hwwhww deleted the shard-fork-choice-fix branch July 29, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants