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

Don't save every state on archive node #1542

Merged
merged 28 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c97fac3
update geth
magicxyyz Mar 29, 2023
65aaa49
add initial test for skipping saving states
magicxyyz Mar 29, 2023
3f46628
improve not saving states tests
magicxyyz Mar 30, 2023
4cbf2eb
update geth
magicxyyz Apr 11, 2023
9d7f088
fix test failure message
magicxyyz Apr 11, 2023
22c9df3
update geth
magicxyyz Jun 13, 2023
482eb81
Merge branch 'recreate-state-for-rpcs' into dont-save-every-state
magicxyyz Jun 13, 2023
1bf5586
update geth
magicxyyz Jun 13, 2023
cb65f7e
fix recreate state test build
magicxyyz Jun 13, 2023
e165f3d
update geth
magicxyyz Jun 15, 2023
fad06ab
Merge branch 'master' into dont-save-every-state
magicxyyz Jun 15, 2023
e8767b7
update geth
magicxyyz Jun 15, 2023
2773f3b
Merge branch 'recreate-state-for-rpcs' into dont-save-every-state
magicxyyz Jun 15, 2023
cba9cea
add MaxNumberOfBlocksToSkipStateSaving and MaxAmountOfGasToSkipStateS…
magicxyyz Jun 16, 2023
3c4ba0a
update geth
magicxyyz Sep 7, 2023
295c90d
Merge branch 'master' into dont-save-every-state
magicxyyz Sep 7, 2023
8e9d787
remove not used parameter of stackConfigForTest
magicxyyz Sep 7, 2023
0b42d1f
make sure that each test tx is included in next block
magicxyyz Sep 7, 2023
68c0039
simplify test params
magicxyyz Sep 7, 2023
c67b318
shorten state saving skipping test
magicxyyz Sep 7, 2023
20b213a
clean extra return values form prepareNodeWithHistory
magicxyyz Sep 7, 2023
0e0fe26
refactor setting cache config in tests
magicxyyz Sep 8, 2023
cc58fbb
fix staker test
magicxyyz Sep 8, 2023
97c0ec5
Merge branch 'master' into dont-save-every-state
magicxyyz Sep 8, 2023
d0aac0f
Merge branch 'master' into dont-save-every-state
magicxyyz Sep 19, 2023
3bf7dd0
update geth
magicxyyz Sep 26, 2023
90a2599
Merge branch 'master' into dont-save-every-state
magicxyyz Sep 26, 2023
4d2ddce
Merge branch 'master' into dont-save-every-state
magicxyyz Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions arbnode/execution/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ import (
)

type CachingConfig struct {
Archive bool `koanf:"archive"`
BlockCount uint64 `koanf:"block-count"`
BlockAge time.Duration `koanf:"block-age"`
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
TrieDirtyCache int `koanf:"trie-dirty-cache"`
TrieCleanCache int `koanf:"trie-clean-cache"`
SnapshotCache int `koanf:"snapshot-cache"`
DatabaseCache int `koanf:"database-cache"`
SnapshotRestoreGasLimit uint64 `koanf:"snapshot-restore-gas-limit"`
Archive bool `koanf:"archive"`
BlockCount uint64 `koanf:"block-count"`
BlockAge time.Duration `koanf:"block-age"`
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
TrieDirtyCache int `koanf:"trie-dirty-cache"`
TrieCleanCache int `koanf:"trie-clean-cache"`
SnapshotCache int `koanf:"snapshot-cache"`
DatabaseCache int `koanf:"database-cache"`
SnapshotRestoreGasLimit uint64 `koanf:"snapshot-restore-gas-limit"`
MaxNumberOfBlocksToSkipStateSaving uint32 `koanf:"max-number-of-blocks-to-skip-state-saving"`
MaxAmountOfGasToSkipStateSaving uint64 `koanf:"max-amount-of-gas-to-skip-state-saving"`
}

func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
Expand All @@ -47,18 +49,22 @@ func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Int(prefix+".snapshot-cache", DefaultCachingConfig.SnapshotCache, "amount of memory in megabytes to cache state snapshots with")
f.Int(prefix+".database-cache", DefaultCachingConfig.DatabaseCache, "amount of memory in megabytes to cache database contents with")
f.Uint64(prefix+".snapshot-restore-gas-limit", DefaultCachingConfig.SnapshotRestoreGasLimit, "maximum gas rolled back to recover snapshot")
f.Uint32(prefix+".max-number-of-blocks-to-skip-state-saving", DefaultCachingConfig.MaxNumberOfBlocksToSkipStateSaving, "maximum number of blocks to skip state saving to persistent storage (archive node only)")
f.Uint64(prefix+".max-amount-of-gas-to-skip-state-saving", DefaultCachingConfig.MaxAmountOfGasToSkipStateSaving, "maximum amount of gas in blocks to skip saving state to Persistent storage (archive node only)")
}

var DefaultCachingConfig = CachingConfig{
Archive: false,
BlockCount: 128,
BlockAge: 30 * time.Minute,
TrieTimeLimit: time.Hour,
TrieDirtyCache: 1024,
TrieCleanCache: 600,
SnapshotCache: 400,
DatabaseCache: 2048,
SnapshotRestoreGasLimit: 300_000_000_000,
Archive: false,
BlockCount: 128,
BlockAge: 30 * time.Minute,
TrieTimeLimit: time.Hour,
TrieDirtyCache: 1024,
TrieCleanCache: 600,
SnapshotCache: 400,
DatabaseCache: 2048,
SnapshotRestoreGasLimit: 300_000_000_000,
MaxNumberOfBlocksToSkipStateSaving: 127,
MaxAmountOfGasToSkipStateSaving: 15 * 1000 * 1000,
}

func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core.CacheConfig {
Expand All @@ -68,18 +74,20 @@ func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core
}

return &core.CacheConfig{
TrieCleanLimit: cachingConfig.TrieCleanCache,
TrieCleanJournal: stack.ResolvePath(baseConf.TrieCleanCacheJournal),
TrieCleanRejournal: baseConf.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: baseConf.NoPrefetch,
TrieDirtyLimit: cachingConfig.TrieDirtyCache,
TrieDirtyDisabled: cachingConfig.Archive,
TrieTimeLimit: cachingConfig.TrieTimeLimit,
TriesInMemory: cachingConfig.BlockCount,
TrieRetention: cachingConfig.BlockAge,
SnapshotLimit: cachingConfig.SnapshotCache,
Preimages: baseConf.Preimages,
SnapshotRestoreMaxGas: cachingConfig.SnapshotRestoreGasLimit,
TrieCleanLimit: cachingConfig.TrieCleanCache,
TrieCleanJournal: stack.ResolvePath(baseConf.TrieCleanCacheJournal),
TrieCleanRejournal: baseConf.TrieCleanCacheRejournal,
TrieCleanNoPrefetch: baseConf.NoPrefetch,
TrieDirtyLimit: cachingConfig.TrieDirtyCache,
TrieDirtyDisabled: cachingConfig.Archive,
TrieTimeLimit: cachingConfig.TrieTimeLimit,
TriesInMemory: cachingConfig.BlockCount,
TrieRetention: cachingConfig.BlockAge,
SnapshotLimit: cachingConfig.SnapshotCache,
Preimages: baseConf.Preimages,
SnapshotRestoreMaxGas: cachingConfig.SnapshotRestoreGasLimit,
MaxNumberOfBlocksToSkipStateSaving: cachingConfig.MaxNumberOfBlocksToSkipStateSaving,
MaxAmountOfGasToSkipStateSaving: cachingConfig.MaxAmountOfGasToSkipStateSaving,
}
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
Submodule go-ethereum updated 1 files
+37 −4 core/blockchain.go
2 changes: 1 addition & 1 deletion system_tests/arbtrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestArbTraceForwarding(t *testing.T) {
nodeConfig := arbnode.ConfigDefaultL1Test()
nodeConfig.RPC.ClassicRedirect = ipcPath
nodeConfig.RPC.ClassicRedirectTimeout = time.Second
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nodeConfig, nil, nil, nil, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nodeConfig, nil, nil, nil)
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)

Expand Down
21 changes: 13 additions & 8 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,13 @@ func DeployOnTestL1(
}

func createL2BlockChain(
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, cacheConfig *core.CacheConfig,
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, cacheConfig *execution.CachingConfig,
) (*BlockchainTestInfo, *node.Node, ethdb.Database, ethdb.Database, *core.BlockChain) {
return createL2BlockChainWithStackConfig(t, l2info, dataDir, chainConfig, nil, nil, cacheConfig)
}

func createL2BlockChainWithStackConfig(
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, stackConfig *node.Config, cacheConfig *core.CacheConfig,
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, stackConfig *node.Config, cacheConfig *execution.CachingConfig,
) (*BlockchainTestInfo, *node.Node, ethdb.Database, ethdb.Database, *core.BlockChain) {
if l2info == nil {
l2info = NewArbTestInfo(t, chainConfig.ChainID)
Expand Down Expand Up @@ -536,7 +536,11 @@ func createL2BlockChainWithStackConfig(
SerializedChainConfig: serializedChainConfig,
}
}
blockchain, err := execution.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, initMessage, arbnode.ConfigDefaultL2Test().TxLookupLimit, 0)
var coreCacheConfig *core.CacheConfig
if cacheConfig != nil {
coreCacheConfig = execution.DefaultCacheConfigFor(stack, cacheConfig)
}
blockchain, err := execution.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, arbnode.ConfigDefaultL2Test().TxLookupLimit, 0)
Require(t, err)

return l2info, stack, chainDb, arbDb, blockchain
Expand Down Expand Up @@ -571,7 +575,7 @@ func createTestNodeOnL1WithConfig(
l2info info, currentNode *arbnode.Node, l2client *ethclient.Client, l1info info,
l1backend *eth.Ethereum, l1client *ethclient.Client, l1stack *node.Node,
) {
l2info, currentNode, l2client, _, l1info, l1backend, l1client, l1stack = createTestNodeOnL1WithConfigImpl(t, ctx, isSequencer, nodeConfig, chainConfig, stackConfig, nil, nil)
l2info, currentNode, l2client, _, l1info, l1backend, l1client, l1stack = createTestNodeOnL1WithConfigImpl(t, ctx, isSequencer, nodeConfig, chainConfig, stackConfig, nil)
return
}

Expand All @@ -582,7 +586,6 @@ func createTestNodeOnL1WithConfigImpl(
nodeConfig *arbnode.Config,
chainConfig *params.ChainConfig,
stackConfig *node.Config,
cacheConfig *core.CacheConfig,
l2info_in info,
) (
l2info info, currentNode *arbnode.Node, l2client *ethclient.Client, l2stack *node.Node,
Expand All @@ -604,7 +607,7 @@ func createTestNodeOnL1WithConfigImpl(
l2info = NewArbTestInfo(t, chainConfig.ChainID)
}
addresses, initMessage := DeployOnTestL1(t, ctx, l1info, l1client, chainConfig)
_, l2stack, l2chainDb, l2arbDb, l2blockchain = createL2BlockChainWithStackConfig(t, l2info, "", chainConfig, initMessage, stackConfig, cacheConfig)
_, l2stack, l2chainDb, l2arbDb, l2blockchain = createL2BlockChainWithStackConfig(t, l2info, "", chainConfig, initMessage, stackConfig, &nodeConfig.Caching)
var sequencerTxOptsPtr *bind.TransactOpts
var dataSigner signature.DataSignerFunc
if isSequencer {
Expand Down Expand Up @@ -650,7 +653,7 @@ func CreateTestL2WithConfig(

AddDefaultValNode(t, ctx, nodeConfig, true)

l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, l2Info, "", params.ArbitrumDevTestChainConfig(), nil)
l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, l2Info, "", params.ArbitrumDevTestChainConfig(), &nodeConfig.Caching)
currentNode, err := arbnode.CreateNode(ctx, stack, chainDb, arbDb, NewFetcherFromConfig(nodeConfig), blockchain, nil, nil, nil, nil, nil, feedErrChan)
Require(t, err)

Expand Down Expand Up @@ -755,7 +758,9 @@ func Create2ndNodeWithConfig(
txOpts := l1info.GetDefaultTransactOpts("Sequencer", ctx)
chainConfig := first.Execution.ArbInterface.BlockChain().Config()
initMessage := getInitMessage(ctx, t, l1client, first.DeployInfo)
l2blockchain, err := execution.WriteOrTestBlockChain(l2chainDb, nil, initReader, chainConfig, initMessage, arbnode.ConfigDefaultL2Test().TxLookupLimit, 0)

coreCacheConfig := execution.DefaultCacheConfigFor(l2stack, &nodeConfig.Caching)
l2blockchain, err := execution.WriteOrTestBlockChain(l2chainDb, coreCacheConfig, initReader, chainConfig, initMessage, arbnode.ConfigDefaultL2Test().TxLookupLimit, 0)
Require(t, err)

AddDefaultValNode(t, ctx, nodeConfig, true)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/debugapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestDebugAPI(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, nil, nil, nil, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, nil, nil, nil)
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)

Expand Down
Loading
Loading