mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Revert "Add Separate Network Config (#5454)"
This reverts commit 28733f2c9e.
This commit is contained in:
@@ -13,10 +13,8 @@ go_library(
|
||||
"//beacon-chain:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -7,19 +7,14 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ = NetworkEncoding(&SszNetworkEncoder{})
|
||||
|
||||
// MaxChunkSize allowed for decoding messages.
|
||||
var MaxChunkSize = params.BeaconNetworkConfig().MaxChunkSize // 1Mib
|
||||
|
||||
// MaxGossipSize allowed for gossip messages.
|
||||
var MaxGossipSize = params.BeaconNetworkConfig().GossipMaxSize // 1 Mib
|
||||
const MaxChunkSize = uint64(1 << 20) // 1Mb
|
||||
|
||||
// SszNetworkEncoder supports p2p networking encoding using SimpleSerialize
|
||||
// with snappy compression (if enabled).
|
||||
@@ -55,9 +50,6 @@ func (e SszNetworkEncoder) EncodeGossip(w io.Writer, msg interface{}) (int, erro
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(b) > int(MaxGossipSize) {
|
||||
return 0, errors.Errorf("gossip message exceeds max gossip size: %d bytes > %d bytes", len(b), MaxGossipSize)
|
||||
}
|
||||
if e.UseSnappyCompression {
|
||||
b = snappy.Encode(nil /*dst*/, b)
|
||||
}
|
||||
@@ -137,9 +129,6 @@ func (e SszNetworkEncoder) DecodeGossip(b []byte, to interface{}) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(b) > int(MaxGossipSize) {
|
||||
return errors.Errorf("gossip message exceeds max gossip size: %d bytes > %d bytes", len(b), MaxGossipSize)
|
||||
}
|
||||
return e.doDecode(b, to)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
// ENR key used for eth2-related fork data.
|
||||
var eth2ENRKey = params.BeaconNetworkConfig().ETH2Key
|
||||
const eth2ENRKey = "eth2"
|
||||
|
||||
// ForkDigest returns the current fork digest of
|
||||
// the node.
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@@ -21,7 +20,7 @@ func (s *Service) Send(ctx context.Context, message interface{}, baseTopic strin
|
||||
span.AddAttributes(trace.StringAttribute("topic", topic))
|
||||
|
||||
// TTFB_TIME (5s) + RESP_TIMEOUT (10s).
|
||||
var deadline = params.BeaconNetworkConfig().TtfbTimeout + params.BeaconNetworkConfig().RespTimeout
|
||||
const deadline = 15 * time.Second
|
||||
ctx, cancel := context.WithTimeout(ctx, deadline)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
var attestationSubnetCount = params.BeaconNetworkConfig().AttestationSubnetCount
|
||||
|
||||
var attSubnetEnrKey = params.BeaconNetworkConfig().AttSubnetKey
|
||||
const attestationSubnetCount = 64
|
||||
const attSubnetEnrKey = "attnets"
|
||||
|
||||
func intializeAttSubnets(node *enode.LocalNode) *enode.LocalNode {
|
||||
bitV := bitfield.NewBitvector64()
|
||||
|
||||
@@ -4,11 +4,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
var defaultReadDuration = ttfbTimeout
|
||||
var defaultWriteDuration = params.BeaconNetworkConfig().RespTimeout // RESP_TIMEOUT
|
||||
const defaultReadDuration = ttfbTimeout
|
||||
const defaultWriteDuration = 10 * time.Second // RESP_TIMEOUT
|
||||
|
||||
func setRPCStreamDeadlines(stream network.Stream) {
|
||||
setStreamReadDeadline(stream, defaultReadDuration)
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
libp2pcore "github.com/libp2p/go-libp2p-core"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
"go.opencensus.io/trace"
|
||||
@@ -18,12 +18,12 @@ import (
|
||||
// Time to first byte timeout. The maximum time to wait for first byte of
|
||||
// request response (time-to-first-byte). The client is expected to give up if
|
||||
// they don't receive the first byte within 5 seconds.
|
||||
var ttfbTimeout = params.BeaconNetworkConfig().TtfbTimeout
|
||||
const ttfbTimeout = 5 * time.Second
|
||||
|
||||
// maxChunkSize would be the maximum allowed size that a request/response chunk can be.
|
||||
// any size beyond that would be rejected and the corresponding stream reset. This would
|
||||
// be 1048576 bytes or 1 MiB.
|
||||
var maxChunkSize = params.BeaconNetworkConfig().MaxChunkSize
|
||||
const maxChunkSize = 1 << 20
|
||||
|
||||
// rpcHandler is responsible for handling and responding to any incoming message.
|
||||
// This method may return an error to internal monitoring, but the error will
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"go.opencensus.io/trace"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
@@ -21,12 +22,10 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
const pubsubMessageTimeout = 30 * time.Second
|
||||
|
||||
var maximumGossipClockDisparity = params.BeaconNetworkConfig().MaximumGossipClockDisparity
|
||||
const maximumGossipClockDisparity = 500 * time.Millisecond
|
||||
|
||||
// subHandler represents handler for a given subscription.
|
||||
type subHandler func(context.Context, proto.Message) error
|
||||
|
||||
@@ -197,7 +197,7 @@ func validateIndexInCommittee(ctx context.Context, s *stateTrie.BeaconState, a *
|
||||
func validateAggregateAttTime(attSlot uint64, genesisTime uint64) error {
|
||||
// in milliseconds
|
||||
attTime := 1000 * (genesisTime + (attSlot * params.BeaconConfig().SecondsPerSlot))
|
||||
attSlotRange := attSlot + params.BeaconNetworkConfig().AttestationPropagationSlotRange
|
||||
attSlotRange := attSlot + params.BeaconConfig().AttestationPropagationSlotRange
|
||||
attTimeRange := 1000 * (genesisTime + (attSlotRange * params.BeaconConfig().SecondsPerSlot))
|
||||
currentTimeInSec := roughtime.Now().Unix()
|
||||
currentTime := 1000 * currentTimeInSec
|
||||
@@ -206,7 +206,7 @@ func validateAggregateAttTime(attSlot uint64, genesisTime uint64) error {
|
||||
currentSlot := (uint64(currentTimeInSec) - genesisTime) / params.BeaconConfig().SecondsPerSlot
|
||||
if attTime-uint64(maximumGossipClockDisparity.Milliseconds()) > uint64(currentTime) ||
|
||||
uint64(currentTime-maximumGossipClockDisparity.Milliseconds()) > attTimeRange {
|
||||
return fmt.Errorf("attestation slot out of range %d <= %d <= %d", attSlot, currentSlot, attSlot+params.BeaconNetworkConfig().AttestationPropagationSlotRange)
|
||||
return fmt.Errorf("attestation slot out of range %d <= %d <= %d", attSlot, currentSlot, attSlot+params.BeaconConfig().AttestationPropagationSlotRange)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"config.go",
|
||||
"network_config.go",
|
||||
],
|
||||
srcs = ["config.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/params",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//shared/bytesutil:go_default_library"],
|
||||
|
||||
@@ -53,6 +53,7 @@ type BeaconChainConfig struct {
|
||||
MinEpochsToInactivityPenalty uint64 `yaml:"MIN_EPOCHS_TO_INACTIVITY_PENALTY"` // MinEpochsToInactivityPenalty defines the minimum amount of epochs since finality to begin penalizing inactivity.
|
||||
Eth1FollowDistance uint64 // Eth1FollowDistance is the number of eth1.0 blocks to wait before considering a new deposit for voting. This only applies after the chain as been started.
|
||||
SafeSlotsToUpdateJustified uint64 // SafeSlotsToUpdateJustified is the minimal slots needed to update justified check point.
|
||||
AttestationPropagationSlotRange uint64 // AttestationPropagationSlotRange is the maximum number of slots during which an attestation can be propagated.
|
||||
SecondsPerETH1Block uint64 `yaml:"SECONDS_PER_ETH1_BLOCK"` // SecondsPerETH1Block is the approximate time for a single eth1 block to be produced.
|
||||
// State list lengths
|
||||
EpochsPerHistoricalVector uint64 `yaml:"EPOCHS_PER_HISTORICAL_VECTOR"` // EpochsPerHistoricalVector defines max length in epoch to store old historical stats in beacon state.
|
||||
@@ -154,6 +155,7 @@ var defaultBeaconConfig = &BeaconChainConfig{
|
||||
MinEpochsToInactivityPenalty: 4,
|
||||
Eth1FollowDistance: 1024,
|
||||
SafeSlotsToUpdateJustified: 8,
|
||||
AttestationPropagationSlotRange: 32,
|
||||
SecondsPerETH1Block: 14,
|
||||
|
||||
// State list length constants.
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package params
|
||||
|
||||
import "time"
|
||||
|
||||
// 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.
|
||||
MaxChunkSize uint64 `yaml:"MAX_CHUNK_SIZE"` // MaxChunkSize is the the maximum allowed size of uncompressed req/resp chunked responses.
|
||||
AttestationSubnetCount uint64 `yaml:"ATTESTATION_SUBNET_COUNT"` // AttestationSubnetCount is the number of attestation subnets used in the gossipsub protocol.
|
||||
AttestationPropagationSlotRange uint64 `yaml:"ATTESTATION_PROPAGATION_SLOT_RANGE"` // AttestationPropagationSlotRange is the maximum number of slots during which an attestation can be propagated.
|
||||
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.
|
||||
|
||||
// DiscoveryV5 Config
|
||||
ETH2Key string // ETH2Key is the ENR key of the eth2 object in an enr.
|
||||
AttSubnetKey string // AttSubnetKey is the ENR key of the subnet bitfield in the enr.
|
||||
}
|
||||
|
||||
var defaultNetworkConfig = &NetworkConfig{
|
||||
GossipMaxSize: 1 << 20, // 1 MiB
|
||||
MaxChunkSize: 1 << 20, // 1 MiB
|
||||
AttestationSubnetCount: 64,
|
||||
AttestationPropagationSlotRange: 32,
|
||||
TtfbTimeout: 5 * time.Second,
|
||||
RespTimeout: 10 * time.Second,
|
||||
MaximumGossipClockDisparity: 500 * time.Millisecond,
|
||||
ETH2Key: "eth2",
|
||||
AttSubnetKey: "attnets",
|
||||
}
|
||||
|
||||
// BeaconNetworkConfig returns the current network config for
|
||||
// the beacon chain.
|
||||
func BeaconNetworkConfig() *NetworkConfig {
|
||||
return defaultNetworkConfig
|
||||
}
|
||||
Reference in New Issue
Block a user