GRANDPA: optimize votes_ancestries when needed (#2262) (#2264)

* GRANDPA: optimize votes_ancestries when needed

* Address review comments
This commit is contained in:
Serban Iorga
2023-07-13 16:24:03 +03:00
committed by Bastian Köcher
parent c5f24cb761
commit b4c7ffd3d3
6 changed files with 254 additions and 114 deletions
@@ -91,8 +91,8 @@ pub trait Engine<C: Chain>: Send {
async fn optimize_proof<TargetChain: Chain>(
target_client: &Client<TargetChain>,
header: &C::Header,
proof: Self::FinalityProof,
) -> Result<Self::FinalityProof, SubstrateError>;
proof: &mut Self::FinalityProof,
) -> Result<(), SubstrateError>;
/// Prepare initialization data for the finality bridge pallet.
async fn prepare_initialization_data(
@@ -149,8 +149,8 @@ impl<C: ChainWithGrandpa> Engine<C> for Grandpa<C> {
async fn optimize_proof<TargetChain: Chain>(
target_client: &Client<TargetChain>,
header: &C::Header,
proof: Self::FinalityProof,
) -> Result<Self::FinalityProof, SubstrateError> {
proof: &mut Self::FinalityProof,
) -> Result<(), SubstrateError> {
let current_authority_set_key = bp_header_chain::storage_keys::current_authority_set_key(
C::WITH_CHAIN_GRANDPA_PALLET_NAME,
);
@@ -275,7 +275,7 @@ impl<C: ChainWithGrandpa> Engine<C> for Grandpa<C> {
(initial_header_hash, initial_header_number),
initial_authorities_set_id,
&authorities_for_verification,
justification.clone(),
&mut justification.clone(),
)
.is_ok();
@@ -109,10 +109,10 @@ where
async fn submit_finality_proof(
&self,
header: SyncHeader<HeaderOf<P::SourceChain>>,
proof: SubstrateFinalityProof<P>,
mut proof: SubstrateFinalityProof<P>,
) -> Result<Self::TransactionTracker, Error> {
// runtime module at target chain may require optimized finality proof
let proof = P::FinalityEngine::optimize_proof(&self.client, &header, proof).await?;
P::FinalityEngine::optimize_proof(&self.client, &header, &mut proof).await?;
// now we may submit optimized finality proof
let transaction_params = self.transaction_params.clone();
@@ -135,11 +135,11 @@ impl<P: SubstrateFinalitySyncPipeline> OnDemandRelay<P::SourceChain, P::TargetCh
) -> Result<(HeaderIdOf<P::SourceChain>, Vec<CallOf<P::TargetChain>>), SubstrateError> {
// first find proper header (either `required_header`) or its descendant
let finality_source = SubstrateFinalitySource::<P>::new(self.source_client.clone(), None);
let (header, proof) = finality_source.prove_block_finality(required_header).await?;
let (header, mut proof) = finality_source.prove_block_finality(required_header).await?;
let header_id = header.id();
// optimize justification before including it into the call
let proof = P::FinalityEngine::optimize_proof(&self.target_client, &header, proof).await?;
P::FinalityEngine::optimize_proof(&self.target_client, &header, &mut proof).await?;
log::debug!(
target: "bridge",