Skip to content

Commit

Permalink
ensure that the bridge GRANDPA pallet is initialized in the finality …
Browse files Browse the repository at this point in the history
…relay (paritytech#1423)
  • Loading branch information
svyatonik authored and serban300 committed Apr 8, 2024
1 parent ccef1ce commit a50316e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bridges/relays/client-substrate/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub enum Error {
/// The bridge pallet is halted and all transactions will be rejected.
#[error("Bridge pallet is halted.")]
BridgePalletIsHalted,
/// The bridge pallet is not yet initialized and all transactions will be rejected.
#[error("Bridge pallet is not initialized.")]
BridgePalletIsNotInitialized,
/// An error has happened when we have tried to parse storage proof.
#[error("Error when parsing storage proof: {0:?}.")]
StorageProofError(bp_runtime::StorageProofError),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ where
}

/// Returns `Ok(true)` if bridge has already been initialized.
async fn is_initialized<E: Engine<SourceChain>, SourceChain: Chain, TargetChain: Chain>(
pub(crate) async fn is_initialized<
E: Engine<SourceChain>,
SourceChain: Chain,
TargetChain: Chain,
>(
target_client: &Client<TargetChain>,
) -> Result<bool, Error<HashOf<SourceChain>, BlockNumberOf<SourceChain>>> {
Ok(target_client
Expand Down
16 changes: 13 additions & 3 deletions bridges/relays/lib-substrate-relay/src/finality/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ impl<P: SubstrateFinalitySyncPipeline> SubstrateFinalityTarget<P> {
pub async fn ensure_pallet_active(&self) -> Result<(), Error> {
let is_halted = self.client.storage_value(P::FinalityEngine::is_halted_key(), None).await?;
if is_halted.unwrap_or(false) {
Err(Error::BridgePalletIsHalted)
} else {
Ok(())
return Err(Error::BridgePalletIsHalted)
}

let is_initialized =
super::initialize::is_initialized::<P::FinalityEngine, P::SourceChain, P::TargetChain>(
&self.client,
)
.await
.map_err(|e| Error::Custom(e.to_string()))?;
if !is_initialized {
return Err(Error::BridgePalletIsNotInitialized)
}

Ok(())
}
}

Expand Down

0 comments on commit a50316e

Please sign in to comment.