@@ -337,7 +337,6 @@ where
337337 traits:: { ConstU32 , TransactionExtension } ,
338338 } ;
339339
340- // Helper: map a Block hash to H256
341340 fn to_h256 < H : AsRef < [ u8 ] > > ( h : H ) -> H256 {
342341 let bytes = h. as_ref ( ) ;
343342 let mut out = [ 0u8 ; 32 ] ;
@@ -356,7 +355,7 @@ where
356355 dst. copy_from_slice ( src) ;
357356 H256 ( out)
358357 } else {
359- // Extremely unlikely; fall back to zeroed H256 if indices are somehow invalid .
358+ // Extremely defensive fallback .
360359 H256 ( [ 0u8 ; 32 ] )
361360 }
362361 }
@@ -365,9 +364,10 @@ where
365364 let public_key: BoundedVec < u8 , MaxPk > = BoundedVec :: try_from ( next_public_key)
366365 . map_err ( |_| anyhow:: anyhow!( "public key too long (>2048 bytes)" ) ) ?;
367366
368- // 1) The runtime call carrying public key bytes.
367+ // 1) Runtime call carrying the public key bytes.
369368 let call = RuntimeCall :: MevShield ( pallet_shield:: Call :: announce_next_key { public_key } ) ;
370369
370+ // 2) Build the transaction extensions exactly like the runtime.
371371 type Extra = runtime:: TransactionExtensions ;
372372 let extra: Extra =
373373 (
@@ -390,42 +390,44 @@ where
390390 frame_metadata_hash_extension:: CheckMetadataHash :: < runtime:: Runtime > :: new ( false ) ,
391391 ) ;
392392
393+ // 3) Manually construct the `Implicit` tuple that the runtime will also derive.
393394 type Implicit = <Extra as TransactionExtension < RuntimeCall > >:: Implicit ;
394395
395396 let info = client. info ( ) ;
396397 let genesis_h256: H256 = to_h256 ( info. genesis_hash ) ;
397398
398399 let implicit: Implicit = (
399400 ( ) , // CheckNonZeroSender
400- runtime:: VERSION . spec_version , // CheckSpecVersion
401- runtime:: VERSION . transaction_version , // CheckTxVersion
402- genesis_h256, // CheckGenesis
403- genesis_h256, // CheckEra (Immortal)
404- ( ) , // CheckNonce (additional part )
405- ( ) , // CheckWeight
406- ( ) , // ChargeTransactionPaymentWrapper (additional part )
407- ( ) , // SubtensorTransactionExtension (additional part )
408- ( ) , // DrandPriority
409- None , // CheckMetadataHash (disabled)
401+ runtime:: VERSION . spec_version , // CheckSpecVersion::Implicit = u32
402+ runtime:: VERSION . transaction_version , // CheckTxVersion::Implicit = u32
403+ genesis_h256, // CheckGenesis::Implicit = Hash
404+ genesis_h256, // CheckEra::Implicit (Immortal => genesis hash )
405+ ( ) , // CheckNonce::Implicit = ( )
406+ ( ) , // CheckWeight::Implicit = ()
407+ ( ) , // ChargeTransactionPaymentWrapper::Implicit = ( )
408+ ( ) , // SubtensorTransactionExtension::Implicit = ( )
409+ ( ) , // DrandPriority::Implicit = ()
410+ None , // CheckMetadataHash::Implicit = Option<[u8; 32]>
410411 ) ;
411412
412- // Build the exact signable payload.
413+ // 4) Build the exact signable payload from call + extra + implicit .
413414 let payload: SignedPayload = SignedPayload :: from_raw ( call. clone ( ) , extra. clone ( ) , implicit) ;
414415
415- let raw_payload = payload. encode ( ) ;
416-
417- // Sign with the local Aura key.
418- let sig_opt = keystore
419- . sr25519_sign ( AURA_KEY_TYPE , & aura_pub, & raw_payload)
416+ // 5) Sign with the local Aura key using the same SCALE bytes the runtime expects.
417+ let sig_opt = payload
418+ . using_encoded ( |bytes| keystore. sr25519_sign ( AURA_KEY_TYPE , & aura_pub, bytes) )
420419 . map_err ( |e| anyhow:: anyhow!( "keystore sr25519_sign error: {e:?}" ) ) ?;
420+
421421 let sig = sig_opt
422422 . ok_or_else ( || anyhow:: anyhow!( "keystore sr25519_sign returned None for Aura key" ) ) ?;
423423
424424 let signature: MultiSignature = sig. into ( ) ;
425425
426+ // 6) Sender address = AccountId32 derived from the Aura sr25519 public key.
426427 let who: AccountId32 = aura_pub. into ( ) ;
427428 let address = sp_runtime:: MultiAddress :: Id ( who) ;
428429
430+ // 7) Assemble the signed extrinsic and submit it to the pool.
429431 let uxt: UncheckedExtrinsic = UncheckedExtrinsic :: new_signed ( call, address, signature, extra) ;
430432
431433 let xt_bytes = uxt. encode ( ) ;
0 commit comments