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

Unmarshal Block instead of State #5246

Merged
merged 10 commits into from Mar 31, 2020
11 changes: 6 additions & 5 deletions beacon-chain/db/kv/state.go
Expand Up @@ -308,20 +308,21 @@ func slotByBlockRoot(ctx context.Context, tx *bolt.Tx, blockRoot []byte) (uint64
return stateSummary.Slot, nil
}

bkt := tx.Bucket(stateBucket)
bkt := tx.Bucket(blocksBucket)
Copy link
Member

Choose a reason for hiding this comment

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

We actually started out by using block. But one very good feedback from @prestonvanloon: what if the block is missing then the node will never be able to delete the state

I know the state is slower, I think the compromise (later) is to add a root->slot storage

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an issue during sync, unmarshalling a state just to delete it is quite inefficient. If a block is missing, then how would we save its resulting state ?
i could add a fallback to retrieve the state in the event the block is missing.

Copy link
Member

Choose a reason for hiding this comment

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

This is just preparing for the worst case (ie, user saves the state then mistakenly deletes the block.. etc)

fallback sounds good

Copy link
Member Author

Choose a reason for hiding this comment

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

ok done, added in a fallback

enc := bkt.Get(blockRoot)
if enc == nil {
return 0, errors.New("state enc can't be nil")
}

s, err := createState(enc)
b := &ethpb.SignedBeaconBlock{}
err := decode(enc, b)
if err != nil {
return 0, err
}
if s == nil {
return 0, errors.New("state can't be nil")
if b.Block == nil {
return 0, errors.New("block can't be nil")
}
return s.Slot, nil
return b.Block.Slot, nil
}

// HighestSlotStates returns the states with the highest slot from the db.
Expand Down