Skip to content

Commit

Permalink
Add configuration argument to decrease checkpoint interval
Browse files Browse the repository at this point in the history
This makes possible introduce early checkpoints and test sonictool heal options.
  • Loading branch information
LuisPH3 committed Dec 23, 2024
1 parent 1cc2285 commit 816d313
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
1 change: 1 addition & 0 deletions cmd/sonicd/app/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func initFlags() {
flags.LiveDbCacheFlag,
flags.ArchiveCacheFlag,
flags.StateDbCacheCapacityFlag,
flags.StateDbCheckPointInterval,
}
networkingFlags = []cli.Flag{
flags.BootnodesFlag,
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ func MakeAllConfigsFromFile(ctx *cli.Context, configFile string) (*Config, error
cfg.OperaStore.EVM.Cache.StateDbCapacity = ctx.GlobalInt(flags.StateDbCacheCapacityFlag.Name)
}

if ctx.IsSet(flags.StateDbCheckPointInterval.Name) {
cfg.OperaStore.EVM.StateDb.CheckpointInterval = ctx.GlobalInt(flags.StateDbCheckPointInterval.Name)
}

return &cfg, nil
}

Expand Down
11 changes: 9 additions & 2 deletions config/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ var (
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 pre-confugired cache capacity of 2KB", CacheFlag.Name),
"Setting this value to <=2000 will result in pre-configured cache capacity of 2KB", CacheFlag.Name),
Value: 0,
}
ArchiveCacheFlag = cli.IntFlag{
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 pre-confugired cache capacity of 2KB", CacheFlag.Name),
"Setting this value to <=2000 will result in pre-configured cache capacity of 2KB", CacheFlag.Name),
Value: 0,
}
StateDbCacheCapacityFlag = cli.IntFlag{
Expand All @@ -372,4 +372,11 @@ var (
"is recommended. Setting this to <1 will automatically set the cache capacity to a DB defined default value.",
Value: 0,
}
StateDbCheckPointInterval = cli.IntFlag{
Name: "statedb.checkpointinterval",
Hidden: true, // Intended for testing
Usage: "The number of blocks after which a db healing checkpoint will be created. " +
"Setting this to <1 will automatically set the value to a DB defined default.",
Value: 0,
}
)
43 changes: 24 additions & 19 deletions tests/integration_test_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ import (
// integration test networks can also be used for automated integration and
// regression tests for client code.
type IntegrationTestNet struct {
directory string
done <-chan struct{}
validator Account
httpPort int
wsPort int
directory string
done <-chan struct{}
validator Account
httpPort int
wsPort int
extraArguments []string
}

func isPortFree(host string, port int) bool {
Expand Down Expand Up @@ -91,13 +92,11 @@ func getFreePort() (int, error) {
// The node serving the network is started in the same process as the caller. This
// is intended to facilitate debugging of client code in the context of a running
// node.
func StartIntegrationTestNet(directory string) (*IntegrationTestNet, error) {
return startIntegrationTestNet(directory, []string{
"genesis", "fake", "1",
})
func StartIntegrationTestNet(directory string, extraArguments ...string) (*IntegrationTestNet, error) {
return startIntegrationTestNet(directory, []string{"genesis", "fake", "1"}, extraArguments)
}

func StartIntegrationTestNetFromJsonGenesis(directory string) (*IntegrationTestNet, error) {
func StartIntegrationTestNetFromJsonGenesis(directory string, extraArguments ...string) (*IntegrationTestNet, error) {
jsonGenesis := makefakegenesis.GenesisJson{
Rules: opera.FakeNetRules(),
BlockZeroTime: time.Now(),
Expand Down Expand Up @@ -181,16 +180,18 @@ func StartIntegrationTestNetFromJsonGenesis(directory string) (*IntegrationTestN
if err != nil {
return nil, fmt.Errorf("failed to write genesis.json file: %w", err)
}
return startIntegrationTestNet(directory, []string{
"genesis", "json", "--experimental", jsonFile,
})
return startIntegrationTestNet(directory,
[]string{"genesis", "json", "--experimental", jsonFile},
extraArguments,
)
}

func startIntegrationTestNet(directory string, args []string) (*IntegrationTestNet, error) {
func startIntegrationTestNet(directory string, sonicToolArguments []string, extraArguments []string) (*IntegrationTestNet, error) {
// start the fakenet sonic node
result := &IntegrationTestNet{
directory: directory,
validator: Account{evmcore.FakeKey(1)},
directory: directory,
validator: Account{evmcore.FakeKey(1)},
extraArguments: extraArguments,
}

// initialize the data directory for the single node on the test network
Expand All @@ -202,7 +203,7 @@ func startIntegrationTestNet(directory string, args []string) (*IntegrationTestN
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}, args...)
}, sonicToolArguments...)
if err := sonictool.Run(); err != nil {
os.Args = originalArgs
return nil, fmt.Errorf("failed to initialize the test network: %w", err)
Expand Down Expand Up @@ -247,7 +248,7 @@ func (n *IntegrationTestNet) start() error {

// start the fakenet sonic node
// equivalent to running `sonicd ...` but in this local process
os.Args = []string{
os.Args = append([]string{
"sonicd",

// data storage options
Expand All @@ -274,7 +275,11 @@ func (n *IntegrationTestNet) start() error {
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}
},

// append extra arguments
n.extraArguments...,
)

err := sonicd.Run()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions tests/sonittool_test.go → tests/sonictool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ func TestSonicTool_genesis_ExecutesWithoutErrors(t *testing.T) {
}

func TestSonicTool_heal_ExecutesWithoutErrors(t *testing.T) {
net, err := StartIntegrationTestNet(t.TempDir())
net, err := StartIntegrationTestNet(t.TempDir(),
"--statedb.checkpointinterval", "1")
require.NoError(t, err)
for range 2 {
for range 3 {
createAccount(t, net)
}
net.Stop()

_, err = executeSonicTool(t,
"--datadir", net.directory+"/state",
"check", "archive")
_, err = executeSonicTool(t, "--datadir", net.directory+"/state", "heal")
require.NoError(t, err)
}

func TestSonicTool_config_ExecutesWithoutErrors(t *testing.T) {

net, err := StartIntegrationTestNet(t.TempDir())
require.NoError(t, err)
for range 2 {
Expand Down

0 comments on commit 816d313

Please sign in to comment.