Skip to content

Commit

Permalink
Revert "Add Separate Network Config (#5454)"
Browse files Browse the repository at this point in the history
This reverts commit 28733f2.
  • Loading branch information
terencechain committed Apr 18, 2020
1 parent 491c3e6 commit d43c2b7
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 72 deletions.
2 changes: 0 additions & 2 deletions beacon-chain/p2p/encoder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
13 changes: 1 addition & 12 deletions beacon-chain/p2p/encoder/ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/p2p/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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()

Expand Down
6 changes: 2 additions & 4 deletions beacon-chain/p2p/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions beacon-chain/sync/deadlines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/sync/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/sync/validate_aggregate_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions shared/params/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 2 additions & 0 deletions shared/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -154,6 +155,7 @@ var defaultBeaconConfig = &BeaconChainConfig{
MinEpochsToInactivityPenalty: 4,
Eth1FollowDistance: 1024,
SafeSlotsToUpdateJustified: 8,
AttestationPropagationSlotRange: 32,
SecondsPerETH1Block: 14,

// State list length constants.
Expand Down
36 changes: 0 additions & 36 deletions shared/params/network_config.go

This file was deleted.

0 comments on commit d43c2b7

Please sign in to comment.