mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 12:27:56 +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:
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user