Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement per-parentchain extrinsic factory and metadata #1501

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,7 @@ dependencies = [
"hex",
"integritee-node-runtime",
"ipfs-api",
"ita-parentchain-interface",
"itc-parentchain",
"itc-parentchain-test",
"itc-rest-client",
Expand Down Expand Up @@ -3010,6 +3011,7 @@ dependencies = [
"bs58",
"env_logger",
"frame-support",
"frame-system",
"futures 0.3.28",
"futures 0.3.8",
"ita-sgx-runtime",
Expand All @@ -3029,6 +3031,7 @@ dependencies = [
"itp-utils",
"log 0.4.19",
"parity-scale-codec",
"scale-info",
"sgx_tstd",
"sgx_types",
"sp-core",
Expand Down Expand Up @@ -3424,6 +3427,7 @@ version = "0.9.0"
dependencies = [
"integritee-node-runtime",
"itp-types",
"parity-scale-codec",
"sp-core",
"sp-runtime",
"substrate-api-client",
Expand Down Expand Up @@ -3536,6 +3540,7 @@ dependencies = [
"itp-node-api",
"itp-nonce-cache",
"itp-types",
"itp-utils",
"log 0.4.19",
"parity-scale-codec",
"sgx_tstd",
Expand Down Expand Up @@ -3586,6 +3591,7 @@ dependencies = [
name = "itp-node-api-factory"
version = "0.9.0"
dependencies = [
"itp-api-client-extensions",
"itp-api-client-types",
"sp-core",
"thiserror 1.0.40",
Expand Down
4 changes: 4 additions & 0 deletions app-libs/parentchain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ log = { version = "0.4", default-features = false }
# substrate dep
binary-merkle-tree = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std enablement

sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }

[dev-dependencies]
env_logger = "0.9.0"
Expand Down Expand Up @@ -75,9 +77,11 @@ std = [
"log/std",
#substrate
"binary-merkle-tree/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"thiserror",
]
sgx = [
Expand Down
133 changes: 131 additions & 2 deletions app-libs/parentchain-interface/src/integritee/extrinsic_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,141 @@
limitations under the License.

*/

use codec::{Decode, Encode};
use core::marker::PhantomData;
use itp_api_client_types::traits::ExtrinsicParamsAdjustments;
use itp_node_api::api_client::{
Address, CallIndex, PairSignature, ParentchainSignedExtra, Signature, UncheckedExtrinsicV4,
Address, CallIndex, DefaultRuntimeConfig, ExtrinsicParams, GenericAdditionalSigned,
GenericExtrinsicParams, PairSignature, Signature, UncheckedExtrinsicV4,
};
use itp_types::parentchain::{Balance, Hash, Index};
use sp_runtime::generic::Era;

// re-export integritee network types
pub use itp_node_api::api_client::{ParentchainTip, Signature as ParentchainSignature};

#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainExtrinsicParams {
era: Era,
nonce: Index,
tip: ParentchainTip,
spec_version: u32,
transaction_version: u32,
genesis_hash: Hash,
mortality_checkpoint: Hash,
}

#[derive(Decode, Encode, Copy, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainAdditionalParams {
era: Era,
mortality_checkpoint: Option<Hash>,
tip: ParentchainTip,
}
impl Default for ParentchainAdditionalParams {
fn default() -> Self {
Self { era: Era::Immortal, mortality_checkpoint: None, tip: ParentchainTip::default() }
}
}

#[derive(Decode, Encode, Copy, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainSignedExtra {
pub era: Era,
#[codec(compact)]
pub nonce: Index,
pub tip: ParentchainTip,
}

pub type ParentchainAdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ());

impl ExtrinsicParams<Index, Hash> for ParentchainExtrinsicParams {
type AdditionalParams = ParentchainAdditionalParams;
type SignedExtra = ParentchainSignedExtra;
type AdditionalSigned = ParentchainAdditionalSigned;

fn new(
spec_version: u32,
transaction_version: u32,
nonce: Index,
genesis_hash: Hash,
additional_params: Self::AdditionalParams,
) -> Self {
Self {
era: additional_params.era,
tip: additional_params.tip,
spec_version,
transaction_version,
genesis_hash,
mortality_checkpoint: additional_params.mortality_checkpoint.unwrap_or(genesis_hash),
nonce,
}
}

fn signed_extra(&self) -> Self::SignedExtra {
Self::SignedExtra { era: self.era, nonce: self.nonce, tip: self.tip }
}

fn additional_signed(&self) -> Self::AdditionalSigned {
(
(),
self.spec_version,
self.transaction_version,
self.genesis_hash,
self.mortality_checkpoint,
(),
(),
(),
)
}
}

impl ExtrinsicParamsAdjustments<ParentchainAdditionalParams> for ParentchainExtrinsicParams {
fn with_nonce(&self, nonce: Index) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version: self.spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce,
}
}
fn with_additional_params(&self, additional_params: ParentchainAdditionalParams) -> Self {
Self {
era: additional_params.era,
tip: additional_params.tip,
spec_version: self.spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: additional_params
.mortality_checkpoint
.unwrap_or(self.genesis_hash),
nonce: self.nonce,
}
}
fn with_spec_version(&self, spec_version: u32) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce: self.nonce,
}
}
fn with_transaction_version(&self, transaction_version: u32) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version: self.spec_version,
transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce: self.nonce,
}
}
}

pub struct ExtrinsicParser<SignedExtra> {
_phantom: PhantomData<SignedExtra>,
Expand Down
5 changes: 4 additions & 1 deletion app-libs/parentchain-interface/src/integritee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use codec::{Decode, Encode};
use core::marker::PhantomData;
pub use event_filter::FilterableEvents;
pub use event_handler::ParentchainEventHandler;
pub use extrinsic_parser::ParentchainExtrinsicParser;
pub use extrinsic_parser::{
ParentchainAdditionalParams, ParentchainAdditionalSigned, ParentchainExtrinsicParams,
ParentchainExtrinsicParser, ParentchainSignedExtra,
};
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
Expand Down
145 changes: 144 additions & 1 deletion app-libs/parentchain-interface/src/target_a/extrinsic_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,153 @@

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{
pallet_prelude::TypeInfo,
traits::{CrateVersion, PalletInfo},
weights::constants::RocksDbWeight,
RuntimeDebug,
};
use ita_sgx_runtime::{BlockHashCount, RuntimeCall, RuntimeEvent, RuntimeOrigin, Version};
use itp_node_api::api_client::{
Address, CallIndex, PairSignature, ParentchainSignedExtra, Signature, UncheckedExtrinsicV4,
traits::ExtrinsicParamsAdjustments, Address, AssetTip, CallIndex, ExtrinsicParams,
GenericExtrinsicParams, PairSignature, Signature, UncheckedExtrinsicV4,
};
use sp_runtime::{
generic::Era,
traits::{AccountIdLookup, BlakeTwo256},
};

use itp_types::parentchain::{AccountId, Balance, BlockNumber, Hash, Header, Index};

// re-export integritee network types
pub use itp_node_api::api_client::Signature as ParentchainSignature;

// define custom properties for Asset Hub
pub type ParentchainTip = AssetTip<Balance>;

#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainExtrinsicParams {
era: Era,
nonce: Index,
tip: ParentchainTip,
spec_version: u32,
transaction_version: u32,
genesis_hash: Hash,
mortality_checkpoint: Hash,
}

#[derive(Decode, Encode, Copy, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainAdditionalParams {
era: Era,
mortality_checkpoint: Option<Hash>,
tip: ParentchainTip,
}
impl Default for ParentchainAdditionalParams {
fn default() -> Self {
Self { era: Era::Immortal, mortality_checkpoint: None, tip: ParentchainTip::default() }
}
}

#[derive(Decode, Encode, Copy, Clone, Eq, PartialEq, Debug)]
pub struct ParentchainSignedExtra {
pub era: Era,
#[codec(compact)]
pub nonce: Index,
pub tip: ParentchainTip,
}

pub type ParentchainAdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ());

impl ExtrinsicParams<Index, Hash> for ParentchainExtrinsicParams {
type AdditionalParams = ParentchainAdditionalParams;
type SignedExtra = ParentchainSignedExtra;
type AdditionalSigned = ParentchainAdditionalSigned;

fn new(
spec_version: u32,
transaction_version: u32,
nonce: Index,
genesis_hash: Hash,
additional_params: Self::AdditionalParams,
) -> Self {
Self {
era: additional_params.era,
tip: additional_params.tip,
spec_version,
transaction_version,
genesis_hash,
mortality_checkpoint: additional_params.mortality_checkpoint.unwrap_or(genesis_hash),
nonce,
}
}

fn signed_extra(&self) -> Self::SignedExtra {
Self::SignedExtra { era: self.era, nonce: self.nonce, tip: self.tip }
}

fn additional_signed(&self) -> Self::AdditionalSigned {
(
(),
self.spec_version,
self.transaction_version,
self.genesis_hash,
self.mortality_checkpoint,
(),
(),
(),
)
}
}

impl ExtrinsicParamsAdjustments<ParentchainAdditionalParams> for ParentchainExtrinsicParams {
fn with_nonce(&self, nonce: Index) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version: self.spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce,
}
}
fn with_additional_params(&self, additional_params: ParentchainAdditionalParams) -> Self {
Self {
era: additional_params.era,
tip: additional_params.tip,
spec_version: self.spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: additional_params
.mortality_checkpoint
.unwrap_or(self.genesis_hash),
nonce: self.nonce,
}
}
fn with_spec_version(&self, spec_version: u32) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version,
transaction_version: self.transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce: self.nonce,
}
}
fn with_transaction_version(&self, transaction_version: u32) -> Self {
Self {
era: self.era,
tip: self.tip,
spec_version: self.spec_version,
transaction_version,
genesis_hash: self.genesis_hash,
mortality_checkpoint: self.mortality_checkpoint,
nonce: self.nonce,
}
}
}

pub struct ExtrinsicParser<SignedExtra> {
_phantom: PhantomData<SignedExtra>,
}
Expand Down
5 changes: 4 additions & 1 deletion app-libs/parentchain-interface/src/target_a/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ use codec::{Decode, Encode};
use core::marker::PhantomData;
pub use event_filter::FilterableEvents;
pub use event_handler::ParentchainEventHandler;
pub use extrinsic_parser::ParentchainExtrinsicParser;
use extrinsic_parser::ParseExtrinsic;
pub use extrinsic_parser::{
ParentchainAdditionalParams, ParentchainAdditionalSigned, ParentchainExtrinsicParams,
ParentchainExtrinsicParser, ParentchainSignedExtra,
};
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
Expand Down
Loading
Loading