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

Update Relay Authorities Protocol #440

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions frame/bridge/relay-authorities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,6 @@ decl_module! {
let (message, mut signatures) = if let Some(signatures) = <AuthoritiesToSign<T, I>>::get() {
signatures
} else {
// Should never enter this condition
// TODO: error log

return Ok(());
};

Expand Down Expand Up @@ -547,7 +544,6 @@ decl_module! {
}

<OldAuthorities<T, I>>::kill();
<AuthorityTerm<I>>::mutate(|term| *term += 1);
<AuthoritiesState<T, I>>::kill();
<AuthoritiesToSign<T, I>>::kill();
{
Expand Down Expand Up @@ -676,7 +672,6 @@ where
pub fn wait_target_chain_authorities_change() {
<AuthoritiesToSign<T, I>>::kill();
<AuthoritiesState<T, I>>::mutate(|authorities_state| authorities_state.1 = 0.into());
<AuthorityTerm<I>>::mutate(|authority_term| *authority_term += 1);

for account_id in <OldAuthoritiesLockToRemove<T, I>>::take() {
<RingCurrency<T, I>>::remove_lock(T::LockId::get(), &account_id);
Expand Down Expand Up @@ -771,6 +766,7 @@ where

fn finish_authorities_change() {
<AuthoritiesState<T, I>>::kill();
<AuthorityTerm<I>>::mutate(|authority_term| *authority_term += 1);
}
}

Expand Down
16 changes: 16 additions & 0 deletions frame/bridge/relay-authorities/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ fn kill_candidates_should_work() {
});
}

#[test]
fn authority_term_should_work() {
new_test_ext().execute_with(|| {
let max_candidates = <MaxCandidates as Get<usize>>::get();

for i in 1..=max_candidates {
assert_eq!(RelayAuthorities::authority_term(), i as Term - 1);
assert_ok!(request_authority(i as _));
assert_ok!(RelayAuthorities::add_authority(Origin::root(), i as _));

RelayAuthorities::finish_authorities_change();
assert_eq!(RelayAuthorities::authority_term(), i as Term);
}
});
}

#[test]
fn encode_message_should_work() {
// --- substrate ---
Expand Down