Skip to content

Commit

Permalink
feat(cl-mimicy): Support custom networks
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed May 13, 2024
1 parent 9e10117 commit 0ac4a56
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/ethpandaops/xatu

go 1.22.0

replace github.com/probe-lab/hermes => github.com/ethpandaops/hermes v0.0.0-20240508034827-0c42cafd65a5
replace github.com/probe-lab/hermes => github.com/ethpandaops/hermes v0.0.0-20240513080348-eafb396a7027

require (
github.com/IBM/sarama v1.43.0
Expand Down Expand Up @@ -31,7 +31,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/probe-lab/hermes v0.0.0-20240327153144-a2528356b4f7
github.com/prometheus/client_golang v1.19.0
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240507051732-39060d20cdd9
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240510074809-a76de4f79a99
github.com/r3labs/sse/v2 v2.10.0
github.com/redis/go-redis/v9 v9.5.1
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -94,7 +94,7 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/c-kzg-4844 v1.0.1-0.20240422190800-13be436f5927 // indirect
github.com/ethereum/c-kzg-4844 v1.0.2-0.20240507203752-26d3b4156f7a // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/ferranbt/fastssz v0.1.3 // indirect
github.com/flynn/noise v1.1.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/c-kzg-4844 v1.0.1-0.20240422190800-13be436f5927 h1:ffWmm0RUR2+VqJsCkf94HqgEwZi2fgbm2iq+O/GdJNI=
github.com/ethereum/c-kzg-4844 v1.0.1-0.20240422190800-13be436f5927/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/c-kzg-4844 v1.0.2-0.20240507203752-26d3b4156f7a h1:EV64oiDZGl97cptCieq1X7KrumSbP4MhmKg0/ll65wo=
github.com/ethereum/c-kzg-4844 v1.0.2-0.20240507203752-26d3b4156f7a/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ=
github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/ethpandaops/beacon v0.36.0 h1:BIsb0ftrrOSwsORCNPvq7df3O5f6sVcFm7guGLpFztc=
Expand All @@ -266,8 +266,8 @@ github.com/ethpandaops/ethcore v0.0.0-20240422023000-2a5727b18756 h1:8JWjrRfP14m
github.com/ethpandaops/ethcore v0.0.0-20240422023000-2a5727b18756/go.mod h1:ZvKqL6CKxiraefdXPHeJurV2pDD/f2HF2uklDVdrry8=
github.com/ethpandaops/ethwallclock v0.3.0 h1:xF5fwtBf+bHFHZKBnwiPFEuelW3sMM7SD3ZNFq1lJY4=
github.com/ethpandaops/ethwallclock v0.3.0/go.mod h1:y0Cu+mhGLlem19vnAV2x0hpFS5KZ7oOi2SWYayv9l24=
github.com/ethpandaops/hermes v0.0.0-20240508034827-0c42cafd65a5 h1:kbXv4MfY+3xJ5ldL5bxf6AVU0CqmmYFfYSSHssoOUYE=
github.com/ethpandaops/hermes v0.0.0-20240508034827-0c42cafd65a5/go.mod h1:Z65YW+OhX67VHToofu2+wZDdMUgQ1AnvaEPgB9GzTC0=
github.com/ethpandaops/hermes v0.0.0-20240513080348-eafb396a7027 h1:Q9QXjCXYsvFmrlZ+F+w1plLufilUVTLS9trGONbV6IE=
github.com/ethpandaops/hermes v0.0.0-20240513080348-eafb396a7027/go.mod h1:Z65YW+OhX67VHToofu2+wZDdMUgQ1AnvaEPgB9GzTC0=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
Expand Down Expand Up @@ -878,8 +878,8 @@ github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c h1:9PHRCuO
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c/go.mod h1:ZRws458tYHS/Zs936OQ6oCrL+Ict5O4Xpwve1UQ6C9M=
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20230228205207-28762a7b9294 h1:q9wE0ZZRdTUAAeyFP/w0SwBEnCqlVy2+on6X2/e+eAU=
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20230228205207-28762a7b9294/go.mod h1:ZVEbRdnMkGhp/pu35zq4SXxtvUwWK0J1MATtekZpH2Y=
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240507051732-39060d20cdd9 h1:z6b+3uqU4t2lJAAYIB75Yp8sBaCeo4p1/+uHxZxXkmw=
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240507051732-39060d20cdd9/go.mod h1:5Pt2wu6NOUTSzLWcoEco/SraJ4kEEx5HubrHBTsmGmE=
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240510074809-a76de4f79a99 h1:RGPhzM/qJR8QqXK8ep2qs3ZABM4tPl0bnGFhDADr+NM=
github.com/prysmaticlabs/prysm/v5 v5.0.4-0.20240510074809-a76de4f79a99/go.mod h1:I3fzhjqrdv/17V3ckLKHLIU2K00kuFzFLw3P24EuKlo=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM=
Expand Down
16 changes: 10 additions & 6 deletions pkg/clmimicry/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ import (
"gopkg.in/yaml.v2"
)

func (m *Mimicry) FetchConfigFromUpstream(ctx context.Context) (*params.BeaconChainConfig, error) {
func (m *Mimicry) FetchConfigFromURL(ctx context.Context, url string) (*params.BeaconChainConfig, error) {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)

Check failure on line 13 in pkg/clmimicry/fetch.go

View workflow job for this annotation

GitHub Actions / lint

httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
if err != nil {
return nil, err
}

spec, err := m.ethereum.Node().FetchRawSpec(ctx)
response, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer response.Body.Close()

// Marshal the spec to a yaml string
yamlSpec, err := yaml.Marshal(spec)
data, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}

config := &params.BeaconChainConfig{}
config := params.MainnetConfig().Copy()

out, err := params.UnmarshalConfig(yamlSpec, config)
out, err := params.UnmarshalConfig(data, config)
if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/clmimicry/mimicry.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ func (m *Mimicry) deriveNetworkConfig(ctx context.Context) (*eth.GenesisConfig,
GenesisTime: genesis.GenesisTime,
}

beaconChainConfig, err := m.FetchConfigFromUpstream(ctx)
beaconChainConfig, err := m.FetchConfigFromURL(ctx, m.Config.Ethereum.CustomNetwork.ConfigURL)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to fetch custom Ethereum network config.yaml: %w", err)
}

if err := params.SetActive(beaconChainConfig); err != nil {

Check failure on line 121 in pkg/clmimicry/mimicry.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 116 (govet)
return nil, nil, nil, fmt.Errorf("failed to set active network config: %w", err)
}

params.OverrideBeaconConfig(beaconChainConfig)

networkConfig := params.BeaconNetworkConfig() // TODO: Support others

bootnodes, err := FetchBootnodeENRsFromURL(ctx, m.Config.Ethereum.CustomNetwork.BootnodeENRURL)
Expand All @@ -133,6 +139,8 @@ func (m *Mimicry) deriveNetworkConfig(ctx context.Context) (*eth.GenesisConfig,
networkConfig.BootstrapNodes = bootnodes
networkConfig.ContractDeploymentBlock = depositContractBlock

params.OverrideBeaconNetworkConfig(networkConfig)

return genesisConfig, networkConfig, beaconChainConfig, nil
}

Expand Down Expand Up @@ -247,7 +255,7 @@ func (m *Mimicry) Start(ctx context.Context) error {
m.log.Info("Ethereum client is ready. Starting Hermes..")

if err := m.startHermes(ctx); err != nil {
m.log.Fatalf("failed to start hermes: %w", err)
m.log.Fatalf("failed to start hermes: %s", err.Error())
}

return nil
Expand Down

0 comments on commit 0ac4a56

Please sign in to comment.