@@ -19,17 +19,18 @@ use crate::cli::{Balance, TargetConnectionParams, TargetSigningParams};
1919use codec:: { Decode , Encode } ;
2020use num_traits:: { One , Zero } ;
2121use relay_substrate_client:: {
22- BlockWithJustification , Chain , Client , Error as SubstrateError , HeaderOf , SignParam ,
23- TransactionSignScheme ,
22+ BlockWithJustification , Chain , Client , Error as SubstrateError , HeaderIdOf , HeaderOf ,
23+ SignParam , TransactionSignScheme ,
2424} ;
25- use relay_utils:: FailedClient ;
25+ use relay_utils:: { FailedClient , HeaderId } ;
2626use sp_core:: Bytes ;
2727use sp_runtime:: {
2828 traits:: { Hash , Header as HeaderT } ,
2929 transaction_validity:: TransactionPriority ,
3030} ;
3131use structopt:: StructOpt ;
3232use strum:: { EnumString , EnumVariantNames , VariantNames } ;
33+ use substrate_relay_helper:: TransactionParams ;
3334
3435/// Start resubmit transactions process.
3536#[ derive( StructOpt ) ]
@@ -122,13 +123,16 @@ impl ResubmitTransactions {
122123 select_bridge ! ( self . chain, {
123124 let relay_loop_name = format!( "ResubmitTransactions{}" , Target :: NAME ) ;
124125 let client = self . target. to_client:: <Target >( TARGET_RUNTIME_VERSION ) . await ?;
125- let key_pair = self . target_sign. to_keypair:: <Target >( ) ?;
126+ let transaction_params = TransactionParams {
127+ signer: self . target_sign. to_keypair:: <Target >( ) ?,
128+ mortality: self . target_sign. target_transactions_mortality,
129+ } ;
126130
127131 relay_utils:: relay_loop( ( ) , client)
128132 . run( relay_loop_name, move |_, client, _| {
129133 run_until_connection_lost:: <Target , TargetSign >(
130134 client,
131- key_pair . clone( ) ,
135+ transaction_params . clone( ) ,
132136 Context {
133137 strategy: self . strategy,
134138 best_header: HeaderOf :: <Target >:: new(
@@ -219,13 +223,14 @@ impl<C: Chain> Context<C> {
219223/// Run resubmit transactions loop.
220224async fn run_until_connection_lost < C : Chain , S : TransactionSignScheme < Chain = C > > (
221225 client : Client < C > ,
222- key_pair : S :: AccountKeyPair ,
226+ transaction_params : TransactionParams < S :: AccountKeyPair > ,
223227 mut context : Context < C > ,
224228) -> Result < ( ) , FailedClient > {
225229 loop {
226230 async_std:: task:: sleep ( C :: AVERAGE_BLOCK_INTERVAL ) . await ;
227231
228- let result = run_loop_iteration :: < C , S > ( client. clone ( ) , key_pair. clone ( ) , context) . await ;
232+ let result =
233+ run_loop_iteration :: < C , S > ( client. clone ( ) , transaction_params. clone ( ) , context) . await ;
229234 context = match result {
230235 Ok ( context) => context,
231236 Err ( error) => {
@@ -244,20 +249,21 @@ async fn run_until_connection_lost<C: Chain, S: TransactionSignScheme<Chain = C>
244249/// Run single loop iteration.
245250async fn run_loop_iteration < C : Chain , S : TransactionSignScheme < Chain = C > > (
246251 client : Client < C > ,
247- key_pair : S :: AccountKeyPair ,
252+ transaction_params : TransactionParams < S :: AccountKeyPair > ,
248253 mut context : Context < C > ,
249254) -> Result < Context < C > , SubstrateError > {
250255 // correct best header is required for all other actions
251256 context. best_header = client. best_header ( ) . await ?;
252257
253258 // check if there's queued transaction, signed by given author
254- let original_transaction = match lookup_signer_transaction :: < C , S > ( & client, & key_pair) . await ? {
255- Some ( original_transaction) => original_transaction,
256- None => {
257- log:: trace!( target: "bridge" , "No {} transactions from required signer in the txpool" , C :: NAME ) ;
258- return Ok ( context)
259- } ,
260- } ;
259+ let original_transaction =
260+ match lookup_signer_transaction :: < C , S > ( & client, & transaction_params. signer ) . await ? {
261+ Some ( original_transaction) => original_transaction,
262+ None => {
263+ log:: trace!( target: "bridge" , "No {} transactions from required signer in the txpool" , C :: NAME ) ;
264+ return Ok ( context)
265+ } ,
266+ } ;
261267 let original_transaction_hash = C :: Hasher :: hash ( & original_transaction. encode ( ) ) ;
262268 let context = context. notice_transaction ( original_transaction_hash) ;
263269
@@ -287,8 +293,8 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
287293 // update transaction tip
288294 let ( is_updated, updated_transaction) = update_transaction_tip :: < C , S > (
289295 & client,
290- & key_pair ,
291- context. best_header . hash ( ) ,
296+ & transaction_params ,
297+ HeaderId ( * context. best_header . number ( ) , context . best_header . hash ( ) ) ,
292298 original_transaction,
293299 context. tip_step ,
294300 context. tip_limit ,
@@ -404,15 +410,15 @@ fn select_transaction_from_queue<C: Chain>(
404410/// Try to find appropriate tip for transaction so that its priority is larger than given.
405411async fn update_transaction_tip < C : Chain , S : TransactionSignScheme < Chain = C > > (
406412 client : & Client < C > ,
407- key_pair : & S :: AccountKeyPair ,
408- at_block : C :: Hash ,
413+ transaction_params : & TransactionParams < S :: AccountKeyPair > ,
414+ at_block : HeaderIdOf < C > ,
409415 tx : S :: SignedTransaction ,
410416 tip_step : C :: Balance ,
411417 tip_limit : C :: Balance ,
412418 target_priority : TransactionPriority ,
413419) -> Result < ( bool , S :: SignedTransaction ) , SubstrateError > {
414420 let stx = format ! ( "{:?}" , tx) ;
415- let mut current_priority = client. validate_transaction ( at_block, tx. clone ( ) ) . await ??. priority ;
421+ let mut current_priority = client. validate_transaction ( at_block. 1 , tx. clone ( ) ) . await ??. priority ;
416422 let mut unsigned_tx = S :: parse_transaction ( tx) . ok_or_else ( || {
417423 SubstrateError :: Custom ( format ! ( "Failed to parse {} transaction {}" , C :: NAME , stx, ) )
418424 } ) ?;
@@ -437,12 +443,12 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
437443 unsigned_tx. tip = next_tip;
438444 current_priority = client
439445 . validate_transaction (
440- at_block,
446+ at_block. 1 ,
441447 S :: sign_transaction ( SignParam {
442448 spec_version,
443449 transaction_version,
444450 genesis_hash : * client. genesis_hash ( ) ,
445- signer : key_pair . clone ( ) ,
451+ signer : transaction_params . signer . clone ( ) ,
446452 era : relay_substrate_client:: TransactionEra :: immortal ( ) ,
447453 unsigned : unsigned_tx. clone ( ) ,
448454 } ) ?,
@@ -465,8 +471,11 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
465471 spec_version,
466472 transaction_version,
467473 genesis_hash : * client. genesis_hash ( ) ,
468- signer : key_pair. clone ( ) ,
469- era : relay_substrate_client:: TransactionEra :: immortal ( ) ,
474+ signer : transaction_params. signer . clone ( ) ,
475+ era : relay_substrate_client:: TransactionEra :: new (
476+ at_block,
477+ transaction_params. mortality ,
478+ ) ,
470479 unsigned : unsigned_tx,
471480 } ) ?,
472481 ) )
0 commit comments