mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Merge branch 'master' into gav-xcm-v3
This commit is contained in:
@@ -7,7 +7,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
async-trait = { version = "0.1.57", optional = true }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ "derive" ] }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.2.0", default-features = false, features = ["derive"] }
|
||||
tracing = { version = "0.1.36", optional = true }
|
||||
|
||||
# Substrate
|
||||
|
||||
@@ -42,7 +42,7 @@ use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
|
||||
/// in addition to the messages themselves, you must provide some information about
|
||||
/// your parachain's configuration in order to mock the MQC heads properly.
|
||||
/// See [`MockXcmConfig`] for more information
|
||||
pub struct MockValidationDataInherentDataProvider {
|
||||
pub struct MockValidationDataInherentDataProvider<R = ()> {
|
||||
/// The current block number of the local block chain (the parachain)
|
||||
pub current_para_block: u32,
|
||||
/// The relay block in which this parachain appeared to start. This will be the relay block
|
||||
@@ -51,6 +51,11 @@ pub struct MockValidationDataInherentDataProvider {
|
||||
/// The number of relay blocks that elapses between each parablock. Probably set this to 1 or 2
|
||||
/// to simulate optimistic or realistic relay chain behavior.
|
||||
pub relay_blocks_per_para_block: u32,
|
||||
/// Number of parachain blocks per relay chain epoch
|
||||
/// Mock epoch is computed by dividing `current_para_block` by this value.
|
||||
pub para_blocks_per_relay_epoch: u32,
|
||||
/// Function to mock BABE one epoch ago randomness
|
||||
pub relay_randomness_config: R,
|
||||
/// XCM messages and associated configuration information.
|
||||
pub xcm_config: MockXcmConfig,
|
||||
/// Inbound downward XCM messages to be injected into the block.
|
||||
@@ -59,6 +64,20 @@ pub struct MockValidationDataInherentDataProvider {
|
||||
pub raw_horizontal_messages: Vec<(ParaId, Vec<u8>)>,
|
||||
}
|
||||
|
||||
pub trait GenerateRandomness<I> {
|
||||
fn generate_randomness(&self, input: I) -> relay_chain::Hash;
|
||||
}
|
||||
|
||||
impl GenerateRandomness<u64> for () {
|
||||
/// Default implementation uses relay epoch as randomness value
|
||||
/// A more seemingly random implementation may hash the relay epoch instead
|
||||
fn generate_randomness(&self, input: u64) -> relay_chain::Hash {
|
||||
let mut mock_randomness: [u8; 32] = [0u8; 32];
|
||||
mock_randomness[..8].copy_from_slice(&input.to_be_bytes());
|
||||
mock_randomness.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Parameters for how the Mock inherent data provider should inject XCM messages.
|
||||
/// In addition to the messages themselves, some information about the parachain's
|
||||
/// configuration is also required so that the MQC heads can be read out of the
|
||||
@@ -130,7 +149,9 @@ impl MockXcmConfig {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl InherentDataProvider for MockValidationDataInherentDataProvider {
|
||||
impl<R: Send + Sync + GenerateRandomness<u64>> InherentDataProvider
|
||||
for MockValidationDataInherentDataProvider<R>
|
||||
{
|
||||
fn provide_inherent_data(
|
||||
&self,
|
||||
inherent_data: &mut InherentData,
|
||||
@@ -178,6 +199,17 @@ impl InherentDataProvider for MockValidationDataInherentDataProvider {
|
||||
sproof_builder.upsert_inbound_channel(*para_id).mqc_head = Some(channel_mqc.head());
|
||||
}
|
||||
|
||||
// Epoch is set equal to current para block / blocks per epoch
|
||||
sproof_builder.current_epoch = if self.para_blocks_per_relay_epoch == 0 {
|
||||
// do not divide by 0 => set epoch to para block number
|
||||
self.current_para_block.into()
|
||||
} else {
|
||||
(self.current_para_block / self.para_blocks_per_relay_epoch).into()
|
||||
};
|
||||
// Randomness is set by randomness generator
|
||||
sproof_builder.randomness =
|
||||
self.relay_randomness_config.generate_randomness(self.current_para_block.into());
|
||||
|
||||
let (relay_parent_storage_root, proof) = sproof_builder.into_state_root_and_proof();
|
||||
|
||||
inherent_data.put_data(
|
||||
|
||||
@@ -7,7 +7,7 @@ description = "Provides timestamp related functionality for parachains."
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [ "derive" ] }
|
||||
futures = "0.3.23"
|
||||
futures = "0.3.24"
|
||||
|
||||
# Substrate
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
@@ -31,7 +31,10 @@ use frame_support::{
|
||||
use polkadot_runtime_common::xcm_sender::ConstantPrice;
|
||||
use sp_runtime::{traits::Saturating, SaturatedConversion};
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
use xcm::{latest::prelude::*, WrapVersion};
|
||||
use xcm::{
|
||||
latest::{prelude::*, Weight as XCMWeight},
|
||||
WrapVersion,
|
||||
};
|
||||
use xcm_builder::TakeRevenue;
|
||||
use xcm_executor::traits::{MatchesFungibles, TransactAsset, WeightTrader};
|
||||
|
||||
@@ -147,7 +150,7 @@ impl<
|
||||
// If everything goes well, we charge.
|
||||
fn buy_weight(
|
||||
&mut self,
|
||||
weight: Weight,
|
||||
weight: XCMWeight,
|
||||
payment: xcm_executor::Assets,
|
||||
) -> Result<xcm_executor::Assets, XcmError> {
|
||||
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::buy_weight weight: {:?}, payment: {:?}", weight, payment);
|
||||
@@ -157,6 +160,8 @@ impl<
|
||||
return Err(XcmError::NotWithdrawable)
|
||||
}
|
||||
|
||||
let weight = Weight::from_ref_time(weight);
|
||||
|
||||
// We take the very first multiasset from payment
|
||||
let multiassets: MultiAssets = payment.clone().into();
|
||||
|
||||
@@ -197,14 +202,14 @@ impl<
|
||||
Ok(unused)
|
||||
}
|
||||
|
||||
fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
|
||||
fn refund_weight(&mut self, weight: XCMWeight) -> Option<MultiAsset> {
|
||||
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::refund_weight weight: {:?}", weight);
|
||||
if let Some(AssetTraderRefunder {
|
||||
mut weight_outstanding,
|
||||
outstanding_concrete_asset: MultiAsset { id, fun },
|
||||
}) = self.0.clone()
|
||||
{
|
||||
let weight = weight.min(weight_outstanding);
|
||||
let weight = Weight::from_ref_time(weight).min(weight_outstanding);
|
||||
|
||||
// Get the local asset id in which we can refund fees
|
||||
let (local_asset_id, outstanding_balance) =
|
||||
|
||||
Reference in New Issue
Block a user