Skip to content

Commit

Permalink
beefy pallet - updates
Browse files Browse the repository at this point in the history
- impl OwnedBridgeModule
- define LOG_TARGET
- fix clippy warnings
  • Loading branch information
serban300 committed Sep 8, 2022
1 parent 1af3985 commit f97c2c1
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 190 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions modules/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "
pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master" }
rand = "0.8"
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
bp-test-utils = { path = "../../primitives/test-utils" }

[features]
default = ["std"]
Expand Down
14 changes: 4 additions & 10 deletions modules/beefy/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::{
BridgedBeefyCommitmentHasher, BridgedBeefySignedCommitment, BridgedBeefyValidatorSet,
BridgedBlockNumber, Config, Error,
BridgedBlockNumber, Config, Error, LOG_TARGET,
};

use bp_beefy::{BeefyMmrHash, BeefyRuntimeAppPublic};
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn verify_beefy_signed_commitment<T: Config<I>, I: 'static>(
}
} else {
log::debug!(
target: "runtime::bridge-beefy",
target: LOG_TARGET,
"Signed commitment contains incorrect signature of validator {} ({:?}): {:?}",
validator_index,
validator_public,
Expand Down Expand Up @@ -254,10 +254,7 @@ mod tests {
&BridgedBeefyValidatorSet::<TestRuntime, ()>::new(validator_ids(0, 8), 0).unwrap(),
&sign_commitment(
Commitment {
payload: BeefyPayload::new(
MMR_ROOT_PAYLOAD_ID,
BeefyMmrHash::from([42u8; 32]).encode(),
),
payload: BeefyPayload::new(MMR_ROOT_PAYLOAD_ID, [42u8; 32].encode()),
block_number: 20,
validator_set_id: 0,
},
Expand All @@ -268,10 +265,7 @@ mod tests {

assert_eq!(
artifacts,
CommitmentVerificationArtifacts {
finalized_block_number: 20,
mmr_root: BeefyMmrHash::from([42u8; 32]),
}
CommitmentVerificationArtifacts { finalized_block_number: 20, mmr_root: [42u8; 32] }
);
}
}
22 changes: 7 additions & 15 deletions modules/beefy/src/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
BridgedBeefyMmrHasher, BridgedBeefyMmrLeaf, BridgedBeefyMmrLeafUnpacked,
BridgedBeefyValidatorIdToMerkleLeaf, BridgedBeefyValidatorSet, BridgedBlockHash,
BridgedBlockNumber, Config, Error,
BridgedBlockNumber, Config, Error, LOG_TARGET,
};

use bp_beefy::{
Expand Down Expand Up @@ -71,7 +71,7 @@ where
);
// technically it is not an error, but we'd like to reduce tx size on real chains
ensure!(
!mmr_leaf.next_validators().is_some() || is_updating_validator_set,
mmr_leaf.next_validators().is_none() || is_updating_validator_set,
Error::<T, I>::RedundantNextValidatorsProvided,
);
ensure!(
Expand All @@ -91,7 +91,7 @@ where
>(mmr_root, MmrDataOrHash::Hash(mmr_leaf_hash), mmr_proof)
.map_err(|e| {
log::error!(
target: "runtime::bridge-beefy",
target: LOG_TARGET,
"MMR proof of leaf {:?} (root: {:?} leaf: {} total: {} len: {}) verification has failed with error: {:?}",
mmr_leaf_hash,
mmr_root,
Expand All @@ -114,7 +114,7 @@ where
.map(BridgedBeefyValidatorIdToMerkleLeaf::<T, I>::convert)
.collect::<Vec<_>>();
let next_validator_addresses_root: BeefyMmrHash =
beefy_merkle_root::<BridgedBeefyMmrHasher<T, I>, _, _>(next_validator_addresses).into();
beefy_merkle_root::<BridgedBeefyMmrHasher<T, I>, _, _>(next_validator_addresses);
ensure!(
next_validator_addresses_root == raw_mmr_leaf.beefy_next_authority_set.root,
Error::<T, I>::InvalidNextValidatorSetRoot
Expand Down Expand Up @@ -147,11 +147,7 @@ fn decode_raw_mmr_leaf<T: Config<I>, I: 'static>(
// this shall never happen, because (as of now) leaf version is simple `u8`
// and we can't fail to decode `u8`. So this is here to support potential
// future changes
log::error!(
target: "runtime::bridge-beefy",
"MMR leaf version decode has failed with error: {:?}",
e,
);
log::error!(target: LOG_TARGET, "MMR leaf version decode has failed with error: {:?}", e,);

Error::<T, I>::FailedToDecodeMmrLeafVersion
})?;
Expand All @@ -162,11 +158,7 @@ fn decode_raw_mmr_leaf<T: Config<I>, I: 'static>(

// decode the whole leaf
BridgedBeefyMmrLeaf::<T, I>::decode(&mut &encoded_leaf[..]).map_err(|e| {
log::error!(
target: "runtime::bridge-beefy",
"MMR leaf decode has failed with error: {:?}",
e,
);
log::error!(target: LOG_TARGET, "MMR leaf decode has failed with error: {:?}", e,);

Error::<T, I>::FailedToDecodeMmrLeaf
})
Expand Down Expand Up @@ -283,7 +275,7 @@ mod tests {
.custom_header()
.customize_leaf(|leaf| {
let mut raw_leaf = BridgedRawMmrLeaf::decode(&mut &leaf.leaf()[..]).unwrap();
raw_leaf.parent_number_and_hash.0 = raw_leaf.parent_number_and_hash.0 + 1;
raw_leaf.parent_number_and_hash.0 += 1;
leaf.set_leaf(raw_leaf.encode())
})
.finalize()
Expand Down
Loading

0 comments on commit f97c2c1

Please sign in to comment.