mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
BlockId removal: refactor: Backend::justifications (#12602)
* BlockId removal: refactor: Backend::justifications It changes the arguments of `Backend::justifications` method from: `BlockId<Block>` to: `&Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * trigger CI job * trigger CI job * bug fix * match -> if Co-authored-by: Adrian Catangiu <adrian@parity.io> Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
committed by
GitHub
parent
8b8675df23
commit
84167bd7d4
+13
-8
@@ -26,7 +26,7 @@ use log::{debug, trace};
|
||||
use sc_client_api::BlockBackend;
|
||||
use sc_network::{config as netconfig, config::RequestResponseConfig, PeerId, ReputationChange};
|
||||
use sc_network_common::protocol::ProtocolName;
|
||||
use sp_runtime::{generic::BlockId, traits::Block};
|
||||
use sp_runtime::traits::Block;
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
|
||||
use crate::communication::request_response::{
|
||||
@@ -149,13 +149,18 @@ where
|
||||
fn handle_request(&self, request: IncomingRequest<B>) -> Result<(), Error> {
|
||||
// TODO (issue #12293): validate `request` and change peer reputation for invalid requests.
|
||||
|
||||
let maybe_encoded_proof = self
|
||||
.client
|
||||
.justifications(&BlockId::Number(request.payload.begin))
|
||||
.map_err(Error::Client)?
|
||||
.and_then(|justifs| justifs.get(BEEFY_ENGINE_ID).cloned())
|
||||
// No BEEFY justification present.
|
||||
.ok_or(());
|
||||
let maybe_encoded_proof = if let Some(hash) =
|
||||
self.client.block_hash(request.payload.begin).map_err(Error::Client)?
|
||||
{
|
||||
self.client
|
||||
.justifications(&hash)
|
||||
.map_err(Error::Client)?
|
||||
.and_then(|justifs| justifs.get(BEEFY_ENGINE_ID).cloned())
|
||||
// No BEEFY justification present.
|
||||
.ok_or(())
|
||||
} else {
|
||||
Err(())
|
||||
};
|
||||
|
||||
request
|
||||
.pending_response
|
||||
|
||||
@@ -741,9 +741,9 @@ fn beefy_importing_blocks() {
|
||||
|
||||
let full_client = client.as_client();
|
||||
let parent_id = BlockId::Number(0);
|
||||
let block_id = BlockId::Number(1);
|
||||
let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap();
|
||||
let block = builder.build().unwrap().block;
|
||||
let hashof1 = block.header.hash();
|
||||
|
||||
// Import without justifications.
|
||||
let mut justif_recv = justif_stream.subscribe();
|
||||
@@ -760,7 +760,7 @@ fn beefy_importing_blocks() {
|
||||
// none in backend,
|
||||
assert_eq!(
|
||||
full_client
|
||||
.justifications(&block_id)
|
||||
.justifications(&hashof1)
|
||||
.unwrap()
|
||||
.and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()),
|
||||
None
|
||||
@@ -784,6 +784,7 @@ fn beefy_importing_blocks() {
|
||||
|
||||
let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap();
|
||||
let block = builder.build().unwrap().block;
|
||||
let hashof2 = block.header.hash();
|
||||
let mut justif_recv = justif_stream.subscribe();
|
||||
assert_eq!(
|
||||
block_on(block_import.import_block(params(block, justif), HashMap::new())).unwrap(),
|
||||
@@ -798,7 +799,7 @@ fn beefy_importing_blocks() {
|
||||
// still not in backend (worker is responsible for appending to backend),
|
||||
assert_eq!(
|
||||
full_client
|
||||
.justifications(&block_id)
|
||||
.justifications(&hashof2)
|
||||
.unwrap()
|
||||
.and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()),
|
||||
None
|
||||
@@ -826,6 +827,7 @@ fn beefy_importing_blocks() {
|
||||
|
||||
let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap();
|
||||
let block = builder.build().unwrap().block;
|
||||
let hashof3 = block.header.hash();
|
||||
let mut justif_recv = justif_stream.subscribe();
|
||||
assert_eq!(
|
||||
block_on(block_import.import_block(params(block, justif), HashMap::new())).unwrap(),
|
||||
@@ -841,7 +843,7 @@ fn beefy_importing_blocks() {
|
||||
// none in backend,
|
||||
assert_eq!(
|
||||
full_client
|
||||
.justifications(&BlockId::Number(block_num))
|
||||
.justifications(&hashof3)
|
||||
.unwrap()
|
||||
.and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()),
|
||||
None
|
||||
|
||||
@@ -709,7 +709,7 @@ where
|
||||
// a BEEFY justification, or at this session's boundary; voter will resume from there.
|
||||
loop {
|
||||
if let Some(true) = blockchain
|
||||
.justifications(BlockId::hash(header.hash()))
|
||||
.justifications(&header.hash())
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|justifs| justifs.get(BEEFY_ENGINE_ID).is_some())
|
||||
@@ -1401,7 +1401,7 @@ pub(crate) mod tests {
|
||||
}));
|
||||
|
||||
// check BEEFY justifications are also appended to backend
|
||||
let justifs = backend.blockchain().justifications(BlockId::number(2)).unwrap().unwrap();
|
||||
let justifs = backend.blockchain().justifications(&hashof2).unwrap().unwrap();
|
||||
assert!(justifs.get(BEEFY_ENGINE_ID).is_some())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user