From 532788c1cd8f8abc7bf27c53bc24325eb3ca5b45 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 23 Feb 2023 08:17:07 +0200 Subject: [PATCH] Fix init-bridge (#1900) --- bridges/modules/grandpa/src/lib.rs | 2 +- bridges/primitives/header-chain/src/justification.rs | 2 +- .../primitives/header-chain/tests/justification.rs | 11 ++++++----- .../relays/lib-substrate-relay/src/finality/engine.rs | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index e94d91a5c16a2..4304e82eeb103 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -181,7 +181,7 @@ pub mod pallet { let is_authorities_change_enacted = try_enact_authority_change::(&finality_target, set_id)?; let may_refund_call_fee = is_authorities_change_enacted && - submit_finality_proof_info_from_args::(&*finality_target, &justification) + submit_finality_proof_info_from_args::(&finality_target, &justification) .fits_limits(); >::mutate(|count| *count += 1); insert_header::(*finality_target, hash); diff --git a/bridges/primitives/header-chain/src/justification.rs b/bridges/primitives/header-chain/src/justification.rs index 1e34f365621b9..88dac0acf9f6d 100644 --- a/bridges/primitives/header-chain/src/justification.rs +++ b/bridges/primitives/header-chain/src/justification.rs @@ -135,7 +135,7 @@ pub fn decode_justification_target( } /// Verify and optimize given justification by removing unknown and duplicate votes. -pub fn optimize_justification( +pub fn verify_and_optimize_justification( finalized_target: (Header::Hash, Header::Number), authorities_set_id: SetId, authorities_set: &VoterSet, diff --git a/bridges/primitives/header-chain/tests/justification.rs b/bridges/primitives/header-chain/tests/justification.rs index f01f4ea2f10ce..52fa33ae97491 100644 --- a/bridges/primitives/header-chain/tests/justification.rs +++ b/bridges/primitives/header-chain/tests/justification.rs @@ -17,7 +17,8 @@ //! Tests for Grandpa Justification code. use bp_header_chain::justification::{ - optimize_justification, required_justification_precommits, verify_justification, Error, + required_justification_precommits, verify_and_optimize_justification, verify_justification, + Error, }; use bp_test_utils::*; @@ -199,7 +200,7 @@ fn optimizer_does_noting_with_minimal_justification() { let justification = make_default_justification::(&test_header(1)); let num_precommits_before = justification.commit.precommits.len(); - let justification = optimize_justification::( + let justification = verify_and_optimize_justification::( header_id::(1), TEST_GRANDPA_SET_ID, &voter_set(), @@ -222,7 +223,7 @@ fn unknown_authority_votes_are_removed_by_optimizer() { )); let num_precommits_before = justification.commit.precommits.len(); - let justification = optimize_justification::( + let justification = verify_and_optimize_justification::( header_id::(1), TEST_GRANDPA_SET_ID, &voter_set(), @@ -243,7 +244,7 @@ fn duplicate_authority_votes_are_removed_by_optimizer() { .push(justification.commit.precommits.first().cloned().unwrap()); let num_precommits_before = justification.commit.precommits.len(); - let justification = optimize_justification::( + let justification = verify_and_optimize_justification::( header_id::(1), TEST_GRANDPA_SET_ID, &voter_set(), @@ -266,7 +267,7 @@ fn redundant_authority_votes_are_removed_by_optimizer() { )); let num_precommits_before = justification.commit.precommits.len(); - let justification = optimize_justification::( + let justification = verify_and_optimize_justification::( header_id::(1), TEST_GRANDPA_SET_ID, &voter_set(), diff --git a/bridges/relays/lib-substrate-relay/src/finality/engine.rs b/bridges/relays/lib-substrate-relay/src/finality/engine.rs index f5ac8539a689e..4fc503011bba1 100644 --- a/bridges/relays/lib-substrate-relay/src/finality/engine.rs +++ b/bridges/relays/lib-substrate-relay/src/finality/engine.rs @@ -19,7 +19,7 @@ use crate::error::Error; use async_trait::async_trait; use bp_header_chain::{ - justification::{verify_justification, GrandpaJustification}, + justification::{verify_and_optimize_justification, GrandpaJustification}, ConsensusLogReader, FinalityProof, GrandpaConsensusLogReader, }; use bp_runtime::{BasicOperatingMode, HeaderIdProvider, OperatingMode}; @@ -172,7 +172,7 @@ impl Engine for Grandpa { // actual authorities set (which we have read now) may have changed, so this // `optimize_justification` may fail. But if target chain is configured properly, it'll fail // anyway, after we submit transaction and failing earlier is better. So - it is fine - bp_header_chain::justification::optimize_justification( + verify_and_optimize_justification( (header.hash(), *header.number()), authority_set_id, &authority_set, @@ -272,11 +272,11 @@ impl Engine for Grandpa { initial_authorities_set_id, ); - let is_valid_set_id = verify_justification::( + let is_valid_set_id = verify_and_optimize_justification( (initial_header_hash, initial_header_number), initial_authorities_set_id, &authorities_for_verification, - &justification, + justification.clone(), ) .is_ok();