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

Commit

Permalink
Merge branch 'master' into ao-disputes-offences-runtime
Browse files Browse the repository at this point in the history
* master:
  Companion for Weight v1.5 Follow Up (#5949)
  [Feature] Make XCM benchmarks more reusable and remove a redundant bench (#5936)
  companion `try-state` (#5907)
  Don't store available data on disputes (#5950)
  • Loading branch information
ordian committed Sep 1, 2022
2 parents 9223d71 + de9e147 commit c48aa45
Show file tree
Hide file tree
Showing 140 changed files with 1,027 additions and 1,125 deletions.
345 changes: 175 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,7 @@ impl Initialized {
.queue_participation(
ctx,
priority,
ParticipationRequest::new(
new_state.candidate_receipt().clone(),
session,
env.validators().len(),
),
ParticipationRequest::new(new_state.candidate_receipt().clone(), session),
)
.await;
log_error(r)?;
Expand Down
7 changes: 1 addition & 6 deletions node/core/dispute-coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ impl DisputeCoordinatorSubsystem {
Some(info) => info.validators.clone(),
};

let n_validators = validators.len();
let voted_indices = votes.voted_indices();

// Determine if there are any missing local statements for this dispute. Validators are
Expand Down Expand Up @@ -335,11 +334,7 @@ impl DisputeCoordinatorSubsystem {
if missing_local_statement {
participation_requests.push((
ParticipationPriority::with_priority_if(is_included),
ParticipationRequest::new(
votes.candidate_receipt.clone(),
session,
n_validators,
),
ParticipationRequest::new(votes.candidate_receipt.clone(), session),
));
}
}
Expand Down
34 changes: 1 addition & 33 deletions node/core/dispute-coordinator/src/participation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use futures_timer::Delay;

use polkadot_node_primitives::{ValidationResult, APPROVAL_EXECUTION_TIMEOUT};
use polkadot_node_subsystem::{
messages::{AvailabilityRecoveryMessage, AvailabilityStoreMessage, CandidateValidationMessage},
messages::{AvailabilityRecoveryMessage, CandidateValidationMessage},
overseer, ActiveLeavesUpdate, RecoveryError,
};
use polkadot_node_subsystem_util::runtime::get_validation_code_by_hash;
Expand Down Expand Up @@ -319,38 +319,6 @@ async fn participate(
},
};

// we dispatch a request to store the available data for the candidate. We
// want to maximize data availability for other potential checkers involved
// in the dispute
let (store_available_data_tx, store_available_data_rx) = oneshot::channel();
sender
.send_message(AvailabilityStoreMessage::StoreAvailableData {
candidate_hash: *req.candidate_hash(),
n_validators: req.n_validators() as u32,
available_data: available_data.clone(),
tx: store_available_data_tx,
})
.await;

match store_available_data_rx.await {
Err(oneshot::Canceled) => {
gum::warn!(
target: LOG_TARGET,
"`Oneshot` got cancelled when storing available data {:?}",
req.candidate_hash(),
);
},
Ok(Err(err)) => {
gum::warn!(
target: LOG_TARGET,
?err,
"Failed to store available data for candidate {:?}",
req.candidate_hash(),
);
},
Ok(Ok(())) => {},
}

// Issue a request to validate the candidate with the provided exhaustive
// parameters
//
Expand Down
12 changes: 2 additions & 10 deletions node/core/dispute-coordinator/src/participation/queues/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub struct ParticipationRequest {
candidate_hash: CandidateHash,
candidate_receipt: CandidateReceipt,
session: SessionIndex,
n_validators: usize,
}

/// Whether a `ParticipationRequest` should be put on best-effort or the priority queue.
Expand Down Expand Up @@ -122,12 +121,8 @@ pub enum QueueError {

impl ParticipationRequest {
/// Create a new `ParticipationRequest` to be queued.
pub fn new(
candidate_receipt: CandidateReceipt,
session: SessionIndex,
n_validators: usize,
) -> Self {
Self { candidate_hash: candidate_receipt.hash(), candidate_receipt, session, n_validators }
pub fn new(candidate_receipt: CandidateReceipt, session: SessionIndex) -> Self {
Self { candidate_hash: candidate_receipt.hash(), candidate_receipt, session }
}

pub fn candidate_receipt(&'_ self) -> &'_ CandidateReceipt {
Expand All @@ -139,9 +134,6 @@ impl ParticipationRequest {
pub fn session(&self) -> SessionIndex {
self.session
}
pub fn n_validators(&self) -> usize {
self.n_validators
}
pub fn into_candidate_info(self) -> (CandidateHash, CandidateReceipt) {
let Self { candidate_hash, candidate_receipt, .. } = self;
(candidate_hash, candidate_receipt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn make_participation_request(hash: Hash) -> ParticipationRequest {
let mut receipt = dummy_candidate_receipt(dummy_hash());
// make it differ:
receipt.commitments_hash = hash;
ParticipationRequest::new(receipt, 1, 100)
ParticipationRequest::new(receipt, 1)
}

/// Make dummy comparator for request, based on the given block number.
Expand Down
65 changes: 2 additions & 63 deletions node/core/dispute-coordinator/src/participation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use parity_scale_codec::Encode;
use polkadot_node_primitives::{AvailableData, BlockData, InvalidCandidate, PoV};
use polkadot_node_subsystem::{
jaeger,
messages::{
AllMessages, DisputeCoordinatorMessage, RuntimeApiMessage, RuntimeApiRequest,
ValidationFailed,
},
messages::{AllMessages, DisputeCoordinatorMessage, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, SpawnGlue,
};
use polkadot_node_subsystem_test_helpers::{
Expand Down Expand Up @@ -71,9 +68,8 @@ async fn participate_with_commitments_hash<Context>(
receipt
};
let session = 1;
let n_validators = 10;

let req = ParticipationRequest::new(candidate_receipt, session, n_validators);
let req = ParticipationRequest::new(candidate_receipt, session);

participation
.queue_participation(ctx, ParticipationPriority::BestEffort, req)
Expand Down Expand Up @@ -116,7 +112,6 @@ pub async fn participation_full_happy_path(
) {
recover_available_data(ctx_handle).await;
fetch_validation_code(ctx_handle).await;
store_available_data(ctx_handle, true).await;

assert_matches!(
ctx_handle.recv().await,
Expand Down Expand Up @@ -185,20 +180,6 @@ async fn fetch_validation_code(virtual_overseer: &mut VirtualOverseer) -> Hash {
)
}

async fn store_available_data(virtual_overseer: &mut VirtualOverseer, success: bool) {
assert_matches!(
virtual_overseer.recv().await,
AllMessages::AvailabilityStore(AvailabilityStoreMessage::StoreAvailableData { tx, .. }) => {
if success {
tx.send(Ok(())).unwrap();
} else {
tx.send(Err(())).unwrap();
}
},
"overseer did not receive store available data request",
);
}

#[test]
fn same_req_wont_get_queued_if_participation_is_already_running() {
futures::executor::block_on(async {
Expand Down Expand Up @@ -423,7 +404,6 @@ fn cast_invalid_vote_if_validation_fails_or_is_invalid() {
fetch_validation_code(&mut ctx_handle).await,
participation.recent_block.unwrap().1
);
store_available_data(&mut ctx_handle, true).await;

assert_matches!(
ctx_handle.recv().await,
Expand Down Expand Up @@ -461,7 +441,6 @@ fn cast_invalid_vote_if_commitments_dont_match() {
fetch_validation_code(&mut ctx_handle).await,
participation.recent_block.unwrap().1
);
store_available_data(&mut ctx_handle, true).await;

assert_matches!(
ctx_handle.recv().await,
Expand Down Expand Up @@ -499,7 +478,6 @@ fn cast_valid_vote_if_validation_passes() {
fetch_validation_code(&mut ctx_handle).await,
participation.recent_block.unwrap().1
);
store_available_data(&mut ctx_handle, true).await;

assert_matches!(
ctx_handle.recv().await,
Expand All @@ -521,42 +499,3 @@ fn cast_valid_vote_if_validation_passes() {
);
})
}

#[test]
fn failure_to_store_available_data_does_not_preclude_participation() {
futures::executor::block_on(async {
let (mut ctx, mut ctx_handle) = make_our_subsystem_context(TaskExecutor::new());

let (sender, mut worker_receiver) = mpsc::channel(1);
let mut participation = Participation::new(sender);
activate_leaf(&mut ctx, &mut participation, 10).await.unwrap();
participate(&mut ctx, &mut participation).await.unwrap();

recover_available_data(&mut ctx_handle).await;
assert_eq!(
fetch_validation_code(&mut ctx_handle).await,
participation.recent_block.unwrap().1
);
// the store available data request should fail:
store_available_data(&mut ctx_handle, false).await;

assert_matches!(
ctx_handle.recv().await,
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx)
) if timeout == APPROVAL_EXECUTION_TIMEOUT => {
tx.send(Err(ValidationFailed("fail".to_string()))).unwrap();
},
"overseer did not receive candidate validation message",
);

let result = participation
.get_participation_result(&mut ctx, worker_receiver.next().await.unwrap())
.await
.unwrap();
assert_matches!(
result.outcome,
ParticipationOutcome::Invalid => {}
);
})
}
2 changes: 1 addition & 1 deletion runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod crowdloan_index_migration {
/// This migration converts crowdloans to use a crowdloan index rather than the parachain id as a
/// unique identifier. This makes it easier to swap two crowdloans between parachains.
pub fn migrate<T: Config>() -> frame_support::weights::Weight {
let mut weight = Weight::new();
let mut weight = Weight::zero();

// First migrate `NextTrieIndex` counter to `NextFundIndex`.

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
/// by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.scalar_saturating_mul(2);
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);

const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/slots/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod slots_crowdloan_index_migration {
}

pub fn migrate<T: Config + crowdloan::Config>() -> frame_support::weights::Weight {
let mut weight = Weight::new();
let mut weight = Weight::zero();

for (para_id, mut leases) in Leases::<T>::iter() {
weight = weight.saturating_add(T::DbWeight::get().reads(2));
Expand Down
4 changes: 3 additions & 1 deletion runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,16 @@ try-runtime = [
"frame-system/try-runtime",
"pallet-authority-discovery/try-runtime",
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-child-bounties/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-collective/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-democracy/try-runtime",
"pallet-gilt/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-identity/try-runtime",
"pallet-im-online/try-runtime",
Expand All @@ -273,6 +274,7 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-babe/try-runtime",
"pallet-xcm/try-runtime",
"runtime-common/try-runtime",
]
# When enabled, the runtime API will not be build.
Expand Down
6 changes: 3 additions & 3 deletions runtime/kusama/constants/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ parameter_types! {
/// 99th: 6_332_047
/// 95th: 6_308_225
/// 75th: 6_236_204
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.scalar_saturating_mul(6_192_341);
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(6_192_341);
}

#[cfg(test)]
Expand All @@ -69,8 +69,8 @@ mod test_weights {
let w = super::BlockExecutionWeight::get();

// At least 100 µs.
assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
assert!(w >= 100u64 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
// At most 50 ms.
assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
assert!(w <= 50u64 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
}
}
4 changes: 2 additions & 2 deletions runtime/kusama/constants/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parameter_types! {
/// 99th: 87_527
/// 95th: 86_901
/// 75th: 86_308
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.scalar_saturating_mul(86_309);
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(86_309);
}

#[cfg(test)]
Expand All @@ -68,7 +68,7 @@ mod test_weights {
let w = super::ExtrinsicBaseWeight::get();

// At least 10 µs.
assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
assert!(w >= 10u64 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
// At most 1 ms.
assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms.");
}
Expand Down
14 changes: 11 additions & 3 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl parachains_paras::Config for Runtime {
}

parameter_types! {
pub const FirstMessageFactorPercent: Weight = Weight::from_ref_time(100);
pub const FirstMessageFactorPercent: u64 = 100;
}

impl parachains_ump::Config for Runtime {
Expand Down Expand Up @@ -1882,8 +1882,16 @@ sp_api::impl_runtime_apis! {
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, BlockWeights::get().max_block)
}
fn execute_block_no_check(block: Block) -> Weight {
Executive::execute_block_no_check(block)

fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight {
log::info!(
target: "runtime::kusama", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}",
block.header.number,
block.header.hash(),
state_root_check,
select,
);
Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
}
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/kusama/src/weights/frame_benchmarking_baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ impl<T: frame_system::Config> frame_benchmarking::baseline::WeightInfo for Weigh
fn sr25519_verification(i: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 38_000
.saturating_add(Weight::from_ref_time(47_929_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(Weight::from_ref_time(47_929_000 as RefTimeWeight).saturating_mul(i as RefTimeWeight))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_read(i: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 4_000
.saturating_add(Weight::from_ref_time(2_101_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(Weight::from_ref_time(2_101_000 as RefTimeWeight).saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().reads((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_write(i: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(330_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(Weight::from_ref_time(330_000 as RefTimeWeight).saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
}
Loading

0 comments on commit c48aa45

Please sign in to comment.