Skip to content

Commit c99cdb0

Browse files
Merge branch 'master' into pmikolajczyk/nit-3121-uncompressed-batch-size-limit
2 parents 99f642a + f71771a commit c99cdb0

File tree

10 files changed

+65
-103
lines changed

10 files changed

+65
-103
lines changed

arbitrum/apibackend.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ func StateAndHeaderFromHeader(ctx context.Context, chainDb ethdb.Database, bc *c
545545
if archiveClientsManager != nil && header.Number.Uint64() <= archiveClientsManager.lastAvailableBlock() {
546546
return nil, header, &types.ErrUseArchiveFallback{BlockNum: header.Number.Uint64()}
547547
}
548+
549+
// use upstream path for PathScheme, as:
550+
// - intermediate state recreation and trie node referencing doesn't apply to pathdb
551+
// - HistoricState is supported only by pathdb
552+
if bc.TrieDB().Scheme() == rawdb.PathScheme {
553+
statedb, err := bc.StateAt(header.Root)
554+
if err != nil {
555+
statedb, err = bc.HistoricState(header.Root)
556+
if err != nil {
557+
return nil, nil, err
558+
}
559+
}
560+
return statedb, header, nil
561+
}
562+
548563
stateFor := func(db state.Database, snapshots *snapshot.Tree) func(header *types.Header) (*state.StateDB, StateReleaseFunc, error) {
549564
return func(header *types.Header) (*state.StateDB, StateReleaseFunc, error) {
550565
if header.Root != (common.Hash{}) {

arbitrum/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Backend struct {
4141
filterSystem *filters.FilterSystem
4242
}
4343

44-
func NewBackend(stack *node.Node, config *Config, chainDb ethdb.Database, publisher ArbInterface, filterConfig filters.Config) (*Backend, *filters.FilterSystem, error) {
44+
func NewBackend(stack *node.Node, config *Config, chainDb ethdb.Database, publisher ArbInterface, filterConfig filters.Config, stateScheme string) (*Backend, *filters.FilterSystem, error) {
4545
backend := &Backend{
4646
arb: publisher,
4747
stack: stack,
@@ -55,7 +55,7 @@ func NewBackend(stack *node.Node, config *Config, chainDb ethdb.Database, publis
5555
chanNewBlock: make(chan struct{}, 1),
5656
}
5757

58-
scheme, err := rawdb.ParseStateScheme(config.StateScheme, chainDb)
58+
scheme, err := rawdb.ParseStateScheme(stateScheme, chainDb)
5959
if err != nil {
6060
return nil, nil, err
6161
}

arbitrum/config.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"time"
77

8-
"github.com/ethereum/go-ethereum/core/rawdb"
98
"github.com/ethereum/go-ethereum/eth/ethconfig"
109
flag "github.com/spf13/pflag"
1110
)
@@ -27,11 +26,6 @@ type Config struct {
2726
LogNoHistory bool `koanf:"log-no-history"` // No log search index is maintained.
2827
LogExportCheckpoints string `koanf:"log-export-checkpoints"` // export log index checkpoints to file
2928

30-
// State scheme represents the scheme used to store states and trie
31-
// nodes on top. It can be 'hash', 'path', or none which means use the scheme
32-
// consistent with persistent state.
33-
StateScheme string `koanf:"state-scheme"`
34-
3529
// Parameters for the filter system
3630
FilterLogCacheSize int `koanf:"filter-log-cache-size"`
3731
FilterTimeout time.Duration `koanf:"filter-timeout"`
@@ -82,7 +76,6 @@ func ConfigAddOptions(prefix string, f *flag.FlagSet) {
8276
f.Uint64(prefix+".log-history", DefaultConfig.LogHistory, "maximum number of blocks from head where a log search index is maintained")
8377
f.Bool(prefix+".log-no-history", DefaultConfig.LogNoHistory, "no log search index is maintained")
8478
f.String(prefix+".log-export-checkpoints", DefaultConfig.LogExportCheckpoints, "export log index checkpoints to file")
85-
f.String(prefix+".state-scheme", DefaultConfig.StateScheme, "state scheme used to store states and trie nodes on top")
8679
f.Uint64(prefix+".feehistory-max-block-count", DefaultConfig.FeeHistoryMaxBlockCount, "max number of blocks a fee history request may cover")
8780
f.String(prefix+".classic-redirect", DefaultConfig.ClassicRedirect, "url to redirect classic requests, use \"error:[CODE:]MESSAGE\" to return specified error instead of redirecting")
8881
f.Duration(prefix+".classic-redirect-timeout", DefaultConfig.ClassicRedirectTimeout, "timeout for forwarded classic requests, where 0 = no timeout")
@@ -120,5 +113,4 @@ var DefaultConfig = Config{
120113
TimeoutQueueBound: 512,
121114
},
122115
BlockRedirectsList: "default",
123-
StateScheme: rawdb.HashScheme,
124116
}

core/blockchain.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ type BlockChainConfig struct {
172172
TrieNoAsyncFlush bool // Whether the asynchronous buffer flushing is disallowed
173173
TrieJournalDirectory string // Directory path to the journal used for persisting trie data across node restarts
174174

175-
Preimages bool // Whether to store preimage of trie key to the disk
176-
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
177-
ArchiveMode bool // Whether to enable the archive mode
175+
Preimages bool // Whether to store preimage of trie key to the disk
176+
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
177+
ArchiveMode bool // Whether to enable the archive mode
178+
MaxDiffLayers int // MaxDiffLayers is the maximum diff layers allowed in the layer tree. (only for path scheme)
178179

179180
// Number of blocks from the chain head for which state histories are retained.
180181
// If set to 0, all state histories across the entire chain will be retained;
@@ -228,6 +229,7 @@ func DefaultConfig() *BlockChainConfig {
228229
TrieTimeLimitRandomOffset: 0,
229230
MaxNumberOfBlocksToSkipStateSaving: 0,
230231
MaxAmountOfGasToSkipStateSaving: 0,
232+
MaxDiffLayers: pathdb.DefaultMaxDiffLayers,
231233

232234
TrieCleanLimit: 256,
233235
TrieDirtyLimit: 256,
@@ -283,6 +285,7 @@ func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config {
283285
TrieCleanSize: cfg.TrieCleanLimit * 1024 * 1024,
284286
StateCleanSize: cfg.SnapshotLimit * 1024 * 1024,
285287
JournalDirectory: cfg.TrieJournalDirectory,
288+
MaxDiffLayers: cfg.MaxDiffLayers,
286289

287290
// TODO(rjl493456442): The write buffer represents the memory limit used
288291
// for flushing both trie data and state data to disk. The config name

eth/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
235235
SnapshotLimit: config.SnapshotCache,
236236
Preimages: config.Preimages,
237237
StateHistory: config.StateHistory,
238+
MaxDiffLayers: config.MaxDiffLayers,
238239
StateScheme: scheme,
239240
ChainHistoryMode: config.HistoryMode,
240241
TxIndexer: &core.TxIndexerConfig{

eth/ethconfig/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/ethereum/go-ethereum/log"
3636
"github.com/ethereum/go-ethereum/miner"
3737
"github.com/ethereum/go-ethereum/params"
38+
"github.com/ethereum/go-ethereum/triedb/pathdb"
3839
)
3940

4041
// FullNodeGPO contains default gasprice oracle settings for full node.
@@ -56,6 +57,7 @@ var Defaults = Config{
5657
TransactionHistory: 2350000,
5758
LogHistory: 2350000,
5859
StateHistory: params.FullImmutabilityThreshold,
60+
MaxDiffLayers: pathdb.DefaultMaxDiffLayers,
5961
DatabaseCache: 512,
6062
TrieCleanCache: 154,
6163
TrieDirtyCache: 256,
@@ -105,6 +107,7 @@ type Config struct {
105107
LogNoHistory bool `toml:",omitempty"` // No log search index is maintained.
106108
LogExportCheckpoints string // export log index checkpoints to file
107109
StateHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
110+
MaxDiffLayers int `toml:",omitempty"` // Maximum diff layers allowed in the layer tree.
108111

109112
// State scheme represents the scheme used to store ethereum states and trie
110113
// nodes on top. It can be 'hash', 'path', or none which means use the scheme

triedb/pathdb/config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ const (
4343
// Do not increase the buffer size arbitrarily, otherwise the system
4444
// pause time will increase when the database writes happen.
4545
defaultBufferSize = 64 * 1024 * 1024
46-
)
4746

48-
var (
49-
// maxDiffLayers is the maximum diff layers allowed in the layer tree.
50-
maxDiffLayers = 128
47+
// Maximum diff layers allowed in the layer tree.
48+
DefaultMaxDiffLayers = 128
5149
)
5250

5351
// Defaults contains default settings for Ethereum mainnet.
@@ -57,18 +55,21 @@ var Defaults = &Config{
5755
TrieCleanSize: defaultTrieCleanSize,
5856
StateCleanSize: defaultStateCleanSize,
5957
WriteBufferSize: defaultBufferSize,
58+
MaxDiffLayers: DefaultMaxDiffLayers,
6059
}
6160

6261
// ReadOnly is the config in order to open database in read only mode.
6362
var ReadOnly = &Config{
6463
ReadOnly: true,
6564
TrieCleanSize: defaultTrieCleanSize,
6665
StateCleanSize: defaultStateCleanSize,
66+
MaxDiffLayers: DefaultMaxDiffLayers,
6767
}
6868

6969
// Config contains the settings for database.
7070
type Config struct {
7171
StateHistory uint64 // Number of recent blocks to maintain state history for, 0: full chain
72+
MaxDiffLayers int // Maximum diff layers allowed in the layer tree.
7273
EnableStateIndexing bool // Whether to enable state history indexing for external state access
7374
TrieCleanSize int // Maximum memory allowance (in bytes) for caching clean trie data
7475
StateCleanSize int // Maximum memory allowance (in bytes) for caching clean state data
@@ -90,6 +91,11 @@ func (c *Config) sanitize() *Config {
9091
log.Warn("Sanitizing invalid node buffer size", "provided", common.StorageSize(conf.WriteBufferSize), "updated", common.StorageSize(maxBufferSize))
9192
conf.WriteBufferSize = maxBufferSize
9293
}
94+
95+
if conf.MaxDiffLayers <= 0 {
96+
log.Warn("Sanitizing invalid max diff layers", "provided", conf.MaxDiffLayers, "updated", DefaultMaxDiffLayers)
97+
conf.MaxDiffLayers = DefaultMaxDiffLayers
98+
}
9399
return &conf
94100
}
95101

triedb/pathdb/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (db *Database) Update(root common.Hash, parentRoot common.Hash, block uint6
342342
// - head-1 layer is paired with HEAD-1 state
343343
// - head-127 layer(bottom-most diff layer) is paired with HEAD-127 state
344344
// - head-128 layer(disk layer) is paired with HEAD-128 state
345-
return db.tree.cap(root, maxDiffLayers)
345+
return db.tree.cap(root, db.config.MaxDiffLayers)
346346
}
347347

348348
// Commit traverses downwards the layer tree from a specified layer with the

triedb/pathdb/database_test.go

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ type tester struct {
139139

140140
// testerConfig holds configuration parameters for running a test scenario.
141141
type testerConfig struct {
142-
stateHistory uint64 // Number of historical states to retain
143-
layers int // Number of state transitions to generate for
144-
enableIndex bool // Enable state history indexing or not
145-
journalDir string // Directory path for persisting journal files
146-
isVerkle bool // Enables Verkle trie mode if true
142+
stateHistory uint64 // Number of historical states to retain
143+
maxDiffLayers int // Maximum number of diff layers to maintain
144+
layers int // Number of state transitions to generate for
145+
enableIndex bool // Enable state history indexing or not
146+
journalDir string // Directory path for persisting journal files
147+
isVerkle bool // Enables Verkle trie mode if true
147148

148149
writeBuffer *int // Optional, the size of memory allocated for write buffer
149150
trieCache *int // Optional, the size of memory allocated for trie cache
@@ -177,6 +178,7 @@ func newTester(t *testing.T, config *testerConfig) *tester {
177178
db = New(disk, &Config{
178179
StateHistory: config.stateHistory,
179180
EnableStateIndexing: config.enableIndex,
181+
MaxDiffLayers: config.maxDiffLayers,
180182
TrieCleanSize: config.trieCacheSize(),
181183
StateCleanSize: config.stateCacheSize(),
182184
WriteBufferSize: config.writeBufferSize(),
@@ -579,13 +581,7 @@ func (t *tester) bottomIndex() int {
579581
}
580582

581583
func TestDatabaseRollback(t *testing.T) {
582-
// Redefine the diff layer depth allowance for faster testing.
583-
maxDiffLayers = 4
584-
defer func() {
585-
maxDiffLayers = 128
586-
}()
587-
588-
tester := newTester(t, &testerConfig{layers: 32})
584+
tester := newTester(t, &testerConfig{layers: 32, maxDiffLayers: 4})
589585
defer tester.release()
590586

591587
if err := tester.verifyHistory(); err != nil {
@@ -612,14 +608,8 @@ func TestDatabaseRollback(t *testing.T) {
612608
}
613609

614610
func TestDatabaseRecoverable(t *testing.T) {
615-
// Redefine the diff layer depth allowance for faster testing.
616-
maxDiffLayers = 4
617-
defer func() {
618-
maxDiffLayers = 128
619-
}()
620-
621611
var (
622-
tester = newTester(t, &testerConfig{layers: 12})
612+
tester = newTester(t, &testerConfig{layers: 12, maxDiffLayers: 4})
623613
index = tester.bottomIndex()
624614
)
625615
defer tester.release()
@@ -657,13 +647,7 @@ func TestDatabaseRecoverable(t *testing.T) {
657647
}
658648

659649
func TestExecuteRollback(t *testing.T) {
660-
// Redefine the diff layer depth allowance for faster testing.
661-
maxDiffLayers = 4
662-
defer func() {
663-
maxDiffLayers = 128
664-
}()
665-
666-
tester := newTester(t, &testerConfig{layers: 32})
650+
tester := newTester(t, &testerConfig{layers: 32, maxDiffLayers: 4})
667651
defer tester.release()
668652

669653
// Revert database from top to bottom
@@ -710,13 +694,7 @@ func TestExecuteRollback(t *testing.T) {
710694
}
711695

712696
func TestDisable(t *testing.T) {
713-
// Redefine the diff layer depth allowance for faster testing.
714-
maxDiffLayers = 4
715-
defer func() {
716-
maxDiffLayers = 128
717-
}()
718-
719-
tester := newTester(t, &testerConfig{layers: 32})
697+
tester := newTester(t, &testerConfig{layers: 32, maxDiffLayers: 4})
720698
defer tester.release()
721699

722700
stored := crypto.Keccak256Hash(rawdb.ReadAccountTrieNode(tester.db.diskdb, nil))
@@ -748,13 +726,7 @@ func TestDisable(t *testing.T) {
748726
}
749727

750728
func TestCommit(t *testing.T) {
751-
// Redefine the diff layer depth allowance for faster testing.
752-
maxDiffLayers = 4
753-
defer func() {
754-
maxDiffLayers = 128
755-
}()
756-
757-
tester := newTester(t, &testerConfig{layers: 12})
729+
tester := newTester(t, &testerConfig{layers: 12, maxDiffLayers: 4})
758730
defer tester.release()
759731

760732
if err := tester.db.Commit(tester.lastHash(), false); err != nil {
@@ -783,13 +755,7 @@ func TestJournal(t *testing.T) {
783755
}
784756

785757
func testJournal(t *testing.T, journalDir string) {
786-
// Redefine the diff layer depth allowance for faster testing.
787-
maxDiffLayers = 4
788-
defer func() {
789-
maxDiffLayers = 128
790-
}()
791-
792-
tester := newTester(t, &testerConfig{layers: 12, journalDir: journalDir})
758+
tester := newTester(t, &testerConfig{layers: 12, maxDiffLayers: 4, journalDir: journalDir})
793759
defer tester.release()
794760

795761
if err := tester.db.Journal(tester.lastHash()); err != nil {
@@ -830,13 +796,7 @@ func TestCorruptedJournal(t *testing.T) {
830796
}
831797

832798
func testCorruptedJournal(t *testing.T, journalDir string, modifyFn func(database ethdb.Database)) {
833-
// Redefine the diff layer depth allowance for faster testing.
834-
maxDiffLayers = 4
835-
defer func() {
836-
maxDiffLayers = 128
837-
}()
838-
839-
tester := newTester(t, &testerConfig{layers: 12, journalDir: journalDir})
799+
tester := newTester(t, &testerConfig{layers: 12, maxDiffLayers: 4, journalDir: journalDir})
840800
defer tester.release()
841801

842802
if err := tester.db.Journal(tester.lastHash()); err != nil {
@@ -875,13 +835,7 @@ func testCorruptedJournal(t *testing.T, journalDir string, modifyFn func(databas
875835
// truncating the tail histories. This ensures that the ID of the persistent state
876836
// always falls within the range of [oldest-history-id, latest-history-id].
877837
func TestTailTruncateHistory(t *testing.T) {
878-
// Redefine the diff layer depth allowance for faster testing.
879-
maxDiffLayers = 4
880-
defer func() {
881-
maxDiffLayers = 128
882-
}()
883-
884-
tester := newTester(t, &testerConfig{layers: 12, stateHistory: 10})
838+
tester := newTester(t, &testerConfig{layers: 12, maxDiffLayers: 4, stateHistory: 10})
885839
defer tester.release()
886840

887841
tester.db.Close()
@@ -919,17 +873,13 @@ func copyStorages(set map[common.Hash]map[common.Hash][]byte) map[common.Hash]ma
919873
}
920874

921875
func TestDatabaseIndexRecovery(t *testing.T) {
922-
maxDiffLayers = 4
923-
defer func() {
924-
maxDiffLayers = 128
925-
}()
926-
927876
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelDebug, true)))
928877
writeBuffer := 512 * 1024
929878
config := &testerConfig{
930-
layers: 64,
931-
enableIndex: true,
932-
writeBuffer: &writeBuffer,
879+
layers: 64,
880+
maxDiffLayers: 4,
881+
enableIndex: true,
882+
writeBuffer: &writeBuffer,
933883
}
934884
env := newTester(t, config)
935885
defer env.release()

0 commit comments

Comments
 (0)