Skip to content

Commit

Permalink
Merge branch 'master' into backport-tests-for-claim-assets
Browse files Browse the repository at this point in the history
  • Loading branch information
programskillforverification committed Jul 16, 2024
2 parents cfd3605 + cde2eb4 commit 3afa7de
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/command-bench-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:
runs-on: arc-runners-polkadot-sdk-weights
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/command-bench-overhead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
runs-on: arc-runners-polkadot-sdk-benchmark
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/command-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ jobs:
runs-on: arc-runners-polkadot-sdk-benchmark
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/command-fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
timeout-minutes: 20
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/command-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
runs-on: arc-runners-polkadot-sdk-warpsync
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/command-update-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
timeout-minutes: 90
container:
image: ${{ needs.set-image.outputs.IMAGE }}
permissions:
contents: write
pull-requests: write
steps:
- name: Download repo
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# this image is built on top of existing Zombienet image
ARG ZOMBIENET_IMAGE
# this image uses substrate-relay image built elsewhere
ARG SUBSTRATE_RELAY_IMAGE=docker.io/paritytech/substrate-relay:v1.6.5
ARG SUBSTRATE_RELAY_IMAGE=docker.io/paritytech/substrate-relay:v1.6.6

# metadata
ARG VCS_REF
Expand Down
30 changes: 21 additions & 9 deletions polkadot/node/network/approval-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,21 @@ impl State {
let required_routing = topology.map_or(RequiredRouting::PendingTopology, |t| {
t.local_grid_neighbors().required_routing_by_index(validator_index, local)
});
// Peers that we will send the assignment to.
let mut peers = HashSet::new();

let peers_to_route_to = topology
.as_ref()
.map(|t| t.peers_to_route(required_routing))
.unwrap_or_default();

for peer in peers_to_route_to {
if !entry.known_by.contains_key(&peer) {
continue
}

peers.insert(peer);
}

// All the peers that know the relay chain block.
let peers_to_filter = entry.known_by();
Expand All @@ -1456,20 +1471,13 @@ impl State {
let n_peers_total = self.peer_views.len();
let source_peer = source.peer_id();

// Peers that we will send the assignment to.
let mut peers = Vec::new();

// Filter destination peers
for peer in peers_to_filter.into_iter() {
if Some(peer) == source_peer {
continue
}

if let Some(true) = topology
.as_ref()
.map(|t| t.local_grid_neighbors().route_to_peer(required_routing, &peer))
{
peers.push(peer);
if peers.contains(&peer) {
continue
}

Expand All @@ -1485,7 +1493,11 @@ impl State {

if route_random {
approval_entry.routing_info_mut().mark_randomly_sent(peer);
peers.push(peer);
peers.insert(peer);
}

if approval_entry.routing_info().random_routing.is_complete() {
break
}
}

Expand Down
12 changes: 8 additions & 4 deletions polkadot/node/network/approval-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ fn propagates_locally_generated_assignment_to_both_dimensions() {
let assignments = vec![(cert.clone(), candidate_index)];
let approvals = vec![approval.clone()];

let assignment_sent_peers = assert_matches!(
let mut assignment_sent_peers = assert_matches!(
overseer_recv(overseer).await,
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
sent_peers,
Expand All @@ -2428,12 +2428,14 @@ fn propagates_locally_generated_assignment_to_both_dimensions() {
assert_matches!(
overseer_recv(overseer).await,
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
sent_peers,
mut sent_peers,
Versioned::V1(protocol_v1::ValidationProtocol::ApprovalDistribution(
protocol_v1::ApprovalDistributionMessage::Approvals(sent_approvals)
))
)) => {
// Random sampling is reused from the assignment.
sent_peers.sort();
assignment_sent_peers.sort();
assert_eq!(sent_peers, assignment_sent_peers);
assert_eq!(sent_approvals, approvals);
}
Expand Down Expand Up @@ -2678,7 +2680,7 @@ fn propagates_to_required_after_connect() {
let assignments = vec![(cert.clone(), candidate_index)];
let approvals = vec![approval.clone()];

let assignment_sent_peers = assert_matches!(
let mut assignment_sent_peers = assert_matches!(
overseer_recv(overseer).await,
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
sent_peers,
Expand All @@ -2702,12 +2704,14 @@ fn propagates_to_required_after_connect() {
assert_matches!(
overseer_recv(overseer).await,
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
sent_peers,
mut sent_peers,
Versioned::V1(protocol_v1::ValidationProtocol::ApprovalDistribution(
protocol_v1::ApprovalDistributionMessage::Approvals(sent_approvals)
))
)) => {
// Random sampling is reused from the assignment.
sent_peers.sort();
assignment_sent_peers.sort();
assert_eq!(sent_peers, assignment_sent_peers);
assert_eq!(sent_approvals, approvals);
}
Expand Down
22 changes: 22 additions & 0 deletions polkadot/node/network/protocol/src/grid_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ impl SessionGridTopologyEntry {
self.topology.is_validator(peer)
}

/// Returns the list of peers to route based on the required routing.
pub fn peers_to_route(&self, required_routing: RequiredRouting) -> Vec<PeerId> {
match required_routing {
RequiredRouting::All => self.topology.peer_ids.iter().copied().collect(),
RequiredRouting::GridX => self.local_neighbors.peers_x.iter().copied().collect(),
RequiredRouting::GridY => self.local_neighbors.peers_y.iter().copied().collect(),
RequiredRouting::GridXY => self
.local_neighbors
.peers_x
.iter()
.chain(self.local_neighbors.peers_y.iter())
.copied()
.collect(),
RequiredRouting::None | RequiredRouting::PendingTopology => Vec::new(),
}
}

/// Updates the known peer ids for the passed authorities ids.
pub fn update_authority_ids(
&mut self,
Expand Down Expand Up @@ -524,6 +541,11 @@ impl RandomRouting {
pub fn inc_sent(&mut self) {
self.sent += 1
}

/// Returns `true` if we already took all the necessary samples.
pub fn is_complete(&self) -> bool {
self.sent >= self.target
}
}

/// Routing mode
Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_4848.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: Optimize logic for gossiping assignments

doc:
- audience: Node Dev
description: |
Optimize the logic for gossiping assignments by obtaining the list of peer ids
from the topology instead of iterating through all connected validators, this
gives us a 15% to 20% reduction in cpu usage.

crates:
- name: polkadot-approval-distribution
bump: minor
- name: polkadot-node-network-protocol
bump: minor
14 changes: 14 additions & 0 deletions prdoc/pr_4972.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Remove `pallet::getter` usage from pallet-session"

doc:
- audience: Runtime Dev
description: |
This PR removes the `pallet::getter`s from `pallet-session`.
The syntax `StorageItem::<T, I>::get()` should be used instead.

crates:
- name: pallet-session
bump: minor
4 changes: 4 additions & 0 deletions substrate/client/network/src/litep2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkBackend<B, H> for Litep2pNetworkBac
"`PUT_VALUE` for {key:?} ({query_id:?}) succeeded",
);

self.event_streams.send(Event::Dht(
DhtEvent::ValuePut(libp2p::kad::RecordKey::new(&key))
));

if let Some(ref metrics) = self.metrics {
metrics
.kademlia_query_duration
Expand Down
5 changes: 3 additions & 2 deletions substrate/client/rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ where
),
};

let rpc_middleware =
RpcServiceBuilder::new().option_layer(middleware_layer.clone());
let rpc_middleware = RpcServiceBuilder::new()
.rpc_logger(1024)
.option_layer(middleware_layer.clone());
let mut svc =
service_builder.set_rpc_middleware(rpc_middleware).build(methods, stop_handle);

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/session/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ set.
use pallet_session as session;

fn validators<T: pallet_session::Config>() -> Vec<<T as pallet_session::Config>::ValidatorId> {
<pallet_session::Pallet<T>>::validators()
pallet_session::Validators::<T>::get()
}
```

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/session/benchmarking/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn check_membership_proof_setup<T: Config>(
Pallet::<T>::on_initialize(frame_system::pallet_prelude::BlockNumberFor::<T>::one());

// skip sessions until the new validator set is enacted
while Session::<T>::validators().len() < n as usize {
while Validators::<T>::get().len() < n as usize {
Session::<T>::rotate_session();
}

Expand Down
Loading

0 comments on commit 3afa7de

Please sign in to comment.