-
Notifications
You must be signed in to change notification settings - Fork 92
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
Don't save every state on archive node #210
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b884ded
add skipping commiting states
magicxyyz c90d530
fix state commit skipping limits
magicxyyz 5d2eddd
update MaxNumberOfBlocksToSkipStateSaving default value
magicxyyz c98e2c3
Merge branch 'recreate-state-for-rpcs' into dont-save-every-state
magicxyyz a47849f
fix merge
magicxyyz a20db86
Merge branch 'recreate-state-for-rpcs' into dont-save-every-state
magicxyyz eb96086
disable state save skipping in default geth cache config
magicxyyz c86303c
remove debug logs
magicxyyz 1a58f1b
Merge branch 'master' into dont-save-every-state
magicxyyz 0b3e0d0
Merge branch 'master' into dont-save-every-state
magicxyyz 89f53b0
update flushing comment
magicxyyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,9 @@ type CacheConfig struct { | |
TriesInMemory uint64 // Height difference before which a trie may not be garbage-collected | ||
TrieRetention time.Duration // Time limit before which a trie may not be garbage-collected | ||
|
||
MaxNumberOfBlocksToSkipStateSaving uint32 | ||
MaxAmountOfGasToSkipStateSaving uint64 | ||
|
||
SnapshotNoBuild bool // Whether the background generation is allowed | ||
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it | ||
} | ||
|
@@ -153,8 +156,10 @@ type CacheConfig struct { | |
var defaultCacheConfig = &CacheConfig{ | ||
|
||
// Arbitrum Config Options | ||
TriesInMemory: DefaultTriesInMemory, | ||
TrieRetention: 30 * time.Minute, | ||
TriesInMemory: DefaultTriesInMemory, | ||
TrieRetention: 30 * time.Minute, | ||
MaxNumberOfBlocksToSkipStateSaving: 127, | ||
MaxAmountOfGasToSkipStateSaving: 15 * 1000 * 1000, | ||
|
||
TrieCleanLimit: 256, | ||
TrieDirtyLimit: 256, | ||
|
@@ -236,6 +241,9 @@ type BlockChain struct { | |
processor Processor // Block transaction processor interface | ||
forker *ForkChoice | ||
vmConfig vm.Config | ||
|
||
numberOfBlocksToSkipStateSaving uint32 | ||
amountOfGasInBlocksToSkipStateSaving uint64 | ||
} | ||
|
||
type trieGcEntry struct { | ||
|
@@ -1442,7 +1450,33 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |
} | ||
// If we're running an archive node, always flush | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably good to update comment to reflect changed code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment, I am open for any suggestions for improvement |
||
if bc.cacheConfig.TrieDirtyDisabled { | ||
return bc.triedb.Commit(root, false) | ||
var maySkipCommiting, blockLimitReached, gasLimitReached bool | ||
if bc.cacheConfig.MaxNumberOfBlocksToSkipStateSaving != 0 { | ||
maySkipCommiting = true | ||
if bc.numberOfBlocksToSkipStateSaving > 0 { | ||
bc.numberOfBlocksToSkipStateSaving-- | ||
} else { | ||
blockLimitReached = true | ||
} | ||
} | ||
if bc.cacheConfig.MaxAmountOfGasToSkipStateSaving != 0 { | ||
maySkipCommiting = true | ||
if bc.amountOfGasInBlocksToSkipStateSaving >= block.GasUsed() { | ||
bc.amountOfGasInBlocksToSkipStateSaving -= block.GasUsed() | ||
} else { | ||
gasLimitReached = true | ||
} | ||
} | ||
if !maySkipCommiting || blockLimitReached || gasLimitReached { | ||
bc.numberOfBlocksToSkipStateSaving = bc.cacheConfig.MaxNumberOfBlocksToSkipStateSaving | ||
bc.amountOfGasInBlocksToSkipStateSaving = bc.cacheConfig.MaxAmountOfGasToSkipStateSaving | ||
// TODO remove log | ||
magicxyyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Debug("Saving state", "blockNumber", block.Number(), "blockHash", block.Hash(), "leftBlocks", bc.numberOfBlocksToSkipStateSaving, "leftGas", bc.amountOfGasInBlocksToSkipStateSaving) | ||
return bc.triedb.Commit(root, false) | ||
} | ||
// TODO remove log | ||
magicxyyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Debug("Skipping saving state", "blockNumber", block.Number(), "blockHash", block.Hash(), "leftBlocks", bc.numberOfBlocksToSkipStateSaving, "leftGas", bc.amountOfGasInBlocksToSkipStateSaving) | ||
return nil | ||
} | ||
|
||
// Full but not archive node, do proper garbage collection | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Defaults in geth should keep geth (ethereum) behavior as much as possible.
These two should definitely be 0.
Defaults in nitro can be debated (I tend for 0 there too but that's different)
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.
On the nitro side, I think trying to match the amount of gas inbetween saved states as L1 (15 million gas) would be good. Saving state for every Arbitrum block isn't as reasonable as it is for L1, but saving it every 15 million gas would mean that the rate of archive disk growth in terms of chain speed should be the same.
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.
Then again, this would be something that'd be very easy to miss in an upgrade and would mean that the node is now somewhat permanently missing state. So maybe we should keep it at 0 for the upgrade, I'm not sure. We can talk about it next standup.