Skip to content

Commit 606768b

Browse files
svyatonikbkchr
authored andcommitted
Use specific error for case when para head is missing from the bridge pallet (#1829)
* use specific error for case when para head is missing from the bridge pallet * fix match to support both error types
1 parent 4689dfa commit 606768b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

bridges/relays/client-substrate/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub enum Error {
6161
/// The bridge pallet is not yet initialized and all transactions will be rejected.
6262
#[error("Bridge pallet is not initialized.")]
6363
BridgePalletIsNotInitialized,
64+
/// There's no best head of the parachain at the `pallet-bridge-parachains` at the target side.
65+
#[error("No head of the ParaId({0}) at the bridge parachains pallet at {1}.")]
66+
NoParachainHeadAtTarget(u32, String),
6467
/// An error has happened when we have tried to parse storage proof.
6568
#[error("Error when parsing storage proof: {0:?}.")]
6669
StorageProofError(bp_runtime::StorageProofError),

bridges/relays/lib-substrate-relay/src/on_demand/parachains.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,13 @@ where
473473
P::SourceParachain,
474474
>(target.client(), best_target_block_hash)
475475
.await;
476-
// if there are no parachain heads at the target (`BridgePalletIsNotInitialized`), we'll need
477-
// to submit at least one. Otherwise the pallet will be treated as uninitialized and messages
476+
// if there are no parachain heads at the target (`NoParachainHeadAtTarget`), we'll need to
477+
// submit at least one. Otherwise the pallet will be treated as uninitialized and messages
478478
// sync will stall.
479479
let para_header_at_target = match para_header_at_target {
480480
Ok(para_header_at_target) => Some(para_header_at_target.0),
481-
Err(SubstrateError::BridgePalletIsNotInitialized) => None,
481+
Err(SubstrateError::BridgePalletIsNotInitialized) |
482+
Err(SubstrateError::NoParachainHeadAtTarget(_, _)) => None,
482483
Err(e) => return Err(map_target_err(e)),
483484
};
484485

bridges/relays/lib-substrate-relay/src/parachains/target.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use parachains_relay::{
3333
};
3434
use relay_substrate_client::{
3535
AccountIdOf, AccountKeyPairOf, BlockNumberOf, Chain, Client, Error as SubstrateError, HashOf,
36-
HeaderIdOf, RelayChain, TransactionEra, TransactionTracker, UnsignedTransaction,
36+
HeaderIdOf, ParachainBase, RelayChain, TransactionEra, TransactionTracker, UnsignedTransaction,
3737
};
3838
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
3939
use sp_core::{Bytes, Pair};
@@ -110,7 +110,10 @@ where
110110
)
111111
.map_err(SubstrateError::ResponseParseFailed)?
112112
.map(Ok)
113-
.unwrap_or(Err(SubstrateError::BridgePalletIsNotInitialized))
113+
.unwrap_or(Err(SubstrateError::NoParachainHeadAtTarget(
114+
P::SourceParachain::PARACHAIN_ID,
115+
P::TargetChain::NAME.into(),
116+
)))
114117
}
115118

116119
async fn parachain_head(

0 commit comments

Comments
 (0)