Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
grandpa: fix enacting forced changes with no delay (#6828)
Browse files Browse the repository at this point in the history
* grandpa: fix enacting forced changes with no delay

* grandpa: fix formatting
  • Loading branch information
andresilva authored Aug 6, 2020
1 parent f17569f commit 5719b8c
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions client/finality-grandpa/src/authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ where
.take_while(|c| c.effective_number() <= best_number) // to prevent iterating too far
.filter(|c| c.effective_number() == best_number)
{
// check if the given best block is in the same branch as the block that signaled the change.
if is_descendent_of(&change.canon_hash, &best_hash)? {
// check if the given best block is in the same branch as
// the block that signaled the change.
if change.canon_hash == best_hash || is_descendent_of(&change.canon_hash, &best_hash)? {
// apply this change: make the set canonical
afg_log!(initial_sync,
"👴 Applying authority set change forced at block #{:?}",
Expand Down Expand Up @@ -984,6 +985,43 @@ mod tests {
);
}

#[test]
fn forced_changes_with_no_delay() {
// NOTE: this is a regression test
let mut authorities = AuthoritySet {
current_authorities: Vec::new(),
set_id: 0,
pending_standard_changes: ForkTree::new(),
pending_forced_changes: Vec::new(),
};

let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];

// we create a forced change with no delay
let change_a = PendingChange {
next_authorities: set_a.clone(),
delay: 0,
canon_height: 5,
canon_hash: "hash_a",
delay_kind: DelayKind::Best {
median_last_finalized: 0,
},
};

// and import it
authorities
.add_pending_change(change_a, &static_is_descendent_of(false))
.unwrap();

// it should be enacted at the same block that signaled it
assert!(
authorities
.apply_forced_changes("hash_a", 5, &static_is_descendent_of(false), false)
.unwrap()
.is_some()
);
}

#[test]
fn next_change_works() {
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
Expand Down

0 comments on commit 5719b8c

Please sign in to comment.