diff --git a/parachain/scripts/launch-network.sh b/parachain/scripts/launch-network.sh index d8a1125f19..a75e6502df 100755 --- a/parachain/scripts/launch-network.sh +++ b/parachain/scripts/launch-network.sh @@ -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 ) -> Result<(), Error>; + fn send_extrinsics(&self, extrinsics: Vec) -> Result<(), Error>; } pub trait LightClientState { diff --git a/tee-worker/common/core/parentchain/light-client/src/light_validation.rs b/tee-worker/common/core/parentchain/light-client/src/light_validation.rs index 43b9836fe6..09af1e1e23 100644 --- a/tee-worker/common/core/parentchain/light-client/src/light_validation.rs +++ b/tee-worker/common/core/parentchain/light-client/src/light_validation.rs @@ -210,7 +210,7 @@ where Block: ParentchainBlockTrait, OCallApi: EnclaveOnChainOCallApi, { - fn send_extrinsics(&mut self, extrinsics: Vec) -> Result<(), Error> { + fn send_extrinsics(&self, extrinsics: Vec) -> Result<(), Error> { self.ocall_api .send_to_parentchain(extrinsics, &self.parentchain_id, None) .map_err(|e| { diff --git a/tee-worker/common/core/parentchain/light-client/src/mocks/validator_mock.rs b/tee-worker/common/core/parentchain/light-client/src/mocks/validator_mock.rs index ed33d59225..17d634b038 100644 --- a/tee-worker/common/core/parentchain/light-client/src/mocks/validator_mock.rs +++ b/tee-worker/common/core/parentchain/light-client/src/mocks/validator_mock.rs @@ -59,7 +59,7 @@ impl Validator for ValidatorMock { } impl ExtrinsicSender for ValidatorMock { - fn send_extrinsics(&mut self, _extrinsics: Vec) -> Result<()> { + fn send_extrinsics(&self, _extrinsics: Vec) -> Result<()> { Ok(()) } } diff --git a/tee-worker/identity/core/offchain-worker-executor/Cargo.toml b/tee-worker/identity/core/offchain-worker-executor/Cargo.toml index a333fc7838..54f7c3676d 100644 --- a/tee-worker/identity/core/offchain-worker-executor/Cargo.toml +++ b/tee-worker/identity/core/offchain-worker-executor/Cargo.toml @@ -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 } @@ -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", @@ -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", diff --git a/tee-worker/identity/core/offchain-worker-executor/src/executor.rs b/tee-worker/identity/core/offchain-worker-executor/src/executor.rs index 5cf3e778b8..132a706f67 100644 --- a/tee-worker/identity/core/offchain-worker-executor/src/executor.rs +++ b/tee-worker/identity/core/offchain-worker-executor/src/executor.rs @@ -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. @@ -82,7 +85,7 @@ impl< TCS, G, > where - ParentchainBlock: Block, + ParentchainBlock: Block, StfExecutor: StateUpdateProposer, TopPoolAuthor: AuthorApi, StateHandler: QueryShardState + HandleState, @@ -175,7 +178,7 @@ impl< Ok(()) } - fn get_latest_parentchain_header(&self) -> Result { + fn get_latest_parentchain_header(&self) -> Result { let header = self.validator_accessor.execute_on_validator(|v| { let latest_parentchain_header = v.latest_finalized_header()?; Ok(latest_parentchain_header) @@ -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(()) } diff --git a/tee-worker/identity/core/parentchain/block-importer/Cargo.toml b/tee-worker/identity/core/parentchain/block-importer/Cargo.toml index 5eabe65488..c060eae67f 100644 --- a/tee-worker/identity/core/parentchain/block-importer/Cargo.toml +++ b/tee-worker/identity/core/parentchain/block-importer/Cargo.toml @@ -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 } @@ -41,6 +42,7 @@ std = [ "sp-runtime/std", "thiserror", "itp-ocall-api/std", + "itp-node-api/std", ] sgx = [ "sgx_tstd", @@ -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! diff --git a/tee-worker/identity/core/parentchain/block-importer/src/block_importer.rs b/tee-worker/identity/core/parentchain/block-importer/src/block_importer.rs index efbb129429..819e290f45 100644 --- a/tee-worker/identity/core/parentchain/block-importer/src/block_importer.rs +++ b/tee-worker/identity/core/parentchain/block-importer/src/block_importer.rs @@ -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::{ @@ -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}; @@ -120,7 +121,7 @@ impl< StfExecutor: StfUpdateState, ExtrinsicsFactory: CreateExtrinsics, IndirectCallsExecutor: ExecuteIndirectCalls, - OcallApi: EnclaveMetricsOCallApi, + OcallApi: EnclaveMetricsOCallApi + EnclaveOnChainOCallApi, { type SignedBlockType = SignedBlockG; @@ -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()) { @@ -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(()) } diff --git a/tee-worker/identity/enclave-runtime/Cargo.lock b/tee-worker/identity/enclave-runtime/Cargo.lock index c3a5ca6eab..c94e71cc70 100644 --- a/tee-worker/identity/enclave-runtime/Cargo.lock +++ b/tee-worker/identity/enclave-runtime/Cargo.lock @@ -1924,6 +1924,8 @@ dependencies = [ "id-itp-top-pool-author", "itc-parentchain-light-client", "itp-extrinsics-factory", + "itp-node-api", + "itp-sgx-runtime-primitives", "itp-stf-interface", "itp-stf-primitives", "itp-stf-state-handler", @@ -1970,6 +1972,7 @@ dependencies = [ "itc-parentchain-light-client", "itp-enclave-metrics", "itp-extrinsics-factory", + "itp-node-api", "itp-ocall-api", "itp-stf-interface", "itp-types", @@ -2767,6 +2770,7 @@ dependencies = [ "itp-enclave-metrics", "itp-extrinsics-factory", "itp-import-queue", + "itp-node-api", "itp-node-api-metadata", "itp-node-api-metadata-provider", "itp-ocall-api", @@ -3154,6 +3158,7 @@ dependencies = [ "serde_json 1.0.133", "sgx_tstd", "sp-core", + "sp-runtime", ] [[package]] @@ -3305,6 +3310,7 @@ dependencies = [ "parity-scale-codec", "sgx_tstd", "sp-core", + "sp-runtime", ] [[package]] diff --git a/tee-worker/identity/enclave-runtime/src/rpc/common_api.rs b/tee-worker/identity/enclave-runtime/src/rpc/common_api.rs index 6995ac26ae..a3a39827a2 100644 --- a/tee-worker/identity/enclave-runtime/src/rpc/common_api.rs +++ b/tee-worker/identity/enclave-runtime/src/rpc/common_api.rs @@ -589,7 +589,7 @@ fn forward_dcap_quote_inner(params: Params) -> Result { 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) @@ -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) diff --git a/tee-worker/identity/enclave-runtime/src/top_pool_execution.rs b/tee-worker/identity/enclave-runtime/src/top_pool_execution.rs index 439a3f2463..35bc9893f2 100644 --- a/tee-worker/identity/enclave-runtime/src/top_pool_execution.rs +++ b/tee-worker/identity/enclave-runtime/src/top_pool_execution.rs @@ -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; @@ -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}; @@ -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 = parentchain_calls .iter() @@ -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 = parentchain_calls .iter() @@ -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(()) diff --git a/tee-worker/identity/litentry/core/native-task/receiver/Cargo.toml b/tee-worker/identity/litentry/core/native-task/receiver/Cargo.toml index 4ec3218592..cc8b7fa5be 100644 --- a/tee-worker/identity/litentry/core/native-task/receiver/Cargo.toml +++ b/tee-worker/identity/litentry/core/native-task/receiver/Cargo.toml @@ -14,6 +14,7 @@ sgx_tstd = { workspace = true, features = ["net", "thread"], optional = true } codec = { package = "parity-scale-codec", workspace = true } log = { workspace = true } sp-core = { workspace = true, features = ["full_crypto"] } +sp-runtime = { workspace = true } ita-sgx-runtime = { package = "id-ita-sgx-runtime", path = "../../../../app-libs/sgx-runtime", default-features = false } ita-stf = { package = "id-ita-stf", path = "../../../../app-libs/stf", default-features = false } @@ -69,6 +70,7 @@ std = [ "itp-stf-primitives/std", "itp-extrinsics-factory/std", "sp-core/std", + "sp-runtime/std", "litentry-primitives/std", "frame-support/std", "itp-node-api/std", diff --git a/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs b/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs index 719bc0ef80..8b226f7164 100644 --- a/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs +++ b/tee-worker/identity/litentry/core/native-task/receiver/src/lib.rs @@ -66,7 +66,7 @@ use ita_stf::{ }; use itp_extrinsics_factory::CreateExtrinsics; use itp_node_api::{ - api_client::{compose_call, XtStatus}, + api_client::{compose_call, ParentchainAdditionalParams, XtStatus}, metadata::{provider::AccessNodeMetadata, NodeMetadata}, }; use itp_ocall_api::{EnclaveAttestationOCallApi, EnclaveMetricsOCallApi, EnclaveOnChainOCallApi}; @@ -94,6 +94,7 @@ use litentry_primitives::{ AesRequest, DecryptableRequest, Identity, Intent, MemberAccount, ValidationData, }; use sp_core::{blake2_256, H160, H256}; +use sp_runtime::generic::Era; use std::collections::HashSet; const THREAD_POOL_SIZE: usize = 480; @@ -538,7 +539,11 @@ fn handle_trusted_call extrinsic, Err(e) => { log::error!("Failed to create extrinsic: {:?}", e); diff --git a/tee-worker/identity/litentry/core/native-task/receiver/src/trusted_call_handlers/request_vc_handler.rs b/tee-worker/identity/litentry/core/native-task/receiver/src/trusted_call_handlers/request_vc_handler.rs index e23256205d..d7bc97a270 100644 --- a/tee-worker/identity/litentry/core/native-task/receiver/src/trusted_call_handlers/request_vc_handler.rs +++ b/tee-worker/identity/litentry/core/native-task/receiver/src/trusted_call_handlers/request_vc_handler.rs @@ -30,7 +30,7 @@ use ita_stf::{ use itp_enclave_metrics::EnclaveMetric; use itp_extrinsics_factory::CreateExtrinsics; use itp_node_api::{ - api_client::compose_call, + api_client::{compose_call, ParentchainAdditionalParams}, metadata::{pallet_system::SystemConstants, provider::AccessNodeMetadata, NodeMetadata}, }; use itp_ocall_api::{EnclaveMetricsOCallApi, EnclaveOnChainOCallApi}; @@ -56,6 +56,7 @@ use litentry_primitives::{ ParentchainBlockNumber, RequestAesKey, }; use sp_core::{H160, H256 as Hash}; +use sp_runtime::generic::Era; use std::{collections::HashMap, time::Instant}; pub type HandleRequestVcResult = Result; @@ -156,9 +157,12 @@ where "create_account_store", who.clone() )); + let params = context.ocall_api.get_header().ok().map(|h: itp_types::Header| { + ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash()) + }); let xt = context .extrinsic_factory - .create_extrinsics(&[create_account_store_call], None) + .create_extrinsics(&[create_account_store_call], params) .map_err(|e| RequestVcErrorDetail::CreateAccountStoreFailed(e.to_string()))?; context .ocall_api @@ -238,9 +242,13 @@ where req_ext_hash )); + let params = context.ocall_api.get_header().ok().map(|h: itp_types::Header| { + ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash()) + }); + let xt = context .extrinsic_factory - .create_extrinsics(&[on_vc_issued_call], None) + .create_extrinsics(&[on_vc_issued_call], params) .map_err(|e| RequestVcErrorDetail::ExtrinsicConstructionFailed(e.to_string()))?; context diff --git a/tee-worker/identity/litentry/core/vc-task/receiver/Cargo.toml b/tee-worker/identity/litentry/core/vc-task/receiver/Cargo.toml index cafe82d635..16789ea81d 100644 --- a/tee-worker/identity/litentry/core/vc-task/receiver/Cargo.toml +++ b/tee-worker/identity/litentry/core/vc-task/receiver/Cargo.toml @@ -11,6 +11,7 @@ sgx_tstd = { workspace = true, features = ["net", "thread"], optional = true } codec = { package = "parity-scale-codec", workspace = true } log = { workspace = true } sp-core = { workspace = true, features = ["full_crypto"] } +sp-runtime = { workspace = true } ita-sgx-runtime = { package = "id-ita-sgx-runtime", path = "../../../../app-libs/sgx-runtime", default-features = false } ita-stf = { package = "id-ita-stf", path = "../../../../app-libs/stf", default-features = false } @@ -69,6 +70,7 @@ std = [ "itp-stf-primitives/std", "itp-extrinsics-factory/std", "sp-core/std", + "sp-runtime/std", "litentry-primitives/std", "ita-sgx-runtime/std", "frame-support/std", diff --git a/tee-worker/identity/litentry/core/vc-task/receiver/src/lib.rs b/tee-worker/identity/litentry/core/vc-task/receiver/src/lib.rs index e4c6400fdd..8b2670dd58 100644 --- a/tee-worker/identity/litentry/core/vc-task/receiver/src/lib.rs +++ b/tee-worker/identity/litentry/core/vc-task/receiver/src/lib.rs @@ -38,9 +38,12 @@ use ita_stf::{ }; use itp_enclave_metrics::EnclaveMetric; use itp_extrinsics_factory::CreateExtrinsics; -use itp_node_api::metadata::{ - pallet_system::SystemConstants, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata, - NodeMetadataTrait, +use itp_node_api::{ + api_client::ParentchainAdditionalParams, + metadata::{ + pallet_system::SystemConstants, pallet_vcmp::VCMPCallIndexes, provider::AccessNodeMetadata, + NodeMetadataTrait, + }, }; use itp_ocall_api::{EnclaveAttestationOCallApi, EnclaveMetricsOCallApi, EnclaveOnChainOCallApi}; use itp_sgx_crypto::{key_repository::AccessKey, ShieldingCryptoDecrypt, ShieldingCryptoEncrypt}; @@ -65,6 +68,7 @@ use litentry_primitives::{ use log::*; use pallet_identity_management_tee::{identity_context::sort_id_graph, IdentityContext}; use sp_core::{blake2_256, H160}; +use sp_runtime::generic::Era; use std::{ boxed::Box, collections::{HashMap, HashSet}, @@ -615,9 +619,13 @@ where .send((shard, c)) .map_err(|e| RequestVcErrorDetail::TrustedCallSendingFailed(e.to_string()))?; + let params = context.ocall_api.get_header().ok().map(|h: itp_types::Header| { + ParentchainAdditionalParams::new().era(Era::mortal(5, h.number.into()), h.hash()) + }); + // this internally fetches nonce from a mutex and then updates it thereby ensuring ordering let xt = extrinsic_factory - .create_extrinsics(&[call], None) + .create_extrinsics(&[call], params) .map_err(|e| RequestVcErrorDetail::ExtrinsicConstructionFailed(e.to_string()))?; context diff --git a/tee-worker/identity/sidechain/consensus/common/Cargo.toml b/tee-worker/identity/sidechain/consensus/common/Cargo.toml index f1457a4298..523d21c9a5 100644 --- a/tee-worker/identity/sidechain/consensus/common/Cargo.toml +++ b/tee-worker/identity/sidechain/consensus/common/Cargo.toml @@ -14,6 +14,7 @@ itc-parentchain-light-client = { workspace = true } itp-enclave-metrics = { workspace = true } itp-extrinsics-factory = { workspace = true } itp-import-queue = { workspace = true } +itp-node-api = { workspace = true } itp-node-api-metadata = { workspace = true } itp-node-api-metadata-provider = { workspace = true } itp-ocall-api = { workspace = true } @@ -51,6 +52,7 @@ std = [ "itp-import-queue/std", "itp-enclave-metrics/std", "itp-extrinsics-factory/std", + "itp-node-api/std", "itp-node-api-metadata/std", "itp-node-api-metadata-provider/std", "itp-ocall-api/std", @@ -70,6 +72,7 @@ sgx = [ "itp-import-queue/sgx", "itp-enclave-metrics/sgx", "itp-extrinsics-factory/sgx", + "itp-node-api/sgx", "itp-node-api-metadata-provider/sgx", "itp-sgx-crypto/sgx", "itp-sgx-externalities/sgx", diff --git a/tee-worker/identity/sidechain/consensus/common/src/block_import_confirmation_handler.rs b/tee-worker/identity/sidechain/consensus/common/src/block_import_confirmation_handler.rs index 759a6e3eee..87351d6da5 100644 --- a/tee-worker/identity/sidechain/consensus/common/src/block_import_confirmation_handler.rs +++ b/tee-worker/identity/sidechain/consensus/common/src/block_import_confirmation_handler.rs @@ -17,16 +17,18 @@ use crate::error::{Error, Result}; use itc_parentchain_light_client::{ - concurrent_access::ValidatorAccess, BlockNumberOps, ExtrinsicSender, NumberFor, + concurrent_access::ValidatorAccess, BlockNumberOps, ExtrinsicSender, LightClientState, + NumberFor, }; use itp_extrinsics_factory::CreateExtrinsics; +use itp_node_api::api_client::ParentchainAdditionalParams; use itp_node_api_metadata::{pallet_teebag::TeebagCallIndexes, NodeMetadataTrait}; use itp_node_api_metadata_provider::AccessNodeMetadata; use itp_settings::worker::BLOCK_NUMBER_FINALIZATION_DIFF; -use itp_types::{OpaqueCall, ShardIdentifier}; +use itp_types::{Header, OpaqueCall, ShardIdentifier}; use its_primitives::traits::Header as HeaderTrait; use log::*; -use sp_runtime::traits::Block as ParentchainBlockTrait; +use sp_runtime::{generic::Era, traits::Block as ParentchainBlockTrait}; use std::{marker::PhantomData, sync::Arc}; /// Trait to confirm a sidechain block import. @@ -91,7 +93,7 @@ impl< ExtrinsicsFactory, ValidatorAccessor, > where - ParentchainBlock: ParentchainBlockTrait, + ParentchainBlock: ParentchainBlockTrait
, NumberFor: BlockNumberOps, SidechainHeader: HeaderTrait, NodeMetadataRepository: AccessNodeMetadata, @@ -115,14 +117,23 @@ impl< header.hash(), )); + 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 xts = self .extrinsics_factory - .create_extrinsics(&[opaque_call], None) + .create_extrinsics(&[opaque_call], params) .map_err(|e| Error::Other(e.into()))?; debug!("Sending sidechain block import confirmation extrinsic.."); self.validator_accessor - .execute_mut_on_validator(|v| v.send_extrinsics(xts)) + .execute_on_validator(|v| v.send_extrinsics(xts)) .map_err(|e| Error::Other(e.into()))?; } Ok(())