Skip to content

Commit 0cb7830

Browse files
committed
dynamic transaction construction
1 parent bdc7ead commit 0cb7830

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

node/src/mev_shield/author.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ pub async fn submit_announce_extrinsic<B, C, Pool>(
316316
) -> anyhow::Result<()>
317317
where
318318
B: sp_runtime::traits::Block,
319-
C: sc_client_api::HeaderBackend<B> + Send + Sync + 'static,
319+
C: sc_client_api::HeaderBackend<B> + sp_api::ProvideRuntimeApi<B> + Send + Sync + 'static,
320+
C::Api: sp_api::Core<B>,
320321
Pool: sc_transaction_pool_api::TransactionPool<Block = B> + Send + Sync + 'static,
321322
B::Extrinsic: From<sp_runtime::OpaqueExtrinsic>,
322323
B::Hash: AsRef<[u8]>,
@@ -325,6 +326,7 @@ where
325326
use runtime::{RuntimeCall, SignedPayload, UncheckedExtrinsic};
326327

327328
use sc_transaction_pool_api::TransactionSource;
329+
use sp_api::Core as _;
328330
use sp_core::H256;
329331
use sp_runtime::codec::Encode;
330332
use sp_runtime::{
@@ -391,19 +393,39 @@ where
391393

392394
let info = client.info();
393395
let genesis_h256: H256 = to_h256(info.genesis_hash);
396+
let at_hash = info.best_hash;
397+
398+
// Try to get the *current* runtime version from on-chain WASM; if that fails,
399+
// fall back to the compiled runtime::VERSION.
400+
let (spec_version, tx_version) = match client.runtime_api().version(at_hash) {
401+
Ok(v) => (v.spec_version, v.transaction_version),
402+
Err(e) => {
403+
log::debug!(
404+
target: "mev-shield",
405+
"runtime_api::version failed at_hash={:?}: {:?}; \
406+
falling back to compiled runtime::VERSION",
407+
at_hash,
408+
e
409+
);
410+
(
411+
runtime::VERSION.spec_version,
412+
runtime::VERSION.transaction_version,
413+
)
414+
}
415+
};
394416

395417
let implicit: Implicit = (
396-
(), // CheckNonZeroSender
397-
runtime::VERSION.spec_version, // CheckSpecVersion::Implicit = u32
398-
runtime::VERSION.transaction_version, // CheckTxVersion::Implicit = u32
399-
genesis_h256, // CheckGenesis::Implicit = Hash
400-
genesis_h256, // CheckEra::Implicit (Immortal => genesis hash)
401-
(), // CheckNonce::Implicit = ()
402-
(), // CheckWeight::Implicit = ()
403-
(), // ChargeTransactionPaymentWrapper::Implicit = ()
404-
(), // SubtensorTransactionExtension::Implicit = ()
405-
(), // DrandPriority::Implicit = ()
406-
None, // CheckMetadataHash::Implicit = Option<[u8; 32]>
418+
(), // CheckNonZeroSender
419+
spec_version, // dynamic or fallback spec_version
420+
tx_version, // dynamic or fallback transaction_version
421+
genesis_h256, // CheckGenesis::Implicit = Hash
422+
genesis_h256, // CheckEra::Implicit (Immortal => genesis hash)
423+
(), // CheckNonce::Implicit = ()
424+
(), // CheckWeight::Implicit = ()
425+
(), // ChargeTransactionPaymentWrapper::Implicit = ()
426+
(), // SubtensorTransactionExtension::Implicit = ()
427+
(), // DrandPriority::Implicit = ()
428+
None, // CheckMetadataHash::Implicit = Option<[u8; 32]>
407429
);
408430

409431
// 4) Build the exact signable payload from call + extra + implicit.
@@ -433,12 +455,12 @@ where
433455
let opaque: sp_runtime::OpaqueExtrinsic = uxt.into();
434456
let xt: <B as sp_runtime::traits::Block>::Extrinsic = opaque.into();
435457

436-
pool.submit_one(info.best_hash, TransactionSource::Local, xt)
458+
pool.submit_one(at_hash, TransactionSource::Local, xt)
437459
.await?;
438460

439461
log::debug!(
440462
target: "mev-shield",
441-
"announce_next_key submitted: xt=0x{xt_hash_hex}, nonce={nonce:?}",
463+
"announce_next_key submitted: xt=0x{xt_hash_hex}, nonce={nonce:?}, spec_version={spec_version}, tx_version={tx_version}",
442464
);
443465

444466
Ok(())

0 commit comments

Comments
 (0)