mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Pass transaction source to validate_transaction (#5366)
* WiP * Support source in the runtime API. * Finish implementation in txpool. * Fix warning. * Fix tests. * Apply suggestions from code review Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-Authored-By: Nikolay Volf <nikvolf@gmail.com> * Extra changes. * Fix test and benches. * fix test * Fix test & benches again. * Fix tests. * Update bumpalo * Fix doc test. * Fix doctest. * Fix doctest. Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -29,10 +29,10 @@ use sc_client_api::{
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::BlockId, traits::{self, Block as BlockT, BlockIdTo, Header as HeaderT, Hash as HashT},
|
||||
transaction_validity::TransactionValidity,
|
||||
transaction_validity::{TransactionValidity, TransactionSource},
|
||||
};
|
||||
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_api::{ProvideRuntimeApi, ApiExt};
|
||||
|
||||
use crate::error::{self, Error};
|
||||
|
||||
@@ -81,6 +81,7 @@ impl<Client, Block> sc_transaction_graph::ChainApi for FullChainApi<Client, Bloc
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
source: TransactionSource,
|
||||
uxt: sc_transaction_graph::ExtrinsicFor<Self>,
|
||||
) -> Self::ValidationFuture {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@@ -88,8 +89,19 @@ impl<Client, Block> sc_transaction_graph::ChainApi for FullChainApi<Client, Bloc
|
||||
let at = at.clone();
|
||||
|
||||
self.pool.spawn_ok(futures_diagnose::diagnose("validate-transaction", async move {
|
||||
let res = client.runtime_api().validate_transaction(&at, uxt)
|
||||
.map_err(|e| Error::RuntimeApi(format!("{:?}", e)));
|
||||
let runtime_api = client.runtime_api();
|
||||
let has_v2 = runtime_api
|
||||
.has_api_with::<dyn TaggedTransactionQueue<Self::Block, Error=()>, _>(
|
||||
&at, |v| v >= 2,
|
||||
)
|
||||
.unwrap_or_default();
|
||||
let res = if has_v2 {
|
||||
runtime_api.validate_transaction(&at, source, uxt)
|
||||
} else {
|
||||
#[allow(deprecated)] // old validate_transaction
|
||||
runtime_api.validate_transaction_before_version_2(&at, uxt)
|
||||
};
|
||||
let res = res.map_err(|e| Error::RuntimeApi(format!("{:?}", e)));
|
||||
if let Err(e) = tx.send(res) {
|
||||
log::warn!("Unable to send a validate transaction result: {:?}", e);
|
||||
}
|
||||
@@ -160,6 +172,7 @@ impl<Client, F, Block> sc_transaction_graph::ChainApi for LightChainApi<Client,
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
source: TransactionSource,
|
||||
uxt: sc_transaction_graph::ExtrinsicFor<Self>,
|
||||
) -> Self::ValidationFuture {
|
||||
let header_hash = self.client.expect_block_hash_from_id(at);
|
||||
@@ -174,7 +187,7 @@ impl<Client, F, Block> sc_transaction_graph::ChainApi for LightChainApi<Client,
|
||||
block,
|
||||
header,
|
||||
method: "TaggedTransactionQueue_validate_transaction".into(),
|
||||
call_data: uxt.encode(),
|
||||
call_data: (source, uxt).encode(),
|
||||
retry_count: None,
|
||||
});
|
||||
let remote_validation_request = remote_validation_request.then(move |result| {
|
||||
|
||||
Reference in New Issue
Block a user