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 0f2ba58fd..6bd03354a 100644 --- a/tests/integration_test_net.go +++ b/tests/integration_test_net.go @@ -58,7 +58,15 @@ func StartIntegrationTestNet(directory string) (*IntegrationTestNet, error) { // 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 = []string{"sonictool", "--datadir", directory, "genesis", "fake", "1"} + os.Args = []string{ + "sonictool", + "--datadir", directory, + "genesis", + "fake", + "--statedb.livecache", "1", + "--statedb.archivecache", "1", + "1", + } sonictool.Run() os.Args = originalArgs @@ -88,10 +96,17 @@ func (n *IntegrationTestNet) start() error { "sonicd", "--datadir", n.directory, "--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() }()