Skip to content

Commit

Permalink
Fixes to foundry connections and configs (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG authored Apr 24, 2024
1 parent 3d0df6a commit 34241fb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 50 deletions.
48 changes: 21 additions & 27 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const (
Base64NetworkConfigEnvVarName = "BASE64_NETWORK_CONFIG"
)

type ForkConfig struct {
URL string `toml:"url"` // URL is the URL of the node to fork from. Refer to https://book.getfoundry.sh/reference/anvil/#options
BlockNumber int64 `toml:"block_number"` // BlockNumber is the block number to fork from. Refer to https://book.getfoundry.sh/reference/anvil/#options
BlockTime int64 `toml:"block_time"` // how frequent blocks are mined. By default, it automatically generates a new block as soon as a transaction is submitted. Refer to https://book.getfoundry.sh/reference/anvil/#options
Retries int `toml:"retries,omitempty"` // Number of retry requests for spurious networks (timed out requests). Refer to https://book.getfoundry.sh/reference/anvil/#options
Timeout int64 `toml:"timeout,omitempty"` // Timeout in ms for requests sent to remote JSON-RPC server in forking mode. Refer to https://book.getfoundry.sh/reference/anvil/#options
ComputePerSecond int64 `toml:"compute_per_second,omitempty"` // Sets the number of assumed available compute units per second for this provider. Refer to https://book.getfoundry.sh/reference/anvil/#options
RateLimitEnabled bool `toml:"rate_limit_enabled,omitempty"` // rate limiting for this node’s provider. Refer to https://book.getfoundry.sh/reference/anvil/#options
type AnvilConfig struct {
URL *string `toml:"url,omitempty"` // Needed if you want to fork a network. URL is the URL of the node to fork from. Refer to https://book.getfoundry.sh/reference/anvil/#options
BlockNumber *int64 `toml:"block_number,omitempty"` // Needed if fork URL is provided for forking. BlockNumber is the block number to fork from. Refer to https://book.getfoundry.sh/reference/anvil/#options
BlockTime *int64 `toml:"block_time,omitempty"` // how frequent blocks are mined. By default, it automatically generates a new block as soon as a transaction is submitted. Refer to https://book.getfoundry.sh/reference/anvil/#options
Retries *int `toml:"retries,omitempty"` // Needed if fork URL is provided for forking. Number of retry requests for spurious networks (timed out requests). Refer to https://book.getfoundry.sh/reference/anvil/#options
Timeout *int64 `toml:"timeout,omitempty"` // Needed if fork URL is provided for forking. Timeout in ms for requests sent to remote JSON-RPC server in forking mode. Refer to https://book.getfoundry.sh/reference/anvil/#options
ComputePerSecond *int64 `toml:"compute_per_second,omitempty"` // Needed if fork URL is provided for forking. Sets the number of assumed available compute units per second for this provider. Refer to https://book.getfoundry.sh/reference/anvil/#options
RateLimitDisabled *bool `toml:"rate_limit_disabled,omitempty"` // Needed if fork URL is provided for forking. Rate limiting for this node’s provider. If set to true the node will start with --no-rate-limit Refer to https://book.getfoundry.sh/reference/anvil/#options
}

// NetworkConfig is the configuration for the networks to be used
Expand All @@ -33,9 +33,9 @@ type NetworkConfig struct {
// EVMNetworks is the configuration for the EVM networks, key is the network name as declared in selected_networks slice.
// if not set, it will try to find the network from defined networks in MappedNetworks under known_networks.go
EVMNetworks map[string]*blockchain.EVMNetwork `toml:"EVMNetworks,omitempty"`
// ForkConfigs is the configuration for forking from a node,
// AnvilConfigs is the configuration for forking from a node,
// key is the network name as declared in selected_networks slice
ForkConfigs map[string]*ForkConfig `toml:"ForkConfigs,omitempty"`
AnvilConfigs map[string]*AnvilConfig `toml:"AnvilConfigs,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 Down Expand Up @@ -149,14 +149,8 @@ func (n *NetworkConfig) Validate() error {
return fmt.Errorf("chain ID for %s network must be set", name)
}
}
if n.ForkConfigs != nil {
if _, ok := n.ForkConfigs[network]; ok {
if n.ForkConfigs[network].URL == "" {
return fmt.Errorf("fork config for %s network must have a URL", network)
}
if n.ForkConfigs[network].BlockNumber == 0 {
return fmt.Errorf("fork config for %s network must have a block number", network)
}
if n.AnvilConfigs != nil {
if _, ok := n.AnvilConfigs[network]; ok {
// we don't need to validate RPC endpoints or private keys for forked networks
continue
}
Expand Down Expand Up @@ -203,10 +197,10 @@ func (n *NetworkConfig) UpperCaseNetworkNames() {
}
}

for network := range n.ForkConfigs {
for network := range n.AnvilConfigs {
if network != strings.ToUpper(network) {
n.ForkConfigs[strings.ToUpper(network)] = n.ForkConfigs[network]
delete(n.ForkConfigs, network)
n.AnvilConfigs[strings.ToUpper(network)] = n.AnvilConfigs[network]
delete(n.AnvilConfigs, network)
}
}

Expand Down Expand Up @@ -234,13 +228,13 @@ func (n *NetworkConfig) applyDefaults(defaults *NetworkConfig) error {
}
}
}
if defaults.ForkConfigs != nil {
if n.ForkConfigs == nil || len(n.ForkConfigs) == 0 {
n.ForkConfigs = defaults.ForkConfigs
if defaults.AnvilConfigs != nil {
if n.AnvilConfigs == nil || len(n.AnvilConfigs) == 0 {
n.AnvilConfigs = defaults.AnvilConfigs
} else {
for network, cfg := range defaults.ForkConfigs {
if _, ok := n.ForkConfigs[network]; !ok {
n.ForkConfigs[network] = cfg
for network, cfg := range defaults.AnvilConfigs {
if _, ok := n.AnvilConfigs[network]; !ok {
n.AnvilConfigs[network] = cfg
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions k8s/pkg/helm/foundry/foundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package foundry

import (
"fmt"
"net/url"
"strings"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -62,26 +63,29 @@ func (m Chart) ExportData(e *environment.Environment) error {
if err != nil {
return err
}
localWs, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.LocalConnection, client.WS)
parsed, err := url.Parse(internalHttp)
if err != nil {
return err
}
internalWs, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.RemoteConnection, client.WS)
port := parsed.Port()
localWs, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.LocalConnection, client.WS)
if err != nil {
return err
}
if e.Cfg.InsideK8s {
services, err := e.Client.ListServices(e.Cfg.Namespace, fmt.Sprintf("app=%s-%s", m.Props.NetworkName, ChartName))
if err != nil {
return err
}
internalWs := fmt.Sprintf("ws://%s:%s", services.Items[0].Name, port)
internalHttp = fmt.Sprintf("http://%s:%s", services.Items[0].Name, port)
e.URLs[m.Props.NetworkName] = []string{internalWs}
e.URLs[m.Props.NetworkName+"_http"] = []string{internalHttp}
} else {
e.URLs[m.Props.NetworkName] = []string{localWs}
e.URLs[m.Props.NetworkName+"_http"] = []string{localHttp}
}

// For cases like starknet we need the internalHttp address to set up the L1<>L2 interaction
e.URLs[m.Props.NetworkName+"_internal"] = []string{internalWs}
e.URLs[m.Props.NetworkName+"_internal_http"] = []string{internalHttp}

for k, v := range e.URLs {
if strings.Contains(k, m.Props.NetworkName) {
log.Info().Str("Name", k).Strs("URLs", v).Msg("Forked network")
Expand Down Expand Up @@ -109,17 +113,18 @@ func defaultProps() *Props {
}
}

func New(props Props) environment.ConnectedChart {
func New(props *Props) environment.ConnectedChart {
return NewVersioned("", props)
}

// NewVersioned enables choosing a specific helm chart version
func NewVersioned(helmVersion string, props Props) environment.ConnectedChart {
func NewVersioned(helmVersion string, props *Props) environment.ConnectedChart {
dp := defaultProps()
config.MustMerge(dp, props)
config.MustMerge(&dp.Values, props.Values)
dp.NetworkName = strings.ReplaceAll(strings.ToLower(dp.NetworkName), " ", "-")
return Chart{
Name: strings.ReplaceAll(strings.ToLower(props.NetworkName), " ", "-"),
Name: dp.NetworkName,
Path: "chainlink-qa/foundry",
Values: &dp.Values,
Props: dp,
Expand Down
6 changes: 0 additions & 6 deletions k8s/pkg/helm/reorg/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/utils/projectpath"
)

const (
URLsKey = "geth"
TXNodesAppLabel = "geth-ethereum-geth"
MinerNodesAppLabel = "geth-ethereum-miner-node" // #nosec G101
)

type Props struct {
NetworkName string `envconfig:"network_name"`
NetworkType string `envconfig:"network_type"`
Expand Down
4 changes: 2 additions & 2 deletions networks/known_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro
var walletKeys, httpUrls, wsUrls []string
networkName := strings.ToUpper(selectedNetworks[i])
forked := false
if networkCfg.ForkConfigs != nil {
_, forked = networkCfg.ForkConfigs[networkName]
if networkCfg.AnvilConfigs != nil {
_, forked = networkCfg.AnvilConfigs[networkName]
}
// if network is not simulated or forked, use the rpc urls and wallet keys from config
if !strings.Contains(networkName, "SIMULATED") && !forked {
Expand Down
12 changes: 6 additions & 6 deletions networks/known_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,18 @@ evm_default_gas_limit = 6000000
networkConfigTOML: `
selected_networks = ["KROMA_SEPOLIA"]
[ForkConfigs.kroma_SEPOLIA]
[AnvilConfigs.kroma_SEPOLIA]
url = "ws://localhost:8546"
block_number = 100
`,
expNetworks: []blockchain.EVMNetwork{KromaSepolia},
},
{
name: "override with new ForkConfigs and new EVMNetworks",
name: "override with new AnvilConfigs and new EVMNetworks",
networkConfigTOML: `
selected_networks = ["KROMA_SEPOLIA","NEW_NETWORK"]
[ForkConfigs.KROMA_SEPOLIA]
[AnvilConfigs.KROMA_SEPOLIA]
url = "ws://localhost:8546"
block_number = 100
`,
Expand All @@ -341,7 +341,7 @@ evm_gas_estimation_buffer = 10000
evm_supports_eip1559 = true
evm_default_gas_limit = 6000000
[ForkConfigs.new_network]
[AnvilConfigs.new_network]
url = "ws://localhost:8546"
block_number = 100
`,
Expand All @@ -352,7 +352,7 @@ block_number = 100
networkConfigTOML: `
selected_networks = ["KROMA_SEPOLIA"]
[ForkConfigs.KROMA_SEPOLIA]
[AnvilConfigs.KROMA_SEPOLIA]
url = "ws://localhost:8546"
block_number = 100
`,
Expand All @@ -375,7 +375,7 @@ evm_gas_estimation_buffer = 10000
evm_supports_eip1559 = true
evm_default_gas_limit = 6000000
[ForkConfigs.new_network]
[AnvilConfigs.new_network]
url = "ws://localhost:8546"
block_number = 100
`,
Expand Down

0 comments on commit 34241fb

Please sign in to comment.