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

core: separated databases for block data #2227

Merged
merged 10 commits into from
Apr 18, 2024

Conversation

jingjunLi
Copy link
Contributor

@jingjunLi jingjunLi commented Feb 21, 2024

Description

This pull request uses the finalized block tag as the indicator for chain freezing and introduces the separation of block data into a dedicated blockdb. The principle support of PR: BEP-365: Support multi-database based on data pattern

uses the finalized block tag as the indicator for chain freezing

Originally, the latest 90K blocks will be retained in the key-value store by default, which is regarded as "non-finalized" in the context of Proof-of-work. However, in Proof-of-Stake, we do have the concrete finalized block tag from the consensus client. Therefore, it makes more sense to directly rely on the Finalized for chain freezing.

By deploying it on a full node, we can see there are only 23 blocks left in the key-value store.
image

introduces the separation of block data into a dedicated blockdb

  • Background
    recent blocks are first stored in a key-value (KV) database. Once they reach the ancient threshold, they will be moved to the ancient database, which wastes some disk bandwidth. Another thing that we should be aware of is EIP-4844. Once BSC supports EIP-4844, the block size will increase due to the inclusion of blobs. The size of the blob storage may not increase over time, but it will still demand extra disk space from the node operators.
  • Implement
    Split database by data pattern will make disk bandwidth usage more reasonable and improve the whole performance.

Rationale

tell us why we need these changes...

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@fynnss fynnss requested a review from RenRick February 22, 2024 02:26
cmd/utils/flags.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/node.go Outdated

if config.SeparateDB {
log.Info("SeparateDB is enabled, open block database, %s", config.DatabaseBlock)
blockStore, err = n.OpenBlockDatabase(name, config.DatabaseHandles-chainDataHandles, config.DatabaseBlock, namespace, readonly)
Copy link
Contributor

Choose a reason for hiding this comment

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

config.DatabaseHandles-chainDataHandles euqals zero , it it no meaning.
You can consider allocating 1/10 of the handlers to the block store

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cache and handles usage is modified as follows:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a new Resource allocation rules:

  1. Allocate a fixed percentage of memory for chainDb based on chainDbMemoryPercentage & chainDbHandlesPercentage.
  2. Allocate a fixed size for blockDb based on blockDbCacheSize & blockDbHandlesSize.
  3. Allocate the remaining resources to stateDb.

core/rawdb/database.go Outdated Show resolved Hide resolved
core/rawdb/database.go Outdated Show resolved Hide resolved
@jingjunLi jingjunLi closed this Mar 6, 2024
@jingjunLi jingjunLi reopened this Mar 6, 2024
@jingjunLi jingjunLi changed the title core: Impl block store core: separated databases for block data Mar 6, 2024
node/node.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/node.go Show resolved Hide resolved
cmd/geth/config.go Outdated Show resolved Hide resolved
cmd/utils/flags.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/node.go Outdated
@@ -73,10 +74,13 @@ const (
initializingState = iota
runningState
closedState
blockDbCacheSize = 256
blockDbHandlesSize = 2000
Copy link
Contributor

@flywukong flywukong Mar 12, 2024

Choose a reason for hiding this comment

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

if handler/10 < 2000 {
	blockDbHandlesSize  = 1000 
}else {
	blockDbHandlesSize   = 2000
}  

Adjust this variable

cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
cmd/geth/chaincmd.go Show resolved Hide resolved
cmd/geth/chaincmd.go Show resolved Hide resolved
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
core/blockchain.go Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
@jingjunLi jingjunLi force-pushed the impl_block_store branch 2 times, most recently from afc3eac to 89b7d3a Compare March 12, 2024 09:39
cmd/geth/config.go Outdated Show resolved Hide resolved
@jingjunLi jingjunLi force-pushed the impl_block_store branch 3 times, most recently from 3e6149f to 7e3e660 Compare March 20, 2024 05:19
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
@jingjunLi jingjunLi added the r4r ready for review label Apr 11, 2024
core/rawdb/database.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/node.go Show resolved Hide resolved
node/node.go Show resolved Hide resolved
@jingjunLi jingjunLi force-pushed the impl_block_store branch 2 times, most recently from 5640825 to 288c534 Compare April 15, 2024 03:03
Copy link
Contributor

@fynnss fynnss 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

@RenRick RenRick left a comment

Choose a reason for hiding this comment

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

LGTM

@zzzckck zzzckck merged commit c0afdc9 into bnb-chain:develop Apr 18, 2024
7 checks passed
Copy link

@Pjrich1313 Pjrich1313 left a comment

Choose a reason for hiding this comment

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

O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r4r ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants