mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 19:51:02 +00:00
Merge commit '392447f5c8f986ded2559a78457f4cd87942f393' into update-bridges-subtree-r/w
This commit is contained in:
@@ -7,7 +7,7 @@ edition = "2018"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
parity-scale-codec = { version = "2.2.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge Dependencies
|
||||
@@ -17,9 +17,9 @@ bp-runtime = { path = "../runtime", default-features = false }
|
||||
|
||||
# Substrate Based Dependencies
|
||||
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
|
||||
@@ -29,6 +29,7 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::limits;
|
||||
use parity_scale_codec::Compact;
|
||||
use scale_info::{StaticTypeInfo, TypeInfo};
|
||||
use sp_core::Hasher as HasherT;
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
@@ -66,18 +67,19 @@ pub const EXTRA_STORAGE_PROOF_SIZE: u32 = 1024;
|
||||
/// All polkadot-like chains are using same crypto.
|
||||
pub const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = 32;
|
||||
|
||||
/// All Polkadot-like chains allow normal extrinsics to fill block up to 75%.
|
||||
/// All Polkadot-like chains allow normal extrinsics to fill block up to 75 percent.
|
||||
///
|
||||
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
/// All Polkadot-like chains allow 2 seconds of compute with a 6 second average block time.
|
||||
/// All Polkadot-like chains allow 2 seconds of compute with a 6-second average block time.
|
||||
///
|
||||
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
|
||||
|
||||
/// All Polkadot-like chains assume that an on-initialize consumes 1% of the weight on average,
|
||||
/// hence a single extrinsic will not be allowed to consume more than `AvailableBlockRatio - 1%`.
|
||||
/// All Polkadot-like chains assume that an on-initialize consumes 1 percent of the weight on
|
||||
/// average, hence a single extrinsic will not be allowed to consume more than
|
||||
/// `AvailableBlockRatio - 1 percent`.
|
||||
///
|
||||
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
|
||||
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
|
||||
@@ -113,7 +115,8 @@ parameter_types! {
|
||||
.build_or_panic();
|
||||
}
|
||||
|
||||
/// Get the maximum weight (compute time) that a Normal extrinsic on the Polkadot-like chain can use.
|
||||
/// Get the maximum weight (compute time) that a Normal extrinsic on the Polkadot-like chain can
|
||||
/// use.
|
||||
pub fn max_extrinsic_weight() -> Weight {
|
||||
BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
@@ -138,6 +141,48 @@ pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128;
|
||||
/// Maximal number of unconfirmed messages at inbound lane.
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 8192;
|
||||
|
||||
// One important thing about weight-related constants here is that actually we may have
|
||||
// different weights on different Polkadot-like chains. But now all deployments are
|
||||
// almost the same, so we're exporting constants from this crate.
|
||||
|
||||
/// Maximal weight of single message delivery confirmation transaction on Polkadot-like chain.
|
||||
///
|
||||
/// This value is a result of `pallet_bridge_messages::Pallet::receive_messages_delivery_proof`
|
||||
/// weight formula computation for the case when single message is confirmed. The result then must
|
||||
/// be rounded up to account possible future runtime upgrades.
|
||||
pub const MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT: Weight = 2_000_000_000;
|
||||
|
||||
/// Increase of delivery transaction weight on Polkadot-like chain with every additional message
|
||||
/// byte.
|
||||
///
|
||||
/// This value is a result of
|
||||
/// `pallet_bridge_messages::WeightInfoExt::storage_proof_size_overhead(1)` call. The result then
|
||||
/// must be rounded up to account possible future runtime upgrades.
|
||||
pub const ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT: Weight = 25_000;
|
||||
|
||||
/// Maximal number of bytes, included in the signed Polkadot-like transaction apart from the encoded
|
||||
/// call itself.
|
||||
///
|
||||
/// Can be computed by subtracting encoded call size from raw transaction size.
|
||||
pub const TX_EXTRA_BYTES: u32 = 256;
|
||||
|
||||
/// Weight of single regular message delivery transaction on Polkadot-like chain.
|
||||
///
|
||||
/// This value is a result of `pallet_bridge_messages::Pallet::receive_messages_proof_weight()` call
|
||||
/// for the case when single message of `pallet_bridge_messages::EXPECTED_DEFAULT_MESSAGE_LENGTH`
|
||||
/// bytes is delivered. The message must have dispatch weight set to zero. The result then must be
|
||||
/// rounded up to account possible future runtime upgrades.
|
||||
pub const DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT: Weight = 1_500_000_000;
|
||||
|
||||
/// Weight of pay-dispatch-fee operation for inbound messages at Polkadot-like chain.
|
||||
///
|
||||
/// This value corresponds to the result of
|
||||
/// `pallet_bridge_messages::WeightInfoExt::pay_inbound_dispatch_fee_overhead()` call for your
|
||||
/// chain. Don't put too much reserve there, because it is used to **decrease**
|
||||
/// `DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT` cost. So putting large reserve would make delivery
|
||||
/// transactions cheaper.
|
||||
pub const PAY_INBOUND_DISPATCH_FEE_WEIGHT: Weight = 600_000_000;
|
||||
|
||||
/// Re-export `time_units` to make usage easier.
|
||||
pub use time_units::*;
|
||||
|
||||
@@ -165,7 +210,7 @@ pub type Index = u32;
|
||||
/// Hashing type.
|
||||
pub type Hashing = BlakeTwo256;
|
||||
|
||||
/// The type of an object that can produce hashes on Polkadot-like chains.
|
||||
/// The type of object that can produce hashes on Polkadot-like chains.
|
||||
pub type Hasher = BlakeTwo256;
|
||||
|
||||
/// The header type used by Polkadot-like chains.
|
||||
@@ -180,6 +225,9 @@ pub type AccountPublic = <Signature as Verify>::Signer;
|
||||
/// Id of account on Polkadot-like chains.
|
||||
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
|
||||
|
||||
/// Address of account on Polkadot-like chains.
|
||||
pub type AccountAddress = MultiAddress<AccountId, ()>;
|
||||
|
||||
/// Index of a transaction on the Polkadot-like chains.
|
||||
pub type Nonce = u32;
|
||||
|
||||
@@ -194,18 +242,13 @@ pub type Balance = u128;
|
||||
|
||||
/// Unchecked Extrinsic type.
|
||||
pub type UncheckedExtrinsic<Call> =
|
||||
generic::UncheckedExtrinsic<MultiAddress<AccountId, ()>, Call, Signature, SignedExtensions<Call>>;
|
||||
generic::UncheckedExtrinsic<AccountAddress, Call, Signature, SignedExtensions<Call>>;
|
||||
|
||||
/// Account address, used by the Polkadot-like chain.
|
||||
pub type Address = MultiAddress<AccountId, ()>;
|
||||
|
||||
/// A type of the data encoded as part of the transaction.
|
||||
pub type SignedExtra = (
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
sp_runtime::generic::Era,
|
||||
Compact<Nonce>,
|
||||
(),
|
||||
Compact<Balance>,
|
||||
);
|
||||
pub type SignedExtra = ((), (), (), sp_runtime::generic::Era, Compact<Nonce>, (), Compact<Balance>);
|
||||
|
||||
/// Parameters which are part of the payload used to produce transaction signature,
|
||||
/// but don't end up in the transaction itself (i.e. inherent part of the runtime).
|
||||
@@ -213,7 +256,7 @@ pub type AdditionalSigned = (u32, u32, Hash, Hash, (), (), ());
|
||||
|
||||
/// A simplified version of signed extensions meant for producing signed transactions
|
||||
/// and signed payload in the client code.
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug, scale_info::TypeInfo)]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
|
||||
pub struct SignedExtensions<Call> {
|
||||
encode_payload: SignedExtra,
|
||||
additional_signed: AdditionalSigned,
|
||||
@@ -227,7 +270,9 @@ impl<Call> parity_scale_codec::Encode for SignedExtensions<Call> {
|
||||
}
|
||||
|
||||
impl<Call> parity_scale_codec::Decode for SignedExtensions<Call> {
|
||||
fn decode<I: parity_scale_codec::Input>(_input: &mut I) -> Result<Self, parity_scale_codec::Error> {
|
||||
fn decode<I: parity_scale_codec::Input>(
|
||||
_input: &mut I,
|
||||
) -> Result<Self, parity_scale_codec::Error> {
|
||||
unimplemented!("SignedExtensions are never meant to be decoded, they are only used to create transaction");
|
||||
}
|
||||
}
|
||||
@@ -235,26 +280,26 @@ impl<Call> parity_scale_codec::Decode for SignedExtensions<Call> {
|
||||
impl<Call> SignedExtensions<Call> {
|
||||
pub fn new(
|
||||
version: sp_version::RuntimeVersion,
|
||||
era: sp_runtime::generic::Era,
|
||||
era: bp_runtime::TransactionEraOf<PolkadotLike>,
|
||||
genesis_hash: Hash,
|
||||
nonce: Nonce,
|
||||
tip: Balance,
|
||||
) -> Self {
|
||||
Self {
|
||||
encode_payload: (
|
||||
(), // spec version
|
||||
(), // tx version
|
||||
(), // genesis
|
||||
era, // era
|
||||
nonce.into(), // nonce (compact encoding)
|
||||
(), // Check weight
|
||||
tip.into(), // transaction payment / tip (compact encoding)
|
||||
(), // spec version
|
||||
(), // tx version
|
||||
(), // genesis
|
||||
era.frame_era(), // era
|
||||
nonce.into(), // nonce (compact encoding)
|
||||
(), // Check weight
|
||||
tip.into(), // transaction payment / tip (compact encoding)
|
||||
),
|
||||
additional_signed: (
|
||||
version.spec_version,
|
||||
version.transaction_version,
|
||||
genesis_hash,
|
||||
genesis_hash,
|
||||
era.signed_payload(genesis_hash),
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
@@ -264,6 +309,18 @@ impl<Call> SignedExtensions<Call> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> SignedExtensions<Call> {
|
||||
/// Return signer nonce, used to craft transaction.
|
||||
pub fn nonce(&self) -> Nonce {
|
||||
self.encode_payload.4.into()
|
||||
}
|
||||
|
||||
/// Return transaction tip.
|
||||
pub fn tip(&self) -> Balance {
|
||||
self.encode_payload.6.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> sp_runtime::traits::SignedExtension for SignedExtensions<Call>
|
||||
where
|
||||
Call: parity_scale_codec::Codec
|
||||
@@ -273,7 +330,7 @@ where
|
||||
+ Clone
|
||||
+ Eq
|
||||
+ PartialEq
|
||||
+ scale_info::StaticTypeInfo,
|
||||
+ StaticTypeInfo,
|
||||
Call: Dispatchable,
|
||||
{
|
||||
const IDENTIFIER: &'static str = "Not needed.";
|
||||
@@ -283,7 +340,9 @@ where
|
||||
type AdditionalSigned = AdditionalSigned;
|
||||
type Pre = ();
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, frame_support::unsigned::TransactionValidityError> {
|
||||
fn additional_signed(
|
||||
&self,
|
||||
) -> Result<Self::AdditionalSigned, frame_support::unsigned::TransactionValidityError> {
|
||||
Ok(self.additional_signed)
|
||||
}
|
||||
}
|
||||
@@ -297,6 +356,11 @@ impl Chain for PolkadotLike {
|
||||
type Hash = Hash;
|
||||
type Hasher = Hasher;
|
||||
type Header = Header;
|
||||
|
||||
type AccountId = AccountId;
|
||||
type Balance = Balance;
|
||||
type Index = Index;
|
||||
type Signature = Signature;
|
||||
}
|
||||
|
||||
/// Convert a 256-bit hash into an AccountId.
|
||||
@@ -311,7 +375,7 @@ impl Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
||||
/// Return a storage key for account data.
|
||||
///
|
||||
/// This is based on FRAME storage-generation code from Substrate:
|
||||
/// https://github.com/paritytech/substrate/blob/c939ceba381b6313462d47334f775e128ea4e95d/frame/support/src/storage/generator/map.rs#L74
|
||||
/// [link](https://github.com/paritytech/substrate/blob/c939ceba381b6313462d47334f775e128ea4e95d/frame/support/src/storage/generator/map.rs#L74)
|
||||
/// The equivalent command to invoke in case full `Runtime` is known is this:
|
||||
/// `let key = frame_system::Account::<Runtime>::storage_map_final_key(&account_id);`
|
||||
pub fn account_info_storage_key(id: &AccountId) -> Vec<u8> {
|
||||
@@ -319,7 +383,9 @@ pub fn account_info_storage_key(id: &AccountId) -> Vec<u8> {
|
||||
let storage_prefix_hashed = Twox128::hash(b"Account");
|
||||
let key_hashed = parity_scale_codec::Encode::using_encoded(id, Blake2_128Concat::hash);
|
||||
|
||||
let mut final_key = Vec::with_capacity(module_prefix_hashed.len() + storage_prefix_hashed.len() + key_hashed.len());
|
||||
let mut final_key = Vec::with_capacity(
|
||||
module_prefix_hashed.len() + storage_prefix_hashed.len() + key_hashed.len(),
|
||||
);
|
||||
|
||||
final_key.extend_from_slice(&module_prefix_hashed[..]);
|
||||
final_key.extend_from_slice(&storage_prefix_hashed[..]);
|
||||
@@ -347,8 +413,8 @@ mod tests {
|
||||
#[test]
|
||||
fn should_generate_storage_key() {
|
||||
let acc = [
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
||||
30, 31, 32,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32,
|
||||
]
|
||||
.into();
|
||||
let key = account_info_storage_key(&acc);
|
||||
|
||||
Reference in New Issue
Block a user