mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
Update bridges subtree (#2903)
* Squashed 'bridges/' changes from 0417308a48..3c4ada921b 3c4ada921b Update dependecies (#2277) (#2281) 3e195c9e76 GRANDPA: optimize votes_ancestries when needed (#2262) (#2264) 7065bbabc6 Implement RuntimeDebug for GrandpaJustification (#2254) 8c9e59bcbc Define generate_grandpa_key_ownership_proof() (#2247) (#2248) 0b46956df7 Deduplicate Grandpa consensus log reading logic (#2245) (#2246) 96c9701710 Fix deps from Cumulus (#2244) git-subtree-dir: bridges git-subtree-split: 3c4ada921bbdbdba945c3aa85d76ce316f7baab3 * removed extra files * post-merge fixes * also post-merge fixes
This commit is contained in:
committed by
GitHub
parent
913b789416
commit
948f80733e
@@ -38,8 +38,8 @@ type TestNumber = <TestHeader as HeaderT>::Number;
|
||||
struct AncestryChain(bp_header_chain::justification::AncestryChain<TestHeader>);
|
||||
|
||||
impl AncestryChain {
|
||||
fn new(ancestry: &[TestHeader]) -> Self {
|
||||
Self(bp_header_chain::justification::AncestryChain::new(ancestry))
|
||||
fn new(justification: &GrandpaJustification<TestHeader>) -> Self {
|
||||
Self(bp_header_chain::justification::AncestryChain::new(justification))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ impl finality_grandpa::Chain<TestHash, TestNumber> for AncestryChain {
|
||||
if current_hash == base {
|
||||
break
|
||||
}
|
||||
match self.0.parents.get(¤t_hash).cloned() {
|
||||
match self.0.parents.get(¤t_hash) {
|
||||
Some(parent_hash) => {
|
||||
current_hash = parent_hash;
|
||||
current_hash = *parent_hash;
|
||||
route.push(current_hash);
|
||||
},
|
||||
_ => return Err(finality_grandpa::Error::NotDescendent),
|
||||
@@ -124,7 +124,7 @@ fn same_result_when_precommit_target_has_lower_number_than_commit_target() {
|
||||
&full_voter_set(),
|
||||
&justification,
|
||||
),
|
||||
Err(Error::PrecommitIsNotCommitDescendant),
|
||||
Err(Error::UnrelatedAncestryVote),
|
||||
);
|
||||
|
||||
// original implementation returns `Ok(validation_result)`
|
||||
@@ -132,7 +132,7 @@ fn same_result_when_precommit_target_has_lower_number_than_commit_target() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -157,7 +157,7 @@ fn same_result_when_precommit_target_is_not_descendant_of_commit_target() {
|
||||
&full_voter_set(),
|
||||
&justification,
|
||||
),
|
||||
Err(Error::PrecommitIsNotCommitDescendant),
|
||||
Err(Error::UnrelatedAncestryVote),
|
||||
);
|
||||
|
||||
// original implementation returns `Ok(validation_result)`
|
||||
@@ -165,7 +165,7 @@ fn same_result_when_precommit_target_is_not_descendant_of_commit_target() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -198,7 +198,7 @@ fn same_result_when_there_are_not_enough_cumulative_weight_to_finalize_commit_ta
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -236,7 +236,7 @@ fn different_result_when_justification_contains_duplicate_vote() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -277,7 +277,7 @@ fn different_results_when_authority_equivocates_once_in_a_round() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -330,7 +330,7 @@ fn different_results_when_authority_equivocates_twice_in_a_round() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -369,7 +369,7 @@ fn different_results_when_there_are_more_than_enough_votes() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -410,7 +410,7 @@ fn different_results_when_there_is_a_vote_of_unknown_authority() {
|
||||
let result = finality_grandpa::validate_commit(
|
||||
&justification.commit,
|
||||
&full_voter_set(),
|
||||
&AncestryChain::new(&justification.votes_ancestries),
|
||||
&AncestryChain::new(&justification),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ use bp_header_chain::justification::{
|
||||
Error,
|
||||
};
|
||||
use bp_test_utils::*;
|
||||
use finality_grandpa::SignedPrecommit;
|
||||
use sp_consensus_grandpa::AuthoritySignature;
|
||||
|
||||
type TestHeader = sp_runtime::testing::Header;
|
||||
|
||||
@@ -133,7 +135,7 @@ fn justification_with_invalid_commit_rejected() {
|
||||
&voter_set(),
|
||||
&justification,
|
||||
),
|
||||
Err(Error::ExtraHeadersInVotesAncestries),
|
||||
Err(Error::TooLowCumulativeWeight),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ fn justification_with_invalid_precommit_ancestry() {
|
||||
&voter_set(),
|
||||
&justification,
|
||||
),
|
||||
Err(Error::ExtraHeadersInVotesAncestries),
|
||||
Err(Error::RedundantVotesAncestries),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -197,14 +199,14 @@ fn justification_is_invalid_if_we_dont_meet_threshold() {
|
||||
|
||||
#[test]
|
||||
fn optimizer_does_noting_with_minimal_justification() {
|
||||
let justification = make_default_justification::<TestHeader>(&test_header(1));
|
||||
let mut justification = make_default_justification::<TestHeader>(&test_header(1));
|
||||
|
||||
let num_precommits_before = justification.commit.precommits.len();
|
||||
let justification = verify_and_optimize_justification::<TestHeader>(
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
justification,
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
@@ -223,11 +225,11 @@ fn unknown_authority_votes_are_removed_by_optimizer() {
|
||||
));
|
||||
|
||||
let num_precommits_before = justification.commit.precommits.len();
|
||||
let justification = verify_and_optimize_justification::<TestHeader>(
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
justification,
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
@@ -244,11 +246,42 @@ 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 = verify_and_optimize_justification::<TestHeader>(
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
justification,
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
|
||||
assert_eq!(num_precommits_before - 1, num_precommits_after);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_authority_signatures_are_removed_by_optimizer() {
|
||||
let mut justification = make_default_justification::<TestHeader>(&test_header(1));
|
||||
|
||||
let target = header_id::<TestHeader>(1);
|
||||
let invalid_raw_signature: Vec<u8> = ALICE.sign(b"").to_bytes().into();
|
||||
justification.commit.precommits.insert(
|
||||
0,
|
||||
SignedPrecommit {
|
||||
precommit: finality_grandpa::Precommit {
|
||||
target_hash: target.0,
|
||||
target_number: target.1,
|
||||
},
|
||||
signature: AuthoritySignature::try_from(invalid_raw_signature).unwrap(),
|
||||
id: ALICE.into(),
|
||||
},
|
||||
);
|
||||
|
||||
let num_precommits_before = justification.commit.precommits.len();
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
@@ -267,14 +300,58 @@ fn redundant_authority_votes_are_removed_by_optimizer() {
|
||||
));
|
||||
|
||||
let num_precommits_before = justification.commit.precommits.len();
|
||||
let justification = verify_and_optimize_justification::<TestHeader>(
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
justification,
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
|
||||
assert_eq!(num_precommits_before - 1, num_precommits_after);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unrelated_ancestry_votes_are_removed_by_optimizer() {
|
||||
let mut justification = make_default_justification::<TestHeader>(&test_header(2));
|
||||
justification.commit.precommits.insert(
|
||||
0,
|
||||
signed_precommit::<TestHeader>(
|
||||
&ALICE,
|
||||
header_id::<TestHeader>(1),
|
||||
justification.round,
|
||||
TEST_GRANDPA_SET_ID,
|
||||
),
|
||||
);
|
||||
|
||||
let num_precommits_before = justification.commit.precommits.len();
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(2),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_precommits_after = justification.commit.precommits.len();
|
||||
|
||||
assert_eq!(num_precommits_before - 1, num_precommits_after);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redundant_votes_ancestries_are_removed_by_optimizer() {
|
||||
let mut justification = make_default_justification::<TestHeader>(&test_header(1));
|
||||
justification.votes_ancestries.push(test_header(100));
|
||||
|
||||
let num_votes_ancestries_before = justification.votes_ancestries.len();
|
||||
verify_and_optimize_justification::<TestHeader>(
|
||||
header_id::<TestHeader>(1),
|
||||
TEST_GRANDPA_SET_ID,
|
||||
&voter_set(),
|
||||
&mut justification,
|
||||
)
|
||||
.unwrap();
|
||||
let num_votes_ancestries_after = justification.votes_ancestries.len();
|
||||
|
||||
assert_eq!(num_votes_ancestries_before - 1, num_votes_ancestries_after);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user