Skip to content

Commit

Permalink
Enable NOISE Handshake by Default v0.11 (#5272)
Browse files Browse the repository at this point in the history
* 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 <nishdas93@gmail.com>
  • Loading branch information
3 people committed Apr 2, 2020
1 parent 16d8114 commit a8d32d5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/p2p/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions beacon-chain/p2p/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion beacon-chain/p2p/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 0 additions & 5 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand 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,
Expand Down Expand Up @@ -193,7 +193,6 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}

deprecatedEnableCustomStateSSZFlag = &cli.BoolFlag{
Name: "enable-custom-state-ssz",
Usage: deprecatedUsage,
Expand Down Expand Up @@ -272,6 +271,7 @@ var (
)

var deprecatedFlags = []cli.Flag{
deprecatedEnableNoiseHandshake,
deprecatedEnableFinalizedBlockRootIndexFlag,
deprecatedScatterFlag,
deprecatedPruneFinalizedStatesFlag,
Expand Down Expand Up @@ -332,7 +332,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
enableByteMempool,
enableStateGenSigVerify,
checkHeadState,
enableNoiseHandshake,
dontPruneStateStartUp,
broadcastSlashingFlag,
newStateMgmt,
Expand Down

0 comments on commit a8d32d5

Please sign in to comment.