From e4f7a372d6340dfc751d4faab30e7dabf7b5c249 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Fri, 20 Jun 2025 14:31:49 +0800 Subject: [PATCH] core: fix broken test --- core/blockchain.go | 16 ++++++++++++---- core/blockchain_snapshot_test.go | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 25b37b5cce..2b48d91794 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -152,9 +152,10 @@ const ( // BlockChainConfig contains the configuration of the BlockChain object. type BlockChainConfig struct { // Trie database related options - TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory - TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk - TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk + TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory + TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk + TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk + TrieNoAsyncFlush bool // Whether the asynchronous buffer flushing is disallowed Preimages bool // Whether to store preimage of trie key to the disk StateHistory uint64 // Number of blocks from head whose state histories are reserved. @@ -200,7 +201,7 @@ func DefaultConfig() *BlockChainConfig { } } -// WithArchive enabled/disables archive mode on the config. +// WithArchive enables/disables archive mode on the config. func (cfg BlockChainConfig) WithArchive(on bool) *BlockChainConfig { cfg.ArchiveMode = on return &cfg @@ -212,6 +213,12 @@ func (cfg BlockChainConfig) WithStateScheme(scheme string) *BlockChainConfig { return &cfg } +// WithNoAsyncFlush enables/disables asynchronous buffer flushing mode on the config. +func (cfg BlockChainConfig) WithNoAsyncFlush(on bool) *BlockChainConfig { + cfg.TrieNoAsyncFlush = on + return &cfg +} + // triedbConfig derives the configures for trie database. func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config { config := &triedb.Config{ @@ -233,6 +240,7 @@ func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config { // for flushing both trie data and state data to disk. The config name // should be updated to eliminate the confusion. WriteBufferSize: cfg.TrieDirtyLimit * 1024 * 1024, + NoAsyncFlush: cfg.TrieNoAsyncFlush, } } return config diff --git a/core/blockchain_snapshot_test.go b/core/blockchain_snapshot_test.go index 5550907b0d..ae9398b97d 100644 --- a/core/blockchain_snapshot_test.go +++ b/core/blockchain_snapshot_test.go @@ -81,7 +81,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo } engine = ethash.NewFullFaker() ) - chain, err := NewBlockChain(db, gspec, engine, DefaultConfig().WithStateScheme(basic.scheme)) + chain, err := NewBlockChain(db, gspec, engine, DefaultConfig().WithStateScheme(basic.scheme).WithNoAsyncFlush(true)) if err != nil { t.Fatalf("Failed to create chain: %v", err) } @@ -572,7 +572,7 @@ func TestHighCommitCrashWithNewSnapshot(t *testing.T) { // // Expected head header : C8 // Expected head fast block: C8 - // Expected head block : G (Hash mode), C6 (Hash mode) + // Expected head block : G (Hash mode), C6 (Path mode) // Expected snapshot disk : C4 (Hash mode) for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} { expHead := uint64(0)