mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Refactor Network Config Into Main Config (#13364)
* change parameters to main config * add more changes * change to accepted format * fix changes in config * gaz * fix test * fix test again
This commit is contained in:
@@ -229,12 +229,23 @@ type BeaconChainConfig struct {
|
||||
MaxRequestBlobSidecars uint64 `yaml:"MAX_REQUEST_BLOB_SIDECARS" spec:"true"` // MaxRequestBlobSidecars is the maximum number of blobs to request in a single request.
|
||||
MaxRequestBlocksDeneb uint64 `yaml:"MAX_REQUEST_BLOCKS_DENEB" spec:"true"` // MaxRequestBlocksDeneb is the maximum number of blocks in a single request after the deneb epoch.
|
||||
|
||||
// Values related to the new subnet backbone
|
||||
EpochsPerSubnetSubscription uint64 `yaml:"EPOCHS_PER_SUBNET_SUBSCRIPTION" spec:"true"` // EpochsPerSubnetSubscription specifies the minimum duration a validator is connected to their subnet.
|
||||
AttestationSubnetExtraBits uint64 `yaml:"ATTESTATION_SUBNET_EXTRA_BITS" spec:"true"` // AttestationSubnetExtraBits is the number of extra bits of a NodeId to use when mapping to a subscribed subnet.
|
||||
AttestationSubnetPrefixBits uint64 `yaml:"ATTESTATION_SUBNET_PREFIX_BITS" spec:"true"` // AttestationSubnetPrefixBits is defined as (ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS).
|
||||
SubnetsPerNode uint64 `yaml:"SUBNETS_PER_NODE" spec:"true"` // SubnetsPerNode is the number of long-lived subnets a beacon node should be subscribed to.
|
||||
NodeIdBits uint64 `yaml:"NODE_ID_BITS" spec:"true"` // NodeIdBits defines the bit length of a node id.
|
||||
// Networking Specific Parameters
|
||||
GossipMaxSize uint64 `yaml:"GOSSIP_MAX_SIZE" spec:"true"` // GossipMaxSize is the maximum allowed size of uncompressed gossip messages.
|
||||
MaxChunkSize uint64 `yaml:"MAX_CHUNK_SIZE" spec:"true"` // MaxChunkSize is the maximum allowed size of uncompressed req/resp chunked responses.
|
||||
AttestationSubnetCount uint64 `yaml:"ATTESTATION_SUBNET_COUNT" spec:"true"` // AttestationSubnetCount is the number of attestation subnets used in the gossipsub protocol.
|
||||
AttestationPropagationSlotRange primitives.Slot `yaml:"ATTESTATION_PROPAGATION_SLOT_RANGE" spec:"true"` // AttestationPropagationSlotRange is the maximum number of slots during which an attestation can be propagated.
|
||||
MaxRequestBlocks uint64 `yaml:"MAX_REQUEST_BLOCKS" spec:"true"` // MaxRequestBlocks is the maximum number of blocks in a single request.
|
||||
TtfbTimeout uint64 `yaml:"TTFB_TIMEOUT" spec:"true"` // TtfbTimeout is the maximum time to wait for first byte of request response (time-to-first-byte).
|
||||
RespTimeout uint64 `yaml:"RESP_TIMEOUT" spec:"true"` // RespTimeout is the maximum time for complete response transfer.
|
||||
MaximumGossipClockDisparity uint64 `yaml:"MAXIMUM_GOSSIP_CLOCK_DISPARITY" spec:"true"` // MaximumGossipClockDisparity is the maximum milliseconds of clock disparity assumed between honest nodes.
|
||||
MessageDomainInvalidSnappy [4]byte `yaml:"MESSAGE_DOMAIN_INVALID_SNAPPY" spec:"true"` // MessageDomainInvalidSnappy is the 4-byte domain for gossip message-id isolation of invalid snappy messages.
|
||||
MessageDomainValidSnappy [4]byte `yaml:"MESSAGE_DOMAIN_VALID_SNAPPY" spec:"true"` // MessageDomainValidSnappy is the 4-byte domain for gossip message-id isolation of valid snappy messages.
|
||||
MinEpochsForBlockRequests uint64 `yaml:"MIN_EPOCHS_FOR_BLOCK_REQUESTS" spec:"true"` // MinEpochsForBlockRequests represents the minimum number of epochs for which we can serve block requests.
|
||||
EpochsPerSubnetSubscription uint64 `yaml:"EPOCHS_PER_SUBNET_SUBSCRIPTION" spec:"true"` // EpochsPerSubnetSubscription specifies the minimum duration a validator is connected to their subnet.
|
||||
AttestationSubnetExtraBits uint64 `yaml:"ATTESTATION_SUBNET_EXTRA_BITS" spec:"true"` // AttestationSubnetExtraBits is the number of extra bits of a NodeId to use when mapping to a subscribed subnet.
|
||||
AttestationSubnetPrefixBits uint64 `yaml:"ATTESTATION_SUBNET_PREFIX_BITS" spec:"true"` // AttestationSubnetPrefixBits is defined as (ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS).
|
||||
SubnetsPerNode uint64 `yaml:"SUBNETS_PER_NODE" spec:"true"` // SubnetsPerNode is the number of long-lived subnets a beacon node should be subscribed to.
|
||||
NodeIdBits uint64 `yaml:"NODE_ID_BITS" spec:"true"` // NodeIdBits defines the bit length of a node id.
|
||||
}
|
||||
|
||||
// InitializeForkSchedule initializes the schedules forks baked into the config.
|
||||
@@ -295,6 +306,21 @@ func (b *BeaconChainConfig) CurrentEpochAttestationsLength() uint64 {
|
||||
return uint64(b.SlotsPerEpoch.Mul(b.MaxAttestations))
|
||||
}
|
||||
|
||||
// TtfbTimeoutDuration returns the time duration of the timeout.
|
||||
func (b *BeaconChainConfig) TtfbTimeoutDuration() time.Duration {
|
||||
return time.Duration(b.TtfbTimeout) * time.Second
|
||||
}
|
||||
|
||||
// RespTimeoutDuration returns the time duration of the timeout.
|
||||
func (b *BeaconChainConfig) RespTimeoutDuration() time.Duration {
|
||||
return time.Duration(b.RespTimeout) * time.Second
|
||||
}
|
||||
|
||||
// MaximumGossipClockDisparityDuration returns the time duration of the clock disparity.
|
||||
func (b *BeaconChainConfig) MaximumGossipClockDisparityDuration() time.Duration {
|
||||
return time.Duration(b.MaximumGossipClockDisparity) * time.Millisecond
|
||||
}
|
||||
|
||||
// DenebEnabled centralizes the check to determine if code paths
|
||||
// that are specific to deneb should be allowed to execute. This will make it easier to find call sites that do this
|
||||
// kind of check and remove them post-deneb.
|
||||
|
||||
@@ -219,28 +219,17 @@ func ConfigToYaml(cfg *BeaconChainConfig) []byte {
|
||||
fmt.Sprintf("ATTESTATION_SUBNET_PREFIX_BITS: %d", cfg.AttestationSubnetPrefixBits),
|
||||
fmt.Sprintf("SUBNETS_PER_NODE: %d", cfg.SubnetsPerNode),
|
||||
fmt.Sprintf("NODE_ID_BITS: %d", cfg.NodeIdBits),
|
||||
}
|
||||
|
||||
yamlFile := []byte(strings.Join(lines, "\n"))
|
||||
return yamlFile
|
||||
}
|
||||
|
||||
// NetworkConfigToYaml takes a provided network config and outputs its contents
|
||||
// in yaml. This allows prysm's network configs to be read by other clients.
|
||||
func NetworkConfigToYaml(cfg *NetworkConfig) []byte {
|
||||
lines := []string{
|
||||
fmt.Sprintf("GOSSIP_MAX_SIZE: %d", cfg.GossipMaxSize),
|
||||
fmt.Sprintf("GOSSIP_MAX_SIZE_BELLATRIX: %d", cfg.GossipMaxSizeBellatrix),
|
||||
fmt.Sprintf("MAX_CHUNK_SIZE: %d", cfg.MaxChunkSize),
|
||||
fmt.Sprintf("MAX_CHUNK_SIZE_BELLATRIX: %d", cfg.MaxChunkSizeBellatrix),
|
||||
fmt.Sprintf("ATTESTATION_SUBNET_COUNT: %d", cfg.AttestationSubnetCount),
|
||||
fmt.Sprintf("ATTESTATION_PROPAGATION_SLOT_RANGE: %d", cfg.AttestationPropagationSlotRange),
|
||||
fmt.Sprintf("MAX_REQUEST_BLOCKS: %d", cfg.MaxRequestBlocks),
|
||||
fmt.Sprintf("TTFB_TIMEOUT: %d", int(cfg.TtfbTimeout.Seconds())),
|
||||
fmt.Sprintf("RESP_TIMEOUT: %d", int(cfg.RespTimeout.Seconds())),
|
||||
fmt.Sprintf("MAXIMUM_GOSSIP_CLOCK_DISPARITY: %d", int(cfg.MaximumGossipClockDisparity.Seconds())),
|
||||
fmt.Sprintf("TTFB_TIMEOUT: %d", int(cfg.TtfbTimeout)),
|
||||
fmt.Sprintf("RESP_TIMEOUT: %d", int(cfg.RespTimeout)),
|
||||
fmt.Sprintf("MAXIMUM_GOSSIP_CLOCK_DISPARITY: %d", int(cfg.MaximumGossipClockDisparity)),
|
||||
fmt.Sprintf("MESSAGE_DOMAIN_INVALID_SNAPPY: %#x", cfg.MessageDomainInvalidSnappy),
|
||||
fmt.Sprintf("MESSAGE_DOMAIN_VALID_SNAPPY: %#x", cfg.MessageDomainValidSnappy),
|
||||
fmt.Sprintf("MIN_EPOCHS_FOR_BLOCK_REQUESTS: %d", int(cfg.MinEpochsForBlockRequests)),
|
||||
}
|
||||
|
||||
yamlFile := []byte(strings.Join(lines, "\n"))
|
||||
|
||||
@@ -23,23 +23,12 @@ import (
|
||||
// These are variables that we don't use in Prysm. (i.e. future hardfork, light client... etc)
|
||||
// IMPORTANT: Use one field per line and sort these alphabetically to reduce conflicts.
|
||||
var placeholderFields = []string{
|
||||
"ATTESTATION_PROPAGATION_SLOT_RANGE",
|
||||
"ATTESTATION_SUBNET_COUNT",
|
||||
"EIP6110_FORK_EPOCH",
|
||||
"EIP6110_FORK_VERSION",
|
||||
"EIP7002_FORK_EPOCH",
|
||||
"EIP7002_FORK_VERSION",
|
||||
"GOSSIP_MAX_SIZE",
|
||||
"MAXIMUM_GOSSIP_CLOCK_DISPARITY",
|
||||
"MAX_BLOBS_PER_BLOCK",
|
||||
"MAX_CHUNK_SIZE",
|
||||
"MAX_REQUEST_BLOCKS",
|
||||
"MESSAGE_DOMAIN_INVALID_SNAPPY",
|
||||
"MESSAGE_DOMAIN_VALID_SNAPPY",
|
||||
"MIN_EPOCHS_FOR_BLOCK_REQUESTS",
|
||||
"REORG_HEAD_WEIGHT_THRESHOLD",
|
||||
"RESP_TIMEOUT",
|
||||
"TTFB_TIMEOUT",
|
||||
"UPDATE_TIMEOUT",
|
||||
"WHISK_EPOCHS_PER_SHUFFLING_PHASE",
|
||||
"WHISK_FORK_EPOCH",
|
||||
|
||||
@@ -27,23 +27,11 @@ const (
|
||||
)
|
||||
|
||||
var mainnetNetworkConfig = &NetworkConfig{
|
||||
GossipMaxSize: 1 << 20, // 1 MiB
|
||||
GossipMaxSizeBellatrix: 10 * 1 << 20, // 10 MiB
|
||||
MaxChunkSize: 1 << 20, // 1 MiB
|
||||
MaxChunkSizeBellatrix: 10 * 1 << 20, // 10 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, // Note: contract was deployed in block 11052984 but no transactions were sent until 11184524.
|
||||
ETH2Key: "eth2",
|
||||
AttSubnetKey: "attnets",
|
||||
SyncCommsSubnetKey: "syncnets",
|
||||
MinimumPeersInSubnetSearch: 20,
|
||||
ContractDeploymentBlock: 11184524, // Note: contract was deployed in block 11052984 but no transactions were sent until 11184524.
|
||||
BootstrapNodes: []string{
|
||||
// Teku team's bootnode
|
||||
"enr:-KG4QMOEswP62yzDjSwWS4YEjtTZ5PO6r65CPqYBkgTTkrpaedQ8uEUo1uMALtJIvb2w_WWEVmg5yt1UAuK1ftxUU7QDhGV0aDKQu6TalgMAAAD__________4JpZIJ2NIJpcIQEnfA2iXNlY3AyNTZrMaEDfol8oLr6XJ7FsdAYE7lpJhKMls4G_v6qQOGKJUWGb_uDdGNwgiMog3VkcIIjKA",
|
||||
@@ -275,12 +263,23 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
MaxRequestBlobSidecars: 768,
|
||||
MaxRequestBlocksDeneb: 128,
|
||||
|
||||
// Values related to the new subnet backbone
|
||||
EpochsPerSubnetSubscription: 256,
|
||||
AttestationSubnetExtraBits: 0,
|
||||
AttestationSubnetPrefixBits: 6,
|
||||
SubnetsPerNode: 2,
|
||||
NodeIdBits: 256,
|
||||
// Values related to networking parameters.
|
||||
GossipMaxSize: 10 * 1 << 20, // 10 MiB
|
||||
MaxChunkSize: 10 * 1 << 20, // 10 MiB
|
||||
AttestationSubnetCount: 64,
|
||||
AttestationPropagationSlotRange: 32,
|
||||
MaxRequestBlocks: 1 << 10, // 1024
|
||||
TtfbTimeout: 5,
|
||||
RespTimeout: 10,
|
||||
MaximumGossipClockDisparity: 500,
|
||||
MessageDomainInvalidSnappy: [4]byte{00, 00, 00, 00},
|
||||
MessageDomainValidSnappy: [4]byte{01, 00, 00, 00},
|
||||
MinEpochsForBlockRequests: 33024, // MIN_VALIDATOR_WITHDRAWABILITY_DELAY + CHURN_LIMIT_QUOTIENT / 2 (= 33024, ~5 months)
|
||||
EpochsPerSubnetSubscription: 256,
|
||||
AttestationSubnetExtraBits: 0,
|
||||
AttestationSubnetPrefixBits: 6,
|
||||
SubnetsPerNode: 2,
|
||||
NodeIdBits: 256,
|
||||
}
|
||||
|
||||
// MainnetTestConfig provides a version of the mainnet config that has a different name
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestMaxRequestBlock(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
epoch: primitives.Epoch(mainnetDenebForkEpoch - 1), // Assuming the fork epoch is not 0
|
||||
expectedMaxBlock: mainnetNetworkConfig.MaxRequestBlocks,
|
||||
expectedMaxBlock: mainnetBeaconConfig.MaxRequestBlocks,
|
||||
},
|
||||
{
|
||||
epoch: primitives.Epoch(mainnetDenebForkEpoch),
|
||||
|
||||
@@ -94,6 +94,7 @@ func MinimalSpecConfig() *BeaconChainConfig {
|
||||
minimalConfig.SyncCommitteeSize = 32
|
||||
minimalConfig.InactivityScoreBias = 4
|
||||
minimalConfig.EpochsPerSyncCommitteePeriod = 8
|
||||
minimalConfig.MinEpochsForBlockRequests = 272
|
||||
|
||||
// Ethereum PoW parameters.
|
||||
minimalConfig.DepositChainID = 5 // Chain ID of eth1 goerli.
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/mohae/deepcopy"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// NetworkConfig defines the spec based network parameters.
|
||||
type NetworkConfig struct {
|
||||
GossipMaxSize uint64 `yaml:"GOSSIP_MAX_SIZE"` // GossipMaxSize is the maximum allowed size of uncompressed gossip messages.
|
||||
GossipMaxSizeBellatrix uint64 `yaml:"GOSSIP_MAX_SIZE_BELLATRIX"` // GossipMaxSizeBellatrix is the maximum allowed size of uncompressed gossip messages after the bellatrix epoch.
|
||||
MaxChunkSize uint64 `yaml:"MAX_CHUNK_SIZE"` // MaxChunkSize is the maximum allowed size of uncompressed req/resp chunked responses.
|
||||
MaxChunkSizeBellatrix uint64 `yaml:"MAX_CHUNK_SIZE_BELLATRIX"` // MaxChunkSizeBellatrix is the maximum allowed size of uncompressed req/resp chunked responses after the bellatrix epoch.
|
||||
AttestationSubnetCount uint64 `yaml:"ATTESTATION_SUBNET_COUNT"` // AttestationSubnetCount is the number of attestation subnets used in the gossipsub protocol.
|
||||
AttestationPropagationSlotRange primitives.Slot `yaml:"ATTESTATION_PROPAGATION_SLOT_RANGE"` // AttestationPropagationSlotRange is the maximum number of slots during which an attestation can be propagated.
|
||||
MaxRequestBlocks uint64 `yaml:"MAX_REQUEST_BLOCKS"` // MaxRequestBlocks is the maximum number of blocks in a single request.
|
||||
TtfbTimeout time.Duration `yaml:"TTFB_TIMEOUT"` // TtfbTimeout is the maximum time to wait for first byte of request response (time-to-first-byte).
|
||||
RespTimeout time.Duration `yaml:"RESP_TIMEOUT"` // RespTimeout is the maximum time for complete response transfer.
|
||||
MaximumGossipClockDisparity time.Duration `yaml:"MAXIMUM_GOSSIP_CLOCK_DISPARITY"` // MaximumGossipClockDisparity is the maximum milliseconds of clock disparity assumed between honest nodes.
|
||||
MessageDomainInvalidSnappy [4]byte `yaml:"MESSAGE_DOMAIN_INVALID_SNAPPY"` // MessageDomainInvalidSnappy is the 4-byte domain for gossip message-id isolation of invalid snappy messages.
|
||||
MessageDomainValidSnappy [4]byte `yaml:"MESSAGE_DOMAIN_VALID_SNAPPY"` // MessageDomainValidSnappy is the 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.
|
||||
@@ -63,5 +48,5 @@ func MaxRequestBlock(e primitives.Epoch) uint64 {
|
||||
if e >= BeaconConfig().DenebForkEpoch {
|
||||
return BeaconConfig().MaxRequestBlocksDeneb
|
||||
}
|
||||
return networkConfig.MaxRequestBlocks
|
||||
return BeaconConfig().MaxRequestBlocks
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user