Skip to content

Commit 503f1f7

Browse files
rjl493456442holimankaralabe
authored
all: activate pbss as experimental feature (#26274)
* all: activate pbss * core/rawdb: fix compilation error * cma, core, eth, les, trie: address comments * cmd, core, eth, trie: polish code * core, cmd, eth: address comments * cmd, core, eth, les, light, tests: address comment * cmd/utils: shorten log message * trie/triedb/pathdb: limit node buffer size to 1gb * cmd/utils: fix opening non-existing db * cmd/utils: rename flag name * cmd, core: group chain history flags and fix tests * core, eth, trie: fix memory leak in snapshot generation * cmd, eth, internal: deprecate flags * all: enable state tests for pathdb, fixes * cmd, core: polish code * trie/triedb/pathdb: limit the node buffer size to 256mb --------- Co-authored-by: Martin Holst Swende <[email protected]> Co-authored-by: Péter Szilágyi <[email protected]>
1 parent 5e89ff4 commit 503f1f7

File tree

96 files changed

+2380
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2380
-1029
lines changed

cmd/evm/blockrunner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"os"
2424

25+
"github.com/ethereum/go-ethereum/core/rawdb"
2526
"github.com/ethereum/go-ethereum/core/vm"
2627
"github.com/ethereum/go-ethereum/eth/tracers/logger"
2728
"github.com/ethereum/go-ethereum/log"
@@ -64,7 +65,7 @@ func blockTestCmd(ctx *cli.Context) error {
6465
return err
6566
}
6667
for i, test := range tests {
67-
if err := test.Run(false, tracer); err != nil {
68+
if err := test.Run(false, rawdb.HashScheme, tracer); err != nil {
6869
return fmt.Errorf("test %v: %w", i, err)
6970
}
7071
}

cmd/evm/runner.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/ethereum/go-ethereum/log"
4343
"github.com/ethereum/go-ethereum/params"
4444
"github.com/ethereum/go-ethereum/trie"
45+
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
4546
"github.com/urfave/cli/v2"
4647
)
4748

@@ -142,12 +143,23 @@ func runCmd(ctx *cli.Context) error {
142143
gen := readGenesis(ctx.String(GenesisFlag.Name))
143144
genesisConfig = gen
144145
db := rawdb.NewMemoryDatabase()
145-
genesis := gen.MustCommit(db)
146-
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: preimages})
146+
triedb := trie.NewDatabase(db, &trie.Config{
147+
Preimages: preimages,
148+
HashDB: hashdb.Defaults,
149+
})
150+
defer triedb.Close()
151+
genesis := gen.MustCommit(db, triedb)
152+
sdb := state.NewDatabaseWithNodeDB(db, triedb)
147153
statedb, _ = state.New(genesis.Root(), sdb, nil)
148154
chainConfig = gen.Config
149155
} else {
150-
sdb := state.NewDatabaseWithConfig(rawdb.NewMemoryDatabase(), &trie.Config{Preimages: preimages})
156+
db := rawdb.NewMemoryDatabase()
157+
triedb := trie.NewDatabase(db, &trie.Config{
158+
Preimages: preimages,
159+
HashDB: hashdb.Defaults,
160+
})
161+
defer triedb.Close()
162+
sdb := state.NewDatabaseWithNodeDB(db, triedb)
151163
statedb, _ = state.New(types.EmptyRootHash, sdb, nil)
152164
genesisConfig = new(core.Genesis)
153165
}

cmd/evm/staterunner.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"os"
2424

2525
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/core/rawdb"
2627
"github.com/ethereum/go-ethereum/core/state"
28+
"github.com/ethereum/go-ethereum/core/state/snapshot"
2729
"github.com/ethereum/go-ethereum/core/vm"
2830
"github.com/ethereum/go-ethereum/eth/tracers/logger"
2931
"github.com/ethereum/go-ethereum/log"
@@ -104,25 +106,22 @@ func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error {
104106
for _, st := range test.Subtests() {
105107
// Run the test and aggregate the result
106108
result := &StatetestResult{Name: key, Fork: st.Fork, Pass: true}
107-
_, s, err := test.Run(st, cfg, false)
108-
// print state root for evmlab tracing
109-
if s != nil {
110-
root := s.IntermediateRoot(false)
111-
result.Root = &root
112-
if jsonOut {
113-
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root)
109+
test.Run(st, cfg, false, rawdb.HashScheme, func(err error, snaps *snapshot.Tree, state *state.StateDB) {
110+
if err != nil {
111+
// Test failed, mark as so and dump any state to aid debugging
112+
result.Pass, result.Error = false, err.Error()
113+
if dump {
114+
dump := state.RawDump(nil)
115+
result.State = &dump
116+
}
117+
} else {
118+
root := state.IntermediateRoot(false)
119+
result.Root = &root
120+
if jsonOut {
121+
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root)
122+
}
114123
}
115-
}
116-
if err != nil {
117-
// Test failed, mark as so and dump any state to aid debugging
118-
result.Pass, result.Error = false, err.Error()
119-
if dump && s != nil {
120-
s, _ = state.New(*result.Root, s.Database(), nil)
121-
dump := s.RawDump(nil)
122-
result.State = &dump
123-
}
124-
}
125-
124+
})
126125
results = append(results, *result)
127126
}
128127
}

cmd/geth/chaincmd.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"github.com/ethereum/go-ethereum/log"
4040
"github.com/ethereum/go-ethereum/metrics"
4141
"github.com/ethereum/go-ethereum/node"
42-
"github.com/ethereum/go-ethereum/trie"
4342
"github.com/urfave/cli/v2"
4443
)
4544

@@ -49,7 +48,10 @@ var (
4948
Name: "init",
5049
Usage: "Bootstrap and initialize a new genesis block",
5150
ArgsUsage: "<genesisPath>",
52-
Flags: flags.Merge([]cli.Flag{utils.CachePreimagesFlag}, utils.DatabasePathFlags),
51+
Flags: flags.Merge([]cli.Flag{
52+
utils.CachePreimagesFlag,
53+
utils.StateSchemeFlag,
54+
}, utils.DatabasePathFlags),
5355
Description: `
5456
The init command initializes a new genesis block and definition for the network.
5557
This is a destructive action and changes the network in which you will be
@@ -94,6 +96,9 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
9496
utils.MetricsInfluxDBBucketFlag,
9597
utils.MetricsInfluxDBOrganizationFlag,
9698
utils.TxLookupLimitFlag,
99+
utils.TransactionHistoryFlag,
100+
utils.StateSchemeFlag,
101+
utils.StateHistoryFlag,
97102
}, utils.DatabasePathFlags),
98103
Description: `
99104
The import command imports blocks from an RLP-encoded form. The form can be one file
@@ -110,6 +115,7 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
110115
Flags: flags.Merge([]cli.Flag{
111116
utils.CacheFlag,
112117
utils.SyncModeFlag,
118+
utils.StateSchemeFlag,
113119
}, utils.DatabasePathFlags),
114120
Description: `
115121
Requires a first argument of the file to write to.
@@ -159,6 +165,7 @@ It's deprecated, please use "geth db export" instead.
159165
utils.IncludeIncompletesFlag,
160166
utils.StartKeyFlag,
161167
utils.DumpLimitFlag,
168+
utils.StateSchemeFlag,
162169
}, utils.DatabasePathFlags),
163170
Description: `
164171
This command dumps out the state for a given block (or latest, if none provided).
@@ -195,14 +202,15 @@ func initGenesis(ctx *cli.Context) error {
195202
if err != nil {
196203
utils.Fatalf("Failed to open database: %v", err)
197204
}
198-
triedb := trie.NewDatabaseWithConfig(chaindb, &trie.Config{
199-
Preimages: ctx.Bool(utils.CachePreimagesFlag.Name),
200-
})
205+
defer chaindb.Close()
206+
207+
triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false)
208+
defer triedb.Close()
209+
201210
_, hash, err := core.SetupGenesisBlock(chaindb, triedb, genesis)
202211
if err != nil {
203212
utils.Fatalf("Failed to write genesis block: %v", err)
204213
}
205-
chaindb.Close()
206214
log.Info("Successfully wrote genesis state", "database", name, "hash", hash)
207215
}
208216
return nil
@@ -241,7 +249,7 @@ func dumpGenesis(ctx *cli.Context) error {
241249
if ctx.IsSet(utils.DataDirFlag.Name) {
242250
utils.Fatalf("no existing datadir at %s", stack.Config().DataDir)
243251
}
244-
utils.Fatalf("no network preset provided. no exisiting genesis in the default datadir")
252+
utils.Fatalf("no network preset provided, no existing genesis in the default datadir")
245253
return nil
246254
}
247255

@@ -465,10 +473,10 @@ func dump(ctx *cli.Context) error {
465473
if err != nil {
466474
return err
467475
}
468-
config := &trie.Config{
469-
Preimages: true, // always enable preimage lookup
470-
}
471-
state, err := state.New(root, state.NewDatabaseWithConfig(db, config), nil)
476+
triedb := utils.MakeTrieDatabase(ctx, db, true, false) // always enable preimage lookup
477+
defer triedb.Close()
478+
479+
state, err := state.New(root, state.NewDatabaseWithNodeDB(db, triedb), nil)
472480
if err != nil {
473481
return err
474482
}

cmd/geth/dbcmd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
151151
ArgsUsage: "<hex-encoded state root> <hex-encoded account hash> <hex-encoded storage trie root> <hex-encoded start (optional)> <int max elements (optional)>",
152152
Flags: flags.Merge([]cli.Flag{
153153
utils.SyncModeFlag,
154+
utils.StateSchemeFlag,
154155
}, utils.NetworkFlags, utils.DatabasePathFlags),
155156
Description: "This command looks up the specified database key from the database.",
156157
}
@@ -482,6 +483,9 @@ func dbDumpTrie(ctx *cli.Context) error {
482483
db := utils.MakeChainDatabase(ctx, stack, true)
483484
defer db.Close()
484485

486+
triedb := utils.MakeTrieDatabase(ctx, db, false, true)
487+
defer triedb.Close()
488+
485489
var (
486490
state []byte
487491
storage []byte
@@ -515,7 +519,7 @@ func dbDumpTrie(ctx *cli.Context) error {
515519
}
516520
}
517521
id := trie.StorageTrieID(common.BytesToHash(state), common.BytesToHash(account), common.BytesToHash(storage))
518-
theTrie, err := trie.New(id, trie.NewDatabase(db))
522+
theTrie, err := trie.New(id, triedb)
519523
if err != nil {
520524
return err
521525
}

cmd/geth/genesis_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func TestCustomBackend(t *testing.T) {
176176
{ // Can't start pebble on top of leveldb
177177
initArgs: []string{"--db.engine", "leveldb"},
178178
execArgs: []string{"--db.engine", "pebble"},
179-
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was pebble but found pre-existing leveldb database in specified data directory`,
179+
execExpect: `Fatal: Could not open database: db.engine choice was pebble but found pre-existing leveldb database in specified data directory`,
180180
},
181181
{ // Can't start leveldb on top of pebble
182182
initArgs: []string{"--db.engine", "pebble"},
183183
execArgs: []string{"--db.engine", "leveldb"},
184-
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was leveldb but found pre-existing pebble database in specified data directory`,
184+
execExpect: `Fatal: Could not open database: db.engine choice was leveldb but found pre-existing pebble database in specified data directory`,
185185
},
186186
{ // Reject invalid backend choice
187187
initArgs: []string{"--db.engine", "mssql"},

cmd/geth/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ var (
8888
utils.GCModeFlag,
8989
utils.SnapshotFlag,
9090
utils.TxLookupLimitFlag,
91+
utils.TransactionHistoryFlag,
92+
utils.StateSchemeFlag,
93+
utils.StateHistoryFlag,
9194
utils.LightServeFlag,
9295
utils.LightIngressFlag,
9396
utils.LightEgressFlag,

0 commit comments

Comments
 (0)