Skip to content

Commit

Permalink
Improve relayer initialization behaviour (paritytech#1743)
Browse files Browse the repository at this point in the history
Wait until the initialization transaction is finalized/lost.
  • Loading branch information
serban300 committed Apr 10, 2024
1 parent 843737a commit 4eac7be
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions bridges/relays/lib-substrate-relay/src/finality/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
use crate::{error::Error, finality::engine::Engine};
use sp_core::Pair;

use bp_runtime::HeaderIdOf;
use relay_substrate_client::{
AccountKeyPairOf, Chain, ChainWithTransactions, Client, Error as SubstrateError,
UnsignedTransaction,
};
use relay_utils::{TrackedTransactionStatus, TransactionTracker};
use sp_runtime::traits::Header as HeaderT;

/// Submit headers-bridge initialization transaction.
Expand Down Expand Up @@ -61,13 +63,26 @@ pub async fn initialize<
.await;

match result {
Ok(Some(tx_hash)) => log::info!(
target: "bridge",
"Successfully submitted {}-headers bridge initialization transaction to {}: {:?}",
SourceChain::NAME,
TargetChain::NAME,
tx_hash,
),
Ok(Some(tx_status)) => match tx_status {
TrackedTransactionStatus::Lost => {
log::error!(
target: "bridge",
"Failed to execute {}-headers bridge initialization transaction on {}: {:?}.",
SourceChain::NAME,
TargetChain::NAME,
tx_status
)
},
TrackedTransactionStatus::Finalized(_) => {
log::info!(
target: "bridge",
"Successfully executed {}-headers bridge initialization transaction on {}: {:?}.",
SourceChain::NAME,
TargetChain::NAME,
tx_status
)
},
},
Ok(None) => (),
Err(err) => log::error!(
target: "bridge",
Expand All @@ -92,7 +107,7 @@ async fn do_initialize<
prepare_initialize_transaction: F,
dry_run: bool,
) -> Result<
Option<TargetChain::Hash>,
Option<TrackedTransactionStatus<HeaderIdOf<TargetChain>>>,
Error<SourceChain::Hash, <SourceChain::Header as HeaderT>::Number>,
>
where
Expand Down Expand Up @@ -128,8 +143,8 @@ where
initialization_data,
);

let initialization_tx_hash = target_client
.submit_signed_extrinsic(&target_signer, move |_, transaction_nonce| {
let tx_status = target_client
.submit_and_watch_signed_extrinsic(&target_signer, move |_, transaction_nonce| {
let tx = prepare_initialize_transaction(transaction_nonce, initialization_data);
if dry_run {
Err(SubstrateError::Custom(
Expand All @@ -140,7 +155,9 @@ where
}
})
.await
.map_err(|err| Error::SubmitTransaction(TargetChain::NAME, err))?;
.map_err(|err| Error::SubmitTransaction(TargetChain::NAME, err))?
.wait()
.await;

Ok(Some(initialization_tx_hash))
Ok(Some(tx_status))
}

0 comments on commit 4eac7be

Please sign in to comment.