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

ethdb/pebble: cherry pick pebble backend from go-ethereum #385

Merged
merged 27 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
566ba97
core, ethdb, tests, trie: implement NewBatchWithSize API for batcher …
rjl493456442 Feb 15, 2022
71e2e71
core, ethdb, tests, trie: introduce database snapshot (#24486)
rjl493456442 Mar 10, 2022
5122ef2
ethdb: pebble backend (64bit platforms only) (#26517)
holiman Feb 9, 2023
94e4dc6
ethdb/pebble: fix nil callbacks (#26650)
karalabe Feb 9, 2023
3b36ec7
ethdb: add benchmark test suite (#26659)
rjl493456442 Feb 10, 2023
48cfe2e
ethdb/pebble: Fix `MemTableStopWritesThreshold` (#26692)
patrick-ogrady Feb 15, 2023
f837845
ethdb/pebble: fix range compaction (#26771)
rjl493456442 Feb 28, 2023
b5c08d3
ethdb/pebble: fix max memorytable size (#26776)
rjl493456442 Feb 28, 2023
3ab599c
core/rawdb, ethdb/pebble: disable pebble on openbsd (#26801)
karalabe Mar 3, 2023
b2814a5
ethdb/pebble: use atomic type (#27014)
s7v7nislands Mar 30, 2023
63f4a11
cmd/utils, node: switch to Pebble as the default db if none exists (#…
karalabe Apr 21, 2023
7307d95
ethdb/pebble: prevent shutdown-panic (#27238)
holiman May 19, 2023
08fc5cd
ethdb/pebble: fix NewBatchWithSize to set db (#27350)
holiman May 25, 2023
6bd92cf
ethdb/pebble: fsync for batch writes (#27522)
holiman Jun 21, 2023
0b1e03e
ethdb/pebble: use sync mode for pebble writes (#27615)
rjl493456442 Jun 27, 2023
45c2182
core/rawdb, ethdb/pebble: avoid fsync db in tests (#27836)
holiman Aug 23, 2023
199e252
ethdb, internal/ethapi: support exposing Pebble stats too, beside Lev…
karalabe Sep 28, 2023
0e1b5c6
ethdb/pebble: upgrade pebble to master (aa077af62593) (#28070)
rjl493456442 Sep 29, 2023
9bbbc94
ethdb/pebble: luv you linter
karalabe Sep 29, 2023
bbb0e80
ethdb/pebble: add level file metrics (#28271)
rjl493456442 Oct 11, 2023
2bb87b0
cmd, core, ethdb: enable Pebble on 32 bits and OpenBSD too (#28335)
karalabe Oct 13, 2023
344d081
ethdb/pebble: cap memory table size as maxMemTableSize-1 (#28444)
rjl493456442 Oct 31, 2023
62a75c0
ethdb/pebble: add `Errorf` function to panicLogger (#28491)
mcdee Nov 9, 2023
cf71b11
ethdb/pebble: don't double-close iterator inside pebbleIterator (#28566)
magicxyyz Nov 21, 2023
725aa97
ethdb/pebble: remove a dependency (#28627)
MariusVanDerWijden Dec 6, 2023
ae9ed21
cmd: add db.engine flags to Ronin commands
minh-bq Dec 13, 2023
dee6db8
entrypoint: add DB_ENGINE environment variable
minh-bq Dec 13, 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
6 changes: 6 additions & 0 deletions cmd/ronin/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
ArgsUsage: "<genesisPath>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.ForceOverrideChainConfigFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Expand Down Expand Up @@ -82,6 +83,7 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.CacheFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
Expand Down Expand Up @@ -119,6 +121,7 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.CacheFlag,
utils.SyncModeFlag,
},
Expand All @@ -137,6 +140,7 @@ be gzipped.`,
ArgsUsage: "<datafile>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.CacheFlag,
utils.SyncModeFlag,
},
Expand All @@ -153,6 +157,7 @@ It's deprecated, please use "geth db import" instead.
ArgsUsage: "<dumpfile>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.CacheFlag,
utils.SyncModeFlag,
},
Expand All @@ -169,6 +174,7 @@ It's deprecated, please use "geth db export" instead.
ArgsUsage: "[? <blockHash> | <blockNum>]",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.CacheFlag,
utils.IterativeOutputFlag,
utils.ExcludeCodeFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/ronin/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
}
// Retrieve the DAO config flag from the database
path := filepath.Join(datadir, "ronin", "chaindata")
db, err := rawdb.NewLevelDBDatabase(path, 0, 0, "", false)
db, err := rawdb.NewPebbleDBDatabase(path, 0, 0, "", false, true)
if err != nil {
t.Fatalf("test %d: failed to open test database: %v", test, err)
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/ronin/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Remove blockchain and state databases`,
ArgsUsage: "<prefix> <start>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
Expand All @@ -94,6 +95,7 @@ Remove blockchain and state databases`,
Usage: "Print leveldb statistics",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -108,6 +110,7 @@ Remove blockchain and state databases`,
Usage: "Compact leveldb database. WARNING: May take a very long time",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -128,6 +131,7 @@ corruption if it is aborted during execution'!`,
ArgsUsage: "<hex-encoded key>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -144,6 +148,7 @@ corruption if it is aborted during execution'!`,
ArgsUsage: "<hex-encoded key>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -161,6 +166,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -178,6 +184,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<hex-encoded storage trie root> <hex-encoded start (optional)> <int max elements (optional)>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -194,6 +201,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<type> <start (int)> <end (int)>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -210,6 +218,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<dumpfile> <start (optional)",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand All @@ -225,6 +234,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<type> <dumpfile>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.SyncModeFlag,
utils.MainnetFlag,
utils.RopstenFlag,
Expand Down
101 changes: 101 additions & 0 deletions cmd/ronin/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"
)

Expand Down Expand Up @@ -71,6 +73,7 @@ var customGenesisTests = []struct {
// Tests that initializing Geth with a custom genesis block and chain definitions
// work properly.
func TestCustomGenesis(t *testing.T) {
t.Parallel()
for i, tt := range customGenesisTests {
// Create a temporary data directory to use and inspect later
datadir := tmpdir(t)
Expand All @@ -92,3 +95,101 @@ func TestCustomGenesis(t *testing.T) {
geth.ExpectExit()
}
}

// TestCustomBackend that the backend selection and detection (leveldb vs pebble) works properly.
func TestCustomBackend(t *testing.T) {
t.Parallel()
// Test pebble, but only on 64-bit platforms
if strconv.IntSize != 64 {
t.Skip("Custom backends are only available on 64-bit platform")
}
genesis := `{
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000001338",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {}
}`
type backendTest struct {
initArgs []string
initExpect string
execArgs []string
execExpect string
}
testfunc := func(t *testing.T, tt backendTest) error {
// Create a temporary data directory to use and inspect later
datadir := t.TempDir()

// Initialize the data directory with the custom genesis block
json := filepath.Join(datadir, "genesis.json")
if err := os.WriteFile(json, []byte(genesis), 0600); err != nil {
return fmt.Errorf("failed to write genesis file: %v", err)
}
{ // Init
args := append(tt.initArgs, "--datadir", datadir, "init", json)
geth := runGeth(t, args...)
geth.ExpectRegexp(tt.initExpect)
geth.ExpectExit()
}
{ // Exec + query
args := append(tt.execArgs, "--networkid", "1337", "--syncmode=full", "--cache", "16",
"--datadir", datadir, "--maxpeers", "0", "--port", "0",
"--nodiscover", "--nat", "none", "--ipcdisable",
"--exec", "eth.getBlock(0).nonce", "console")
geth := runGeth(t, args...)
geth.ExpectRegexp(tt.execExpect)
geth.ExpectExit()
}
return nil
}
for i, tt := range []backendTest{
{ // When not specified, it should default to pebble
execArgs: []string{"--db.engine", "pebble"},
execExpect: "0x0000000000001338",
},
{ // Explicit leveldb
initArgs: []string{"--db.engine", "leveldb"},
execArgs: []string{"--db.engine", "leveldb"},
execExpect: "0x0000000000001338",
},
{ // Explicit leveldb first, then autodiscover
initArgs: []string{"--db.engine", "leveldb"},
execExpect: "0x0000000000001338",
},
{ // Explicit pebble
initArgs: []string{"--db.engine", "pebble"},
execArgs: []string{"--db.engine", "pebble"},
execExpect: "0x0000000000001338",
},
{ // Explicit pebble, then auto-discover
initArgs: []string{"--db.engine", "pebble"},
execExpect: "0x0000000000001338",
},
{ // Can't start pebble on top of leveldb
initArgs: []string{"--db.engine", "leveldb"},
execArgs: []string{"--db.engine", "pebble"},
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was pebble but found pre-existing leveldb database in specified data directory`,
},
{ // Can't start leveldb on top of pebble
initArgs: []string{"--db.engine", "pebble"},
execArgs: []string{"--db.engine", "leveldb"},
execExpect: `Fatal: Failed to register the Ethereum service: db.engine choice was leveldb but found pre-existing pebble database in specified data directory`,
},
{ // Reject invalid backend choice
initArgs: []string{"--db.engine", "mssql"},
initExpect: `Fatal: Invalid choice for db.engine 'mssql', allowed 'leveldb' or 'pebble'`,
// Since the init fails, this will return the (default) mainnet genesis
// block nonce
execExpect: `0x0000000000000042`,
},
} {
if err := testfunc(t, tt); err != nil {
t.Fatalf("test %d-leveldb: %v", i, err)
}
}
}
1 change: 1 addition & 0 deletions cmd/ronin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ var (
utils.BlsWalletPath,
utils.DisableRoninProtocol,
utils.AdditionalChainEventFlag,
utils.DBEngineFlag,
}

rpcFlags = []cli.Flag{
Expand Down
5 changes: 5 additions & 0 deletions cmd/ronin/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
Expand Down Expand Up @@ -91,6 +92,7 @@ the trie clean cache with default directory will be deleted.
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
Expand All @@ -112,6 +114,7 @@ In other words, this command does the snapshot to trie conversion.
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
Expand All @@ -135,6 +138,7 @@ It's also usable without snapshot enabled.
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
Expand All @@ -159,6 +163,7 @@ It's also usable without snapshot enabled.
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.DBEngineFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/ronin/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.StoreInternalTransactions,
utils.DisableRoninProtocol,
utils.AdditionalChainEventFlag,
utils.DBEngineFlag,
},
},
{
Expand Down
17 changes: 15 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ var (
Name: "datadir.minfreedisk",
Usage: "Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled)",
}
DBEngineFlag = cli.StringFlag{
Name: "db.engine",
Usage: "Backing database implementation to use ('leveldb' or 'pebble')",
Value: node.DefaultConfig.DBEngine,
}
KeyStoreDirFlag = DirectoryFlag{
Name: "keystore",
Usage: "Directory for the keystore (default = inside the datadir)",
Expand Down Expand Up @@ -915,12 +920,12 @@ var (
}

MockValidatorsFlag = cli.StringFlag{
Name: "mock.validators",
Name: "mock.validators",
Usage: "List of mock validators",
}

MockBlsPublicKeysFlag = cli.StringFlag{
Name: "mock.blspublickeys",
Name: "mock.blspublickeys",
Usage: "List of mock bls public keys which are reflect 1:1 with mock.validators",
}
)
Expand Down Expand Up @@ -1381,6 +1386,14 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(EnableSigningMethodsFlag.Name) {
cfg.EnableSigningMethods = ctx.GlobalBool(EnableSigningMethodsFlag.Name)
}
if ctx.GlobalIsSet(DBEngineFlag.Name) {
dbEngine := ctx.GlobalString(DBEngineFlag.Name)
if dbEngine != "leveldb" && dbEngine != "pebble" {
Fatalf("Invalid choice for db.engine '%s', allowed 'leveldb' or 'pebble'", dbEngine)
}
log.Info(fmt.Sprintf("Using %s as db engine", dbEngine))
cfg.DBEngine = dbEngine
}
}

func setFastFinality(ctx *cli.Context, cfg *node.Config) {
Expand Down
Loading