Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored Dec 30, 2024
2 parents 2b26396 + b4177a9 commit 838f88d
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 34 deletions.
4 changes: 3 additions & 1 deletion .config/lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exclude = [
"http://visitme/",
"https://visitme/",

# TODO <https://github.com/paritytech/polkadot-sdk/issues/134>
# TODO meta issue: <https://github.com/paritytech/polkadot-sdk/issues/134>
"https://docs.substrate.io/main-docs/build/custom-rpc/#public-rpcs",
"https://docs.substrate.io/rustdocs/latest/sp_api/macro.decl_runtime_apis.html",
"https://github.com/ipfs/js-ipfs-bitswap/blob/",
Expand All @@ -50,8 +50,10 @@ exclude = [
"https://w3f.github.io/parachain-implementers-guide/runtime/session_info.html",

# Behind a captcha (code 403):
"https://chainlist.org/chain/*",
"https://iohk.io/en/blog/posts/2023/11/03/partner-chains-are-coming-to-cardano/",
"https://www.reddit.com/r/rust/comments/3spfh1/does_collect_allocate_more_than_once_while/",

# 403 rate limited:
"https://etherscan.io/block/11090290",
"https://subscan.io/",
Expand Down
7 changes: 7 additions & 0 deletions prdoc/pr_7005.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Log peerset set ID -> protocol name mapping
doc:
- audience: Node Dev
description: To simplify debugging of peerset related issues like https://github.com/paritytech/polkadot-sdk/issues/6573#issuecomment-2563091343.
crates:
- name: sc-network
bump: patch
16 changes: 16 additions & 0 deletions prdoc/pr_7011.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: 'sync: Send already connected peers to new subscribers'
doc:
- audience: Node Dev
description: |-
Introduce `SyncEvent::InitialPeers` message sent to new subscribers to allow them correctly tracking sync peers. This resolves a race condition described in https://github.com/paritytech/polkadot-sdk/issues/6573#issuecomment-2563091343.

Fixes https://github.com/paritytech/polkadot-sdk/issues/6573.
crates:
- name: sc-network-gossip
bump: major
- name: sc-network-statement
bump: patch
- name: sc-network-sync
bump: major
- name: sc-network-transactions
bump: patch
7 changes: 7 additions & 0 deletions prdoc/pr_7013.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: 'pallet-bounties: Fix benchmarks for 0 ED'
doc:
- audience: Runtime Dev
description: 'Closes: https://github.com/paritytech/polkadot-sdk/issues/7009'
crates:
- name: pallet-bounties
bump: patch
10 changes: 6 additions & 4 deletions substrate/client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ impl<B: BlockT> Future for GossipEngine<B> {

match sync_event_stream {
Poll::Ready(Some(event)) => match event {
SyncEvent::PeerConnected(remote) =>
this.network.add_set_reserved(remote, this.protocol.clone()),
SyncEvent::PeerDisconnected(remote) =>
this.network.remove_set_reserved(remote, this.protocol.clone()),
SyncEvent::InitialPeers(peer_ids) =>
this.network.add_set_reserved(peer_ids, this.protocol.clone()),
SyncEvent::PeerConnected(peer_id) =>
this.network.add_set_reserved(vec![peer_id], this.protocol.clone()),
SyncEvent::PeerDisconnected(peer_id) =>
this.network.remove_set_reserved(peer_id, this.protocol.clone()),
},
// The sync event stream closed. Do the same for [`GossipValidator`].
Poll::Ready(None) => {
Expand Down
13 changes: 8 additions & 5 deletions substrate/client/network-gossip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ mod validator;

/// Abstraction over a network.
pub trait Network<B: BlockT>: NetworkPeers + NetworkEventStream {
fn add_set_reserved(&self, who: PeerId, protocol: ProtocolName) {
let addr = Multiaddr::empty().with(Protocol::P2p(*who.as_ref()));
let result = self.add_peers_to_reserved_set(protocol, iter::once(addr).collect());
fn add_set_reserved(&self, peer_ids: Vec<PeerId>, protocol: ProtocolName) {
let addrs = peer_ids
.into_iter()
.map(|peer_id| Multiaddr::empty().with(Protocol::P2p(peer_id.into())))
.collect();
let result = self.add_peers_to_reserved_set(protocol, addrs);
if let Err(err) = result {
log::error!(target: "gossip", "add_set_reserved failed: {}", err);
}
}
fn remove_set_reserved(&self, who: PeerId, protocol: ProtocolName) {
let result = self.remove_peers_from_reserved_set(protocol, iter::once(who).collect());
fn remove_set_reserved(&self, peer_id: PeerId, protocol: ProtocolName) {
let result = self.remove_peers_from_reserved_set(protocol, iter::once(peer_id).collect());
if let Err(err) = result {
log::error!(target: "gossip", "remove_set_reserved failed: {}", err);
}
Expand Down
11 changes: 9 additions & 2 deletions substrate/client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use libp2p::{
},
Multiaddr, PeerId,
};
use log::warn;
use log::{debug, warn};

use codec::DecodeAll;
use sc_network_common::role::Roles;
Expand All @@ -53,6 +53,9 @@ mod notifications;

pub mod message;

// Log target for this file.
const LOG_TARGET: &str = "sub-libp2p";

/// Maximum size used for notifications in the block announce and transaction protocols.
// Must be equal to `max(MAX_BLOCK_ANNOUNCE_SIZE, MAX_TRANSACTIONS_SIZE)`.
pub(crate) const BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE: u64 = MAX_RESPONSE_SIZE;
Expand Down Expand Up @@ -124,6 +127,10 @@ impl<B: BlockT> Protocol<B> {
handle.set_metrics(notification_metrics.clone());
});

protocol_configs.iter().enumerate().for_each(|(i, (p, _, _))| {
debug!(target: LOG_TARGET, "Notifications protocol {:?}: {}", SetId::from(i), p.name);
});

(
Notifications::new(
protocol_controller_handles,
Expand Down Expand Up @@ -164,7 +171,7 @@ impl<B: BlockT> Protocol<B> {
{
self.behaviour.disconnect_peer(peer_id, SetId::from(position));
} else {
warn!(target: "sub-libp2p", "disconnect_peer() with invalid protocol name")
warn!(target: LOG_TARGET, "disconnect_peer() with invalid protocol name")
}
}

Expand Down
23 changes: 17 additions & 6 deletions substrate/client/network/statement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use futures::{channel::oneshot, prelude::*, stream::FuturesUnordered, FutureExt}
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use sc_network::{
config::{NonReservedPeerMode, SetConfig},
error, multiaddr,
error,
multiaddr::{Multiaddr, Protocol},
peer_store::PeerStoreProvider,
service::{
traits::{NotificationEvent, NotificationService, ValidationResult},
Expand Down Expand Up @@ -296,9 +297,19 @@ where

fn handle_sync_event(&mut self, event: SyncEvent) {
match event {
SyncEvent::PeerConnected(remote) => {
let addr = iter::once(multiaddr::Protocol::P2p(remote.into()))
.collect::<multiaddr::Multiaddr>();
SyncEvent::InitialPeers(peer_ids) => {
let addrs = peer_ids
.into_iter()
.map(|peer_id| Multiaddr::empty().with(Protocol::P2p(peer_id.into())))
.collect();
let result =
self.network.add_peers_to_reserved_set(self.protocol_name.clone(), addrs);
if let Err(err) = result {
log::error!(target: LOG_TARGET, "Add reserved peers failed: {}", err);
}
},
SyncEvent::PeerConnected(peer_id) => {
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
let result = self.network.add_peers_to_reserved_set(
self.protocol_name.clone(),
iter::once(addr).collect(),
Expand All @@ -307,10 +318,10 @@ where
log::error!(target: LOG_TARGET, "Add reserved peer failed: {}", err);
}
},
SyncEvent::PeerDisconnected(remote) => {
SyncEvent::PeerDisconnected(peer_id) => {
let result = self.network.remove_peers_from_reserved_set(
self.protocol_name.clone(),
iter::once(remote).collect(),
iter::once(peer_id).collect(),
);
if let Err(err) = result {
log::error!(target: LOG_TARGET, "Failed to remove reserved peer: {err}");
Expand Down
6 changes: 5 additions & 1 deletion substrate/client/network/sync/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,11 @@ where
ToServiceCommand::SetSyncForkRequest(peers, hash, number) => {
self.strategy.set_sync_fork_request(peers, &hash, number);
},
ToServiceCommand::EventStream(tx) => self.event_streams.push(tx),
ToServiceCommand::EventStream(tx) => {
let _ = tx
.unbounded_send(SyncEvent::InitialPeers(self.peers.keys().cloned().collect()));
self.event_streams.push(tx);
},
ToServiceCommand::RequestJustification(hash, number) =>
self.strategy.request_justification(&hash, number),
ToServiceCommand::ClearJustificationRequests =>
Expand Down
4 changes: 4 additions & 0 deletions substrate/client/network/sync/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ where

/// Syncing-related events that other protocols can subscribe to.
pub enum SyncEvent {
/// All connected peers that the syncing implementation is tracking.
/// Always sent as the first message to the stream.
InitialPeers(Vec<PeerId>),

/// Peer that the syncing implementation is tracking connected.
PeerConnected(PeerId),

Expand Down
23 changes: 17 additions & 6 deletions substrate/client/network/transactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use log::{debug, trace, warn};
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use sc_network::{
config::{NonReservedPeerMode, ProtocolId, SetConfig},
error, multiaddr,
error,
multiaddr::{Multiaddr, Protocol},
peer_store::PeerStoreProvider,
service::{
traits::{NotificationEvent, NotificationService, ValidationResult},
Expand Down Expand Up @@ -377,9 +378,19 @@ where

fn handle_sync_event(&mut self, event: SyncEvent) {
match event {
SyncEvent::PeerConnected(remote) => {
let addr = iter::once(multiaddr::Protocol::P2p(remote.into()))
.collect::<multiaddr::Multiaddr>();
SyncEvent::InitialPeers(peer_ids) => {
let addrs = peer_ids
.into_iter()
.map(|peer_id| Multiaddr::empty().with(Protocol::P2p(peer_id.into())))
.collect();
let result =
self.network.add_peers_to_reserved_set(self.protocol_name.clone(), addrs);
if let Err(err) = result {
log::error!(target: LOG_TARGET, "Add reserved peers failed: {}", err);
}
},
SyncEvent::PeerConnected(peer_id) => {
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
let result = self.network.add_peers_to_reserved_set(
self.protocol_name.clone(),
iter::once(addr).collect(),
Expand All @@ -388,10 +399,10 @@ where
log::error!(target: LOG_TARGET, "Add reserved peer failed: {}", err);
}
},
SyncEvent::PeerDisconnected(remote) => {
SyncEvent::PeerDisconnected(peer_id) => {
let result = self.network.remove_peers_from_reserved_set(
self.protocol_name.clone(),
iter::once(remote).collect(),
iter::once(peer_id).collect(),
);
if let Err(err) = result {
log::error!(target: LOG_TARGET, "Remove reserved peer failed: {}", err);
Expand Down
24 changes: 15 additions & 9 deletions substrate/frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! bounties pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]
//! Bounties pallet benchmarking.
use super::*;

Expand All @@ -37,6 +35,16 @@ fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T, I>) {
<T as pallet_treasury::Config<I>>::BlockNumberProvider::set_block_number(n);
}

fn minimum_balance<T: Config<I>, I: 'static>() -> BalanceOf<T, I> {
let minimum_balance = T::Currency::minimum_balance();

if minimum_balance.is_zero() {
1u32.into()
} else {
minimum_balance
}
}

// Create bounties that are approved for use in `on_initialize`.
fn create_approved_bounties<T: Config<I>, I: 'static>(n: u32) -> Result<(), BenchmarkError> {
for i in 0..n {
Expand All @@ -62,12 +70,10 @@ fn setup_bounty<T: Config<I>, I: 'static>(
let fee = value / 2u32.into();
let deposit = T::BountyDepositBase::get() +
T::DataDepositPerByte::get() * T::MaximumReasonLength::get().into();
let _ = T::Currency::make_free_balance_be(&caller, deposit + T::Currency::minimum_balance());
let _ = T::Currency::make_free_balance_be(&caller, deposit + minimum_balance::<T, I>());
let curator = account("curator", u, SEED);
let _ = T::Currency::make_free_balance_be(
&curator,
fee / 2u32.into() + T::Currency::minimum_balance(),
);
let _ =
T::Currency::make_free_balance_be(&curator, fee / 2u32.into() + minimum_balance::<T, I>());
let reason = vec![0; d as usize];
(caller, curator, fee, value, reason)
}
Expand All @@ -91,7 +97,7 @@ fn create_bounty<T: Config<I>, I: 'static>(

fn setup_pot_account<T: Config<I>, I: 'static>() {
let pot_account = Bounties::<T, I>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
let value = minimum_balance::<T, I>().saturating_mul(1_000_000_000u32.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
}

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod migrations;
mod tests;
Expand Down

0 comments on commit 838f88d

Please sign in to comment.