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

[config change] Improve BlocksReExecutor implementation #2714

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ganeshvanahalli
Copy link
Contributor

@ganeshvanahalli ganeshvanahalli commented Oct 1, 2024

This PR changes the implementation of blocks re-execution mainly to use a separate stateDB during each block's re-execution and to verify that the resulting state successfully commits.

Config option --blocks-reexecutor.blocks-per-thread is renamed to --blocks-reexecutor.min-blocks-per-thread.
A new config option trie-clean-limit (memory allowance in MB to use for caching trie nodes in memory) is added.

Pulls geth PR- OffchainLabs/go-ethereum#364
Resolves NIT-2810

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Oct 1, 2024
@ganeshvanahalli ganeshvanahalli marked this pull request as ready for review October 1, 2024 11:58
eljobe
eljobe previously approved these changes Oct 1, 2024
Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@magicxyyz magicxyyz left a comment

Choose a reason for hiding this comment

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

looks good, but we should configure cleans cache + we potentially can simplify / clean up arbitrum.AdvanceStateUpToBlock and follow the release func pattern

},
trieConfig := triedb.Config{
Preimages: false,
HashDB: hashdb.Defaults,
Copy link
Contributor

Choose a reason for hiding this comment

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

hashdb.Defaults have CleanCacheSize = 0 (cleans cache disabled). We should use cleans cache here to have better perfomance, similarly to:

hashConfig := *hashdb.Defaults
hashConfig.CleanCacheSize = cacheConfig.TrieCleanLimit * 1024 * 1024
trieConfig := &triedb.Config{
Preimages: false,
HashDB: &hashConfig,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I've added a new config field trie-clean-limit and have set the default value for this as 600 sourcing from here let me know if it should be adjusted

blocksReExecutor.stateFor = func(header *types.Header) (*state.StateDB, arbitrum.StateReleaseFunc, error) {
sdb, err := state.NewDeterministic(header.Root, blocksReExecutor.db)
if err == nil {
_ = blocksReExecutor.db.TrieDB().Reference(header.Root, common.Hash{}) // Will be dereferenced later in advanceStateUpToBlock
Copy link
Contributor

Choose a reason for hiding this comment

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

how about following the release function pattern?

  • we could return arbitrum.StateReleaseFunc that will call Dereference. That can be something like func() {triedb.Dereference(root)})

  • we would need to move the call to release func returned from arbitrum.FindLastAvailableState to the thread started with LaunchThread so as it would be called after AdvanceStateUpToBlock or even better - we could pass the startStateRelease to advanceStateUpToBlock and call it after we reference next state

  • arbitrum.AdvanceStateUpToBlock was used only here, so we can modify it to commit statedb after each reexecuted block and check the hashes OR we can just remove arbitrum.AdvanceStateUpToBlock

  • we can return release func also from advanceStateUpToBlock and have something like:


startState, startHeader, startStateRelease, err := arbitrum.FindLastAvailableState(ctx, s.blockchain, s.stateFor, s.blockchain.GetHeaderByNumber(start), nil, -1)
...
s.LaunchThread(func(ctx context.Context) {
    ...
    _, release, err := advanceStateUpToBlock(..., startHeader, startStateRelease, ...)
    ...
    defer release()
    ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

note to startStateRelease - we should make sure that it will be called also in case of an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, its a great idea to utilize StateReleaseFuncs here!
Also removed AdvanceStateUpToBlock from geth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants