BlockId removal: refactor: Backend::append_justification (#12551)

* BlockId removal: refactor: Backend::append_justification

It changes the arguments of `Backend::append_justification`
from: block: `BlockId<Block>` to: hash: `&Block::Hash`

This PR is part of `BlockId::Number` refactoring analysis (paritytech/substrate#11292)

* Error message improved

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* single error message in beefy::finalize

* println removed

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Michal Kucharczyk
2022-10-30 18:58:29 +01:00
committed by GitHub
parent 9bc59da6b3
commit 0ef7e261a3
4 changed files with 38 additions and 34 deletions
+19 -13
View File
@@ -500,20 +500,22 @@ where
self.on_demand_justifications.cancel_requests_older_than(block_num);
if let Err(e) = self.backend.append_justification(
BlockId::Number(block_num),
(BEEFY_ENGINE_ID, finality_proof.encode()),
) {
if let Err(e) = self
.backend
.blockchain()
.expect_block_hash_from_id(&BlockId::Number(block_num))
.and_then(|hash| {
self.links
.to_rpc_best_block_sender
.notify(|| Ok::<_, ()>(hash))
.expect("forwards closure result; the closure always returns Ok; qed.");
self.backend
.append_justification(&hash, (BEEFY_ENGINE_ID, finality_proof.encode()))
}) {
error!(target: "beefy", "🥩 Error {:?} on appending justification: {:?}", e, finality_proof);
}
self.backend.blockchain().hash(block_num).ok().flatten().map(|hash| {
self.links
.to_rpc_best_block_sender
.notify(|| Ok::<_, ()>(hash))
.expect("forwards closure result; the closure always returns Ok; qed.")
});
self.links
.to_rpc_justif_sender
.notify(|| Ok::<_, ()>(finality_proof))
@@ -1546,8 +1548,10 @@ pub(crate) mod tests {
commitment,
signatures: vec![None],
});
let hashof10 =
backend.blockchain().expect_block_hash_from_id(&BlockId::Number(10)).unwrap();
backend
.append_justification(BlockId::Number(10), (BEEFY_ENGINE_ID, justif.encode()))
.append_justification(&hashof10, (BEEFY_ENGINE_ID, justif.encode()))
.unwrap();
// initialize voter at block 13, expect rounds initialized at last beefy finalized 10
@@ -1580,8 +1584,10 @@ pub(crate) mod tests {
commitment,
signatures: vec![None],
});
let hashof12 =
backend.blockchain().expect_block_hash_from_id(&BlockId::Number(12)).unwrap();
backend
.append_justification(BlockId::Number(12), (BEEFY_ENGINE_ID, justif.encode()))
.append_justification(&hashof12, (BEEFY_ENGINE_ID, justif.encode()))
.unwrap();
// initialize voter at block 13, expect rounds initialized at last beefy finalized 12