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

feat: add TrieCommitInterval configuration, commit trie every TrieCommitInterval blocks. #45

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

welkin22
Copy link
Contributor

@welkin22 welkin22 commented Jan 3, 2024

Description

Currently, all of our nodes can only be set to archive mode for gcMode. As the amount of data gradually increases, each of our nodes needs to be able to configure to full mode. This mode will delete Trie data that is lower than the latest block height minus TriesInMemory blocks, instead of committing and storing it in the database. This way, our nodes will occupy less disk space and have better performance. However, our official bridge and proposer components both need to use Trie data from about 1 hour ago. After enabling full mode, both the official bridge and proposer components will not function properly.
We need to enable full mode, and at the same time, we need to solve the problem of the official bridge and proposer using Trie data.

Rationale

It should be noted that the full mode does not discard all Trie data. It has a gcproc statistic that tracks the cumulative time spent processing blocks. When gcproc is greater than flushInterval (default is 1 hour), the full mode will commit and store the complete Trie data for the current block height minus TriesInMemory in the database. On the other hand, the submission frequency of our Mainnet and Testnet proposers is fixed and controlled by the configuration l2OutputOracleSubmissionInterval. We can use this configuration to calculate which block heights the official bridge and proposers need to use. Therefore, we add a TrieCommitInterval configuration in geth, whose value is equal to the value of l2OutputOracleSubmissionInterval for the corresponding network. In our code, we add a judgment condition that when the target block height (i.e. the latest block height minus TriesInMemory) divided by TrieCommitInterval results in a remainder of 0, it means that the target block height is the block height where we need to save the Trie data. We then commit the Trie data and store it in the database.

Example

add TrieCommitInterval config in config.toml

[Eth]
TrieCommitInterval = 240

then add gcMode=full to geth param.
All Trie data for block heights that are multiples of 240 will be available.

Changes

Notable changes:

  • Add TrieCommitInterval configuration option
  • Add an additional condition after bc.gcproc > flushInterval, where chosen block height is divisible by TrieCommitInterval, commit triedb.

Copy link
Contributor

@krish-nr krish-nr left a comment

Choose a reason for hiding this comment

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

/LGTM

@owen-reorg owen-reorg merged commit 99f8289 into bnb-chain:develop Jan 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants