diff --git a/charts/foundry/Chart.yaml b/charts/foundry/Chart.yaml index d67b36768..2393e40a2 100644 --- a/charts/foundry/Chart.yaml +++ b/charts/foundry/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: foundry description: A Helm chart for foundry, mostly used to run Anvil node type: application -version: 0.1.8 +version: 0.1.9 appVersion: 'latest' diff --git a/charts/foundry/templates/_helpers.tpl b/charts/foundry/templates/_helpers.tpl index d413ea63a..94afd0e8d 100644 --- a/charts/foundry/templates/_helpers.tpl +++ b/charts/foundry/templates/_helpers.tpl @@ -8,20 +8,15 @@ Expand the name of the chart. {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. */}} {{- define "foundry.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} {{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} {{- end }} {{- end }} -{{- end }} {{/* Create chart name and version as used by the chart label. diff --git a/k8s/pkg/helm/foundry/foundry.go b/k8s/pkg/helm/foundry/foundry.go index 348d03ae7..4619f2c94 100644 --- a/k8s/pkg/helm/foundry/foundry.go +++ b/k8s/pkg/helm/foundry/foundry.go @@ -2,7 +2,6 @@ package foundry import ( "fmt" - "net/url" "strings" "github.com/rs/zerolog/log" @@ -17,16 +16,20 @@ const ( ) type Props struct { - NetworkName string - Values map[string]interface{} + Values map[string]interface{} } type Chart struct { - Name string - Path string - Version string - Props *Props - Values *map[string]any + ServiceName string + AppLabel string + Path string + Version string + Props *Props + Values *map[string]any + ClusterWSURL string + ClusterHTTPURL string + ForwardedWSURL string + ForwardedHTTPURL string } func (m Chart) IsDeploymentNeeded() bool { @@ -34,7 +37,7 @@ func (m Chart) IsDeploymentNeeded() bool { } func (m Chart) GetName() string { - return m.Name + return ChartName } func (m Chart) GetPath() string { @@ -53,42 +56,26 @@ func (m Chart) GetValues() *map[string]interface{} { return m.Values } -func (m Chart) ExportData(e *environment.Environment) error { - podName := fmt.Sprintf("%s-%s:0", m.Props.NetworkName, ChartName) - localHttp, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.LocalConnection, client.HTTP) +func (m *Chart) ExportData(e *environment.Environment) error { + appInstance := fmt.Sprintf("%s:0", m.ServiceName) // uniquely identifies an instance of an anvil service running in a pod + var err error + m.ForwardedHTTPURL, err = e.Fwd.FindPort(appInstance, ChartName, "http").As(client.LocalConnection, client.HTTP) if err != nil { return err } - internalHttp, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.RemoteConnection, client.HTTP) + m.ForwardedWSURL, err = e.Fwd.FindPort(appInstance, ChartName, "http").As(client.LocalConnection, client.WS) if err != nil { return err } - parsed, err := url.Parse(internalHttp) - if err != nil { - return err - } - 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} - } + + e.URLs[appInstance+"_cluster_ws"] = []string{m.ClusterWSURL} + e.URLs[appInstance+"_cluster_http"] = []string{m.ClusterHTTPURL} + e.URLs[appInstance+"_forwarded_ws"] = []string{m.ForwardedWSURL} + e.URLs[appInstance+"_forwarded_http"] = []string{m.ForwardedHTTPURL} for k, v := range e.URLs { - if strings.Contains(k, m.Props.NetworkName) { - log.Info().Str("Name", k).Strs("URLs", v).Msg("Forked network") + if strings.Contains(k, appInstance) { + log.Info().Str("Name", k).Strs("URLs", v).Msg("Anvil URLs") } } @@ -97,7 +84,6 @@ func (m Chart) ExportData(e *environment.Environment) error { func defaultProps() *Props { return &Props{ - NetworkName: "fork", Values: map[string]any{ "replicaCount": "1", "anvil": map[string]any{ @@ -113,21 +99,33 @@ func defaultProps() *Props { } } -func New(props *Props) environment.ConnectedChart { +func New(props *Props) *Chart { 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) *Chart { dp := defaultProps() config.MustMerge(dp, props) config.MustMerge(&dp.Values, props.Values) - dp.NetworkName = strings.ReplaceAll(strings.ToLower(dp.NetworkName), " ", "-") - return Chart{ - Name: dp.NetworkName, - Path: "chainlink-qa/foundry", - Values: &dp.Values, - Props: dp, - Version: helmVersion, + var serviceName, appLabel string + // If fullnameOverride is set it is used as the service name and app label + if props.Values["fullnameOverride"] != nil { + serviceName = dp.Values["fullnameOverride"].(string) + appLabel = fmt.Sprintf("app=%s", dp.Values["fullnameOverride"].(string)) + } else { + serviceName = ChartName + appLabel = fmt.Sprintf("app=%s", ChartName) + } + anvilValues := dp.Values["anvil"].(map[string]any) + return &Chart{ + ServiceName: serviceName, + ClusterWSURL: fmt.Sprintf("ws://%s:%s", serviceName, anvilValues["port"].(string)), + ClusterHTTPURL: fmt.Sprintf("http://%s:%s", serviceName, anvilValues["port"].(string)), + AppLabel: appLabel, + Path: "chainlink-qa/foundry", + Values: &dp.Values, + Props: dp, + Version: helmVersion, } } diff --git a/networks/known_networks.go b/networks/known_networks.go index b24df25e4..8e6e0db9a 100644 --- a/networks/known_networks.go +++ b/networks/known_networks.go @@ -148,6 +148,25 @@ var ( GasEstimationBuffer: 10000, } + Anvil = blockchain.EVMNetwork{ + Name: "Anvil", + Simulated: true, + SupportsEIP1559: true, + ClientImplementation: blockchain.EthereumClientImplementation, + ChainID: 31337, + PrivateKeys: []string{ + "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", + "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", + "5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", + "7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", + "47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a", + }, + ChainlinkTransactionLimit: 500000, + Timeout: blockchain.StrDuration{Duration: 2 * time.Minute}, + MinimumConfirmations: 1, + GasEstimationBuffer: 10000, + } + EthereumMainnet blockchain.EVMNetwork = blockchain.EVMNetwork{ Name: "Ethereum Mainnet", SupportsEIP1559: true, @@ -859,6 +878,7 @@ var ( MappedNetworks = map[string]blockchain.EVMNetwork{ "SIMULATED": SimulatedEVM, + "ANVIL": Anvil, "SIMULATED_1": SimulatedEVMNonDev1, "SIMULATED_2": SimulatedEVMNonDev2, "SIMULATED_BESU_NONDEV_1": SimulatedBesuNonDev1, diff --git a/utils/seth/seth.go b/utils/seth/seth.go index 388a6f6f3..89d97ea88 100644 --- a/utils/seth/seth.go +++ b/utils/seth/seth.go @@ -149,7 +149,7 @@ func MergeSethAndEvmNetworkConfigs(evmNetwork blockchain.EVMNetwork, sethConfig for _, conf := range sethConfig.Networks { if evmNetwork.Simulated { - if conf.Name == pkg_seth.GETH { + if conf.Name == pkg_seth.GETH || conf.Name == pkg_seth.ANVIL { conf.PrivateKeys = evmNetwork.PrivateKeys if len(conf.URLs) == 0 { conf.URLs = evmNetwork.URLs