Skip to content

Commit

Permalink
Address reviewers feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador committed Nov 26, 2024
1 parent 371d0a4 commit e64997f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
10 changes: 6 additions & 4 deletions cmd/sonicd/app/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions cmd/sonictool/app/export_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/sonictool/chain/export_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
30 changes: 18 additions & 12 deletions cmd/sonictool/db/dbutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/sonictool/genesis/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 13 additions & 4 deletions config/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package flags

import (
"fmt"
"strings"

"github.com/Fantom-foundation/go-opera/evmcore"
Expand Down Expand Up @@ -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,
}
)

0 comments on commit e64997f

Please sign in to comment.