Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into execution-service-3
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Sep 27, 2023
2 parents 4d04419 + 5534bc6 commit 5a4d987
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 106 deletions.
68 changes: 38 additions & 30 deletions execution/gethexec/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) {
execConfig := gethexec.ConfigDefaultTest()
execConfig.RPC.ClassicRedirect = ipcPath
execConfig.RPC.ClassicRedirectTimeout = time.Second
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, execConfig, nil, nil, nil, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, execConfig, 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 *gethexec.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 *gethexec.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 := gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, initMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)
var coreCacheConfig *core.CacheConfig
if cacheConfig != nil {
coreCacheConfig = gethexec.DefaultCacheConfigFor(stack, cacheConfig)
}
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)
Require(t, err)

return l2info, stack, chainDb, arbDb, blockchain
Expand Down Expand Up @@ -572,7 +576,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, execConfig, chainConfig, stackConfig, nil, nil)
l2info, currentNode, l2client, _, l1info, l1backend, l1client, l1stack = createTestNodeOnL1WithConfigImpl(t, ctx, isSequencer, nodeConfig, execConfig, chainConfig, stackConfig, nil)
return
}

Expand All @@ -584,7 +588,6 @@ func createTestNodeOnL1WithConfigImpl(
execConfig *gethexec.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 @@ -609,7 +612,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, &execConfig.Caching)
var sequencerTxOptsPtr *bind.TransactOpts
var dataSigner signature.DataSignerFunc
if isSequencer {
Expand Down Expand Up @@ -667,7 +670,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(), &execConfig.Caching)

Require(t, execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return execConfig }
Expand Down Expand Up @@ -787,7 +790,9 @@ func Create2ndNodeWithConfig(

chainConfig := firstExec.ArbInterface.BlockChain().Config()
initMessage := getInitMessage(ctx, t, l1client, first.DeployInfo)
l2blockchain, err := gethexec.WriteOrTestBlockChain(l2chainDb, nil, initReader, chainConfig, initMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)

coreCacheConfig := gethexec.DefaultCacheConfigFor(l2stack, &execConfig.Caching)
l2blockchain, err := gethexec.WriteOrTestBlockChain(l2chainDb, coreCacheConfig, initReader, chainConfig, initMessage, gethexec.ConfigDefaultTest().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, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, nil, nil, nil, nil)
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)

Expand Down
Loading

0 comments on commit 5a4d987

Please sign in to comment.