From 7718987df479e931a60442114e64fa1573ec4874 Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Fri, 22 Nov 2024 10:45:32 +0100 Subject: [PATCH 1/8] Lower memory consumption for testnet and integration tests. --- cmd/sonicd/app/launcher.go | 4 ++++ cmd/sonicd/app/run_test.go | 2 +- cmd/sonictool/app/export_genesis.go | 2 +- cmd/sonictool/app/genesis.go | 6 +++--- cmd/sonictool/chain/export_events.go | 2 +- cmd/sonictool/db/dbutils.go | 9 +++++++-- cmd/sonictool/genesis/import.go | 4 ++-- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/sonicd/app/launcher.go b/cmd/sonicd/app/launcher.go index 6bf9120dc..fe7582fff 100644 --- a/cmd/sonicd/app/launcher.go +++ b/cmd/sonicd/app/launcher.go @@ -222,6 +222,10 @@ func lachesisMain(ctx *cli.Context) error { } metrics.SetDataDir(cfg.Node.DataDir) // report disk space usage into metrics + if ctx.GlobalIsSet(config.FakeNetFlag.Name) { + cfg.OperaStore.EVM.StateDb.LiveCache = 1 + cfg.OperaStore.EVM.StateDb.ArchiveCache = 1 + } node, _, nodeClose, err := config.MakeNode(ctx, cfg) if err != nil { diff --git a/cmd/sonicd/app/run_test.go b/cmd/sonicd/app/run_test.go index 910f88d9f..41c8105b3 100644 --- a/cmd/sonicd/app/run_test.go +++ b/cmd/sonicd/app/run_test.go @@ -26,7 +26,7 @@ func tmpdir(t *testing.T) string { func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) { genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - if err := genesis.ImportGenesisStore(genesisStore, dataDir, false, cachescale.Identity); err != nil { + if err := genesis.ImportGenesisStore(genesisStore, dataDir, false, cachescale.Identity, true); err != nil { panic(err) } } diff --git a/cmd/sonictool/app/export_genesis.go b/cmd/sonictool/app/export_genesis.go index 60380a5ad..5251bc94f 100644 --- a/cmd/sonictool/app/export_genesis.go +++ b/cmd/sonictool/app/export_genesis.go @@ -48,7 +48,7 @@ func exportGenesis(ctx *cli.Context) error { } defer dbs.Close() - gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity) + gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false) if err != nil { return err } diff --git a/cmd/sonictool/app/genesis.go b/cmd/sonictool/app/genesis.go index 024e17505..1bcfe4920 100644 --- a/cmd/sonictool/app/genesis.go +++ b/cmd/sonictool/app/genesis.go @@ -66,7 +66,7 @@ func gfileGenesisImport(ctx *cli.Context) error { return fmt.Errorf("genesis file check failed: %w", err) } } - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false) } func jsonGenesisImport(ctx *cli.Context) error { @@ -98,7 +98,7 @@ func jsonGenesisImport(ctx *cli.Context) error { return fmt.Errorf("failed to prepare JSON genesis: %w", err) } defer genesisStore.Close() - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false) } func fakeGenesisImport(ctx *cli.Context) error { @@ -127,7 +127,7 @@ func fakeGenesisImport(ctx *cli.Context) error { genesisStore := makefakegenesis.FakeGenesisStore(idx.Validator(validatorsNumber), futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, true) } func isValidatorModeSet(ctx *cli.Context) (bool, error) { diff --git a/cmd/sonictool/chain/export_events.go b/cmd/sonictool/chain/export_events.go index 3d90ec078..983649313 100644 --- a/cmd/sonictool/chain/export_events.go +++ b/cmd/sonictool/chain/export_events.go @@ -32,7 +32,7 @@ func ExportEvents(w io.Writer, dataDir string, from, to idx.Epoch) (err error) { } defer dbs.Close() - gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity) + gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false) if err != nil { return err } diff --git a/cmd/sonictool/db/dbutils.go b/cmd/sonictool/db/dbutils.go index e344d2b40..8eb0dec9c 100644 --- a/cmd/sonictool/db/dbutils.go +++ b/cmd/sonictool/db/dbutils.go @@ -31,7 +31,7 @@ func makeDatabaseHandles() uint64 { if err != nil { panic(fmt.Errorf("failed to raise file descriptor allowance: %v", err)) } - return raised / 6 + 1 + return raised/6 + 1 } func AssertDatabaseNotInitialized(dataDir string) error { @@ -61,7 +61,7 @@ func MakeDbProducer(chaindataDir string, cacheRatio cachescale.Func) (kvdb.FullD }) } -func MakeGossipDb(dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func) (*gossip.Store, error) { +func MakeGossipDb(dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) (*gossip.Store, error) { gdbConfig := gossip.DefaultStoreConfig(cacheRatio) gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen") if validatorMode { @@ -70,6 +70,11 @@ func MakeGossipDb(dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, c gdbConfig.EVM.DisableTxHashesIndexing = true } + if isFakeNet { + gdbConfig.EVM.StateDb.ArchiveCache = 1 + gdbConfig.EVM.StateDb.LiveCache = 1 + } + gdb, err := gossip.NewStore(dbs, gdbConfig) if err != nil { return nil, fmt.Errorf("failed to create gossip store: %w", err) diff --git a/cmd/sonictool/genesis/import.go b/cmd/sonictool/genesis/import.go index 5fefc0fc8..696ffee85 100644 --- a/cmd/sonictool/genesis/import.go +++ b/cmd/sonictool/genesis/import.go @@ -13,7 +13,7 @@ import ( "path/filepath" ) -func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func) error { +func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) error { if err := db.AssertDatabaseNotInitialized(dataDir); err != nil { return fmt.Errorf("database in datadir is already initialized: %w", err) } @@ -29,7 +29,7 @@ func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, valida defer dbs.Close() setGenesisProcessing(chaindataDir) - gdb, err := db.MakeGossipDb(dbs, dataDir, validatorMode, cacheRatio) + gdb, err := db.MakeGossipDb(dbs, dataDir, validatorMode, cacheRatio, isFakeNet) if err != nil { return err } From a54ab46c6f418f3ec75708c9c5b358cb5c26d3de Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Tue, 26 Nov 2024 08:24:53 +0100 Subject: [PATCH 2/8] Use flags when changing the cache --- cmd/sonicd/app/launcher.go | 11 ++++++++--- cmd/sonicd/app/run_test.go | 3 ++- cmd/sonictool/app/chain.go | 2 +- cmd/sonictool/app/export_genesis.go | 2 +- cmd/sonictool/app/genesis.go | 6 +++--- cmd/sonictool/app/main.go | 2 ++ cmd/sonictool/chain/export_events.go | 5 +++-- cmd/sonictool/db/dbutils.go | 15 ++++++++++----- cmd/sonictool/genesis/import.go | 5 +++-- config/flags/flags.go | 10 ++++++++++ tests/integration_test_net.go | 23 ++++++++++++++++++++--- 11 files changed, 63 insertions(+), 21 deletions(-) diff --git a/cmd/sonicd/app/launcher.go b/cmd/sonicd/app/launcher.go index fe7582fff..a341e999b 100644 --- a/cmd/sonicd/app/launcher.go +++ b/cmd/sonicd/app/launcher.go @@ -65,6 +65,8 @@ func initFlags() { } performanceFlags = []cli.Flag{ flags.CacheFlag, + flags.LiveDbCacheFlag, + flags.ArchiveCacheFlag, } networkingFlags = []cli.Flag{ flags.BootnodesFlag, @@ -222,9 +224,12 @@ func lachesisMain(ctx *cli.Context) error { } metrics.SetDataDir(cfg.Node.DataDir) // report disk space usage into metrics - if ctx.GlobalIsSet(config.FakeNetFlag.Name) { - cfg.OperaStore.EVM.StateDb.LiveCache = 1 - cfg.OperaStore.EVM.StateDb.ArchiveCache = 1 + if ctx.IsSet(flags.LiveDbCacheFlag.Name) { + cfg.OperaStore.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name) + } + + if ctx.IsSet(flags.ArchiveCacheFlag.Name) { + cfg.OperaStore.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name) } node, _, nodeClose, err := config.MakeNode(ctx, cfg) diff --git a/cmd/sonicd/app/run_test.go b/cmd/sonicd/app/run_test.go index 41c8105b3..26e5c4cc0 100644 --- a/cmd/sonicd/app/run_test.go +++ b/cmd/sonicd/app/run_test.go @@ -2,6 +2,7 @@ package app import ( "fmt" + "gopkg.in/urfave/cli.v1" "os" "strings" "testing" @@ -26,7 +27,7 @@ func tmpdir(t *testing.T) string { func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) { genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - if err := genesis.ImportGenesisStore(genesisStore, dataDir, false, cachescale.Identity, true); err != nil { + if err := genesis.ImportGenesisStore(&cli.Context{}, genesisStore, dataDir, false, cachescale.Identity); err != nil { panic(err) } } diff --git a/cmd/sonictool/app/chain.go b/cmd/sonictool/app/chain.go index f58f0668a..876fa45ae 100644 --- a/cmd/sonictool/app/chain.go +++ b/cmd/sonictool/app/chain.go @@ -58,7 +58,7 @@ func exportEvents(ctx *cli.Context) error { } log.Info("Exporting events to file", "file", fn) - err = chain.ExportEvents(writer, dataDir, from, to) + err = chain.ExportEvents(ctx, writer, dataDir, from, to) if err != nil { return fmt.Errorf("export error: %w", err) } diff --git a/cmd/sonictool/app/export_genesis.go b/cmd/sonictool/app/export_genesis.go index 5251bc94f..7032d743c 100644 --- a/cmd/sonictool/app/export_genesis.go +++ b/cmd/sonictool/app/export_genesis.go @@ -48,7 +48,7 @@ func exportGenesis(ctx *cli.Context) error { } defer dbs.Close() - gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false) + gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity) if err != nil { return err } diff --git a/cmd/sonictool/app/genesis.go b/cmd/sonictool/app/genesis.go index 1bcfe4920..2754b04f7 100644 --- a/cmd/sonictool/app/genesis.go +++ b/cmd/sonictool/app/genesis.go @@ -66,7 +66,7 @@ func gfileGenesisImport(ctx *cli.Context) error { return fmt.Errorf("genesis file check failed: %w", err) } } - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false) + return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) } func jsonGenesisImport(ctx *cli.Context) error { @@ -98,7 +98,7 @@ func jsonGenesisImport(ctx *cli.Context) error { return fmt.Errorf("failed to prepare JSON genesis: %w", err) } defer genesisStore.Close() - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false) + return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) } func fakeGenesisImport(ctx *cli.Context) error { @@ -127,7 +127,7 @@ func fakeGenesisImport(ctx *cli.Context) error { genesisStore := makefakegenesis.FakeGenesisStore(idx.Validator(validatorsNumber), futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, true) + return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) } func isValidatorModeSet(ctx *cli.Context) (bool, error) { diff --git a/cmd/sonictool/app/main.go b/cmd/sonictool/app/main.go index 23ee43f04..75173cf44 100644 --- a/cmd/sonictool/app/main.go +++ b/cmd/sonictool/app/main.go @@ -60,6 +60,8 @@ Initialize the database using data from the experimental genesis file. ArgsUsage: "", Action: fakeGenesisImport, Flags: []cli.Flag{ + flags.LiveDbCacheFlag, + flags.ArchiveCacheFlag, ModeFlag, }, Description: ` diff --git a/cmd/sonictool/chain/export_events.go b/cmd/sonictool/chain/export_events.go index 983649313..5519af418 100644 --- a/cmd/sonictool/chain/export_events.go +++ b/cmd/sonictool/chain/export_events.go @@ -3,6 +3,7 @@ package chain import ( "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" + "gopkg.in/urfave/cli.v1" "io" "path/filepath" "time" @@ -24,7 +25,7 @@ var ( // always print out progress. This avoids the user wondering what's going on. const statsReportLimit = 8 * time.Second -func ExportEvents(w io.Writer, dataDir string, from, to idx.Epoch) (err error) { +func ExportEvents(ctx *cli.Context, w io.Writer, dataDir string, from, to idx.Epoch) (err error) { chaindataDir := filepath.Join(dataDir, "chaindata") dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity) if err != nil { @@ -32,7 +33,7 @@ func ExportEvents(w io.Writer, dataDir string, from, to idx.Epoch) (err error) { } defer dbs.Close() - gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false) + gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity) if err != nil { return err } diff --git a/cmd/sonictool/db/dbutils.go b/cmd/sonictool/db/dbutils.go index 8eb0dec9c..adba423d6 100644 --- a/cmd/sonictool/db/dbutils.go +++ b/cmd/sonictool/db/dbutils.go @@ -4,12 +4,14 @@ import ( "errors" "fmt" carmen "github.com/Fantom-foundation/Carmen/go/state" + "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/go-opera/gossip" "github.com/Fantom-foundation/go-opera/integration" "github.com/Fantom-foundation/lachesis-base/kvdb" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "github.com/ethereum/go-ethereum/common/fdlimit" "github.com/syndtr/goleveldb/leveldb/opt" + "gopkg.in/urfave/cli.v1" "os" "path/filepath" ) @@ -61,19 +63,22 @@ func MakeDbProducer(chaindataDir string, cacheRatio cachescale.Func) (kvdb.FullD }) } -func MakeGossipDb(dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) (*gossip.Store, error) { +func MakeGossipDb(ctx *cli.Context, dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func) (*gossip.Store, error) { gdbConfig := gossip.DefaultStoreConfig(cacheRatio) - gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen") if validatorMode { gdbConfig.EVM.StateDb.Archive = carmen.NoArchive gdbConfig.EVM.DisableLogsIndexing = true gdbConfig.EVM.DisableTxHashesIndexing = true } - if isFakeNet { - gdbConfig.EVM.StateDb.ArchiveCache = 1 - gdbConfig.EVM.StateDb.LiveCache = 1 + if ctx.IsSet(flags.LiveDbCacheFlag.Name) { + gdbConfig.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name) + } + + if ctx.IsSet(flags.ArchiveCacheFlag.Name) { + gdbConfig.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name) } + gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen") gdb, err := gossip.NewStore(dbs, gdbConfig) if err != nil { diff --git a/cmd/sonictool/genesis/import.go b/cmd/sonictool/genesis/import.go index 696ffee85..7e082ca76 100644 --- a/cmd/sonictool/genesis/import.go +++ b/cmd/sonictool/genesis/import.go @@ -10,10 +10,11 @@ import ( "github.com/Fantom-foundation/lachesis-base/kvdb" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "github.com/ethereum/go-ethereum/log" + "gopkg.in/urfave/cli.v1" "path/filepath" ) -func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) error { +func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func) error { if err := db.AssertDatabaseNotInitialized(dataDir); err != nil { return fmt.Errorf("database in datadir is already initialized: %w", err) } @@ -29,7 +30,7 @@ func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, valida defer dbs.Close() setGenesisProcessing(chaindataDir) - gdb, err := db.MakeGossipDb(dbs, dataDir, validatorMode, cacheRatio, isFakeNet) + gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cacheRatio) if err != nil { return err } diff --git a/config/flags/flags.go b/config/flags/flags.go index 2dfd254e5..580b90549 100644 --- a/config/flags/flags.go +++ b/config/flags/flags.go @@ -348,4 +348,14 @@ var ( Name: "lachesis.suppress-frame-panic", Usage: "Suppress frame missmatch error (when testing on historical imported/synced events)", } + + // StateDb + LiveDbCacheFlag = cli.Int64Flag{ + Name: "statedb.livecache", + Usage: "Size of live db cache in bytes.", + } + ArchiveCacheFlag = cli.IntFlag{ + Name: "statedb.archivecache", + Usage: "Size of archive cache in bytes.", + } ) diff --git a/tests/integration_test_net.go b/tests/integration_test_net.go index ad80c9085..75e404504 100644 --- a/tests/integration_test_net.go +++ b/tests/integration_test_net.go @@ -169,13 +169,23 @@ func startIntegrationTestNet(directory string, args []string) (*IntegrationTestN // initialize the data directory for the single node on the test network // equivalent to running `sonictool --datadir genesis fake 1` originalArgs := os.Args - os.Args = append([]string{"sonictool", "--datadir", result.stateDir()}, args...) + os.Args = append([]string{ + "sonictool", + "--datadir", result.stateDir(), + "genesis", + "fake", + "--statedb.livecache", "1", + "--statedb.archivecache", "1", + "1", + }, args...) if err := sonictool.Run(); err != nil { os.Args = originalArgs return nil, fmt.Errorf("failed to initialize the test network: %w", err) } os.Args = originalArgs + os.Args = originalArgs + if err := result.start(); err != nil { return nil, fmt.Errorf("failed to start the test network: %w", err) } @@ -200,10 +210,17 @@ func (n *IntegrationTestNet) start() error { "sonicd", "--datadir", n.stateDir(), "--fakenet", "1/1", - "--http", "--http.addr", "0.0.0.0", "--http.port", "18545", + "--http", + "--http.addr", "0.0.0.0", + "--http.port", "18545", "--http.api", "admin,eth,web3,net,txpool,ftm,trace,debug", - "--ws", "--ws.addr", "0.0.0.0", "--ws.port", "18546", "--ws.api", "admin,eth,ftm", + "--ws", + "--ws.addr", "0.0.0.0", + "--ws.port", "18546", + "--ws.api", "admin,eth,ftm", "--datadir.minfreedisk", "0", + "--statedb.livecache", "1", + "--statedb.archivecache", "1", } sonicd.Run() }() From ec4a3d9a68199d2ef85292cc691000e70eea1e6d Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Tue, 26 Nov 2024 09:30:56 +0100 Subject: [PATCH 3/8] Fix test --- cmd/sonicd/app/run_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/sonicd/app/run_test.go b/cmd/sonicd/app/run_test.go index 26e5c4cc0..36d2b2665 100644 --- a/cmd/sonicd/app/run_test.go +++ b/cmd/sonicd/app/run_test.go @@ -1,6 +1,7 @@ package app import ( + "flag" "fmt" "gopkg.in/urfave/cli.v1" "os" @@ -27,7 +28,13 @@ func tmpdir(t *testing.T) string { func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) { genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - if err := genesis.ImportGenesisStore(&cli.Context{}, genesisStore, dataDir, false, cachescale.Identity); err != nil { + if err := genesis.ImportGenesisStore( + cli.NewContext(cli.NewApp(), new(flag.FlagSet), nil), + genesisStore, + dataDir, + false, + cachescale.Identity, + ); err != nil { panic(err) } } From 583707b0cf8b6bb048e18e898ce7e0d66cb9f71a Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Tue, 26 Nov 2024 12:51:00 +0100 Subject: [PATCH 4/8] Address reviewers feedback --- cmd/sonicd/app/launcher.go | 10 ++++++---- cmd/sonictool/app/export_genesis.go | 10 ++++++++-- cmd/sonictool/chain/export_events.go | 10 +++++++++- cmd/sonictool/db/dbutils.go | 30 +++++++++++++++++----------- cmd/sonictool/genesis/import.go | 10 +++++++++- config/flags/flags.go | 17 ++++++++++++---- 6 files changed, 63 insertions(+), 24 deletions(-) diff --git a/cmd/sonicd/app/launcher.go b/cmd/sonicd/app/launcher.go index a341e999b..38892ccbd 100644 --- a/cmd/sonicd/app/launcher.go +++ b/cmd/sonicd/app/launcher.go @@ -224,12 +224,14 @@ func lachesisMain(ctx *cli.Context) error { } metrics.SetDataDir(cfg.Node.DataDir) // report disk space usage into metrics - if ctx.IsSet(flags.LiveDbCacheFlag.Name) { - cfg.OperaStore.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name) + liveCache := ctx.Int64(flags.LiveDbCacheFlag.Name) + if liveCache > 0 { + cfg.OperaStore.EVM.StateDb.LiveCache = liveCache } - if ctx.IsSet(flags.ArchiveCacheFlag.Name) { - cfg.OperaStore.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name) + archiveCache := ctx.Int64(flags.ArchiveCacheFlag.Name) + if archiveCache > 0 { + cfg.OperaStore.EVM.StateDb.ArchiveCache = archiveCache } node, _, nodeClose, err := config.MakeNode(ctx, cfg) diff --git a/cmd/sonictool/app/export_genesis.go b/cmd/sonictool/app/export_genesis.go index 7032d743c..184f37dc7 100644 --- a/cmd/sonictool/app/export_genesis.go +++ b/cmd/sonictool/app/export_genesis.go @@ -7,7 +7,6 @@ import ( "github.com/Fantom-foundation/go-opera/cmd/sonictool/genesis" "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/go-opera/integration" - "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "github.com/syndtr/goleveldb/leveldb/opt" "gopkg.in/urfave/cli.v1" "os" @@ -48,7 +47,14 @@ func exportGenesis(ctx *cli.Context) error { } defer dbs.Close() - gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity) + gdb, err := db.MakeGossipDb(db.GossipDbParameters{ + Dbs: dbs, + DataDir: dataDir, + ValidatorMode: false, + CacheRatio: cacheRatio, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) if err != nil { return err } diff --git a/cmd/sonictool/chain/export_events.go b/cmd/sonictool/chain/export_events.go index 5519af418..876c0816f 100644 --- a/cmd/sonictool/chain/export_events.go +++ b/cmd/sonictool/chain/export_events.go @@ -2,6 +2,7 @@ package chain import ( "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" + "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "gopkg.in/urfave/cli.v1" "io" @@ -33,7 +34,14 @@ func ExportEvents(ctx *cli.Context, w io.Writer, dataDir string, from, to idx.Ep } defer dbs.Close() - gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity) + gdb, err := db.MakeGossipDb(db.GossipDbParameters{ + Dbs: dbs, + DataDir: dataDir, + ValidatorMode: false, + CacheRatio: cachescale.Identity, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) if err != nil { return err } diff --git a/cmd/sonictool/db/dbutils.go b/cmd/sonictool/db/dbutils.go index adba423d6..1e7ce3d7d 100644 --- a/cmd/sonictool/db/dbutils.go +++ b/cmd/sonictool/db/dbutils.go @@ -4,14 +4,12 @@ import ( "errors" "fmt" carmen "github.com/Fantom-foundation/Carmen/go/state" - "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/go-opera/gossip" "github.com/Fantom-foundation/go-opera/integration" "github.com/Fantom-foundation/lachesis-base/kvdb" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "github.com/ethereum/go-ethereum/common/fdlimit" "github.com/syndtr/goleveldb/leveldb/opt" - "gopkg.in/urfave/cli.v1" "os" "path/filepath" ) @@ -63,24 +61,32 @@ func MakeDbProducer(chaindataDir string, cacheRatio cachescale.Func) (kvdb.FullD }) } -func MakeGossipDb(ctx *cli.Context, dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func) (*gossip.Store, error) { - gdbConfig := gossip.DefaultStoreConfig(cacheRatio) - if validatorMode { +// GossipDbParameters are parameters for GossipDb factory func. +type GossipDbParameters struct { + Dbs kvdb.FullDBProducer + DataDir string + ValidatorMode bool + CacheRatio cachescale.Func + LiveDbCache, ArchiveCache int64 +} + +func MakeGossipDb(params GossipDbParameters) (*gossip.Store, error) { + gdbConfig := gossip.DefaultStoreConfig(params.CacheRatio) + if params.ValidatorMode { gdbConfig.EVM.StateDb.Archive = carmen.NoArchive gdbConfig.EVM.DisableLogsIndexing = true gdbConfig.EVM.DisableTxHashesIndexing = true } - if ctx.IsSet(flags.LiveDbCacheFlag.Name) { - gdbConfig.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name) + if params.LiveDbCache > 0 { + gdbConfig.EVM.StateDb.LiveCache = params.LiveDbCache } - - if ctx.IsSet(flags.ArchiveCacheFlag.Name) { - gdbConfig.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name) + if params.ArchiveCache > 0 { + gdbConfig.EVM.StateDb.ArchiveCache = params.ArchiveCache } - gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen") + gdbConfig.EVM.StateDb.Directory = filepath.Join(params.DataDir, "carmen") - gdb, err := gossip.NewStore(dbs, gdbConfig) + gdb, err := gossip.NewStore(params.Dbs, gdbConfig) if err != nil { return nil, fmt.Errorf("failed to create gossip store: %w", err) } diff --git a/cmd/sonictool/genesis/import.go b/cmd/sonictool/genesis/import.go index 7e082ca76..04da6c5e5 100644 --- a/cmd/sonictool/genesis/import.go +++ b/cmd/sonictool/genesis/import.go @@ -3,6 +3,7 @@ package genesis import ( "fmt" "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" + "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/go-opera/opera/genesis" "github.com/Fantom-foundation/go-opera/opera/genesisstore" "github.com/Fantom-foundation/lachesis-base/abft" @@ -30,7 +31,14 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data defer dbs.Close() setGenesisProcessing(chaindataDir) - gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cacheRatio) + gdb, err := db.MakeGossipDb(db.GossipDbParameters{ + Dbs: dbs, + DataDir: dataDir, + ValidatorMode: validatorMode, + CacheRatio: cacheRatio, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) if err != nil { return err } diff --git a/config/flags/flags.go b/config/flags/flags.go index 580b90549..ab59f1355 100644 --- a/config/flags/flags.go +++ b/config/flags/flags.go @@ -17,6 +17,7 @@ package flags import ( + "fmt" "strings" "github.com/Fantom-foundation/go-opera/evmcore" @@ -351,11 +352,19 @@ var ( // StateDb LiveDbCacheFlag = cli.Int64Flag{ - Name: "statedb.livecache", - Usage: "Size of live db cache in bytes.", + Name: "statedb.livecache", + Usage: fmt.Sprintf("Size of live db cache in bytes. Leaving this blank (which is generally recommended),"+ + "or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+ + "Setting this value to <=2000 will result in cache capacity of 2KB (which is the lowest value that Carmen allows)", + CacheFlag.Name), + Value: 0, } ArchiveCacheFlag = cli.IntFlag{ - Name: "statedb.archivecache", - Usage: "Size of archive cache in bytes.", + Name: "statedb.archivecache", + Usage: fmt.Sprintf("Size of archive cache in bytes. Leaving this blank (which is generally recommended),"+ + "or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+ + "Setting this value to <=2000 will result in cache capacity of 2KB (which is the lowest value that Carmen allows)", + CacheFlag.Name), + Value: 0, } ) From 40b7bbc173031da118c30b65a0195ce72778a222 Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Tue, 26 Nov 2024 13:08:13 +0100 Subject: [PATCH 5/8] Use better words in documentation --- config/flags/flags.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config/flags/flags.go b/config/flags/flags.go index ab59f1355..3f9582e41 100644 --- a/config/flags/flags.go +++ b/config/flags/flags.go @@ -355,16 +355,14 @@ var ( Name: "statedb.livecache", Usage: fmt.Sprintf("Size of live db cache in bytes. Leaving this blank (which is generally recommended),"+ "or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+ - "Setting this value to <=2000 will result in cache capacity of 2KB (which is the lowest value that Carmen allows)", - CacheFlag.Name), + "Setting this value to <=2000 will result in pre-confugired cache capacity of 2KB", CacheFlag.Name), Value: 0, } ArchiveCacheFlag = cli.IntFlag{ Name: "statedb.archivecache", Usage: fmt.Sprintf("Size of archive cache in bytes. Leaving this blank (which is generally recommended),"+ "or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+ - "Setting this value to <=2000 will result in cache capacity of 2KB (which is the lowest value that Carmen allows)", - CacheFlag.Name), + "Setting this value to <=2000 will result in pre-confugired cache capacity of 2KB", CacheFlag.Name), Value: 0, } ) From e65e7cceaedc505cddd4bd06c1fce91208d9d31b Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Wed, 27 Nov 2024 10:05:14 +0100 Subject: [PATCH 6/8] Address reviewers feedback --- cmd/sonicd/app/run_test.go | 20 +++++++--------- cmd/sonictool/app/chain.go | 9 ++++++- cmd/sonictool/app/genesis.go | 27 ++++++++++++++++++--- cmd/sonictool/app/main.go | 4 ++-- cmd/sonictool/chain/export_events.go | 17 +++++--------- cmd/sonictool/db/dbutils.go | 2 +- cmd/sonictool/genesis/import.go | 35 +++++++++++++++++----------- tests/integration_test_net.go | 5 +--- 8 files changed, 72 insertions(+), 47 deletions(-) diff --git a/cmd/sonicd/app/run_test.go b/cmd/sonicd/app/run_test.go index 36d2b2665..98e830a94 100644 --- a/cmd/sonicd/app/run_test.go +++ b/cmd/sonicd/app/run_test.go @@ -1,9 +1,8 @@ package app import ( - "flag" "fmt" - "gopkg.in/urfave/cli.v1" + "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "os" "strings" "testing" @@ -13,8 +12,6 @@ import ( "github.com/Fantom-foundation/go-opera/integration/makefakegenesis" futils "github.com/Fantom-foundation/go-opera/utils" "github.com/Fantom-foundation/lachesis-base/inter/idx" - "github.com/Fantom-foundation/lachesis-base/utils/cachescale" - "github.com/docker/docker/pkg/reexec" "github.com/ethereum/go-ethereum/common" @@ -28,13 +25,14 @@ func tmpdir(t *testing.T) string { func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) { genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - if err := genesis.ImportGenesisStore( - cli.NewContext(cli.NewApp(), new(flag.FlagSet), nil), - genesisStore, - dataDir, - false, - cachescale.Identity, - ); err != nil { + + if err := genesis.ImportGenesisStore(genesis.ImportParams{ + GenesisStore: genesisStore, + DataDir: dataDir, + CacheRatio: cachescale.Identity, + LiveDbCache: 1, // Set lowest cache + ArchiveCache: 1, // Set lowest cache + }); err != nil { panic(err) } } diff --git a/cmd/sonictool/app/chain.go b/cmd/sonictool/app/chain.go index 876fa45ae..cd482aff1 100644 --- a/cmd/sonictool/app/chain.go +++ b/cmd/sonictool/app/chain.go @@ -3,6 +3,7 @@ package app import ( "compress/gzip" "fmt" + "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" "io" "os" "strconv" @@ -57,8 +58,14 @@ func exportEvents(ctx *cli.Context) error { to = idx.Epoch(n) } + gdbParams := db.GossipDbParameters{ + DataDir: dataDir, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + } + log.Info("Exporting events to file", "file", fn) - err = chain.ExportEvents(ctx, writer, dataDir, from, to) + err = chain.ExportEvents(gdbParams, writer, dataDir, from, to) if err != nil { return fmt.Errorf("export error: %w", err) } diff --git a/cmd/sonictool/app/genesis.go b/cmd/sonictool/app/genesis.go index 2754b04f7..42b8b42f5 100644 --- a/cmd/sonictool/app/genesis.go +++ b/cmd/sonictool/app/genesis.go @@ -66,7 +66,14 @@ func gfileGenesisImport(ctx *cli.Context) error { return fmt.Errorf("genesis file check failed: %w", err) } } - return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesis.ImportParams{ + GenesisStore: genesisStore, + DataDir: dataDir, + ValidatorMode: validatorMode, + CacheRatio: cacheRatio, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) } func jsonGenesisImport(ctx *cli.Context) error { @@ -98,7 +105,14 @@ func jsonGenesisImport(ctx *cli.Context) error { return fmt.Errorf("failed to prepare JSON genesis: %w", err) } defer genesisStore.Close() - return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesis.ImportParams{ + GenesisStore: genesisStore, + DataDir: dataDir, + ValidatorMode: validatorMode, + CacheRatio: cacheRatio, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) } func fakeGenesisImport(ctx *cli.Context) error { @@ -127,7 +141,14 @@ func fakeGenesisImport(ctx *cli.Context) error { genesisStore := makefakegenesis.FakeGenesisStore(idx.Validator(validatorsNumber), futils.ToFtm(1000000000), futils.ToFtm(5000000)) defer genesisStore.Close() - return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio) + return genesis.ImportGenesisStore(genesis.ImportParams{ + GenesisStore: genesisStore, + DataDir: dataDir, + ValidatorMode: validatorMode, + CacheRatio: cacheRatio, + LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + }) } func isValidatorModeSet(ctx *cli.Context) (bool, error) { diff --git a/cmd/sonictool/app/main.go b/cmd/sonictool/app/main.go index 75173cf44..d71ffb5eb 100644 --- a/cmd/sonictool/app/main.go +++ b/cmd/sonictool/app/main.go @@ -18,6 +18,8 @@ func Run() error { app.Flags = []cli.Flag{ flags.DataDirFlag, flags.CacheFlag, + flags.LiveDbCacheFlag, + flags.ArchiveCacheFlag, } app.Commands = []cli.Command{ { @@ -60,8 +62,6 @@ Initialize the database using data from the experimental genesis file. ArgsUsage: "", Action: fakeGenesisImport, Flags: []cli.Flag{ - flags.LiveDbCacheFlag, - flags.ArchiveCacheFlag, ModeFlag, }, Description: ` diff --git a/cmd/sonictool/chain/export_events.go b/cmd/sonictool/chain/export_events.go index 876c0816f..0fef11474 100644 --- a/cmd/sonictool/chain/export_events.go +++ b/cmd/sonictool/chain/export_events.go @@ -2,9 +2,7 @@ package chain import ( "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" - "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" - "gopkg.in/urfave/cli.v1" "io" "path/filepath" "time" @@ -26,7 +24,7 @@ var ( // always print out progress. This avoids the user wondering what's going on. const statsReportLimit = 8 * time.Second -func ExportEvents(ctx *cli.Context, w io.Writer, dataDir string, from, to idx.Epoch) (err error) { +func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, dataDir string, from, to idx.Epoch) (err error) { chaindataDir := filepath.Join(dataDir, "chaindata") dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity) if err != nil { @@ -34,14 +32,11 @@ func ExportEvents(ctx *cli.Context, w io.Writer, dataDir string, from, to idx.Ep } defer dbs.Close() - gdb, err := db.MakeGossipDb(db.GossipDbParameters{ - Dbs: dbs, - DataDir: dataDir, - ValidatorMode: false, - CacheRatio: cachescale.Identity, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), - }) + // Fill the rest of the params + gdbParams.Dbs = dbs + gdbParams.CacheRatio = cachescale.Identity + + gdb, err := db.MakeGossipDb(gdbParams) if err != nil { return err } diff --git a/cmd/sonictool/db/dbutils.go b/cmd/sonictool/db/dbutils.go index 1e7ce3d7d..84ce3b060 100644 --- a/cmd/sonictool/db/dbutils.go +++ b/cmd/sonictool/db/dbutils.go @@ -67,7 +67,7 @@ type GossipDbParameters struct { DataDir string ValidatorMode bool CacheRatio cachescale.Func - LiveDbCache, ArchiveCache int64 + LiveDbCache, ArchiveCache int64 // in bytes } func MakeGossipDb(params GossipDbParameters) (*gossip.Store, error) { diff --git a/cmd/sonictool/genesis/import.go b/cmd/sonictool/genesis/import.go index 04da6c5e5..88886cf93 100644 --- a/cmd/sonictool/genesis/import.go +++ b/cmd/sonictool/genesis/import.go @@ -3,7 +3,6 @@ package genesis import ( "fmt" "github.com/Fantom-foundation/go-opera/cmd/sonictool/db" - "github.com/Fantom-foundation/go-opera/config/flags" "github.com/Fantom-foundation/go-opera/opera/genesis" "github.com/Fantom-foundation/go-opera/opera/genesisstore" "github.com/Fantom-foundation/lachesis-base/abft" @@ -11,20 +10,28 @@ import ( "github.com/Fantom-foundation/lachesis-base/kvdb" "github.com/Fantom-foundation/lachesis-base/utils/cachescale" "github.com/ethereum/go-ethereum/log" - "gopkg.in/urfave/cli.v1" "path/filepath" ) -func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func) error { - if err := db.AssertDatabaseNotInitialized(dataDir); err != nil { +// ImportParams are parameters for ImportGenesisStore func. +type ImportParams struct { + GenesisStore *genesisstore.Store + DataDir string + ValidatorMode bool + CacheRatio cachescale.Func + LiveDbCache, ArchiveCache int64 // in bytes +} + +func ImportGenesisStore(params ImportParams) error { + if err := db.AssertDatabaseNotInitialized(params.DataDir); err != nil { return fmt.Errorf("database in datadir is already initialized: %w", err) } - if err := db.RemoveDatabase(dataDir); err != nil { + if err := db.RemoveDatabase(params.DataDir); err != nil { return fmt.Errorf("failed to remove existing data from the datadir: %w", err) } - chaindataDir := filepath.Join(dataDir, "chaindata") - dbs, err := db.MakeDbProducer(chaindataDir, cacheRatio) + chaindataDir := filepath.Join(params.DataDir, "chaindata") + dbs, err := db.MakeDbProducer(chaindataDir, params.CacheRatio) if err != nil { return err } @@ -33,18 +40,18 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data gdb, err := db.MakeGossipDb(db.GossipDbParameters{ Dbs: dbs, - DataDir: dataDir, - ValidatorMode: validatorMode, - CacheRatio: cacheRatio, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + DataDir: params.DataDir, + ValidatorMode: params.ValidatorMode, + CacheRatio: params.CacheRatio, + LiveDbCache: params.LiveDbCache, + ArchiveCache: params.ArchiveCache, }) if err != nil { return err } defer gdb.Close() - err = gdb.ApplyGenesis(genesisStore.Genesis()) + err = gdb.ApplyGenesis(params.GenesisStore.Genesis()) if err != nil { return fmt.Errorf("failed to write Gossip genesis state: %v", err) } @@ -63,7 +70,7 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data abftCrit := func(err error) { panic(fmt.Errorf("lachesis store error: %w", err)) } - cdb := abft.NewStore(cMainDb, cGetEpochDB, abftCrit, abft.DefaultStoreConfig(cacheRatio)) + cdb := abft.NewStore(cMainDb, cGetEpochDB, abftCrit, abft.DefaultStoreConfig(params.CacheRatio)) defer cdb.Close() err = cdb.ApplyGenesis(&abft.Genesis{ diff --git a/tests/integration_test_net.go b/tests/integration_test_net.go index 75e404504..bb44c3283 100644 --- a/tests/integration_test_net.go +++ b/tests/integration_test_net.go @@ -169,14 +169,11 @@ func startIntegrationTestNet(directory string, args []string) (*IntegrationTestN // initialize the data directory for the single node on the test network // equivalent to running `sonictool --datadir genesis fake 1` originalArgs := os.Args - os.Args = append([]string{ + os.Args = append([]string{ "sonictool", "--datadir", result.stateDir(), - "genesis", - "fake", "--statedb.livecache", "1", "--statedb.archivecache", "1", - "1", }, args...) if err := sonictool.Run(); err != nil { os.Args = originalArgs From bec05e148916b2bcb1e7641284f52349521bc507 Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Thu, 28 Nov 2024 12:16:01 +0100 Subject: [PATCH 7/8] Remove unnecessary param --- cmd/sonictool/app/chain.go | 2 +- cmd/sonictool/chain/export_events.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/sonictool/app/chain.go b/cmd/sonictool/app/chain.go index cd482aff1..8a2dcc7df 100644 --- a/cmd/sonictool/app/chain.go +++ b/cmd/sonictool/app/chain.go @@ -65,7 +65,7 @@ func exportEvents(ctx *cli.Context) error { } log.Info("Exporting events to file", "file", fn) - err = chain.ExportEvents(gdbParams, writer, dataDir, from, to) + err = chain.ExportEvents(gdbParams, writer, from, to) if err != nil { return fmt.Errorf("export error: %w", err) } diff --git a/cmd/sonictool/chain/export_events.go b/cmd/sonictool/chain/export_events.go index 0fef11474..492e404c7 100644 --- a/cmd/sonictool/chain/export_events.go +++ b/cmd/sonictool/chain/export_events.go @@ -24,8 +24,8 @@ var ( // always print out progress. This avoids the user wondering what's going on. const statsReportLimit = 8 * time.Second -func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, dataDir string, from, to idx.Epoch) (err error) { - chaindataDir := filepath.Join(dataDir, "chaindata") +func ExportEvents(gdbParams db.GossipDbParameters, w io.Writer, from, to idx.Epoch) (err error) { + chaindataDir := filepath.Join(gdbParams.DataDir, "chaindata") dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity) if err != nil { return err From 0e31d8c7e7ecfd3eb1bed652a9730b3dbf57984f Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Thu, 28 Nov 2024 12:35:52 +0100 Subject: [PATCH 8/8] Use globalint64 --- cmd/sonicd/app/launcher.go | 4 ++-- cmd/sonictool/app/chain.go | 4 ++-- cmd/sonictool/app/export_genesis.go | 4 ++-- cmd/sonictool/app/genesis.go | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/sonicd/app/launcher.go b/cmd/sonicd/app/launcher.go index 38892ccbd..0fa26ac22 100644 --- a/cmd/sonicd/app/launcher.go +++ b/cmd/sonicd/app/launcher.go @@ -224,12 +224,12 @@ func lachesisMain(ctx *cli.Context) error { } metrics.SetDataDir(cfg.Node.DataDir) // report disk space usage into metrics - liveCache := ctx.Int64(flags.LiveDbCacheFlag.Name) + liveCache := ctx.GlobalInt64(flags.LiveDbCacheFlag.Name) if liveCache > 0 { cfg.OperaStore.EVM.StateDb.LiveCache = liveCache } - archiveCache := ctx.Int64(flags.ArchiveCacheFlag.Name) + archiveCache := ctx.GlobalInt64(flags.ArchiveCacheFlag.Name) if archiveCache > 0 { cfg.OperaStore.EVM.StateDb.ArchiveCache = archiveCache } diff --git a/cmd/sonictool/app/chain.go b/cmd/sonictool/app/chain.go index 8a2dcc7df..9896502ce 100644 --- a/cmd/sonictool/app/chain.go +++ b/cmd/sonictool/app/chain.go @@ -60,8 +60,8 @@ func exportEvents(ctx *cli.Context) error { gdbParams := db.GossipDbParameters{ DataDir: dataDir, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + LiveDbCache: ctx.GlobalInt64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.GlobalInt64(flags.ArchiveCacheFlag.Name), } log.Info("Exporting events to file", "file", fn) diff --git a/cmd/sonictool/app/export_genesis.go b/cmd/sonictool/app/export_genesis.go index 184f37dc7..6dbeae51e 100644 --- a/cmd/sonictool/app/export_genesis.go +++ b/cmd/sonictool/app/export_genesis.go @@ -52,8 +52,8 @@ func exportGenesis(ctx *cli.Context) error { DataDir: dataDir, ValidatorMode: false, CacheRatio: cacheRatio, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + LiveDbCache: ctx.GlobalInt64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.GlobalInt64(flags.ArchiveCacheFlag.Name), }) if err != nil { return err diff --git a/cmd/sonictool/app/genesis.go b/cmd/sonictool/app/genesis.go index 42b8b42f5..a98044677 100644 --- a/cmd/sonictool/app/genesis.go +++ b/cmd/sonictool/app/genesis.go @@ -71,8 +71,8 @@ func gfileGenesisImport(ctx *cli.Context) error { DataDir: dataDir, ValidatorMode: validatorMode, CacheRatio: cacheRatio, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + LiveDbCache: ctx.GlobalInt64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.GlobalInt64(flags.ArchiveCacheFlag.Name), }) } @@ -110,8 +110,8 @@ func jsonGenesisImport(ctx *cli.Context) error { DataDir: dataDir, ValidatorMode: validatorMode, CacheRatio: cacheRatio, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + LiveDbCache: ctx.GlobalInt64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.GlobalInt64(flags.ArchiveCacheFlag.Name), }) } @@ -146,8 +146,8 @@ func fakeGenesisImport(ctx *cli.Context) error { DataDir: dataDir, ValidatorMode: validatorMode, CacheRatio: cacheRatio, - LiveDbCache: ctx.Int64(flags.LiveDbCacheFlag.Name), - ArchiveCache: ctx.Int64(flags.ArchiveCacheFlag.Name), + LiveDbCache: ctx.GlobalInt64(flags.LiveDbCacheFlag.Name), + ArchiveCache: ctx.GlobalInt64(flags.ArchiveCacheFlag.Name), }) }