Skip to content

Commit

Permalink
Merge pull request #2578 from subspace/messenger_versioning
Browse files Browse the repository at this point in the history
Bump messenger api version and remove xdm validation for domain tx pool
  • Loading branch information
vedhavyas authored Mar 1, 2024
2 parents 200f949 + 2a7ccda commit a986e2a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
26 changes: 17 additions & 9 deletions domains/client/block-preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<dyn MessengerApi<Block, NumberFor<Block>>>(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);
Expand Down
1 change: 1 addition & 0 deletions domains/primitives/messenger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ sp_api::decl_runtime_apis! {
}

/// Api to provide XDM extraction from Runtime Calls.
#[api_version(2)]
pub trait MessengerApi<BlockNumber> where BlockNumber: Encode + Decode{
/// Returns `Some(true)` if valid XDM or `Some(false)` if not
/// Returns None if this is not an XDM
Expand Down
27 changes: 5 additions & 22 deletions domains/service/src/transaction_pool.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -77,7 +75,7 @@ where
+ Send
+ Sync
+ 'static,
Client::Api: TaggedTransactionQueue<Block> + MessengerApi<Block, NumberFor<Block>>,
Client::Api: TaggedTransactionQueue<Block>,
{
type Block = Block;
type Error = sc_transaction_pool::error::Error;
Expand All @@ -90,22 +88,7 @@ where
source: TransactionSource,
uxt: ExtrinsicFor<Self>,
) -> 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(
Expand Down Expand Up @@ -160,7 +143,7 @@ where
+ Send
+ Sync
+ 'static,
Client::Api: TaggedTransactionQueue<Block> + MessengerApi<Block, NumberFor<Block>>,
Client::Api: TaggedTransactionQueue<Block>,
{
let prometheus = config.prometheus_registry();
let pool_api = Arc::new(FullChainApiWrapper::new(
Expand Down

0 comments on commit a986e2a

Please sign in to comment.