Skip to content

Commit

Permalink
Lower memory consumption for integration tests. (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador authored Dec 4, 2024
1 parent 2494188 commit 4a2d82b
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/sonicd/app/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func initFlags() {
flags.CacheFlag,
flags.LiveDbCacheFlag,
flags.ArchiveCacheFlag,
flags.StateDbCacheCapacityFlag,
}
networkingFlags = []cli.Flag{
flags.BootnodesFlag,
Expand Down
6 changes: 5 additions & 1 deletion cmd/sonicd/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func tmpdir(t *testing.T) string {
}

func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) {
genesisStore := makefakegenesis.FakeGenesisStore(validatorsNum, futils.ToFtm(1000000000), futils.ToFtm(5000000))
genesisStore := makefakegenesis.FakeGenesisStore(
validatorsNum,
futils.ToFtm(1000000000),
futils.ToFtm(5000000),
)
defer genesisStore.Close()

if err := genesis.ImportGenesisStore(genesis.ImportParams{
Expand Down
7 changes: 6 additions & 1 deletion cmd/sonictool/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func jsonGenesisImport(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to load JSON genesis: %w", err)
}

genesisStore, err := makefakegenesis.ApplyGenesisJson(genesisJson)
if err != nil {
return fmt.Errorf("failed to prepare JSON genesis: %w", err)
Expand Down Expand Up @@ -139,7 +140,11 @@ func fakeGenesisImport(ctx *cli.Context) error {
return err
}

genesisStore := makefakegenesis.FakeGenesisStore(idx.Validator(validatorsNumber), futils.ToFtm(1000000000), futils.ToFtm(5000000))
genesisStore := makefakegenesis.FakeGenesisStore(
idx.Validator(validatorsNumber),
futils.ToFtm(1000000000),
futils.ToFtm(5000000),
)
defer genesisStore.Close()
return genesis.ImportGenesisStore(genesis.ImportParams{
GenesisStore: genesisStore,
Expand Down
1 change: 1 addition & 0 deletions cmd/sonictool/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Run() error {
flags.CacheFlag,
flags.LiveDbCacheFlag,
flags.ArchiveCacheFlag,
flags.StateDbCacheCapacityFlag,
}
app.Commands = []cli.Command{
{
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ func MakeAllConfigsFromFile(ctx *cli.Context, configFile string) (*Config, error
cfg.Lachesis.SuppressFramePanic = true
}

if ctx.IsSet(flags.StateDbCacheCapacityFlag.Name) {
cfg.OperaStore.EVM.Cache.StateDbCapacity = ctx.GlobalInt(flags.StateDbCacheCapacityFlag.Name)
}

return &cfg, nil
}

Expand Down
7 changes: 7 additions & 0 deletions config/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,11 @@ var (
"Setting this value to <=2000 will result in pre-confugired cache capacity of 2KB", CacheFlag.Name),
Value: 0,
}
StateDbCacheCapacityFlag = cli.IntFlag{
Name: "statedb.cache",
Usage: "The number of cached data elements by each StateDb instance. Since this is an experimental feature " +
"used mainly by tests it is generally recommended leaving this blank. In tests no value lower than 1024 " +
"is recommended. Setting this to <1 will automatically set the cache capacity to a DB defined default value.",
Value: 0,
}
)
9 changes: 8 additions & 1 deletion gossip/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ func newTestEnv(firstEpoch idx.Epoch, validatorsNum idx.Validator, tb testing.TB
rules.Blocks.MaxEmptyBlockSkipPeriod = 0
rules.Emitter.Interval = 0

genStore := makefakegenesis.FakeGenesisStoreWithRulesAndStart(validatorsNum, utils.ToFtm(genesisBalance), utils.ToFtm(genesisStake), rules, firstEpoch, 2)
genStore := makefakegenesis.FakeGenesisStoreWithRulesAndStart(
validatorsNum,
utils.ToFtm(genesisBalance),
utils.ToFtm(genesisStake),
rules,
firstEpoch,
2,
)
genesis := genStore.Genesis()

store, err := NewMemStore(tb)
Expand Down
12 changes: 7 additions & 5 deletions gossip/evmstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type (
EvmBlocksNum int
// Cache size for EvmBlock (size in bytes).
EvmBlocksSize uint
// Cache size for StateDb instances (0 for DB-selected default)
StateDbCapacity int
}
// StoreConfig is a config for store db.
StoreConfig struct {
Expand All @@ -38,11 +40,11 @@ type (
func DefaultStoreConfig(scale cachescale.Func) StoreConfig {
return StoreConfig{
Cache: StoreCacheConfig{
ReceiptsSize: scale.U(4 * opt.MiB),
ReceiptsBlocks: scale.I(4000),
TxPositions: scale.I(20000),
EvmBlocksNum: scale.I(5000),
EvmBlocksSize: scale.U(6 * opt.MiB),
ReceiptsSize: scale.U(4 * opt.MiB),
ReceiptsBlocks: scale.I(4000),
TxPositions: scale.I(20000),
EvmBlocksNum: scale.I(5000),
EvmBlocksSize: scale.U(6 * opt.MiB),
},
StateDb: carmen.Parameters{
Variant: "go-file",
Expand Down
2 changes: 1 addition & 1 deletion gossip/evmstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *Store) Open() error {
if err != nil {
return fmt.Errorf("failed to create carmen state; %s", err)
}
s.liveStateDb = carmen.CreateStateDBUsing(s.carmenState)
s.liveStateDb = carmen.CreateCustomStateDBUsing(s.carmenState, s.cfg.Cache.StateDbCapacity)
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion gossip/handler_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func makeFuzzedHandler() (h *handler, err error) {
genesisStake = 2 * 4e6
)

genStore := makefakegenesis.FakeGenesisStore(genesisStakers, utils.ToFtm(genesisBalance), utils.ToFtm(genesisStake))
genStore := makefakegenesis.FakeGenesisStore(
genesisStakers,
utils.ToFtm(genesisBalance),
utils.ToFtm(genesisStake),
)
genesis := genStore.Genesis()

config := DefaultConfig(cachescale.Identity)
Expand Down
8 changes: 7 additions & 1 deletion integration/makefakegenesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ func FakeGenesisStoreWithRules(num idx.Validator, balance, stake *big.Int, rules
return FakeGenesisStoreWithRulesAndStart(num, balance, stake, rules, 2, 1)
}

func FakeGenesisStoreWithRulesAndStart(num idx.Validator, balance, stake *big.Int, rules opera.Rules, epoch idx.Epoch, block idx.Block) *genesisstore.Store {
func FakeGenesisStoreWithRulesAndStart(
num idx.Validator,
balance, stake *big.Int,
rules opera.Rules,
epoch idx.Epoch,
block idx.Block,
) *genesisstore.Store {
builder := makegenesis.NewGenesisBuilder()

validators := GetFakeValidators(num)
Expand Down
3 changes: 2 additions & 1 deletion integration/makegenesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func NewGenesisBuilder() *GenesisBuilder {
if err != nil {
panic(fmt.Errorf("failed to create carmen state; %s", err))
}
carmenStateDb := carmen.CreateStateDBUsing(carmenState)
// Set cache size to lowest value possible
carmenStateDb := carmen.CreateCustomStateDBUsing(carmenState, 1024)
tmpStateDB := evmstore.CreateCarmenStateDb(carmenStateDb)
return &GenesisBuilder{
tmpStateDB: tmpStateDB,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_test_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,14 @@ func startIntegrationTestNet(directory string, args []string) (*IntegrationTestN
"--datadir", result.stateDir(),
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}, 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)
}
Expand Down Expand Up @@ -274,6 +273,7 @@ func (n *IntegrationTestNet) start() error {
// database memory usage options
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}

err := sonicd.Run()
Expand Down

0 comments on commit 4a2d82b

Please sign in to comment.