erigon-pulse/cmd/lightclient/clparams/config.go
Giulio rebuffo 6d6e511b0f
added ENR setup for subnets (#5511)
Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
2022-09-25 22:41:51 +02:00

193 lines
12 KiB
Go

/*
Copyright 2022 Erigon-Lightclient contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package clparams
import (
"time"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/p2p/discover"
"github.com/ledgerwatch/erigon/p2p/enode"
)
type NetworkType int
var (
MainnetNetwork NetworkType = 0
GoerliNetwork NetworkType = 1
SepoliaNetwork NetworkType = 2
)
var (
MainnetBootstrapNodes = []string{
// Teku team's bootnode
"enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2Gxb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNlY3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA",
"enr:-KG4QL-eqFoHy0cI31THvtZjpYUu_Jdw_MO7skQRJxY1g5HTN1A0epPCU6vi0gLGUgrzpU-ygeMSS8ewVxDpKfYmxMMGhGV0aDKQtTA_KgAAAAD__________4JpZIJ2NIJpcIQ2_DUbiXNlY3AyNTZrMaED8GJ2vzUqgL6-KD1xalo1CsmY4X1HaDnyl6Y_WayCo9GDdGNwgiMog3VkcIIjKA",
// Prylab team's bootnodes
"enr:-Ku4QImhMc1z8yCiNJ1TyUxdcfNucje3BGwEHzodEZ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xz8M1IHwJqRIpDqdVW_U1PeixMW5SfnBD-8idYIQrIhzeW5jbmV0cw-DdGNwgiMog3VkcIIjKA",
"enr:-L64QJmwSDtaHVgGiqIxJWUtxWg6uLCipsms6j-8BdsOJfTWAs7CLF9HJnVqFE728O-JYUDCxzKvRdeMqBSauHVCMdaCAVWHYXR0bmV0c4j__________4RldGgykIL0pysCABAghLYBAAAAAACCaWSCdjSCaXCEQWxOdolzZWNwMjU2azGhA7Qmod9fK86WidPOzLsn5_8QyzL7ZcJ1Reca7RnD54vuiHN5bmNuZXRzD4N0Y3CCIyiDdWRwgiMo",
"enr:-KG4QCIzJZTY_fs_2vqWEatJL9RrtnPwDCv-jRBuO5FQ2qBrfJubWOWazri6s9HsyZdu-fRUfEzkebhf1nvO42_FVzwDhGV0aDKQed8EKAAAECD__________4JpZIJ2NIJpcISHtbYziXNlY3AyNTZrMaED4m9AqVs6F32rSCGsjtYcsyfQE2K8nDiGmocUY_iq-TSDdGNwgiMog3VkcIIjKA",
}
SepoliaBootstrapNodes = []string{
// EF boot nodes
"enr:-Iq4QMCTfIMXnow27baRUb35Q8iiFHSIDBJh6hQM5Axohhf4b6Kr_cOCu0htQ5WvVqKvFgY28893DHAg8gnBAXsAVqmGAX53x8JggmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk",
"enr:-KG4QE5OIg5ThTjkzrlVF32WT_-XT14WeJtIz2zoTqLLjQhYAmJlnk4ItSoH41_2x0RX0wTFIe5GgjRzU2u7Q1fN4vADhGV0aDKQqP7o7pAAAHAyAAAAAAAAAIJpZIJ2NIJpcISlFsStiXNlY3AyNTZrMaEC-Rrd_bBZwhKpXzFCrStKp1q_HmGOewxY3KwM8ofAj_ODdGNwgiMog3VkcIIjKA",
// Teku boot node
"enr:-Ly4QFoZTWR8ulxGVsWydTNGdwEESueIdj-wB6UmmjUcm-AOPxnQi7wprzwcdo7-1jBW_JxELlUKJdJES8TDsbl1EdNlh2F0dG5ldHOI__78_v2bsV-EZXRoMpA2-lATkAAAcf__________gmlkgnY0gmlwhBLYJjGJc2VjcDI1NmsxoQI0gujXac9rMAb48NtMqtSTyHIeNYlpjkbYpWJw46PmYYhzeW5jbmV0cw-DdGNwgiMog3VkcIIjKA",
}
)
type NetworkConfig struct {
GossipMaxSize uint64 `json:"gossip_max_size"` // The maximum allowed size of uncompressed gossip messages.
MaxRequestBlocks uint64 `json:"max_request_blocks"` // Maximum number of blocks in a single request
MinEpochsForBlockRequests uint64 `json:"min_epochs_for_block_requests"` // The minimum epoch range over which a node must serve blocks
MaxChunkSize uint64 `json:"max_chunk_size"` // The maximum allowed size of uncompressed req/resp chunked responses.
AttestationSubnetCount uint64 `json:"attestation_subnet_count"` // The number of attestation subnets used in the gossipsub protocol.
TtfbTimeout time.Duration `json:"ttfbt_timeout"` // The maximum time to wait for first byte of request response (time-to-first-byte).
RespTimeout time.Duration `json:"resp_timeout"` // The maximum time for complete response transfer.
AttestationPropagationSlotRange uint64 `json:"attestation_propagation_slot_range"` // The maximum number of slots during which an attestation can be propagated.
MaximumGossipClockDisparity time.Duration `json:"maximum_gossip_clock_disparity"` // The maximum milliseconds of clock disparity assumed between honest nodes.
MessageDomainInvalidSnappy [4]byte `json:"message_domain_invalid_snappy"` // 4-byte domain for gossip message-id isolation of invalid snappy messages
MessageDomainValidSnappy [4]byte `json:"message_domain_valid_snappy"` // 4-byte domain for gossip message-id isolation of valid snappy messages
// DiscoveryV5 Config
Eth2key string // ETH2Key is the ENR key of the Ethereum consensus object in an enr.
AttSubnetKey string // AttSubnetKey is the ENR key of the subnet bitfield in the enr.
SyncCommsSubnetKey string // SyncCommsSubnetKey is the ENR key of the sync committee subnet bitfield in the enr.
MinimumPeersInSubnetSearch uint64 // PeersInSubnetSearch is the required amount of peers that we need to be able to lookup in a subnet search.
ContractDeploymentBlock uint64 // the eth1 block in which the deposit contract is deployed.
bootNodes []string
}
type GenesisConfig struct {
GenesisValidatorRoot common.Hash // Merkle Root at Genesis
GenesisTime uint64 // Unix time at Genesis
}
var NetworkConfigs map[NetworkType]NetworkConfig = map[NetworkType]NetworkConfig{
MainnetNetwork: {
GossipMaxSize: 1 << 20, // 1 MiB
MaxChunkSize: 1 << 20, // 1 MiB
AttestationSubnetCount: 64,
AttestationPropagationSlotRange: 32,
MaxRequestBlocks: 1 << 10, // 1024
TtfbTimeout: 5 * time.Second,
RespTimeout: 10 * time.Second,
MaximumGossipClockDisparity: 500 * time.Millisecond,
MessageDomainInvalidSnappy: [4]byte{00, 00, 00, 00},
MessageDomainValidSnappy: [4]byte{01, 00, 00, 00},
Eth2key: "eth2",
AttSubnetKey: "attnets",
SyncCommsSubnetKey: "syncnets",
MinimumPeersInSubnetSearch: 20,
ContractDeploymentBlock: 11184524,
bootNodes: MainnetBootstrapNodes,
},
SepoliaNetwork: {
GossipMaxSize: 1 << 20, // 1 MiB
MaxChunkSize: 1 << 20, // 1 MiB
AttestationSubnetCount: 64,
AttestationPropagationSlotRange: 32,
MaxRequestBlocks: 1 << 10, // 1024
TtfbTimeout: 5 * time.Second,
RespTimeout: 10 * time.Second,
MaximumGossipClockDisparity: 500 * time.Millisecond,
MessageDomainInvalidSnappy: [4]byte{00, 00, 00, 00},
MessageDomainValidSnappy: [4]byte{01, 00, 00, 00},
Eth2key: "eth2",
AttSubnetKey: "attnets",
SyncCommsSubnetKey: "syncnets",
MinimumPeersInSubnetSearch: 20,
ContractDeploymentBlock: 1273020,
bootNodes: SepoliaBootstrapNodes,
},
GoerliNetwork: {
GossipMaxSize: 1 << 20, // 1 MiB
MaxChunkSize: 1 << 20, // 1 MiB
AttestationSubnetCount: 64,
AttestationPropagationSlotRange: 32,
MaxRequestBlocks: 1 << 10, // 1024
TtfbTimeout: 5 * time.Second,
RespTimeout: 10 * time.Second,
MaximumGossipClockDisparity: 500 * time.Millisecond,
MessageDomainInvalidSnappy: [4]byte{00, 00, 00, 00},
MessageDomainValidSnappy: [4]byte{01, 00, 00, 00},
Eth2key: "eth2",
AttSubnetKey: "attnets",
SyncCommsSubnetKey: "syncnets",
MinimumPeersInSubnetSearch: 20,
ContractDeploymentBlock: 4367322,
bootNodes: GoerliBootstrapNodes,
},
}
var GenesisConfigs map[NetworkType]GenesisConfig = map[NetworkType]GenesisConfig{
MainnetNetwork: {
GenesisValidatorRoot: common.HexToHash("4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"),
GenesisTime: 1606824023,
},
SepoliaNetwork: {
GenesisValidatorRoot: common.HexToHash("d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078"),
GenesisTime: 1655733600,
},
GoerliNetwork: {
GenesisValidatorRoot: common.HexToHash("043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb"),
GenesisTime: 1616508000,
},
}
func GetConfigsByNetwork(net NetworkType) (*discover.Config, GenesisConfig, NetworkConfig, error) {
networkConfig := NetworkConfigs[net]
bootnodes := networkConfig.bootNodes
privateKey, err := crypto.GenerateKey()
if err != nil {
return nil, GenesisConfig{}, NetworkConfig{}, err
}
enodes := []*enode.Node{}
for _, addr := range bootnodes {
enode, err := enode.Parse(enode.ValidSchemes, addr)
if err != nil {
return nil, GenesisConfig{}, NetworkConfig{}, err
}
enodes = append(enodes, enode)
}
return &discover.Config{
PrivateKey: privateKey,
Bootnodes: enodes,
}, GenesisConfigs[net], networkConfig, nil
}