Skip to content

Commit b6894ff

Browse files
feat: disable default dht discovery forwarding (#7128)
Description --- - Disabled default forwarding of DHT discovery messages as this is not required for the proper operation of the network. A config option has been added to enable or disable this, but the default is false. - Adjusted the DHT dedup cache default config to be a lot more conservative before starting new dedup cycle - the amount of time an identical inbound message will be ignored before being processed again. Motivation and Context --- Mainnet is being flooded with messages that do not contribute to the blockchain. How Has This Been Tested? --- System-level testing shows markedly reduced overheads, inbound pipeline finish times and overall memory usage. The dedup cache also does its job much better now so the base node does not can ignore the endless round robbin of the messages. What process can a PR reviewer use to test or verify this change? --- Code review. System-level testing. <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new configuration option to enable or disable message forwarding in the network's DHT. This option is disabled by default and can be enabled for communication nodes. - **Improvements** - Increased the default cache capacity for deduplication and extended the default cache trim interval, enhancing overall message handling efficiency. - **Documentation** - Updated configuration files and documentation comments to reflect the new forwarding option and revised cache settings. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: SW van Heerden <swvheerden@gmail.com>
1 parent da7cd26 commit b6894ff

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

common/config/presets/c_base_node_c.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ database_url = "data/base_node/dht.db"
331331
# or
332332
# `excluded_dial_addresses = ["/ip4/127.0:0.1/tcp/122", "/ip4/127.0:0.1/tcp/1000:2000"]`
333333
excluded_dial_addresses = []
334+
# Enables the DHT to forward messages to other nodes in the network - communication nodes only (Default: false)
335+
#enable_forwarding = false
334336

335337
# setting this to some version will reject peers that dont meet the min version or the agent string in the correct string.
336338
# peer string should match X/X/X/X/{VERSION} where the last segment is the version in semer versioning scheme

common/config/presets/d_console_wallet.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ ban_duration_short = 60 # 1 min
369369
# or
370370
# `excluded_dial_addresses = ["/ip4/127.0:0.1/tcp/122", "/ip4/127.0:0.1/tcp/1000:2000"]`
371371
excluded_dial_addresses = []
372+
# Enables the DHT to forward messages to other nodes in the network - communication nodes only (Default: false)
373+
#enable_forwarding = false
372374

373375
# setting this to some version will reject peers that dont meet the min version or the agent string in the correct string.
374376
# peer string should match X/X/X/X/{VERSION} where the last segment is the version in semer versioning scheme

comms/dht/src/config.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ pub struct DhtConfig {
5252
/// Default: 4
5353
pub propagation_factor: usize,
5454
/// The max capacity of the message hash cache
55-
/// Default: 2,500
55+
/// Default: 50,000
5656
pub dedup_cache_capacity: usize,
5757
/// The periodic trim interval for items in the message hash cache
58-
/// Default: 300s (5 mins)
58+
/// Default: 12 x 60 x 60s (12 hours)
5959
#[serde(with = "serializers::seconds")]
6060
pub dedup_cache_trim_interval: Duration,
6161
/// The number of occurrences of a message is allowed to pass through the DHT pipeline before being
@@ -111,6 +111,9 @@ pub struct DhtConfig {
111111
/// or
112112
/// `excluded_dial_addresses = ["/ip4/127.0:0.1/tcp/122", "/ip4/127.0:0.1/tcp/1000:2000"]`
113113
pub excluded_dial_addresses: MultiaddrRangeList,
114+
/// Enables the DHT to forward messages to other nodes in the network - communication nodes only
115+
/// Default: false
116+
pub enable_forwarding: bool,
114117
}
115118

116119
impl DhtConfig {
@@ -140,6 +143,7 @@ impl DhtConfig {
140143
..Default::default()
141144
},
142145
excluded_dial_addresses: vec![].into(),
146+
enable_forwarding: true,
143147
..Default::default()
144148
}
145149
}
@@ -168,8 +172,8 @@ impl Default for DhtConfig {
168172
minimize_connections: false,
169173
propagation_factor: 20,
170174
broadcast_factor: 8,
171-
dedup_cache_capacity: 2_500,
172-
dedup_cache_trim_interval: Duration::from_secs(5 * 60),
175+
dedup_cache_capacity: 50_000,
176+
dedup_cache_trim_interval: Duration::from_secs(12 * 60 * 60), // 12 hours
173177
dedup_allowed_message_occurrences: 1,
174178
database_url: DbConnectionUrl::Memory,
175179
discovery_request_timeout: Duration::from_secs(2 * 60),
@@ -185,6 +189,7 @@ impl Default for DhtConfig {
185189
offline_peer_cooldown: Duration::from_secs(24 * 60 * 60),
186190
peer_validator_config: Default::default(),
187191
excluded_dial_addresses: vec![].into(),
192+
enable_forwarding: false,
188193
}
189194
}
190195
}

comms/dht/src/dht.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ impl Dht {
272272
.layer(ForwardLayer::new(
273273
self.dht_requester(),
274274
self.outbound_requester(),
275-
self.node_identity.features().contains(PeerFeatures::DHT_STORE_FORWARD),
275+
self.node_identity.features().contains(PeerFeatures::DHT_STORE_FORWARD) &&
276+
self.config.enable_forwarding,
276277
))
277278
.layer(inbound::DhtHandlerLayer::new(
278279
self.config.clone(),
@@ -532,6 +533,7 @@ mod test {
532533
// Send all outbound requests to the mock
533534
let dht = Dht::builder()
534535
.with_outbound_sender(oms_requester.get_mpsc_sender())
536+
.with_config(DhtConfig::default_local_test())
535537
.build(
536538
Arc::clone(&node_identity),
537539
peer_manager,

0 commit comments

Comments
 (0)