Skip to content

Commit

Permalink
Add GethReorgConfig to Network (#983)
Browse files Browse the repository at this point in the history
* Add GethReorgConfig configuration for handling reorgs on Simulated Geth

* Always set detachRunner and InsideK8s config fields
  • Loading branch information
lukaszcl authored Jun 11, 2024
1 parent 4e243a6 commit 5eea86e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 17 additions & 0 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type NetworkConfig struct {
// AnvilConfigs is the configuration for forking from a node,
// key is the network name as declared in selected_networks slice
AnvilConfigs map[string]*AnvilConfig `toml:"AnvilConfigs,omitempty"`
// GethReorgConfig is the configuration for handling reorgs on Simulated Geth
GethReorgConfig ReorgConfig `toml:"GethReorgConfig,omitempty"`
// RpcHttpUrls is the RPC HTTP endpoints for each network,
// key is the network name as declared in selected_networks slice
RpcHttpUrls map[string][]string `toml:"RpcHttpUrls,omitempty"`
Expand All @@ -52,6 +54,21 @@ type NetworkConfig struct {
WalletKeys map[string][]string `toml:"WalletKeys,omitempty"`
}

type ReorgConfig struct {
Enabled bool `toml:"enabled,omitempty"`
Depth int `toml:"depth,omitempty"`
DelayCreate blockchain.StrDuration `toml:"delay_create,omitempty"` // Delay before creating, expressed in Go duration format (e.g., "1m", "30s")
}

func (n NetworkConfig) IsSimulatedGethSelected() bool {
for _, network := range n.SelectedNetworks {
if strings.ToLower(network) == "simulated" {
return true
}
}
return false
}

func (n *NetworkConfig) applySecrets() error {
encodedEndpoints, isSet := os.LookupEnv(Base64NetworkConfigEnvVarName)
if !isSet {
Expand Down
10 changes: 3 additions & 7 deletions k8s/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,9 @@ func New(cfg *Config) *Environment {
targetCfg.Namespace = fmt.Sprintf("%s-%s", targetCfg.NamespacePrefix, uuid.NewString()[0:5])
log.Info().Str("Namespace", targetCfg.Namespace).Msg("Creating new namespace")
}
jobImage := os.Getenv(config.EnvVarJobImage)
if jobImage != "" {
targetCfg.JobImage = jobImage
targetCfg.detachRunner, _ = strconv.ParseBool(os.Getenv(config.EnvVarDetachRunner))
} else {
targetCfg.InsideK8s, _ = strconv.ParseBool(os.Getenv(config.EnvVarInsideK8s))
}
targetCfg.JobImage = os.Getenv(config.EnvVarJobImage)
targetCfg.detachRunner, _ = strconv.ParseBool(os.Getenv(config.EnvVarDetachRunner))
targetCfg.InsideK8s, _ = strconv.ParseBool(os.Getenv(config.EnvVarInsideK8s))

c, err := client.NewK8sClient()
if err != nil {
Expand Down

0 comments on commit 5eea86e

Please sign in to comment.