mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 00:41:03 +00:00
Deduplicate pallet call structs used for indirect runtime calls (#1744)
* Small changes * Define generic bridge pallets call structs * polkadot-core SignedExtension simplifications - we don't seem to need to pass the Call as a generic param - we can use codec(skip) instead of implementing Encode and Decode * Split BridgeHubRococo and BridgeHubWococo calls * code review fixes
This commit is contained in:
committed by
Bastian Köcher
parent
a21617082e
commit
63a538a9bb
@@ -7,8 +7,6 @@ edition = "2021"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
smallvec = "1.10.0"
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
|
||||
@@ -23,15 +21,15 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
|
||||
# Polkadot Dependencies
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
|
||||
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-polkadot-core/std",
|
||||
"bp-messages/std",
|
||||
"bp-runtime/std",
|
||||
"bp-messages/std",
|
||||
"frame-system/std",
|
||||
"frame-support/std",
|
||||
"sp-api/std",
|
||||
|
||||
@@ -7,8 +7,6 @@ edition = "2021"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
smallvec = "1.10.0"
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-bridge-hub-cumulus = { path = "../chain-bridge-hub-cumulus", default-features = false }
|
||||
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
//! Module with configuration which reflects BridgeHubWococo runtime setup
|
||||
//! (AccountId, Headers, Hashes...)
|
||||
//!
|
||||
//! but actually this is just reexported BridgeHubRococo stuff, because they are supposed to be
|
||||
//! identical, at least uses the same parachain runtime
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
// Re-export only what is really needed
|
||||
pub use bp_bridge_hub_cumulus::*;
|
||||
use bp_messages::*;
|
||||
use bp_runtime::{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, StorageProofChecker};
|
||||
use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, StorageProofChecker};
|
||||
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
|
||||
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
|
||||
use frame_support::PalletError;
|
||||
@@ -169,3 +169,18 @@ impl<Number: Codec> ConsensusLogReader for GrandpaConsensusLogReader<Number> {
|
||||
GrandpaConsensusLogReader::<Number>::find_authorities_change(digest).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// A minimized version of `pallet-bridge-grandpa::Call` that can be used without a runtime.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum BridgeGrandpaCall<Header: HeaderT> {
|
||||
/// `pallet-bridge-grandpa::Call::submit_finality_proof`
|
||||
#[codec(index = 0)]
|
||||
submit_finality_proof(Box<Header>, justification::GrandpaJustification<Header>),
|
||||
/// `pallet-bridge-grandpa::Call::initialize`
|
||||
#[codec(index = 1)]
|
||||
initialize(InitializationData<Header>),
|
||||
}
|
||||
|
||||
/// The `BridgeGrandpaCall` used by a chain.
|
||||
pub type BridgeGrandpaCallOf<C> = BridgeGrandpaCall<HeaderOf<C>>;
|
||||
|
||||
@@ -391,6 +391,18 @@ where
|
||||
relayers_rewards
|
||||
}
|
||||
|
||||
/// A minimized version of `pallet-bridge-messages::Call` that can be used without a runtime.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum BridgeMessagesCall<AccountId, MessagesProof, MessagesDeliveryProof> {
|
||||
/// `pallet-bridge-messages::Call::receive_messages_proof`
|
||||
#[codec(index = 2)]
|
||||
receive_messages_proof(AccountId, MessagesProof, u32, Weight),
|
||||
/// `pallet-bridge-messages::Call::receive_messages_delivery_proof`
|
||||
#[codec(index = 3)]
|
||||
receive_messages_delivery_proof(MessagesDeliveryProof, UnrewardedRelayersState),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
pub use bp_header_chain::StoredHeaderData;
|
||||
|
||||
use bp_polkadot_core::{
|
||||
parachains::{ParaHash, ParaHead, ParaId},
|
||||
BlockNumber as RelayBlockNumber,
|
||||
parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId},
|
||||
BlockNumber as RelayBlockNumber, Hash as RelayBlockHash,
|
||||
};
|
||||
use bp_runtime::{
|
||||
BlockNumberOf, Chain, HashOf, HeaderOf, Parachain, StorageDoubleMapKeyProvider,
|
||||
@@ -150,3 +150,16 @@ impl ParaStoredHeaderDataBuilder for C {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// A minimized version of `pallet-bridge-parachains::Call` that can be used without a runtime.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum BridgeParachainCall {
|
||||
/// `pallet-bridge-parachains::Call::submit_parachain_heads`
|
||||
#[codec(index = 0)]
|
||||
submit_parachain_heads(
|
||||
(RelayBlockNumber, RelayBlockHash),
|
||||
Vec<(ParaId, ParaHash)>,
|
||||
ParaHeadsProof,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use bp_messages::MessageNonce;
|
||||
use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider};
|
||||
use codec::Compact;
|
||||
use frame_support::{
|
||||
dispatch::{DispatchClass, Dispatchable},
|
||||
dispatch::DispatchClass,
|
||||
parameter_types,
|
||||
weights::{
|
||||
constants::{BlockExecutionWeight, WEIGHT_PER_SECOND},
|
||||
@@ -29,7 +29,7 @@ use frame_support::{
|
||||
Blake2_128Concat, RuntimeDebug,
|
||||
};
|
||||
use frame_system::limits;
|
||||
use scale_info::{StaticTypeInfo, TypeInfo};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{storage::StorageKey, Hasher as HasherT};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
@@ -194,7 +194,7 @@ pub type UncheckedExtrinsic<Call> = generic::UncheckedExtrinsic<
|
||||
AccountAddress,
|
||||
EncodedOrDecodedCall<Call>,
|
||||
Signature,
|
||||
SignedExtensions<Call>,
|
||||
SignedExtensions,
|
||||
>;
|
||||
|
||||
/// Account address, used by the Polkadot-like chain.
|
||||
@@ -210,34 +210,18 @@ 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, TypeInfo)]
|
||||
pub struct SignedExtensions<Call> {
|
||||
#[derive(codec::Encode, codec::Decode, PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
|
||||
pub struct SignedExtensions {
|
||||
encode_payload: SignedExtra,
|
||||
// It may be set to `None` if extensions are decoded. We are never reconstructing transactions
|
||||
// (and it makes no sense to do that) => decoded version of `SignedExtensions` is only used to
|
||||
// read fields of `encode_payload`. And when resigning transaction, we're reconstructing
|
||||
// `SignedExtensions` from the scratch.
|
||||
#[codec(skip)]
|
||||
additional_signed: Option<AdditionalSigned>,
|
||||
_data: sp_std::marker::PhantomData<Call>,
|
||||
}
|
||||
|
||||
impl<Call> codec::Encode for SignedExtensions<Call> {
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.encode_payload.using_encoded(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> codec::Decode for SignedExtensions<Call> {
|
||||
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
|
||||
SignedExtra::decode(input).map(|encode_payload| SignedExtensions {
|
||||
encode_payload,
|
||||
additional_signed: None,
|
||||
_data: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> SignedExtensions<Call> {
|
||||
impl SignedExtensions {
|
||||
pub fn new(
|
||||
spec_version: u32,
|
||||
transaction_version: u32,
|
||||
@@ -267,12 +251,11 @@ impl<Call> SignedExtensions<Call> {
|
||||
(),
|
||||
(),
|
||||
)),
|
||||
_data: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> SignedExtensions<Call> {
|
||||
impl SignedExtensions {
|
||||
/// Return signer nonce, used to craft transaction.
|
||||
pub fn nonce(&self) -> Nonce {
|
||||
self.encode_payload.5.into()
|
||||
@@ -284,15 +267,11 @@ impl<Call> SignedExtensions<Call> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Call> sp_runtime::traits::SignedExtension for SignedExtensions<Call>
|
||||
where
|
||||
Call: codec::Codec + sp_std::fmt::Debug + Sync + Send + Clone + Eq + PartialEq + StaticTypeInfo,
|
||||
Call: Dispatchable,
|
||||
{
|
||||
impl sp_runtime::traits::SignedExtension for SignedExtensions {
|
||||
const IDENTIFIER: &'static str = "Not needed.";
|
||||
|
||||
type AccountId = AccountId;
|
||||
type Call = Call;
|
||||
type Call = ();
|
||||
type AdditionalSigned = AdditionalSigned;
|
||||
type Pre = ();
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Basic runtime calls.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// A minimized version of `frame-system::Call` that can be used without a runtime.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum SystemCall {
|
||||
/// `frame-system::Call::remark`
|
||||
#[codec(index = 1)]
|
||||
remark(Vec<u8>),
|
||||
}
|
||||
@@ -47,6 +47,7 @@ pub use storage_types::BoundedStorageValue;
|
||||
#[cfg(feature = "std")]
|
||||
pub use storage_proof::craft_valid_storage_proof;
|
||||
|
||||
pub mod calls;
|
||||
pub mod messages;
|
||||
|
||||
mod chain;
|
||||
|
||||
Reference in New Issue
Block a user