Skip to content

Commit

Permalink
Send parentchain extrinsics as mortal (#3205)
Browse files Browse the repository at this point in the history
* remove bitacross

* init

* remove macros

* try to add params

* use immortal for registration

* add back

---------

Co-authored-by: Kasper Ziemianek <[email protected]>
  • Loading branch information
Kailai-Wang and kziemianek authored Dec 16, 2024
1 parent af738b7 commit 993f883
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 44 deletions.
2 changes: 1 addition & 1 deletion parachain/scripts/launch-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function print_divider() {

CHAIN=$1

ZOMBIENET_VERSION=v1.3.116
ZOMBIENET_VERSION=v1.3.117
ZOMBIENET_DIR=$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 8; echo)

LITENTRY_PARACHAIN_DIR=${LITENTRY_PARACHAIN_DIR:-"/tmp/parachain_dev"}
Expand Down
2 changes: 1 addition & 1 deletion parachain/zombienet/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ args = [
"--enable-evm-rpc",
"--state-pruning=archive",
"--delayed-best-block",
"-l=parachain=debug,txpool=debug"
"-l=parachain=debug,txpool=trace"
]
ws_port = {{COLLATOR_WS_PORT}}
6 changes: 6 additions & 0 deletions tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tee-worker/common/core/parentchain/light-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where

pub trait ExtrinsicSender {
/// Sends encoded extrinsics to the parentchain and cache them internally for later confirmation.
fn send_extrinsics(&mut self, extrinsics: Vec<OpaqueExtrinsic>) -> Result<(), Error>;
fn send_extrinsics(&self, extrinsics: Vec<OpaqueExtrinsic>) -> Result<(), Error>;
}

pub trait LightClientState<Block: ParentchainBlockTrait> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ where
Block: ParentchainBlockTrait,
OCallApi: EnclaveOnChainOCallApi,
{
fn send_extrinsics(&mut self, extrinsics: Vec<OpaqueExtrinsic>) -> Result<(), Error> {
fn send_extrinsics(&self, extrinsics: Vec<OpaqueExtrinsic>) -> Result<(), Error> {
self.ocall_api
.send_to_parentchain(extrinsics, &self.parentchain_id, None)
.map_err(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Validator<Block> for ValidatorMock {
}

impl ExtrinsicSender for ValidatorMock {
fn send_extrinsics(&mut self, _extrinsics: Vec<OpaqueExtrinsic>) -> Result<()> {
fn send_extrinsics(&self, _extrinsics: Vec<OpaqueExtrinsic>) -> Result<()> {
Ok(())
}
}
Expand Down
5 changes: 5 additions & 0 deletions tee-worker/identity/core/offchain-worker-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ thiserror_sgx = { workspace = true, optional = true }

itc-parentchain-light-client = { workspace = true }
itp-extrinsics-factory = { workspace = true }
itp-node-api = { workspace = true }
itp-sgx-runtime-primitives = { workspace = true }
itp-stf-executor = { package = "id-itp-stf-executor", path = "../../core-primitives/stf-executor", default-features = false }
itp-stf-interface = { workspace = true }
itp-stf-primitives = { workspace = true }
Expand All @@ -40,7 +42,9 @@ sp-core = { workspace = true, features = ["full_crypto"] }
default = ["std"]
std = [
"itc-parentchain-light-client/std",
"itp-sgx-runtime-primitives/std",
"itp-extrinsics-factory/std",
"itp-node-api/std",
"itp-stf-executor/std",
"itp-stf-interface/std",
"itp-stf-primitives/std",
Expand All @@ -52,6 +56,7 @@ std = [
]
sgx = [
"itc-parentchain-light-client/sgx",
"itp-node-api/sgx",
"itp-extrinsics-factory/sgx",
"itp-stf-executor/sgx",
"itp-stf-state-handler/sgx",
Expand Down
18 changes: 12 additions & 6 deletions tee-worker/identity/core/offchain-worker-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ use itc_parentchain_light_client::{
NumberFor,
};
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::api_client::ParentchainAdditionalParams;
use itp_stf_executor::{traits::StateUpdateProposer, ExecutedOperation};
use itp_stf_interface::system_pallet::SystemPalletEventInterface;
use itp_stf_primitives::{traits::TrustedCallVerification, types::TrustedOperationOrHash};
use itp_stf_state_handler::{handle_state::HandleState, query_shard_state::QueryShardState};
use itp_top_pool_author::traits::AuthorApi;
use itp_types::{parentchain::ParentchainCall, OpaqueCall, ShardIdentifier, H256};
use itp_types::{
parentchain::ParentchainCall, Header as ParentchainHeader, OpaqueCall, ShardIdentifier, H256,
};
use log::*;
use sp_runtime::traits::Block;
use sp_runtime::{generic::Era, traits::Block};
use std::{marker::PhantomData, sync::Arc, time::Duration, vec::Vec};

/// Off-chain worker executor implementation.
Expand Down Expand Up @@ -82,7 +85,7 @@ impl<
TCS,
G,
> where
ParentchainBlock: Block<Hash = H256>,
ParentchainBlock: Block<Hash = H256, Header = ParentchainHeader>,
StfExecutor: StateUpdateProposer<TCS, G>,
TopPoolAuthor: AuthorApi<H256, ParentchainBlock::Hash, TCS, G>,
StateHandler: QueryShardState + HandleState<StateT = StfExecutor::Externalities>,
Expand Down Expand Up @@ -175,7 +178,7 @@ impl<
Ok(())
}

fn get_latest_parentchain_header(&self) -> Result<ParentchainBlock::Header> {
fn get_latest_parentchain_header(&self) -> Result<ParentchainHeader> {
let header = self.validator_accessor.execute_on_validator(|v| {
let latest_parentchain_header = v.latest_finalized_header()?;
Ok(latest_parentchain_header)
Expand Down Expand Up @@ -218,10 +221,13 @@ impl<
warn!("sending extrinsics to target B unimplemented")
};

let params = self.get_latest_parentchain_header().ok().map(|h| {
ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash())
});
let extrinsics =
self.extrinsics_factory.create_extrinsics(integritee_calls.as_slice(), None)?;
self.extrinsics_factory.create_extrinsics(integritee_calls.as_slice(), params)?;
self.validator_accessor
.execute_mut_on_validator(|v| v.send_extrinsics(extrinsics))?;
.execute_on_validator(|v| v.send_extrinsics(extrinsics))?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ itc-parentchain-indirect-calls-executor = { package = "id-itc-parentchain-indire
itc-parentchain-light-client = { workspace = true }
itp-enclave-metrics = { workspace = true }
itp-extrinsics-factory = { workspace = true }
itp-node-api = { workspace = true }
itp-ocall-api = { workspace = true }
itp-stf-executor = { package = "id-itp-stf-executor", path = "../../../core-primitives/stf-executor", default-features = false }
itp-stf-interface = { workspace = true }
Expand Down Expand Up @@ -41,6 +42,7 @@ std = [
"sp-runtime/std",
"thiserror",
"itp-ocall-api/std",
"itp-node-api/std",
]
sgx = [
"sgx_tstd",
Expand All @@ -51,6 +53,7 @@ sgx = [
"itp-extrinsics-factory/sgx",
"itp-stf-executor/sgx",
"thiserror_sgx",
"itp-node-api/sgx",
]

# feature to export mock implementations, only to be used for dev-dependencies!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use crate::{error::Result, ImportParentchainBlocks};
use ita_stf::ParentchainHeader;
use itc_parentchain_indirect_calls_executor::ExecuteIndirectCalls;
use itc_parentchain_light_client::{
concurrent_access::ValidatorAccess, BlockNumberOps, ExtrinsicSender, Validator,
concurrent_access::ValidatorAccess, BlockNumberOps, LightClientState, Validator,
};
use itp_enclave_metrics::EnclaveMetric;
use itp_extrinsics_factory::CreateExtrinsics;
use itp_ocall_api::EnclaveMetricsOCallApi;
use itp_node_api::api_client::ParentchainAdditionalParams;
use itp_ocall_api::{EnclaveMetricsOCallApi, EnclaveOnChainOCallApi};
use itp_stf_executor::traits::StfUpdateState;
use itp_stf_interface::ShardCreationInfo;
use itp_types::{
Expand All @@ -35,7 +36,7 @@ use itp_types::{
};
use log::*;
use sp_runtime::{
generic::SignedBlock as SignedBlockG,
generic::{Era, SignedBlock as SignedBlockG},
traits::{Block as ParentchainBlockTrait, Header as HeaderT, NumberFor},
};
use std::{marker::PhantomData, sync::Arc, vec, vec::Vec};
Expand Down Expand Up @@ -120,7 +121,7 @@ impl<
StfExecutor: StfUpdateState<ParentchainHeader, ParentchainId>,
ExtrinsicsFactory: CreateExtrinsics,
IndirectCallsExecutor: ExecuteIndirectCalls,
OcallApi: EnclaveMetricsOCallApi,
OcallApi: EnclaveMetricsOCallApi + EnclaveOnChainOCallApi,
{
type SignedBlockType = SignedBlockG<ParentchainBlock>;

Expand All @@ -143,6 +144,7 @@ impl<
} else {
events_to_import
};

for (signed_block, raw_events) in
blocks_to_import.into_iter().zip(events_to_import_aligned.into_iter())
{
Expand Down Expand Up @@ -205,13 +207,22 @@ impl<
);
}

// Create extrinsics for all `unshielding` and `block processed` calls we've gathered.
let params = self
.validator_accessor
.execute_on_validator(|v| v.latest_finalized_header())
.ok()
.map(|h| {
ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash())
});

let parentchain_extrinsics =
self.extrinsics_factory.create_extrinsics(calls.as_slice(), None)?;
self.extrinsics_factory.create_extrinsics(calls.as_slice(), params)?;

// Sending the extrinsic requires mut access because the validator caches the sent extrinsics internally.
self.validator_accessor
.execute_mut_on_validator(|v| v.send_extrinsics(parentchain_extrinsics))?;
self.ocall_api.send_to_parentchain(
parentchain_extrinsics,
&ParentchainId::Litentry,
None,
)?;

Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions tee-worker/identity/enclave-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tee-worker/identity/enclave-runtime/src/rpc/common_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ fn forward_dcap_quote_inner(params: Params) -> Result<OpaqueExtrinsic, String> {
let validator_access = get_validator_accessor_from_integritee_solo_or_parachain()
.map_err(|e| format!("{:?}", e))?;
validator_access
.execute_mut_on_validator(|v| v.send_extrinsics(vec![ext.clone()]))
.execute_on_validator(|v| v.send_extrinsics(vec![ext.clone()]))
.map_err(|e| format!("{:?}", e))?;

Ok(ext)
Expand Down Expand Up @@ -623,7 +623,7 @@ fn attesteer_forward_ias_attestation_report_inner(
let validator_access = get_validator_accessor_from_integritee_solo_or_parachain()
.map_err(|e| format!("{:?}", e))?;
validator_access
.execute_mut_on_validator(|v| v.send_extrinsics(vec![ext.clone()]))
.execute_on_validator(|v| v.send_extrinsics(vec![ext.clone()]))
.map_err(|e| format!("{:?}", e))?;

Ok(ext)
Expand Down
35 changes: 28 additions & 7 deletions tee-worker/identity/enclave-runtime/src/top_pool_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use itc_parentchain::{
use itp_component_container::ComponentGetter;
use itp_enclave_metrics::EnclaveMetric;
use itp_extrinsics_factory::CreateExtrinsics;
use itp_node_api::api_client::ParentchainAdditionalParams;
use itp_ocall_api::{EnclaveMetricsOCallApi, EnclaveOnChainOCallApi, EnclaveSidechainOCallApi};
use itp_settings::sidechain::SLOT_DURATION;
use itp_sgx_crypto::key_repository::AccessKey;
Expand All @@ -72,7 +73,9 @@ use log::*;
use sgx_types::sgx_status_t;
use sp_core::{crypto::UncheckedFrom, Pair};
use sp_runtime::{
generic::SignedBlock as SignedParentchainBlock, traits::Block as BlockTrait, MultiSignature,
generic::{Era, SignedBlock as SignedParentchainBlock},
traits::Block as BlockTrait,
MultiSignature,
};
use std::{sync::Arc, time::Instant, vec::Vec};

Expand Down Expand Up @@ -364,9 +367,15 @@ where
debug!("Enclave wants to send {} extrinsics to Integritee Parentchain", calls.len());
if !calls.is_empty() {
let extrinsics_factory = get_extrinsic_factory_from_integritee_solo_or_parachain()?;
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), None)?;
let validator_access = get_validator_accessor_from_integritee_solo_or_parachain()?;
validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?;
let params = validator_access
.execute_on_validator(|v| v.latest_finalized_header())
.ok()
.map(|h| {
ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash())
});
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), params)?;
validator_access.execute_on_validator(|v| v.send_extrinsics(xts))?;
}
let calls: Vec<OpaqueCall> = parentchain_calls
.iter()
Expand All @@ -375,9 +384,15 @@ where
debug!("Enclave wants to send {} extrinsics to TargetA Parentchain", calls.len());
if !calls.is_empty() {
let extrinsics_factory = get_extrinsic_factory_from_target_a_solo_or_parachain()?;
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), None)?;
let validator_access = get_validator_accessor_from_target_a_solo_or_parachain()?;
validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?;
let params = validator_access
.execute_on_validator(|v| v.latest_finalized_header())
.ok()
.map(|h| {
ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash())
});
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), params)?;
validator_access.execute_on_validator(|v| v.send_extrinsics(xts))?;
}
let calls: Vec<OpaqueCall> = parentchain_calls
.iter()
Expand All @@ -386,9 +401,15 @@ where
debug!("Enclave wants to send {} extrinsics to TargetB Parentchain", calls.len());
if !calls.is_empty() {
let extrinsics_factory = get_extrinsic_factory_from_target_b_solo_or_parachain()?;
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), None)?;
let validator_access = get_validator_accessor_from_target_b_solo_or_parachain()?;
validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?;
let params = validator_access
.execute_on_validator(|v| v.latest_finalized_header())
.ok()
.map(|h| {
ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash())
});
let xts = extrinsics_factory.create_extrinsics(calls.as_slice(), params)?;
validator_access.execute_on_validator(|v| v.send_extrinsics(xts))?;
}

Ok(())
Expand Down
Loading

0 comments on commit 993f883

Please sign in to comment.