Skip to content

Commit

Permalink
Update Anvil (#979)
Browse files Browse the repository at this point in the history
* Add anvil to known networks

* Allow custom names in foundry chart and save urls

* Fix foundry helm wrapper

* Revert change in seth

* Update Anvil network name to match name set in Seth

* Fix exported urls

* Bump chart version
  • Loading branch information
lukaszcl committed Jun 5, 2024
1 parent 65293ba commit 404d898
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion charts/foundry/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
5 changes: 0 additions & 5 deletions charts/foundry/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
92 changes: 45 additions & 47 deletions k8s/pkg/helm/foundry/foundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package foundry

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

"github.com/rs/zerolog/log"
Expand All @@ -17,24 +16,28 @@ 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 {
return true
}

func (m Chart) GetName() string {
return m.Name
return ChartName
}

func (m Chart) GetPath() string {
Expand All @@ -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")
}
}

Expand All @@ -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{
Expand All @@ -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,
}
}
20 changes: 20 additions & 0 deletions networks/known_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion utils/seth/seth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 404d898

Please sign in to comment.