Skip to content

Commit

Permalink
Address CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Sep 30, 2024
1 parent e7687d6 commit 2dfffc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
12 changes: 7 additions & 5 deletions substrate/frame/beefy-mmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,14 @@ where
},
};

let mut found_commitment_root = false;
let commitment_roots = commitment
.payload
.get_all_decoded::<MerkleRootOf<T>>(&known_payloads::MMR_ROOT_ID);
if commitment_roots.is_empty() {
// If the commitment doesn't contain any MMR root, while the proof is valid,
// the commitment is invalid
return true;
}
for maybe_commitment_root in commitment_roots {
match maybe_commitment_root {
Some(commitment_root) => {
found_commitment_root = true;
if canonical_prev_root != commitment_root {
// If the commitment contains an MMR root, that is not equal to
// `canonical_prev_root`, the commitment is invalid
Expand All @@ -281,6 +278,11 @@ where
},
}
}
if !found_commitment_root {
// If the commitment doesn't contain any MMR root, while the proof is valid,
// the commitment is invalid
return true;
}

false
}
Expand Down
15 changes: 10 additions & 5 deletions substrate/primitives/consensus/beefy/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ impl Payload {
}

/// Returns all the raw payloads under given `id`.
pub fn get_all_raw(&self, id: &BeefyPayloadId) -> Vec<&Vec<u8>> {
pub fn get_all_raw<'a>(
&'a self,
id: &'a BeefyPayloadId,
) -> impl Iterator<Item = &Vec<u8>> + 'a {
self.0
.iter()
.filter_map(|probe| if &probe.0 != id { return None } else { Some(&probe.1) })
.collect()
.filter_map(move |probe| if &probe.0 != id { return None } else { Some(&probe.1) })
}

/// Returns a decoded payload value under given `id`.
Expand All @@ -72,8 +74,11 @@ impl Payload {
}

/// Returns all decoded payload values under given `id`.
pub fn get_all_decoded<T: Decode>(&self, id: &BeefyPayloadId) -> Vec<Option<T>> {
self.get_all_raw(id).iter().map(|raw| T::decode(&mut &raw[..]).ok()).collect()
pub fn get_all_decoded<'a, T: Decode>(
&'a self,
id: &'a BeefyPayloadId,
) -> impl Iterator<Item = Option<T>> + 'a {
self.get_all_raw(id).map(|raw| T::decode(&mut &raw[..]).ok())
}

/// Push a `Vec<u8>` with a given id into the payload vec.
Expand Down

0 comments on commit 2dfffc6

Please sign in to comment.