Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.
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
8 changes: 5 additions & 3 deletions frame/bridge/relay-authorities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ decl_module! {
pub fn submit_signed_mmr_root(
origin,
block_number: BlockNumber<T>,
mmr_root: MMRRoot<T>,
signature: RelayAuthoritySignature<T, I>
) {
let authority = ensure_signed(origin)?;
Expand All @@ -441,14 +440,17 @@ decl_module! {
&authorities,
&authority
).ok_or(<Error<T, I>>::AuthorityNE)?;
let mmr_root =
T::DarwiniaMMR::get_root(block_number).ok_or(<Error<T, I>>::DarwiniaMMRRootNRY)?;

// The message is composed of:
//
// hash(codec(spec_name: String, block number: Compact<BlockNumber>, mmr_root: Hash))
let message = T::Sign::hash(
&_S {
_1: T::Version::get().spec_name,
_2: block_number,
_3: T::DarwiniaMMR::get_root(block_number).ok_or(<Error<T, I>>::DarwiniaMMRRootNRY)?
_3: mmr_root
}
.encode()
);
Expand All @@ -460,7 +462,7 @@ decl_module! {

signatures.push((authority, signature));

if Perbill::from_rational_approximation(signatures.len() as u32 + 1, authorities.len() as _)
if Perbill::from_rational_approximation(signatures.len() as u32, authorities.len() as _)
>= T::SignThreshold::get()
{
// TODO: clean the mmr root which was contains in this mmr root?
Expand Down
2 changes: 1 addition & 1 deletion frame/bridge/relay-authorities/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct Test;
pub struct DarwiniaMMR;
impl MMR<BlockNumber, H256> for DarwiniaMMR {
fn get_root(_: BlockNumber) -> Option<H256> {
unimplemented!()
Some(Default::default())
}
}
pub struct Sign;
Expand Down
40 changes: 40 additions & 0 deletions frame/bridge/relay-authorities/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,46 @@ fn encode_message_should_work() {
println!("{:?}", message);
}

#[test]
fn mmr_root_signed_event_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);

assert_ok!(request_authority(1));
assert_ok!(RelayAuthorities::add_authority(Origin::root(), 1));
assert_ok!(RelayAuthorities::submit_signed_authorities(
Origin::signed(9),
[0; 65]
));

RelayAuthorities::finish_authorities_change();
events();

RelayAuthorities::new_mmr_to_sign(10);
events();

assert_ok!(RelayAuthorities::submit_signed_mmr_root(
Origin::signed(9),
10,
[0; 65],
));
assert!(relay_authorities_events().is_empty());
assert_ok!(RelayAuthorities::submit_signed_mmr_root(
Origin::signed(1),
10,
[0; 65],
));
assert_eq!(
relay_authorities_events(),
vec![Event::relay_authorities(RawEvent::MMRRootSigned(
10,
Default::default(),
vec![(9, [0; 65]), (1, [0; 65])]
))]
);
});
}

#[test]
fn authorities_set_signed_event_should_work() {
new_test_ext().execute_with(|| {
Expand Down