-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Integrate state-diff into State()
#16033
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
Conversation
e30a4fd to
4dc14e5
Compare
| // If state diff is enabled, we get the state from the state-diff db. | ||
| if features.Get().EnableStateDiff { | ||
| st, err := s.getStateUsingStateDiff(ctx, blockRoot) | ||
| if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there error is a state not found error, could it fallback to the original implementation? I am thinking about folks that enabled state diff on a fully or partially synced node and they may have some states in the other bucket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we won't have coexisting dbs. If the node reaches this point it can't use the previous impl.
potuz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a request for a change in tests.
beacon-chain/db/kv/state_test.go
Outdated
| err = db.saveStateByDiff(context.Background(), st1) | ||
| require.NoError(t, err) | ||
|
|
||
| slot := primitives.Slot(math.PowerOf2(5)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chaindiff is trivial for this slot, better to do something like 2^exponents[len(exponents)-2] + 2^exponents[len(exponents)-1] to have some non-trivial diffs, you´ll also need to save the anchor at the penultimate level.
**What type of PR is this?** Feature **What does this PR do? Why is it needed?** This PR integrates the state diff path into the `State()` function from `db/kv`, which allows reading of states using the state diff db, when the `EnableStateDiff` flag is enabled. **Notes for reviewers:** Files `kv/state_diff_test.go` and `config/features/config.go` only contain renamings: - `kv/state_diff_test.go`: rename `setDefaultExponents()` to `setDefaultStateDiffExponents()` to be less vague. - `config/features/config.go`: rename `enableStateDiff` to `EnableStateDiff` to make it public.
**Review after #16033 is merged** **What type of PR is this?** Other **What does this PR do? Why is it needed?** This PR refactors the code to find the corresponding slot of a given block root using state summary or the block itself, into its own function `SlotByBlockRoot(ctx, blockroot)`. Note that there exists a function `slotByBlockRoot(ctx context.Context, tx *bolt.Tx, blockRoot []byte)` immediately below the new function. Also note that this function has two drawbacks, which led to creation of the new function: - the old function requires a boltdb tx, which is not necessarily available to the caller. - the old function does NOT make use of the state summary cache. edit: - the old function also uses the state bucket to retrieve the state and it's slot. this is not something we want in the state diff feature, since there is no state bucket.
**Review after #16033 is merged** **What type of PR is this?** Other **What does this PR do? Why is it needed?** This PR refactors the code to find the corresponding slot of a given block root using state summary or the block itself, into its own function `SlotByBlockRoot(ctx, blockroot)`. Note that there exists a function `slotByBlockRoot(ctx context.Context, tx *bolt.Tx, blockRoot []byte)` immediately below the new function. Also note that this function has two drawbacks, which led to creation of the new function: - the old function requires a boltdb tx, which is not necessarily available to the caller. - the old function does NOT make use of the state summary cache. edit: - the old function also uses the state bucket to retrieve the state and it's slot. this is not something we want in the state diff feature, since there is no state bucket.
What type of PR is this?
Feature
What does this PR do? Why is it needed?
This PR integrates the state diff path into the
State()function fromdb/kv, which allows reading of states using the state diff db, when theEnableStateDiffflag is enabled.Notes for reviewers:
Files
kv/state_diff_test.goandconfig/features/config.goonly contain renamings:kv/state_diff_test.go: renamesetDefaultExponents()tosetDefaultStateDiffExponents()to be less vague.config/features/config.go: renameenableStateDifftoEnableStateDiffto make it public.