Skip to content

Commit

Permalink
Caplin: Add support for beacon snapshots (also stops relying on Engin…
Browse files Browse the repository at this point in the history
…e API) (#11250)

I had to:

* Add Caplin snapshot download
* Fix Snapshot Downloader on Holesky
* Fixed Holesky's chainspec
  • Loading branch information
Giulio2002 authored Jul 22, 2024
1 parent e761db4 commit dcc686e
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 33 deletions.
5 changes: 4 additions & 1 deletion cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,10 @@ func EmbeddedEnabledByDefault(id uint64) bool {
}

func SupportBackfilling(networkId uint64) bool {
return networkId == uint64(MainnetNetwork) || networkId == uint64(SepoliaNetwork) || networkId == uint64(GnosisNetwork)
return networkId == uint64(MainnetNetwork) ||
networkId == uint64(SepoliaNetwork) ||
networkId == uint64(GnosisNetwork) ||
networkId == uint64(HoleskyNetwork)
}

func EpochToPaths(slot uint64, config *BeaconChainConfig, suffix string) (string, string) {
Expand Down
28 changes: 27 additions & 1 deletion cl/clparams/initial_state/initial_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ package initial_state

import (
_ "embed"
"fmt"
"io"
"net/http"

"github.com/erigontech/erigon/cl/phase1/core/state"

"github.com/erigontech/erigon/cl/clparams"
)

func downloadGenesisState(url string) ([]byte, error) {
// Download genesis state by wget the url. MUST NOT RETURN NIL thorugh GET request. use go stnadard library
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to download genesis state: %s", resp.Status)
}
return io.ReadAll(resp.Body)

}

//go:embed mainnet.state.ssz
var mainnetStateSSZ []byte

Expand Down Expand Up @@ -51,12 +68,21 @@ func GetGenesisState(network clparams.NetworkType) (*state.CachingBeaconState, e
if err := returnState.DecodeSSZ(gnosisStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
case clparams.HoleskyNetwork:
// Download genesis state by wget the url
encodedState, err := downloadGenesisState("https://github.com/eth-clients/holesky/raw/main/metadata/genesis.ssz")
if err != nil {
return nil, err
}
if err := returnState.DecodeSSZ(encodedState, int(clparams.BellatrixVersion)); err != nil {
return nil, err
}
default:
return nil, nil
}
return returnState, nil
}

func IsGenesisStateSupported(network clparams.NetworkType) bool {
return network == clparams.MainnetNetwork || network == clparams.SepoliaNetwork || network == clparams.GnosisNetwork
return network == clparams.MainnetNetwork || network == clparams.SepoliaNetwork || network == clparams.GnosisNetwork || network == clparams.HoleskyNetwork
}
1 change: 1 addition & 0 deletions core/snaptype/block_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func init() {
snapcfg.RegisterKnownTypes(networkname.SepoliaChainName, ethereumTypes)
snapcfg.RegisterKnownTypes(networkname.GnosisChainName, ethereumTypes)
snapcfg.RegisterKnownTypes(networkname.ChiadoChainName, ethereumTypes)
snapcfg.RegisterKnownTypes(networkname.HoleskyChainName, ethereumTypes)
}

var Enums = struct {
Expand Down
12 changes: 7 additions & 5 deletions erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package snapcfg
import (
_ "embed"
"encoding/json"
"fmt"
"path/filepath"
"slices"
"sort"
Expand All @@ -36,8 +37,8 @@ import (
)

var (
Mainnet = fromToml(snapshothashes.Mainnet)
// Holesky = fromToml(snapshothashes.Holesky)
Mainnet = fromToml(snapshothashes.Mainnet)
Holesky = fromToml(snapshothashes.Holesky)
Sepolia = fromToml(snapshothashes.Sepolia)
Mumbai = fromToml(snapshothashes.Mumbai)
Amoy = fromToml(snapshothashes.Amoy)
Expand Down Expand Up @@ -357,8 +358,8 @@ func (c Cfg) MergeLimit(t snaptype.Enum, fromBlock uint64) uint64 {
}

var knownPreverified = map[string]Preverified{
networkname.MainnetChainName: Mainnet,
// networkname.HoleskyChainName: HoleskyChainSnapshotCfg,
networkname.MainnetChainName: Mainnet,
networkname.HoleskyChainName: Holesky,
networkname.SepoliaChainName: Sepolia,
networkname.MumbaiChainName: Mumbai,
networkname.AmoyChainName: Amoy,
Expand Down Expand Up @@ -413,7 +414,7 @@ func MergeSteps(networkName string, snapType snaptype.Enum, fromBlock uint64) []
// KnownCfg return list of preverified hashes for given network, but apply whiteList filter if it's not empty
func KnownCfg(networkName string) *Cfg {
c, ok := knownPreverified[networkName]

fmt.Println(networkName, c, ok)
if !ok {
return newCfg(networkName, Preverified{})
}
Expand All @@ -438,6 +439,7 @@ var KnownWebseeds = map[string][]string{
networkname.BorMainnetChainName: webseedsParse(webseed.BorMainnet),
networkname.GnosisChainName: webseedsParse(webseed.Gnosis),
networkname.ChiadoChainName: webseedsParse(webseed.Chiado),
networkname.HoleskyChainName: webseedsParse(webseed.Holesky),
}

func webseedsParse(in []byte) (res []string) {
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/erigontech/erigon-lib
go 1.21.5

require (
github.com/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33
github.com/erigontech/interfaces v0.0.0-20240716134413-fc4152088ee6
github.com/erigontech/mdbx-go v0.38.4
github.com/erigontech/secp256k1 v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894 h1:7ykEB96Z1HUYBuvAiawJkdXSvsmp1uv0BrGDhTD5nOA=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33 h1:LDj3PcKBduXQLD9PzvdCr6Ks94lB4p0/5+Y1/Gb73eQ=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/interfaces v0.0.0-20240716134413-fc4152088ee6 h1:R1AYJT2FeMEwvBcAuYw7QTezk8DpXTQjCN1y5o0YBvI=
github.com/erigontech/interfaces v0.0.0-20240716134413-fc4152088ee6/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE=
github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo=
Expand Down
24 changes: 6 additions & 18 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,24 +926,12 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
executionRpc := direct.NewExecutionClientDirect(backend.eth1ExecutionServer)

var executionEngine executionclient.ExecutionEngine
caplinUseEngineAPI := config.NetworkID == uint64(clparams.HoleskyNetwork)
// Gnosis has too few blocks on his network for phase2 to work. Once we have proper snapshot automation, it can go back to normal.
if caplinUseEngineAPI {
// Read the jwt secret
jwtSecret, err := cli.ObtainJWTSecret(&stack.Config().Http, logger)
if err != nil {
return nil, err
}
executionEngine, err = executionclient.NewExecutionClientRPC(jwtSecret, stack.Config().Http.AuthRpcHTTPListenAddress, stack.Config().Http.AuthRpcPort)
if err != nil {
return nil, err
}
} else {
executionEngine, err = executionclient.NewExecutionClientDirect(eth1_chain_reader.NewChainReaderEth1(chainConfig, executionRpc, 1000))
if err != nil {
return nil, err
}

executionEngine, err = executionclient.NewExecutionClientDirect(eth1_chain_reader.NewChainReaderEth1(chainConfig, executionRpc, 1000))
if err != nil {
return nil, err
}

engineBackendRPC := engineapi.NewEngineServer(
logger,
chainConfig,
Expand All @@ -953,7 +941,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
logger, backend.sentriesClient.Hd, executionRpc,
backend.sentriesClient.Bd, backend.sentriesClient.BroadcastNewBlock, backend.sentriesClient.SendBodyRequest, blockReader,
backend.chainDB, chainConfig, tmpdir, config.Sync),
config.InternalCL && !caplinUseEngineAPI, // If the chain supports the engine API, then we should not make the server fail.
config.InternalCL, // If the chain supports the engine API, then we should not make the server fail.
false,
config.Miner.EnabledPOS)
backend.engineBackendRPC = engineBackendRPC
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894 // indirect
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,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/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894 h1:7ykEB96Z1HUYBuvAiawJkdXSvsmp1uv0BrGDhTD5nOA=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240717150728-8e0fa991b894/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33 h1:LDj3PcKBduXQLD9PzvdCr6Ks94lB4p0/5+Y1/Gb73eQ=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240720122906-e073fcdeca33/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/erigonwatch v0.0.0-20240718131902-b6576bde1116 h1:KCFa2uXEfZoBjV4buzjWmCmoqVLXiGCq0ZmQ2OjeRvQ=
github.com/erigontech/erigonwatch v0.0.0-20240718131902-b6576bde1116/go.mod h1:8vQ+VjvLu2gkPs8EwdPrOTAAo++WuLuBi54N7NuAF0I=
github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo=
Expand All @@ -278,10 +278,10 @@ github.com/erigontech/secp256k1 v1.1.0 h1:mO3YJMUSoASE15Ya//SoHiisptUhdXExuMUN1M
github.com/erigontech/secp256k1 v1.1.0/go.mod h1:GokhPepsMB+EYDs7I5JZCprxHW6+yfOcJKaKtoZ+Fls=
github.com/erigontech/silkworm-go v0.18.0 h1:j56p61xZHBFhZGH1OixlGU8KcfjHzcw9pjAfjmVsOZA=
github.com/erigontech/silkworm-go v0.18.0/go.mod h1:O50ux0apICEVEGyRWiE488K8qz8lc3PA/SXbQQAc8SU=
github.com/erigontech/torrent v1.54.2-alpha-32 h1:Ly8W2JvD7r1o5TklXxKEV9D9Tr664tSrgj5OPpOrlWg=
github.com/erigontech/torrent v1.54.2-alpha-32/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/erigontech/speedtest v0.0.2 h1:W9Cvky/8AMUtUONwkLA/dZjeQ2XfkBdYfJzvhMZUO+U=
github.com/erigontech/speedtest v0.0.2/go.mod h1:vulsRNiM51BmSTbVtch4FWxKxx53pS2D35lZTtao0bw=
github.com/erigontech/torrent v1.54.2-alpha-32 h1:Ly8W2JvD7r1o5TklXxKEV9D9Tr664tSrgj5OPpOrlWg=
github.com/erigontech/torrent v1.54.2-alpha-32/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0=
Expand Down
1 change: 1 addition & 0 deletions params/chainspecs/holesky.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"chainName": "holesky",
"chainId": 17000,
"homesteadBlock": 0,
"eip150Block": 0,
Expand Down
1 change: 1 addition & 0 deletions turbo/snapshotsync/snapshotsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func WaitForDownloader(ctx context.Context, logPrefix string, headerchain, blobs
// send all hashes to the Downloader service
snapCfg := snapcfg.KnownCfg(cc.ChainName)
preverifiedBlockSnapshots := snapCfg.Preverified
fmt.Println(snapCfg)
downloadRequest := make([]services.DownloadRequest, 0, len(preverifiedBlockSnapshots))

blockPrune, historyPrune := computeBlocksToPrune(blockReader, prune)
Expand Down

0 comments on commit dcc686e

Please sign in to comment.