diff --git a/domains/client/block-preprocessor/src/lib.rs b/domains/client/block-preprocessor/src/lib.rs index bf229d3f79..fe3df98b98 100644 --- a/domains/client/block-preprocessor/src/lib.rs +++ b/domains/client/block-preprocessor/src/lib.rs @@ -18,7 +18,7 @@ use crate::inherents::is_runtime_upgraded; use codec::Encode; use domain_runtime_primitives::opaque::AccountId; use sc_client_api::BlockBackend; -use sp_api::ProvideRuntimeApi; +use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_core::H256; use sp_domains::core_api::DomainCoreApi; @@ -316,14 +316,22 @@ where ))); } - // TODO: the behavior is changed, as before invalid XDM will be dropped silently, - // and the other extrinsic of the bundle will be continue processed, now the whole - // bundle is considered as invalid and excluded from further processing. - if let Some(false) = runtime_api.is_xdm_valid(at, extrinsic.encode())? { - // TODO: Generate a fraud proof for this invalid bundle - return Ok(BundleValidity::Invalid(InvalidBundleType::InvalidXDM( - index as u32, - ))); + // TODO: remove version check before next network + let messenger_api_version = runtime_api + .api_version::>>(at)? + // safe to return default version as 1 since there will always be version 1. + .unwrap_or(1); + + if messenger_api_version >= 2 { + // TODO: the behavior is changed, as before invalid XDM will be dropped silently, + // and the other extrinsic of the bundle will be continue processed, now the whole + // bundle is considered as invalid and excluded from further processing. + if let Some(false) = runtime_api.is_xdm_valid(at, extrinsic.encode())? { + // TODO: Generate a fraud proof for this invalid bundle + return Ok(BundleValidity::Invalid(InvalidBundleType::InvalidXDM( + index as u32, + ))); + } } extrinsics.push(extrinsic); diff --git a/domains/primitives/messenger/src/lib.rs b/domains/primitives/messenger/src/lib.rs index 717d0f8a27..b877e755b7 100644 --- a/domains/primitives/messenger/src/lib.rs +++ b/domains/primitives/messenger/src/lib.rs @@ -113,6 +113,7 @@ sp_api::decl_runtime_apis! { } /// Api to provide XDM extraction from Runtime Calls. + #[api_version(2)] pub trait MessengerApi where BlockNumber: Encode + Decode{ /// Returns `Some(true)` if valid XDM or `Some(false)` if not /// Returns None if this is not an XDM diff --git a/domains/service/src/transaction_pool.rs b/domains/service/src/transaction_pool.rs index 28904d41b8..06aa88a080 100644 --- a/domains/service/src/transaction_pool.rs +++ b/domains/service/src/transaction_pool.rs @@ -1,14 +1,12 @@ -use futures::future::{Future, FutureExt, Ready}; -use parity_scale_codec::Encode; +use futures::future::{Future, Ready}; use sc_client_api::blockchain::HeaderBackend; use sc_client_api::{BlockBackend, ExecutorProvider, UsageProvider}; use sc_service::{Configuration, TaskManager}; -use sc_transaction_pool::error::{Error as TxPoolError, Result as TxPoolResult}; +use sc_transaction_pool::error::Result as TxPoolResult; use sc_transaction_pool::{BasicPool, ChainApi, FullChainApi, RevalidationType}; use sc_transaction_pool_api::TransactionSource; use sp_api::ProvideRuntimeApi; use sp_blockchain::{HeaderMetadata, TreeRoute}; -use sp_messenger::MessengerApi; use sp_runtime::generic::BlockId; use sp_runtime::traits::{Block as BlockT, BlockIdTo, NumberFor}; use sp_runtime::transaction_validity::TransactionValidity; @@ -77,7 +75,7 @@ where + Send + Sync + 'static, - Client::Api: TaggedTransactionQueue + MessengerApi>, + Client::Api: TaggedTransactionQueue, { type Block = Block; type Error = sc_transaction_pool::error::Error; @@ -90,22 +88,7 @@ where source: TransactionSource, uxt: ExtrinsicFor, ) -> Self::ValidationFuture { - let chain_api = self.inner.clone(); - let client = self.client.clone(); - async move { - if let Some(false) = client - .runtime_api() - .is_xdm_valid(at, uxt.encode()) - .map_err(|err| TxPoolError::RuntimeApi(err.to_string()))? - { - return Err(TxPoolError::Pool( - sc_transaction_pool_api::error::Error::ImmediatelyDropped, - )); - } - - chain_api.validate_transaction(at, source, uxt).await - } - .boxed() + self.inner.validate_transaction(at, source, uxt) } fn block_id_to_number( @@ -160,7 +143,7 @@ where + Send + Sync + 'static, - Client::Api: TaggedTransactionQueue + MessengerApi>, + Client::Api: TaggedTransactionQueue, { let prometheus = config.prometheus_registry(); let pool_api = Arc::new(FullChainApiWrapper::new(