diff --git a/app-libs/stf/src/stf_sgx.rs b/app-libs/stf/src/stf_sgx.rs index c7551bcd69..16b5ca3da4 100644 --- a/app-libs/stf/src/stf_sgx.rs +++ b/app-libs/stf/src/stf_sgx.rs @@ -21,7 +21,7 @@ use crate::test_genesis::test_genesis_setup; use crate::{helpers::enclave_signer_account, Stf, StfError, ENCLAVE_ACCOUNT_KEY}; use codec::Encode; use frame_support::traits::{OriginTrait, UnfilteredDispatchable}; -use itp_node_api::metadata::{pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata}; +use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait}; use itp_sgx_externalities::SgxExternalitiesTrait; use itp_stf_interface::{ parentchain_pallet::ParentchainPalletInterface, @@ -126,7 +126,7 @@ where Call: ExecuteCall, State: SgxExternalitiesTrait + Debug, NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, { type Error = Call::Error; diff --git a/app-libs/stf/src/trusted_call.rs b/app-libs/stf/src/trusted_call.rs index 025dc45437..d4f035f050 100644 --- a/app-libs/stf/src/trusted_call.rs +++ b/app-libs/stf/src/trusted_call.rs @@ -26,7 +26,8 @@ use codec::{Decode, Encode}; use frame_support::{ensure, traits::UnfilteredDispatchable}; pub use ita_sgx_runtime::{Balance, Index}; use ita_sgx_runtime::{Runtime, System}; -use itp_node_api::metadata::{pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata}; +use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait}; +use itp_node_api_metadata::pallet_teerex::TeerexCallIndexes; use itp_stf_interface::ExecuteCall; use itp_stf_primitives::types::{AccountId, KeyPair, ShardIdentifier, Signature}; use itp_types::OpaqueCall; @@ -169,7 +170,7 @@ impl TrustedReturnValue impl ExecuteCall for TrustedCallSigned where NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, { type Error = StfError; @@ -202,8 +203,13 @@ where .map_err(|e| { Self::Error::Dispatch(format!("Balance Set Balance error: {:?}", e.error)) })?; - // TODO: we need clearly define the types so that the compiler can infer types - // see https://github.com/integritee-network/worker/issues/1145 + // This explicit Error type is somehow still needed, otherwise the compiler complains + // multiple `impl`s satisfying `StfError: std::convert::From<_>` + // note: and another `impl` found in the `core` crate: `impl std::convert::From for T;` + // the impl From<..> for StfError conflicts with the standard convert + // + // Alternatively, removing the customised "impl From<..> for StfError" and use map_err directly + // would also work Ok::<(), Self::Error>(()) }, TrustedCall::balance_transfer(from, to, value) => { diff --git a/core-primitives/node-api/metadata-provider/src/lib.rs b/core-primitives/node-api/metadata-provider/src/lib.rs index c63a028613..9d2f16d54d 100644 --- a/core-primitives/node-api/metadata-provider/src/lib.rs +++ b/core-primitives/node-api/metadata-provider/src/lib.rs @@ -56,10 +56,7 @@ pub struct NodeMetadataRepository { metadata_lock: RwLock>, } -impl NodeMetadataRepository -where - NodeMetadata: Default, -{ +impl NodeMetadataRepository { pub fn new(metadata: NodeMetadata) -> Self { NodeMetadataRepository { metadata_lock: RwLock::new(Some(metadata)) } } diff --git a/core-primitives/node-api/metadata/src/lib.rs b/core-primitives/node-api/metadata/src/lib.rs index 34671a3452..396c06a30a 100644 --- a/core-primitives/node-api/metadata/src/lib.rs +++ b/core-primitives/node-api/metadata/src/lib.rs @@ -19,7 +19,9 @@ #![cfg_attr(not(feature = "std"), no_std)] -use crate::error::Result; +use crate::{ + error::Result, pallet_sidechain::SidechainCallIndexes, pallet_teerex::TeerexCallIndexes, +}; use codec::{Decode, Encode}; use sp_core::storage::StorageKey; use substrate_api_client::{Metadata, MetadataError}; @@ -35,6 +37,9 @@ pub mod pallet_teerex; #[cfg(feature = "mocks")] pub mod metadata_mocks; +pub trait NodeMetadataTrait: TeerexCallIndexes + SidechainCallIndexes {} +impl NodeMetadataTrait for T {} + #[derive(Default, Encode, Decode, Debug, Clone)] pub struct NodeMetadata { node_metadata: Option, diff --git a/core-primitives/stf-executor/src/executor.rs b/core-primitives/stf-executor/src/executor.rs index 20c5a2772e..161bd5824c 100644 --- a/core-primitives/stf-executor/src/executor.rs +++ b/core-primitives/stf-executor/src/executor.rs @@ -26,7 +26,7 @@ use ita_stf::{ stf_sgx::{shards_key_hash, storage_hashes_to_update_per_shard}, ParentchainHeader, TrustedCallSigned, TrustedOperation, }; -use itp_node_api::metadata::{pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata}; +use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait}; use itp_ocall_api::{EnclaveAttestationOCallApi, EnclaveOnChainOCallApi}; use itp_sgx_externalities::{SgxExternalitiesTrait, StateHash}; use itp_stf_interface::{ @@ -56,7 +56,7 @@ where StateHandler: HandleState, StateHandler::StateT: SgxExternalitiesTrait + Encode, NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, Stf: UpdateState< StateHandler::StateT, ::SgxExternalitiesDiffType, @@ -231,7 +231,7 @@ where StateHandler::StateT: SgxExternalitiesTrait + Encode + StateHash, ::SgxExternalitiesType: Encode, NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, Stf: UpdateState< StateHandler::StateT, ::SgxExternalitiesDiffType, diff --git a/core-primitives/stf-interface/src/lib.rs b/core-primitives/stf-interface/src/lib.rs index 666a6d2d6a..4137834625 100644 --- a/core-primitives/stf-interface/src/lib.rs +++ b/core-primitives/stf-interface/src/lib.rs @@ -23,7 +23,7 @@ extern crate alloc; use alloc::{sync::Arc, vec::Vec}; -use itp_node_api_metadata::pallet_teerex::TeerexCallIndexes; +use itp_node_api_metadata::NodeMetadataTrait; use itp_node_api_metadata_provider::AccessNodeMetadata; use itp_types::OpaqueCall; @@ -51,7 +51,7 @@ pub trait UpdateState { pub trait StateCallInterface where NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, { type Error; @@ -74,7 +74,7 @@ pub trait StateGetterInterface { pub trait ExecuteCall where NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: TeerexCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, { type Error; diff --git a/core/parentchain/indirect-calls-executor/src/indirect_calls_executor.rs b/core/parentchain/indirect-calls-executor/src/indirect_calls_executor.rs index 73813c088d..a641b56f5f 100644 --- a/core/parentchain/indirect-calls-executor/src/indirect_calls_executor.rs +++ b/core/parentchain/indirect-calls-executor/src/indirect_calls_executor.rs @@ -27,7 +27,7 @@ use futures::executor; use ita_stf::{TrustedCall, TrustedOperation}; use itp_node_api::{ api_client::ParentchainUncheckedExtrinsic, - metadata::{pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata}, + metadata::{pallet_teerex::TeerexCallIndexes, provider::AccessNodeMetadata, NodeMetadataTrait}, }; use itp_sgx_crypto::{key_repository::AccessKey, ShieldingCryptoDecrypt, ShieldingCryptoEncrypt}; use itp_stf_executor::traits::StfEnclaveSigning; @@ -73,7 +73,7 @@ where StfEnclaveSigner: StfEnclaveSigning, TopPoolAuthor: AuthorApi + Send + Sync + 'static, NodeMetadataProvider: AccessNodeMetadata, - NodeMetadataProvider::MetadataType: TeerexCallIndexes, + NodeMetadataProvider::MetadataType: NodeMetadataTrait, { pub fn new( shielding_key_repo: Arc, @@ -188,7 +188,7 @@ impl + Send + Sync + 'static, NodeMetadataProvider: AccessNodeMetadata, - NodeMetadataProvider::MetadataType: TeerexCallIndexes, + NodeMetadataProvider::MetadataType: NodeMetadataTrait, { fn execute_indirect_calls_in_extrinsics( &self, diff --git a/sidechain/consensus/common/src/block_import_confirmation_handler.rs b/sidechain/consensus/common/src/block_import_confirmation_handler.rs index 4fb7c72f6b..be93feb51c 100644 --- a/sidechain/consensus/common/src/block_import_confirmation_handler.rs +++ b/sidechain/consensus/common/src/block_import_confirmation_handler.rs @@ -20,7 +20,7 @@ use itc_parentchain_light_client::{ concurrent_access::ValidatorAccess, BlockNumberOps, ExtrinsicSender, NumberFor, }; use itp_extrinsics_factory::CreateExtrinsics; -use itp_node_api_metadata::pallet_sidechain::SidechainCallIndexes; +use itp_node_api_metadata::{pallet_sidechain::SidechainCallIndexes, NodeMetadataTrait}; use itp_node_api_metadata_provider::AccessNodeMetadata; use itp_settings::worker::BLOCK_NUMBER_FINALIZATION_DIFF; use itp_types::{OpaqueCall, ShardIdentifier}; @@ -95,7 +95,7 @@ impl< NumberFor: BlockNumberOps, SidechainHeader: HeaderTrait, NodeMetadataRepository: AccessNodeMetadata, - NodeMetadataRepository::MetadataType: SidechainCallIndexes, + NodeMetadataRepository::MetadataType: NodeMetadataTrait, ExtrinsicsFactory: CreateExtrinsics, ValidatorAccessor: ValidatorAccess + Send + Sync + 'static, {