Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 51b2f0e

Browse files
authored
[frame/im-online] remove network state from heartbeats (#14251)
* [frame/im-online] remove `external_addresses` from heartbeats Users should use DHT for discovering new nodes. The reason for adding external addresses was unstable work of authority discovery (see #2719), which is now stable. Hence we can safely remove `external_addresses`. Refs https://github.com/paritytech/polkadot/issues/7181 * remove unused import * run benchmark * remove external_addresses from offchain NetworkState * add missing fn to TestNetwork * Revert "run benchmark" This reverts commit a282042. * update weights * address @bkchr comments * remove duplicate fn * cleanup benchmarking.rs * fix executor tests * remove peer_id from hearbeat as well #14251 (comment) * remove MaxPeerDataEncodingSize * change storage value type to `()` #14251 (comment) * scaffold storage migration * no need to check the type actually * remove unnecessary types from v0 mod * add a test for migration * expose Config types + pre_upgrade and post_upgrade working fn * fix test * replace dummy type with ConstU32 * add some comments to migration test * fix comment * respond to @bkchr comments * use BoundedOpaqueNetworkState::default intead of using default for each field
1 parent 075ba84 commit 51b2f0e

File tree

10 files changed

+226
-198
lines changed

10 files changed

+226
-198
lines changed

bin/node/executor/tests/submit_transaction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ fn should_submit_unsigned_transaction() {
3737
pallet_im_online::sr25519::AuthoritySignature::try_from(vec![0; 64]).unwrap();
3838
let heartbeat_data = pallet_im_online::Heartbeat {
3939
block_number: 1,
40-
network_state: Default::default(),
4140
session_index: 1,
4241
authority_index: 0,
4342
validators_len: 0,

bin/node/runtime/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,9 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
328328
RuntimeCall::Elections(..) |
329329
RuntimeCall::Treasury(..)
330330
),
331-
ProxyType::Staking =>
332-
matches!(c, RuntimeCall::Staking(..) | RuntimeCall::FastUnstake(..)),
331+
ProxyType::Staking => {
332+
matches!(c, RuntimeCall::Staking(..) | RuntimeCall::FastUnstake(..))
333+
},
333334
}
334335
}
335336
fn is_superset(&self, o: &Self) -> bool {
@@ -1261,7 +1262,6 @@ parameter_types! {
12611262
pub const MaxAuthorities: u32 = 100;
12621263
pub const MaxKeys: u32 = 10_000;
12631264
pub const MaxPeerInHeartbeats: u32 = 10_000;
1264-
pub const MaxPeerDataEncodingSize: u32 = 1_000;
12651265
}
12661266

12671267
impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
@@ -1329,7 +1329,6 @@ impl pallet_im_online::Config for Runtime {
13291329
type WeightInfo = pallet_im_online::weights::SubstrateWeight<Runtime>;
13301330
type MaxKeys = MaxKeys;
13311331
type MaxPeerInHeartbeats = MaxPeerInHeartbeats;
1332-
type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize;
13331332
}
13341333

13351334
impl pallet_offences::Config for Runtime {

client/offchain/src/api.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ impl AsyncApi {
324324
#[cfg(test)]
325325
mod tests {
326326
use super::*;
327-
use libp2p::PeerId;
328327
use sc_client_db::offchain::LocalStorage;
329328
use sc_network::{
330329
config::MultiaddrWithPeerId, types::ProtocolName, NetworkPeers, NetworkStateInfo,

frame/im-online/src/benchmarking.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use super::*;
2424
use frame_benchmarking::v1::benchmarks;
2525
use frame_support::{traits::UnfilteredDispatchable, WeakBoundedVec};
2626
use frame_system::RawOrigin;
27-
use sp_core::{offchain::OpaqueMultiaddr, OpaquePeerId};
2827
use sp_runtime::{
2928
traits::{ValidateUnsigned, Zero},
3029
transaction_validity::TransactionSource,
@@ -33,11 +32,9 @@ use sp_runtime::{
3332
use crate::Pallet as ImOnline;
3433

3534
const MAX_KEYS: u32 = 1000;
36-
const MAX_EXTERNAL_ADDRESSES: u32 = 100;
3735

3836
pub fn create_heartbeat<T: Config>(
3937
k: u32,
40-
e: u32,
4138
) -> Result<
4239
(crate::Heartbeat<T::BlockNumber>, <T::AuthorityId as RuntimeAppPublic>::Signature),
4340
&'static str,
@@ -50,13 +47,8 @@ pub fn create_heartbeat<T: Config>(
5047
.map_err(|()| "More than the maximum number of keys provided")?;
5148
Keys::<T>::put(bounded_keys);
5249

53-
let network_state = OpaqueNetworkState {
54-
peer_id: OpaquePeerId::default(),
55-
external_addresses: vec![OpaqueMultiaddr::new(vec![0; 32]); e as usize],
56-
};
5750
let input_heartbeat = Heartbeat {
5851
block_number: T::BlockNumber::zero(),
59-
network_state,
6052
session_index: 0,
6153
authority_index: k - 1,
6254
validators_len: keys.len() as u32,
@@ -73,15 +65,13 @@ benchmarks! {
7365
#[extra]
7466
heartbeat {
7567
let k in 1 .. MAX_KEYS;
76-
let e in 1 .. MAX_EXTERNAL_ADDRESSES;
77-
let (input_heartbeat, signature) = create_heartbeat::<T>(k, e)?;
68+
let (input_heartbeat, signature) = create_heartbeat::<T>(k)?;
7869
}: _(RawOrigin::None, input_heartbeat, signature)
7970

8071
#[extra]
8172
validate_unsigned {
8273
let k in 1 .. MAX_KEYS;
83-
let e in 1 .. MAX_EXTERNAL_ADDRESSES;
84-
let (input_heartbeat, signature) = create_heartbeat::<T>(k, e)?;
74+
let (input_heartbeat, signature) = create_heartbeat::<T>(k)?;
8575
let call = Call::heartbeat { heartbeat: input_heartbeat, signature };
8676
}: {
8777
ImOnline::<T>::validate_unsigned(TransactionSource::InBlock, &call)
@@ -90,8 +80,7 @@ benchmarks! {
9080

9181
validate_unsigned_and_then_heartbeat {
9282
let k in 1 .. MAX_KEYS;
93-
let e in 1 .. MAX_EXTERNAL_ADDRESSES;
94-
let (input_heartbeat, signature) = create_heartbeat::<T>(k, e)?;
83+
let (input_heartbeat, signature) = create_heartbeat::<T>(k)?;
9584
let call = Call::heartbeat { heartbeat: input_heartbeat, signature };
9685
let call_enc = call.encode();
9786
}: {

0 commit comments

Comments
 (0)