From d3b4cbed53b91b85f5cba0a9e49413d403827eae Mon Sep 17 00:00:00 2001 From: Pawan Dhananjay Date: Thu, 26 Aug 2021 00:29:39 +0000 Subject: [PATCH] Packet filter cli option (#2523) ## Issue Addressed N/A ## Proposed Changes Adds a cli option to disable packet filter in `lighthouse bootnode`. This is useful in running local testnets as the bootnode bans requests from the same ip(localhost) if the packet filter is enabled. --- beacon_node/src/cli.rs | 6 ++++++ beacon_node/src/config.rs | 5 +++++ boot_node/src/cli.rs | 5 +++++ boot_node/src/config.rs | 3 +++ boot_node/src/server.rs | 4 +++- scripts/local_testnet/beacon_node.sh | 1 + scripts/local_testnet/bootnode.sh | 1 + 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index e6f167396..712f0eae7 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -45,6 +45,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { --subscribe-all-subnets to ensure all attestations are received for import.") .takes_value(false), ) + .arg( + Arg::with_name("disable-packet-filter") + .long("disable-packet-filter") + .help("Disables the discovery packet filter. Useful for testing in smaller networks") + .takes_value(false), + ) .arg( Arg::with_name("zero-ports") .long("zero-ports") diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 40b9ced58..628ecf316 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -612,6 +612,11 @@ pub fn set_network_config( config.discv5_config.enr_update = false; } + if cli_args.is_present("disable-packet-filter") { + warn!(log, "Discv5 packet filter is disabled"); + config.discv5_config.enable_packet_filter = false; + } + if cli_args.is_present("disable-discovery") { config.disable_discovery = true; warn!(log, "Discovery is disabled. New peers will not be found"); diff --git a/boot_node/src/cli.rs b/boot_node/src/cli.rs index c82a452b0..9a3732002 100644 --- a/boot_node/src/cli.rs +++ b/boot_node/src/cli.rs @@ -60,6 +60,11 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .help("Discovery can automatically update the node's local ENR with an external IP address and port as seen by other peers on the network. \ This enables this feature.") ) + .arg( + Arg::with_name("disable-packet-filter") + .long("disable-packet-filter") + .help("Disables discv5 packet filter. Useful for testing in smaller networks") + ) .arg( Arg::with_name("network-dir") .value_name("NETWORK_DIR") diff --git a/boot_node/src/config.rs b/boot_node/src/config.rs index 00a1ab560..0d5aab1ab 100644 --- a/boot_node/src/config.rs +++ b/boot_node/src/config.rs @@ -19,6 +19,7 @@ pub struct BootNodeConfig { pub local_enr: Enr, pub local_key: CombinedKey, pub auto_update: bool, + pub disable_packet_filter: bool, phantom: PhantomData, } @@ -69,6 +70,7 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { } let auto_update = matches.is_present("enable-enr_auto_update"); + let disable_packet_filter = matches.is_present("disable-packet-filter"); // the address to listen on let listen_socket = @@ -128,6 +130,7 @@ impl TryFrom<&ArgMatches<'_>> for BootNodeConfig { local_enr, local_key, auto_update, + disable_packet_filter, phantom: PhantomData, }) } diff --git a/boot_node/src/server.rs b/boot_node/src/server.rs index 3cdd8789a..fc1de95f4 100644 --- a/boot_node/src/server.rs +++ b/boot_node/src/server.rs @@ -32,7 +32,9 @@ pub async fn run(config: BootNodeConfig, log: slog::Logger) { let discv5_config = { let mut builder = Discv5ConfigBuilder::new(); - builder.enable_packet_filter(); + if !config.disable_packet_filter { + builder.enable_packet_filter(); + } if !config.auto_update { builder.disable_enr_update(); } diff --git a/scripts/local_testnet/beacon_node.sh b/scripts/local_testnet/beacon_node.sh index 5c286e319..6b66bec05 100755 --- a/scripts/local_testnet/beacon_node.sh +++ b/scripts/local_testnet/beacon_node.sh @@ -21,4 +21,5 @@ exec lighthouse \ --enr-tcp-port $2 \ --port $2 \ --http-port $3 \ + --disable-packet-filter \ --target-peers $((NODE_COUNT - 1)) diff --git a/scripts/local_testnet/bootnode.sh b/scripts/local_testnet/bootnode.sh index 9558a487b..bef207a69 100755 --- a/scripts/local_testnet/bootnode.sh +++ b/scripts/local_testnet/bootnode.sh @@ -30,4 +30,5 @@ exec lighthouse boot_node \ --testnet-dir $TESTNET_DIR \ --port $BOOTNODE_PORT \ --listen-address 127.0.0.1 \ + --disable-packet-filter \ --network-dir $DATADIR/bootnode \