Skip to content

Commit 7eb6764

Browse files
committed
Use flags when changing the cache
1 parent 21b3f29 commit 7eb6764

File tree

11 files changed

+61
-21
lines changed

11 files changed

+61
-21
lines changed

cmd/sonicd/app/launcher.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func initFlags() {
6565
}
6666
performanceFlags = []cli.Flag{
6767
flags.CacheFlag,
68+
flags.LiveDbCacheFlag,
69+
flags.ArchiveCacheFlag,
6870
}
6971
networkingFlags = []cli.Flag{
7072
flags.BootnodesFlag,
@@ -222,9 +224,12 @@ func lachesisMain(ctx *cli.Context) error {
222224
}
223225

224226
metrics.SetDataDir(cfg.Node.DataDir) // report disk space usage into metrics
225-
if ctx.GlobalIsSet(config.FakeNetFlag.Name) {
226-
cfg.OperaStore.EVM.StateDb.LiveCache = 1
227-
cfg.OperaStore.EVM.StateDb.ArchiveCache = 1
227+
if ctx.IsSet(flags.LiveDbCacheFlag.Name) {
228+
cfg.OperaStore.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name)
229+
}
230+
231+
if ctx.IsSet(flags.ArchiveCacheFlag.Name) {
232+
cfg.OperaStore.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name)
228233
}
229234

230235
node, _, nodeClose, err := config.MakeNode(ctx, cfg)

cmd/sonicd/app/run_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"fmt"
5+
"gopkg.in/urfave/cli.v1"
56
"os"
67
"strings"
78
"testing"
@@ -26,7 +27,7 @@ func tmpdir(t *testing.T) string {
2627
func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) {
2728
genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000))
2829
defer genesisStore.Close()
29-
if err := genesis.ImportGenesisStore(genesisStore, dataDir, false, cachescale.Identity, true); err != nil {
30+
if err := genesis.ImportGenesisStore(&cli.Context{}, genesisStore, dataDir, false, cachescale.Identity); err != nil {
3031
panic(err)
3132
}
3233
}

cmd/sonictool/app/chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func exportEvents(ctx *cli.Context) error {
5858
}
5959

6060
log.Info("Exporting events to file", "file", fn)
61-
err = chain.ExportEvents(writer, dataDir, from, to)
61+
err = chain.ExportEvents(ctx, writer, dataDir, from, to)
6262
if err != nil {
6363
return fmt.Errorf("export error: %w", err)
6464
}

cmd/sonictool/app/export_genesis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func exportGenesis(ctx *cli.Context) error {
4848
}
4949
defer dbs.Close()
5050

51-
gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false)
51+
gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity)
5252
if err != nil {
5353
return err
5454
}

cmd/sonictool/app/genesis.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func gfileGenesisImport(ctx *cli.Context) error {
6666
return fmt.Errorf("genesis file check failed: %w", err)
6767
}
6868
}
69-
return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false)
69+
return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio)
7070
}
7171

7272
func jsonGenesisImport(ctx *cli.Context) error {
@@ -98,7 +98,7 @@ func jsonGenesisImport(ctx *cli.Context) error {
9898
return fmt.Errorf("failed to prepare JSON genesis: %w", err)
9999
}
100100
defer genesisStore.Close()
101-
return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, false)
101+
return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio)
102102
}
103103

104104
func fakeGenesisImport(ctx *cli.Context) error {
@@ -127,7 +127,7 @@ func fakeGenesisImport(ctx *cli.Context) error {
127127

128128
genesisStore := makefakegenesis.FakeGenesisStore(idx.Validator(validatorsNumber), futils.ToFtm(1000000000), futils.ToFtm(5000000))
129129
defer genesisStore.Close()
130-
return genesis.ImportGenesisStore(genesisStore, dataDir, validatorMode, cacheRatio, true)
130+
return genesis.ImportGenesisStore(ctx, genesisStore, dataDir, validatorMode, cacheRatio)
131131
}
132132

133133
func isValidatorModeSet(ctx *cli.Context) (bool, error) {

cmd/sonictool/app/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Initialize the database using data from the experimental genesis file.
6060
ArgsUsage: "<validators>",
6161
Action: fakeGenesisImport,
6262
Flags: []cli.Flag{
63+
flags.LiveDbCacheFlag,
64+
flags.ArchiveCacheFlag,
6365
ModeFlag,
6466
},
6567
Description: `

cmd/sonictool/chain/export_events.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package chain
33
import (
44
"github.com/Fantom-foundation/go-opera/cmd/sonictool/db"
55
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
6+
"gopkg.in/urfave/cli.v1"
67
"io"
78
"path/filepath"
89
"time"
@@ -24,15 +25,15 @@ var (
2425
// always print out progress. This avoids the user wondering what's going on.
2526
const statsReportLimit = 8 * time.Second
2627

27-
func ExportEvents(w io.Writer, dataDir string, from, to idx.Epoch) (err error) {
28+
func ExportEvents(ctx *cli.Context, w io.Writer, dataDir string, from, to idx.Epoch) (err error) {
2829
chaindataDir := filepath.Join(dataDir, "chaindata")
2930
dbs, err := db.MakeDbProducer(chaindataDir, cachescale.Identity)
3031
if err != nil {
3132
return err
3233
}
3334
defer dbs.Close()
3435

35-
gdb, err := db.MakeGossipDb(dbs, dataDir, false, cachescale.Identity, false)
36+
gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cachescale.Identity)
3637
if err != nil {
3738
return err
3839
}

cmd/sonictool/db/dbutils.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"errors"
55
"fmt"
66
carmen "github.com/Fantom-foundation/Carmen/go/state"
7+
"github.com/Fantom-foundation/go-opera/config/flags"
78
"github.com/Fantom-foundation/go-opera/gossip"
89
"github.com/Fantom-foundation/go-opera/integration"
910
"github.com/Fantom-foundation/lachesis-base/kvdb"
1011
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
1112
"github.com/ethereum/go-ethereum/common/fdlimit"
1213
"github.com/syndtr/goleveldb/leveldb/opt"
14+
"gopkg.in/urfave/cli.v1"
1315
"os"
1416
"path/filepath"
1517
)
@@ -61,19 +63,22 @@ func MakeDbProducer(chaindataDir string, cacheRatio cachescale.Func) (kvdb.FullD
6163
})
6264
}
6365

64-
func MakeGossipDb(dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) (*gossip.Store, error) {
66+
func MakeGossipDb(ctx *cli.Context, dbs kvdb.FullDBProducer, dataDir string, validatorMode bool, cacheRatio cachescale.Func) (*gossip.Store, error) {
6567
gdbConfig := gossip.DefaultStoreConfig(cacheRatio)
66-
gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen")
6768
if validatorMode {
6869
gdbConfig.EVM.StateDb.Archive = carmen.NoArchive
6970
gdbConfig.EVM.DisableLogsIndexing = true
7071
gdbConfig.EVM.DisableTxHashesIndexing = true
7172
}
7273

73-
if isFakeNet {
74-
gdbConfig.EVM.StateDb.ArchiveCache = 1
75-
gdbConfig.EVM.StateDb.LiveCache = 1
74+
if ctx.IsSet(flags.LiveDbCacheFlag.Name) {
75+
gdbConfig.EVM.StateDb.LiveCache = ctx.Int64(flags.LiveDbCacheFlag.Name)
76+
}
77+
78+
if ctx.IsSet(flags.ArchiveCacheFlag.Name) {
79+
gdbConfig.EVM.StateDb.ArchiveCache = ctx.Int64(flags.ArchiveCacheFlag.Name)
7680
}
81+
gdbConfig.EVM.StateDb.Directory = filepath.Join(dataDir, "carmen")
7782

7883
gdb, err := gossip.NewStore(dbs, gdbConfig)
7984
if err != nil {

cmd/sonictool/genesis/import.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"github.com/Fantom-foundation/lachesis-base/kvdb"
1111
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
1212
"github.com/ethereum/go-ethereum/log"
13+
"gopkg.in/urfave/cli.v1"
1314
"path/filepath"
1415
)
1516

16-
func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func, isFakeNet bool) error {
17+
func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, dataDir string, validatorMode bool, cacheRatio cachescale.Func) error {
1718
if err := db.AssertDatabaseNotInitialized(dataDir); err != nil {
1819
return fmt.Errorf("database in datadir is already initialized: %w", err)
1920
}
@@ -29,7 +30,7 @@ func ImportGenesisStore(genesisStore *genesisstore.Store, dataDir string, valida
2930
defer dbs.Close()
3031
setGenesisProcessing(chaindataDir)
3132

32-
gdb, err := db.MakeGossipDb(dbs, dataDir, validatorMode, cacheRatio, isFakeNet)
33+
gdb, err := db.MakeGossipDb(ctx, dbs, dataDir, false, cacheRatio)
3334
if err != nil {
3435
return err
3536
}

config/flags/flags.go

+10
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,14 @@ var (
348348
Name: "lachesis.suppress-frame-panic",
349349
Usage: "Suppress frame missmatch error (when testing on historical imported/synced events)",
350350
}
351+
352+
// StateDb
353+
LiveDbCacheFlag = cli.Int64Flag{
354+
Name: "statedb.livecache",
355+
Usage: "Size of live db cache in bytes.",
356+
}
357+
ArchiveCacheFlag = cli.IntFlag{
358+
Name: "statedb.archivecache",
359+
Usage: "Size of archive cache in bytes.",
360+
}
351361
)

tests/integration_test_net.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ func StartIntegrationTestNet(directory string) (*IntegrationTestNet, error) {
5858
// initialize the data directory for the single node on the test network
5959
// equivalent to running `sonictool --datadir <dataDir> genesis fake 1`
6060
originalArgs := os.Args
61-
os.Args = []string{"sonictool", "--datadir", directory, "genesis", "fake", "1"}
61+
os.Args = []string{
62+
"sonictool",
63+
"--datadir", directory,
64+
"genesis",
65+
"fake",
66+
"--statedb.livecache", "1",
67+
"--statedb.archivecache", "1",
68+
"1",
69+
}
6270
sonictool.Run()
6371
os.Args = originalArgs
6472

@@ -88,10 +96,17 @@ func (n *IntegrationTestNet) start() error {
8896
"sonicd",
8997
"--datadir", n.directory,
9098
"--fakenet", "1/1",
91-
"--http", "--http.addr", "0.0.0.0", "--http.port", "18545",
99+
"--http",
100+
"--http.addr", "0.0.0.0",
101+
"--http.port", "18545",
92102
"--http.api", "admin,eth,web3,net,txpool,ftm,trace,debug",
93-
"--ws", "--ws.addr", "0.0.0.0", "--ws.port", "18546", "--ws.api", "admin,eth,ftm",
103+
"--ws",
104+
"--ws.addr", "0.0.0.0",
105+
"--ws.port", "18546",
106+
"--ws.api", "admin,eth,ftm",
94107
"--datadir.minfreedisk", "0",
108+
"--statedb.livecache", "1",
109+
"--statedb.archivecache", "1",
95110
}
96111
sonicd.Run()
97112
}()

0 commit comments

Comments
 (0)