impl: rm unwrap and expect from mfv::submit_finality_proof
@@ -160,24 +160,30 @@ pub mod pallet {
<Error<T, I>>::TooManyRequests
);
+ log::debug!("Going to try and finalize header {:?} gateway {:?}", finality_target, gateway_id);
+
let (hash, number) = (finality_target.hash(), finality_target.number());
- log::trace!("Going to try and finalize header {:?}", finality_target);
let best_finalized = <MultiImportedHeaders<T, I>>::get(
gateway_id,
- <BestFinalizedMap<T, I>>::get(gateway_id).expect(
- " Every time `BestFinalized` is updated `ImportedHeaders` is also updated. Therefore
- `ImportedHeaders` must contain an entry for `BestFinalized`.",
- ),
+ <BestFinalizedMap<T, I>>::get(gateway_id)
+ // Every time `BestFinalized` is updated `ImportedHeaders` is also updated. Therefore
+ // `ImportedHeaders` must contain an entry for `BestFinalized`.
+ .ok_or_else(|| <Error<T, I>>::NoFinalizedHeader)?
)
- .expect("In order to reach this point the bridge must have been initialized for given gateway.");
+ // In order to reach this point the bridge must have been initialized for given gateway.
+ .ok_or_else(|| <Error<T, I>>::InvalidAnchorHeader)?;
// We do a quick check here to ensure that our header chain is making progress and isn't
// "travelling back in time" (which could be indicative of something bad, e.g a hard-fork).
ensure!(best_finalized.number() < number, <Error<T, I>>::OldHeader);
+
let authority_set = <CurrentAuthoritySetMap<T, I>>::get(gateway_id)
- .expect("Expects authorities to be set before verify_justification");
+ // Expects authorities to be set before verify_justification
+ .ok_or_else(|| <Error<T, I>>::InvalidAuthoritySet)?;
+
let set_id = authority_set.set_id;
+
verify_justification_single::<T, I>(
&justification,
hash,
@@ -189,6 +195,7 @@ pub mod pallet {
// We have to incentivise authority_set update submissions in some way. Important to receive proofs of changing set, even when no transaction is included
let _enacted =
try_enact_authority_change_single::<T, I>(&finality_target, set_id, gateway_id)?;
+
let index = <MultiImportedHashesPointer<T, I>>::get(gateway_id).unwrap_or_default();
let pruning = <MultiImportedHashes<T, I>>::try_get(gateway_id, index);
@@ -223,7 +230,8 @@ pub mod pallet {
<MultiImportedHeaders<T, I>>::remove(gateway_id, hash);
<MultiImportedRoots<T, I>>::remove(gateway_id, hash);
}
- log::info!(
+
+ log::debug!(
"Successfully imported finalized header with hash {:?} for gateway {:?}!",
hash,
gateway_id
@@ -234,7 +242,7 @@ pub mod pallet {
pallet_xdns::Pallet::<T>::update_gateway_ttl(gateway_id, now)?;
- log::info!(
+ log::debug!(
"Successfully updated gateway {:?} with finalized timestamp {:?}!",
gateway_id,
now.clone()
@@ -583,6 +591,8 @@ pub mod pallet {
StorageRootMismatch,
// Submitted anchor header(verified header stored on circuit) was not found
InvalidAnchorHeader,
+ // No finalized header known for the corresponding gateway.
+ NoFinalizedHeader
}
/// Check the given header for a GRANDPA scheduled authority set change. If a change
