From a8d32d504a8f923cdf7fa9dfc2684f8804fbab92 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 1 Apr 2020 22:17:00 -0500 Subject: [PATCH] Enable NOISE Handshake by Default v0.11 (#5272) * noise handshakes by default * fix build * noisy noise everywhere * deprecated noisy noise flag with more noise * add secio as fallback Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas --- beacon-chain/p2p/BUILD.bazel | 2 +- beacon-chain/p2p/options.go | 8 +++----- beacon-chain/p2p/service_test.go | 9 ++++++++- shared/featureconfig/config.go | 5 ----- shared/featureconfig/flags.go | 13 ++++++------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 724732499d4..166513e9b00 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -39,7 +39,6 @@ go_library( "//beacon-chain/p2p/peers:go_default_library", "//proto/beacon/p2p/v1:go_default_library", "//shared:go_default_library", - "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/iputils:go_default_library", "//shared/params:go_default_library", @@ -121,6 +120,7 @@ go_test( "@com_github_libp2p_go_libp2p_core//host:go_default_library", "@com_github_libp2p_go_libp2p_core//network:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", + "@com_github_libp2p_go_libp2p_noise//:go_default_library", "@com_github_libp2p_go_libp2p_pubsub//:go_default_library", "@com_github_libp2p_go_libp2p_swarm//testing:go_default_library", "@com_github_multiformats_go_multiaddr//:go_default_library", diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index 7607efd0c30..b7b7763d1c8 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -12,7 +12,6 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/connmgr" - "github.com/prysmaticlabs/prysm/shared/featureconfig" ) // buildOptions for the libp2p host. @@ -29,10 +28,9 @@ func buildOptions(cfg *Config, ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt // Add one for the boot node and another for the relay, otherwise when we are close to maxPeers we will be above the high // water mark and continually trigger pruning. libp2p.ConnectionManager(connmgr.NewConnManager(int(cfg.MaxPeers+2), int(cfg.MaxPeers+2), 1*time.Second)), - } - if featureconfig.Get().EnableNoise { - // Enable NOISE for the beacon node - options = append(options, libp2p.Security(noise.ID, noise.New)) + // Enable NOISE handshakes by default in the beacon node. + libp2p.Security(noise.ID, noise.New), + libp2p.DefaultSecurity, } if cfg.EnableUPnP { options = append(options, libp2p.NATPortMap()) //Allow to use UPnP diff --git a/beacon-chain/p2p/service_test.go b/beacon-chain/p2p/service_test.go index 01002ff211c..1cb27d4eeca 100644 --- a/beacon-chain/p2p/service_test.go +++ b/beacon-chain/p2p/service_test.go @@ -13,6 +13,7 @@ import ( libp2p "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/peer" + noise "github.com/libp2p/go-libp2p-noise" multiaddr "github.com/multiformats/go-multiaddr" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -64,7 +65,13 @@ func createHost(t *testing.T, port int) (host.Host, *ecdsa.PrivateKey, net.IP) { if err != nil { t.Fatalf("Failed to p2p listen: %v", err) } - h, err := libp2p.New(context.Background(), []libp2p.Option{privKeyOption(pkey), libp2p.ListenAddrs(listen)}...) + h, err := libp2p.New( + context.Background(), + []libp2p.Option{ + privKeyOption(pkey), + libp2p.ListenAddrs(listen), + libp2p.Security(noise.ID, noise.New), + }...) if err != nil { t.Fatal(err) } diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 3180fce6d07..cdc741053a4 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -47,7 +47,6 @@ type Flags struct { EnableDomainDataCache bool // EnableDomainDataCache caches validator calls to DomainData per epoch. EnableStateGenSigVerify bool // EnableStateGenSigVerify verifies proposer and randao signatures during state gen. CheckHeadState bool // CheckHeadState checks the current headstate before retrieving the desired state from the db. - EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer. DontPruneStateStartUp bool // DontPruneStateStartUp disables pruning state upon beacon node start up. NewStateMgmt bool // NewStateMgmt enables the new experimental state mgmt service. EnableInitSyncQueue bool // EnableInitSyncQueue enables the new initial sync implementation. @@ -162,10 +161,6 @@ func ConfigureBeaconChain(ctx *cli.Context) { log.Warn("Enabling check head state for chainservice") cfg.CheckHeadState = true } - if ctx.Bool(enableNoiseHandshake.Name) { - log.Warn("Enabling noise handshake for peer") - cfg.EnableNoise = true - } if ctx.Bool(dontPruneStateStartUp.Name) { log.Warn("Not enabling state pruning upon start up") cfg.DontPruneStateStartUp = true diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index 11dc9ede855..6e005c2bddb 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -112,11 +112,6 @@ var ( Name: "check-head-state", Usage: "Enables the checking of head state in chainservice first before retrieving the desired state from the db.", } - enableNoiseHandshake = &cli.BoolFlag{ - Name: "enable-noise", - Usage: "This enables the beacon node to use NOISE instead of SECIO for performing handshakes between peers and " + - "securing transports between peers", - } dontPruneStateStartUp = &cli.BoolFlag{ Name: "dont-prune-state-start-up", Usage: "Don't prune historical states upon start up", @@ -148,6 +143,11 @@ var ( const deprecatedUsage = "DEPRECATED. DO NOT USE." var ( + deprecatedEnableNoiseHandshake = &cli.BoolFlag{ + Name: "enable-noise", + Usage: deprecatedUsage, + Hidden: true, + } deprecatedEnableFinalizedBlockRootIndexFlag = &cli.BoolFlag{ Name: "enable-finalized-block-root-index", Usage: deprecatedUsage, @@ -193,7 +193,6 @@ var ( Usage: deprecatedUsage, Hidden: true, } - deprecatedEnableCustomStateSSZFlag = &cli.BoolFlag{ Name: "enable-custom-state-ssz", Usage: deprecatedUsage, @@ -272,6 +271,7 @@ var ( ) var deprecatedFlags = []cli.Flag{ + deprecatedEnableNoiseHandshake, deprecatedEnableFinalizedBlockRootIndexFlag, deprecatedScatterFlag, deprecatedPruneFinalizedStatesFlag, @@ -332,7 +332,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{ enableByteMempool, enableStateGenSigVerify, checkHeadState, - enableNoiseHandshake, dontPruneStateStartUp, broadcastSlashingFlag, newStateMgmt,