diff --git a/beacon-chain/p2p/encoder/BUILD.bazel b/beacon-chain/p2p/encoder/BUILD.bazel index bb1d9a90d1b..059d9148e18 100644 --- a/beacon-chain/p2p/encoder/BUILD.bazel +++ b/beacon-chain/p2p/encoder/BUILD.bazel @@ -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", ], diff --git a/beacon-chain/p2p/encoder/ssz.go b/beacon-chain/p2p/encoder/ssz.go index 0ece15056a6..69e3b37559a 100644 --- a/beacon-chain/p2p/encoder/ssz.go +++ b/beacon-chain/p2p/encoder/ssz.go @@ -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) } diff --git a/beacon-chain/p2p/fork.go b/beacon-chain/p2p/fork.go index e0b6d3cce15..07c29ad9e71 100644 --- a/beacon-chain/p2p/fork.go +++ b/beacon-chain/p2p/fork.go @@ -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. diff --git a/beacon-chain/p2p/sender.go b/beacon-chain/p2p/sender.go index 8df56273b09..d24302056e5 100644 --- a/beacon-chain/p2p/sender.go +++ b/beacon-chain/p2p/sender.go @@ -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() diff --git a/beacon-chain/p2p/subnets.go b/beacon-chain/p2p/subnets.go index fa5a4e69dd5..b73eb3bcdb1 100644 --- a/beacon-chain/p2p/subnets.go +++ b/beacon-chain/p2p/subnets.go @@ -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() diff --git a/beacon-chain/sync/deadlines.go b/beacon-chain/sync/deadlines.go index 178ce31e651..11bbab0be72 100644 --- a/beacon-chain/sync/deadlines.go +++ b/beacon-chain/sync/deadlines.go @@ -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) diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index 22d365e2763..7fa3b5fb9e9 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -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 diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index 6eecf6e45d3..d4be1dde036 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -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 diff --git a/beacon-chain/sync/validate_aggregate_proof.go b/beacon-chain/sync/validate_aggregate_proof.go index 7be744cc180..501efd01681 100644 --- a/beacon-chain/sync/validate_aggregate_proof.go +++ b/beacon-chain/sync/validate_aggregate_proof.go @@ -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 } diff --git a/shared/params/BUILD.bazel b/shared/params/BUILD.bazel index e796ac865b2..d27f10843f8 100644 --- a/shared/params/BUILD.bazel +++ b/shared/params/BUILD.bazel @@ -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"], diff --git a/shared/params/config.go b/shared/params/config.go index 9ed2fe16ecc..e507666ce06 100644 --- a/shared/params/config.go +++ b/shared/params/config.go @@ -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. diff --git a/shared/params/network_config.go b/shared/params/network_config.go deleted file mode 100644 index f471901531f..00000000000 --- a/shared/params/network_config.go +++ /dev/null @@ -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 -}