Skip to content

Commit

Permalink
Address reviewers feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador committed Dec 4, 2024
1 parent 98464fe commit fd02a53
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 18 deletions.
1 change: 0 additions & 1 deletion cmd/sonicd/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) {
validatorsNum,
futils.ToFtm(1000000000),
futils.ToFtm(5000000),
1024, // 1024 bytes is both small and safe value used by tests
)
defer genesisStore.Close()

Expand Down
4 changes: 1 addition & 3 deletions cmd/sonictool/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func jsonGenesisImport(ctx *cli.Context) error {
return fmt.Errorf("failed to load JSON genesis: %w", err)
}

stateDbCacheCapacity := ctx.GlobalInt(flags.StateDbCacheCapacityFlag.Name)
genesisStore, err := makefakegenesis.ApplyGenesisJson(genesisJson, stateDbCacheCapacity)
genesisStore, err := makefakegenesis.ApplyGenesisJson(genesisJson)
if err != nil {
return fmt.Errorf("failed to prepare JSON genesis: %w", err)
}
Expand Down Expand Up @@ -145,7 +144,6 @@ func fakeGenesisImport(ctx *cli.Context) error {
idx.Validator(validatorsNumber),
futils.ToFtm(1000000000),
futils.ToFtm(5000000),
ctx.GlobalInt(flags.StateDbCacheCapacityFlag.Name),
)
defer genesisStore.Close()
return genesis.ImportGenesisStore(genesis.ImportParams{
Expand Down
5 changes: 3 additions & 2 deletions config/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ var (
}
StateDbCacheCapacityFlag = cli.IntFlag{
Name: "statedb.cache",
Usage: "Size of StateDb instances cache in bytes. Leaving this blank (which is generally recommended), or setting" +
"this to <1 will automatically set the cache capacity a hard-coded constant.",
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,
}
)
1 change: 0 additions & 1 deletion gossip/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func newTestEnv(firstEpoch idx.Epoch, validatorsNum idx.Validator, tb testing.TB
rules,
firstEpoch,
2,
1024,
)
genesis := genStore.Genesis()

Expand Down
1 change: 0 additions & 1 deletion gossip/handler_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func makeFuzzedHandler() (h *handler, err error) {
genesisStakers,
utils.ToFtm(genesisBalance),
utils.ToFtm(genesisStake),
0, // 0 sets default value
)
genesis := genStore.Genesis()

Expand Down
11 changes: 5 additions & 6 deletions integration/makefakegenesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func FakeKey(n idx.ValidatorID) *ecdsa.PrivateKey {
return evmcore.FakeKey(uint32(n))
}

func FakeGenesisStore(num idx.Validator, balance, stake *big.Int, stateDbCacheCapacity int) *genesisstore.Store {
return FakeGenesisStoreWithRules(num, balance, stake, opera.FakeNetRules(), stateDbCacheCapacity)
func FakeGenesisStore(num idx.Validator, balance, stake *big.Int) *genesisstore.Store {
return FakeGenesisStoreWithRules(num, balance, stake, opera.FakeNetRules())
}

func FakeGenesisStoreWithRules(num idx.Validator, balance, stake *big.Int, rules opera.Rules, stateDbCacheCapacity int) *genesisstore.Store {
return FakeGenesisStoreWithRulesAndStart(num, balance, stake, rules, 2, 1, stateDbCacheCapacity)
func FakeGenesisStoreWithRules(num idx.Validator, balance, stake *big.Int, rules opera.Rules) *genesisstore.Store {
return FakeGenesisStoreWithRulesAndStart(num, balance, stake, rules, 2, 1)
}

func FakeGenesisStoreWithRulesAndStart(
Expand All @@ -56,9 +56,8 @@ func FakeGenesisStoreWithRulesAndStart(
rules opera.Rules,
epoch idx.Epoch,
block idx.Block,
stateDbCacheCapacity int,
) *genesisstore.Store {
builder := makegenesis.NewGenesisBuilder(stateDbCacheCapacity)
builder := makegenesis.NewGenesisBuilder()

validators := GetFakeValidators(num)

Expand Down
4 changes: 2 additions & 2 deletions integration/makefakegenesis/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func LoadGenesisJson(filename string) (*GenesisJson, error) {
return &decoded, nil
}

func ApplyGenesisJson(json *GenesisJson, stateDbCacheCapacity int) (*genesisstore.Store, error) {
func ApplyGenesisJson(json *GenesisJson) (*genesisstore.Store, error) {
if json.BlockZeroTime.IsZero() {
return nil, fmt.Errorf("block zero time must be set")
}

builder := makegenesis.NewGenesisBuilder(stateDbCacheCapacity)
builder := makegenesis.NewGenesisBuilder()

fmt.Printf("Building genesis file - rules: %+v\n", json.Rules)

Expand Down
5 changes: 3 additions & 2 deletions integration/makegenesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (b *GenesisBuilder) CurrentHash() hash.Hash {
return er.Hash()
}

func NewGenesisBuilder(stateDbCacheCapacity int) *GenesisBuilder {
func NewGenesisBuilder() *GenesisBuilder {
carmenDir, err := os.MkdirTemp("", "opera-tmp-genesis")
if err != nil {
panic(fmt.Errorf("failed to create temporary dir for GenesisBuilder: %v", err))
Expand All @@ -128,7 +128,8 @@ func NewGenesisBuilder(stateDbCacheCapacity int) *GenesisBuilder {
if err != nil {
panic(fmt.Errorf("failed to create carmen state; %s", err))
}
carmenStateDb := carmen.CreateCustomStateDBUsing(carmenState, stateDbCacheCapacity)
// Set cache size to lowest value possible
carmenStateDb := carmen.CreateCustomStateDBUsing(carmenState, 1024)
tmpStateDB := evmstore.CreateCarmenStateDb(carmenStateDb)
return &GenesisBuilder{
tmpStateDB: tmpStateDB,
Expand Down

0 comments on commit fd02a53

Please sign in to comment.