mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Build block without checking signatures (#4916)
* in executive * in other places * to UnsafeResult * move doc comment * apply suggestions * allow validity mocking for TestXt * add test * augment checkable instead of another trait * fix im online test * blockbuilder dihotomy * review suggestions * update test * Update client/block-builder/src/lib.rs * updae spec_version Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -195,7 +195,7 @@ impl<Block, B, E, RA, A> ProposerInner<Block, SubstrateClient<B, E, Block, RA>,
|
||||
inherent_data
|
||||
)?
|
||||
{
|
||||
block_builder.push(extrinsic)?;
|
||||
block_builder.push_trusted(extrinsic)?;
|
||||
}
|
||||
|
||||
// proceed with transactions
|
||||
@@ -218,7 +218,7 @@ impl<Block, B, E, RA, A> ProposerInner<Block, SubstrateClient<B, E, Block, RA>,
|
||||
let pending_tx_data = pending_tx.data().clone();
|
||||
let pending_tx_hash = pending_tx.hash().clone();
|
||||
trace!("[{:?}] Pushing to the block.", pending_tx_hash);
|
||||
match sc_block_builder::BlockBuilder::push(&mut block_builder, pending_tx_data) {
|
||||
match sc_block_builder::BlockBuilder::push_trusted(&mut block_builder, pending_tx_data) {
|
||||
Ok(()) => {
|
||||
debug!("[{:?}] Pushed to the block.", pending_tx_hash);
|
||||
}
|
||||
|
||||
@@ -121,11 +121,23 @@ where
|
||||
backend,
|
||||
})
|
||||
}
|
||||
|
||||
/// Push onto the block's list of extrinsics.
|
||||
///
|
||||
/// This will ensure the extrinsic can be validly executed (by executing it).
|
||||
pub fn push(&mut self, xt: <Block as BlockT>::Extrinsic) -> Result<(), ApiErrorFor<A, Block>> {
|
||||
self.push_internal(xt, false)
|
||||
}
|
||||
|
||||
/// Push onto the block's list of extrinsics.
|
||||
///
|
||||
/// This will ensure the extrinsic can be validly executed (by executing it);
|
||||
pub fn push(&mut self, xt: <Block as BlockT>::Extrinsic) -> Result<(), ApiErrorFor<A, Block>> {
|
||||
/// This will treat incoming extrinsic `xt` as untrusted and perform additional checks
|
||||
/// (currenty checking signature).
|
||||
pub fn push_trusted(&mut self, xt: <Block as BlockT>::Extrinsic) -> Result<(), ApiErrorFor<A, Block>> {
|
||||
self.push_internal(xt, true)
|
||||
}
|
||||
|
||||
fn push_internal(&mut self, xt: <Block as BlockT>::Extrinsic, skip_signature: bool) -> Result<(), ApiErrorFor<A, Block>> {
|
||||
let block_id = &self.block_id;
|
||||
let extrinsics = &mut self.extrinsics;
|
||||
|
||||
@@ -152,12 +164,29 @@ where
|
||||
}
|
||||
})
|
||||
} else {
|
||||
self.api.map_api_result(|api| {
|
||||
match api.apply_extrinsic_with_context(
|
||||
let use_trusted = skip_signature && self
|
||||
.api
|
||||
.has_api_with::<dyn BlockBuilderApi<Block, Error = ApiErrorFor<A, Block>>, _>(
|
||||
block_id,
|
||||
ExecutionContext::BlockConstruction,
|
||||
xt.clone(),
|
||||
)? {
|
||||
|version| version >= 5,
|
||||
)?;
|
||||
|
||||
self.api.map_api_result(|api| {
|
||||
let apply_result = if use_trusted {
|
||||
api.apply_trusted_extrinsic_with_context(
|
||||
block_id,
|
||||
ExecutionContext::BlockConstruction,
|
||||
xt.clone(),
|
||||
)?
|
||||
} else {
|
||||
api.apply_extrinsic_with_context(
|
||||
block_id,
|
||||
ExecutionContext::BlockConstruction,
|
||||
xt.clone(),
|
||||
)?
|
||||
};
|
||||
|
||||
match apply_result {
|
||||
Ok(_) => {
|
||||
extrinsics.push(xt);
|
||||
Ok(())
|
||||
|
||||
@@ -402,7 +402,7 @@ fn should_return_runtime_version() {
|
||||
|
||||
let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\
|
||||
\"specVersion\":1,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",2],\
|
||||
[\"0x37e397fc7c91f5e4\",1],[\"0xd2bc9897eed08f15\",1],[\"0x40fe3ad401f8959a\",4],\
|
||||
[\"0x37e397fc7c91f5e4\",1],[\"0xd2bc9897eed08f15\",1],[\"0x40fe3ad401f8959a\",5],\
|
||||
[\"0xc6e9a76309f39b09\",1],[\"0xdd718d5cc53262d4\",1],[\"0xcbca25e39f142387\",1],\
|
||||
[\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]]}";
|
||||
|
||||
|
||||
@@ -705,6 +705,7 @@ mod tests {
|
||||
use futures::executor::block_on;
|
||||
use sp_consensus::SelectChain;
|
||||
use sp_runtime::traits::BlindCheckable;
|
||||
use sp_runtime::generic::CheckSignature;
|
||||
use substrate_test_runtime_client::{prelude::*, runtime::{Extrinsic, Transfer}};
|
||||
use sc_transaction_pool::{BasicPool, FullChainApi};
|
||||
|
||||
@@ -733,7 +734,7 @@ mod tests {
|
||||
|
||||
// then
|
||||
assert_eq!(transactions.len(), 1);
|
||||
assert!(transactions[0].1.clone().check().is_ok());
|
||||
assert!(transactions[0].1.clone().check(CheckSignature::Yes).is_ok());
|
||||
// this should not panic
|
||||
let _ = transactions[0].1.transfer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user