Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into snowbridge
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Apr 11, 2024
2 parents 0893dad + 69cc7f2 commit 68ab248
Show file tree
Hide file tree
Showing 21 changed files with 2,212 additions and 3,087 deletions.
213 changes: 192 additions & 21 deletions cumulus/parachains/chain-specs/people-westend.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl ClusterTracker {
target: LOG_TARGET,
pending_statements = ?self.pending,
?parent_hash,
"Cluster has too many pending statements, something wrong with our connection to our group peers \n
"Cluster has too many pending statements, something wrong with our connection to our group peers
Restart might be needed if validator gets 0 backing rewards for more than 3-4 consecutive sessions"
);
}
Expand Down
14 changes: 13 additions & 1 deletion polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@

use crate::scheduler;
use primitives::{CoreIndex, Id as ParaId};
use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque};
use sp_runtime::traits::One;
use sp_std::{
collections::{btree_map::BTreeMap, vec_deque::VecDeque},
vec::Vec,
};

/// Returns the claimqueue from the scheduler
pub fn claim_queue<T: scheduler::Config>() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
let now = <frame_system::Pallet<T>>::block_number() + One::one();

// This explicit update is only strictly required for session boundaries:
//
// At the end of a session we clear the claim queues: Without this update call, nothing would be
// scheduled to the client.
<scheduler::Pallet<T>>::free_cores_and_fill_claimqueue(Vec::new(), now);

scheduler::ClaimQueue::<T>::get()
.into_iter()
.map(|(core_index, entries)| {
Expand Down
12 changes: 12 additions & 0 deletions prdoc/pr_3789.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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: "[pallet-contracts] Benchmarks improvements"

doc:
- audience: Runtime Dev
description: Reuse wasmi module when validating the wasm code.
crates:
- name: pallet-contracts
bump: patch

14 changes: 14 additions & 0 deletions prdoc/pr_3915.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: "[pallet-contracts] Weights update"

doc:
- audience: Runtime Dev
description: |
Update Host functions benchmarks, instead of benchmarking the whole call extrinsic, this PR solely benchmark the execution of the Host function.
Previously, some benchmarks would overestimate the weight as both the parsing and execution of the contract were included in the benchmark.

crates:
- name: pallet-contracts
bump: patch
10 changes: 10 additions & 0 deletions prdoc/pr_4072.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "Amend chainspecs for people-westend and add IBP bootnodes"

doc:
- audience: Node Operator
description: |
Fixes the people-westend chain spec.

crates:
- name: polkadot-parachain-bin
bump: patch
2 changes: 1 addition & 1 deletion substrate/client/network/sync/src/strategy/chain_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ where
let peer = if let Some(peer) = self.peers.get_mut(&peer_id) {
peer
} else {
error!(target: LOG_TARGET, "💔 Called `on_validated_block_announce` with a bad peer ID");
error!(target: LOG_TARGET, "💔 Called `on_validated_block_announce` with a bad peer ID {peer_id}");
return Some((hash, number))
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub extern "C" fn call() {
output: [u8],
);

// Burn some PoV, clear_storage consumes some PoV as in order to clear the storage we need to we
// need to read its size first.
api::clear_storage_v1(b"");

let exit_status = uapi::ReturnFlags::from_bits(exit_status[0] as u32).unwrap();
api::return_value(exit_status, output);
}
170 changes: 170 additions & 0 deletions substrate/frame/contracts/src/benchmarking/call_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{
benchmarking::{Contract, WasmModule},
exec::Stack,
storage::meter::Meter,
wasm::Runtime,
BalanceOf, Config, DebugBufferVec, Determinism, ExecReturnValue, GasMeter, Origin, Schedule,
TypeInfo, WasmBlob, Weight,
};
use codec::{Encode, HasCompact};
use core::fmt::Debug;
use sp_core::Get;
use sp_std::prelude::*;

type StackExt<'a, T> = Stack<'a, T, WasmBlob<T>>;

/// A prepared contract call ready to be executed.
pub struct PreparedCall<'a, T: Config> {
func: wasmi::Func,
store: wasmi::Store<Runtime<'a, StackExt<'a, T>>>,
}

impl<'a, T: Config> PreparedCall<'a, T> {
pub fn call(mut self) -> ExecReturnValue {
let result = self.func.call(&mut self.store, &[], &mut []);
WasmBlob::<T>::process_result(self.store, result).unwrap()
}
}

/// A builder used to prepare a contract call.
pub struct CallSetup<T: Config> {
contract: Contract<T>,
dest: T::AccountId,
origin: Origin<T>,
gas_meter: GasMeter<T>,
storage_meter: Meter<T>,
schedule: Schedule<T>,
value: BalanceOf<T>,
debug_message: Option<DebugBufferVec<T>>,
determinism: Determinism,
data: Vec<u8>,
}

impl<T> CallSetup<T>
where
T: Config + pallet_balances::Config,
<BalanceOf<T> as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode,
{
/// Setup a new call for the given module.
pub fn new(module: WasmModule<T>) -> Self {
let contract = Contract::<T>::new(module.clone(), vec![]).unwrap();
let dest = contract.account_id.clone();
let origin = Origin::from_account_id(contract.caller.clone());

let storage_meter = Meter::new(&origin, None, 0u32.into()).unwrap();

Self {
contract,
dest,
origin,
gas_meter: GasMeter::new(Weight::MAX),
storage_meter,
schedule: T::Schedule::get(),
value: 0u32.into(),
debug_message: None,
determinism: Determinism::Enforced,
data: vec![],
}
}

/// Set the meter's storage deposit limit.
pub fn set_storage_deposit_limit(&mut self, balance: BalanceOf<T>) {
self.storage_meter = Meter::new(&self.origin, Some(balance), 0u32.into()).unwrap();
}

/// Set the call's origin.
pub fn set_origin(&mut self, origin: Origin<T>) {
self.origin = origin;
}

/// Set the contract's balance.
pub fn set_balance(&mut self, value: BalanceOf<T>) {
self.contract.set_balance(value);
}

/// Set the call's input data.
pub fn set_data(&mut self, value: Vec<u8>) {
self.data = value;
}

/// Set the debug message.
pub fn enable_debug_message(&mut self) {
self.debug_message = Some(Default::default());
}

/// Get the debug message.
pub fn debug_message(&self) -> Option<DebugBufferVec<T>> {
self.debug_message.clone()
}

/// Get the call's input data.
pub fn data(&self) -> Vec<u8> {
self.data.clone()
}

/// Get the call's contract.
pub fn contract(&self) -> Contract<T> {
self.contract.clone()
}

/// Build the call stack.
pub fn ext(&mut self) -> (StackExt<'_, T>, WasmBlob<T>) {
StackExt::bench_new_call(
self.dest.clone(),
self.origin.clone(),
&mut self.gas_meter,
&mut self.storage_meter,
&self.schedule,
self.value,
self.debug_message.as_mut(),
self.determinism,
)
}

/// Prepare a call to the module.
pub fn prepare_call<'a>(
ext: &'a mut StackExt<'a, T>,
module: WasmBlob<T>,
input: Vec<u8>,
) -> PreparedCall<'a, T> {
let (func, store) = module.bench_prepare_call(ext, input);
PreparedCall { func, store }
}
}

#[macro_export]
macro_rules! call_builder(
($func: ident, $module:expr) => {
$crate::call_builder!($func, _contract, $module);
};
($func: ident, $contract: ident, $module:expr) => {
let mut setup = CallSetup::<T>::new($module);
$crate::call_builder!($func, $contract, setup: setup);
};
($func:ident, setup: $setup: ident) => {
$crate::call_builder!($func, _contract, setup: $setup);
};
($func:ident, $contract: ident, setup: $setup: ident) => {
let data = $setup.data();
let $contract = $setup.contract();
let (mut ext, module) = $setup.ext();
let $func = CallSetup::<T>::prepare_call(&mut ext, module, data);
};
);
Loading

0 comments on commit 68ab248

Please sign in to comment.