ensure that the bridge GRANDPA pallet is initialized in the finality relay (#1423)

This commit is contained in:
Svyatoslav Nikolsky
2022-05-30 16:31:57 +03:00
committed by Bastian Köcher
parent 4001cfb758
commit 78a43c561a
3 changed files with 21 additions and 4 deletions
@@ -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
@@ -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(())
}
}