Skip to content

Commit

Permalink
propagate parentchain(s) timestamps (#1572)
Browse files Browse the repository at this point in the history
* filter timestamp set extrinsic and add trusted call to set timestamp

* use all extrinsic parsers to propagate parentchain timestamps

* extend to target_b and generically solve parentchain instance type branching

* lift patches

* split out shard creation into module

* WIP: get shard creation info back to service

* implemented shard creation info refactoring. untested

* initialize creation timestamp (has ~3 blocks delay to creation number

* fix secondary validateer handling

* cargo fix

* carg fix ++

* clippy

* fmt
  • Loading branch information
brenzi authored Jan 15, 2024
1 parent c640ddc commit 061aff2
Show file tree
Hide file tree
Showing 50 changed files with 777 additions and 548 deletions.
32 changes: 18 additions & 14 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ dependencies = [
[[package]]
name = "common-primitives"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"derive_more",
"parity-scale-codec",
Expand Down Expand Up @@ -1216,7 +1216,7 @@ dependencies = [
[[package]]
name = "enclave-bridge-primitives"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"common-primitives",
"log 0.4.20",
Expand Down Expand Up @@ -2581,7 +2581,7 @@ dependencies = [

[[package]]
name = "integritee-cli"
version = "0.12.10"
version = "0.12.11"
dependencies = [
"array-bytes 6.1.0",
"base58",
Expand Down Expand Up @@ -2631,7 +2631,7 @@ dependencies = [

[[package]]
name = "integritee-service"
version = "0.12.10"
version = "0.12.11"
dependencies = [
"anyhow",
"async-trait",
Expand All @@ -2655,6 +2655,7 @@ dependencies = [
"itp-enclave-metrics",
"itp-node-api",
"itp-settings",
"itp-stf-interface",
"itp-storage",
"itp-types",
"itp-utils",
Expand Down Expand Up @@ -2859,6 +2860,7 @@ dependencies = [
"itp-node-api",
"itp-node-api-metadata",
"itp-sgx-externalities",
"itp-sgx-runtime-primitives",
"itp-stf-interface",
"itp-stf-primitives",
"itp-storage",
Expand Down Expand Up @@ -2957,6 +2959,7 @@ dependencies = [
"itc-parentchain-light-client",
"itp-extrinsics-factory",
"itp-stf-executor",
"itp-stf-interface",
"itp-types",
"log 0.4.20",
"parity-scale-codec",
Expand Down Expand Up @@ -3227,6 +3230,7 @@ dependencies = [
"itc-parentchain",
"itp-enclave-api-ffi",
"itp-settings",
"itp-stf-interface",
"itp-storage",
"itp-types",
"log 0.4.20",
Expand Down Expand Up @@ -5154,7 +5158,7 @@ dependencies = [
[[package]]
name = "pallet-enclave-bridge"
version = "0.12.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"enclave-bridge-primitives",
"frame-support",
Expand Down Expand Up @@ -5212,8 +5216,8 @@ dependencies = [

[[package]]
name = "pallet-parentchain"
version = "0.10.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
version = "0.11.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"frame-support",
"frame-system",
Expand All @@ -5231,7 +5235,7 @@ dependencies = [
[[package]]
name = "pallet-sidechain"
version = "0.11.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"enclave-bridge-primitives",
"frame-support",
Expand Down Expand Up @@ -5268,7 +5272,7 @@ dependencies = [
[[package]]
name = "pallet-teeracle"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"frame-support",
"frame-system",
Expand All @@ -5288,7 +5292,7 @@ dependencies = [
[[package]]
name = "pallet-teerex"
version = "0.10.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"frame-support",
"frame-system",
Expand Down Expand Up @@ -6813,7 +6817,7 @@ dependencies = [
[[package]]
name = "sgx-verify"
version = "0.1.4"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"base64 0.13.1",
"chrono 0.4.26",
Expand Down Expand Up @@ -7088,7 +7092,7 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "sidechain-primitives"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"parity-scale-codec",
"scale-info",
Expand Down Expand Up @@ -7973,7 +7977,7 @@ checksum = "1d2faeef5759ab89935255b1a4cd98e0baf99d1085e37d36599c625dac49ae8e"
[[package]]
name = "teeracle-primitives"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"common-primitives",
"sp-std",
Expand All @@ -7983,7 +7987,7 @@ dependencies = [
[[package]]
name = "teerex-primitives"
version = "0.1.0"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.10-polkadot-v0.9.42#91321c805edc1e94d9ba04a5a6d74d63cf6c59e6"
source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.12.11-polkadot-v0.9.42#094b1e982b4637ebfbf5afb985100417215d49a0"
dependencies = [
"common-primitives",
"derive_more",
Expand Down
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ ring = { git = "https://github.com/betrusted-io/ring-xous", branch = "0.16.20-cl
#substrate-client-keystore = { path = "../../scs/substrate-api-client/client-keystore" }

#[patch."https://github.com/integritee-network/pallets.git"]
#pallet-claims = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-enclave-bridge = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-teerex = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-sidechain = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-parentchain = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#sgx-verify = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-teeracle = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#test-utils = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#claims-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#enclave-bridge-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#teerex-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#teeracle-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#common-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/make_parentchain_pallet_instantiable" }
#pallet-claims = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#pallet-enclave-bridge = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#pallet-teerex = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#pallet-sidechain = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#pallet-parentchain = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#sgx-verify = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#pallet-teeracle = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#test-utils = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#claims-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#enclave-bridge-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#teerex-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#teeracle-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
#common-primitives = { git = "https://github.com/integritee-network//pallets", branch = "ab/parentchian-set-timestamp" }
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
use codec::{Decode, Encode};
use core::marker::PhantomData;
use itp_node_api::api_client::{
Address, CallIndex, PairSignature, ParentchainSignedExtra, Signature, UncheckedExtrinsicV4,
Address, CallIndex, PairSignature, Signature, UncheckedExtrinsicV4,
};

pub struct ExtrinsicParser<SignedExtra> {
_phantom: PhantomData<SignedExtra>,
}

/// Parses the extrinsics corresponding to the parentchain.
pub type ParentchainExtrinsicParser = ExtrinsicParser<ParentchainSignedExtra>;

/// Partially interpreted extrinsic containing the `signature` and the `call_index` whereas
/// the `call_args` remain in encoded form.
///
Expand Down
1 change: 1 addition & 0 deletions app-libs/parentchain-interface/src/indirect_calls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

pub mod invoke;
pub mod shield_funds;
pub mod timestamp_set;
pub mod transfer_to_alice_shields_funds;

pub use invoke::InvokeArgs;
Expand Down
62 changes: 62 additions & 0 deletions app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2021 Integritee AG and Supercomputing Systems AG
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::{Integritee, ParentchainInstance, TargetA, TargetB};
use codec::{Compact, Decode, Encode};
use core::{any::TypeId, marker::PhantomData};
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
IndirectDispatch,
};
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_types::{parentchain::ParentchainId, Moment};
use log::info;

#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct TimestampSetArgs<I: ParentchainInstance> {
now: Compact<Moment>,
_phantom: PhantomData<I>,
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>, I: ParentchainInstance + 'static>
IndirectDispatch<Executor, TrustedCallSigned> for TimestampSetArgs<I>
{
fn dispatch(&self, executor: &Executor) -> Result<()> {
info!("Found TimestampSet extrinsic in block: now = {:?}", self.now);
let enclave_account_id = executor.get_enclave_account()?;
let parentchain_id = if TypeId::of::<I>() == TypeId::of::<Integritee>() {
ParentchainId::Integritee
} else if TypeId::of::<I>() == TypeId::of::<TargetA>() {
ParentchainId::TargetA
} else if TypeId::of::<I>() == TypeId::of::<TargetB>() {
ParentchainId::TargetB
} else {
return Err(Error::Other("unknown parentchain instance".into()))
};
let trusted_call =
TrustedCall::timestamp_set(enclave_account_id, self.now.0, parentchain_id);
let shard = executor.get_default_shard();
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?;
let trusted_operation =
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call);

let encrypted_trusted_call = executor.encrypt(&trusted_operation.encode())?;
executor.submit_trusted_call(shard, encrypted_trusted_call);
Ok(())
}
}
55 changes: 29 additions & 26 deletions app-libs/parentchain-interface/src/integritee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,47 @@
mod event_filter;
mod event_handler;

mod extrinsic_parser;

use crate::{
decode_and_log_error,
indirect_calls::{invoke::InvokeArgs, shield_funds::ShieldFundsArgs},
integritee::extrinsic_parser::ParseExtrinsic,
extrinsic_parser::ParseExtrinsic,
indirect_calls::{
invoke::InvokeArgs, shield_funds::ShieldFundsArgs, timestamp_set::TimestampSetArgs,
},
Integritee,
};
use codec::{Decode, Encode};
use core::marker::PhantomData;
pub use event_filter::FilterableEvents;
pub use event_handler::ParentchainEventHandler;
pub use extrinsic_parser::ParentchainExtrinsicParser;
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
filter_metadata::FilterIntoDataFrom,
IndirectDispatch,
};
use itp_node_api::metadata::NodeMetadataTrait;
use itp_api_client_types::ParentchainSignedExtra;
use itp_node_api::metadata::{
pallet_enclave_bridge::EnclaveBridgeCallIndexes, pallet_timestamp::TimestampCallIndexes,
};
use itp_stf_primitives::traits::IndirectExecutor;
use log::trace;
use log::*;
use sp_runtime::traits::BlakeTwo256;

pub type BlockNumber = u32;
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
use crate::extrinsic_parser::ExtrinsicParser;
pub use itp_types::parentchain::{AccountId, Balance, Hash};

pub type Signature = sp_runtime::MultiSignature;

/// Parses the extrinsics corresponding to the parentchain.
pub type ParentchainExtrinsicParser = ExtrinsicParser<ParentchainSignedExtra>;

/// The default indirect call (extrinsic-triggered) of the Integritee-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub enum IndirectCall {
ShieldFunds(ShieldFundsArgs),
Invoke(InvokeArgs),
TimestampSet(TimestampSetArgs<Integritee>),
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
Expand All @@ -61,22 +69,19 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
match self {
IndirectCall::ShieldFunds(shieldfunds_args) => shieldfunds_args.dispatch(executor),
IndirectCall::Invoke(invoke_args) => invoke_args.dispatch(executor),
IndirectCall::TimestampSet(timestamp_set_args) => timestamp_set_args.dispatch(executor),
}
}
}

/// Default filter we use for the Integritee-Parachain.
pub struct ShieldFundsAndInvokeFilter<ExtrinsicParser> {
_phantom: PhantomData<ExtrinsicParser>,
}
pub struct ExtrinsicFilter {}

impl<ExtrinsicParser, NodeMetadata: NodeMetadataTrait> FilterIntoDataFrom<NodeMetadata>
for ShieldFundsAndInvokeFilter<ExtrinsicParser>
where
ExtrinsicParser: ParseExtrinsic,
impl<NodeMetadata: EnclaveBridgeCallIndexes + TimestampCallIndexes> FilterIntoDataFrom<NodeMetadata>
for ExtrinsicFilter
{
type Output = IndirectCall;
type ParseParentchainMetadata = ExtrinsicParser;
type ParseParentchainMetadata = ParentchainExtrinsicParser;

fn filter_into_from_metadata(
encoded_data: &[u8],
Expand All @@ -89,27 +94,25 @@ where
let xt = match Self::ParseParentchainMetadata::parse(call_mut) {
Ok(xt) => xt,
Err(e) => {
log::error!(
"[ShieldFundsAndInvokeFilter] Could not parse parentchain extrinsic: {:?}",
e
);
error!("ExtrinsicFilter: Could not parse parentchain extrinsic: {:?}", e);
return None
},
};
let index = xt.call_index;
let call_args = &mut &xt.call_args[..];
log::trace!(
"[ShieldFundsAndInvokeFilter] attempting to execute indirect call with index {:?}",
index
);
trace!("ExtrinsicFilter: attempting to execute indirect call with index {:?}", index);
if index == metadata.shield_funds_call_indexes().ok()? {
log::debug!("executing shield funds call");
debug!("ExtrinsicFilter: executing shield funds call");
let args = decode_and_log_error::<ShieldFundsArgs>(call_args)?;
Some(IndirectCall::ShieldFunds(args))
} else if index == metadata.invoke_call_indexes().ok()? {
log::debug!("executing invoke call");
debug!("ExtrinsicFilter: executing invoke call");
let args = decode_and_log_error::<InvokeArgs>(call_args)?;
Some(IndirectCall::Invoke(args))
} else if index == metadata.timestamp_set_call_indexes().ok()? {
debug!("ExtrinsicFilter: found timestamp set extrinsic");
let args = decode_and_log_error::<TimestampSetArgs<Integritee>>(call_args)?;
Some(IndirectCall::TimestampSet(args))
} else {
None
}
Expand Down
Loading

0 comments on commit 061aff2

Please sign in to comment.