mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
BlockId removal: &Hash to Hash (#12626)
It changes &Block::Hash argument to Block::Hash. This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
This commit is contained in:
committed by
GitHub
parent
7c4bfc9749
commit
1ed70004e7
@@ -203,7 +203,7 @@ impl<B: BlockT> BitswapRequestHandler<B> {
|
||||
|
||||
let mut hash = B::Hash::default();
|
||||
hash.as_mut().copy_from_slice(&cid.hash().digest()[0..32]);
|
||||
let transaction = match self.client.indexed_transaction(&hash) {
|
||||
let transaction = match self.client.indexed_transaction(hash) {
|
||||
Ok(ex) => ex,
|
||||
Err(e) => {
|
||||
error!(target: LOG_TARGET, "Error retrieving transaction {}: {}", hash, e);
|
||||
|
||||
@@ -172,7 +172,7 @@ where
|
||||
|
||||
let block = Decode::decode(&mut request.block.as_ref())?;
|
||||
|
||||
let response = match self.client.execution_proof(&block, &request.method, &request.data) {
|
||||
let response = match self.client.execution_proof(block, &request.method, &request.data) {
|
||||
Ok((_, proof)) => {
|
||||
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
|
||||
Some(schema::v1::light::response::Response::RemoteCallResponse(r))
|
||||
@@ -212,7 +212,7 @@ where
|
||||
let block = Decode::decode(&mut request.block.as_ref())?;
|
||||
|
||||
let response =
|
||||
match self.client.read_proof(&block, &mut request.keys.iter().map(AsRef::as_ref)) {
|
||||
match self.client.read_proof(block, &mut request.keys.iter().map(AsRef::as_ref)) {
|
||||
Ok(proof) => {
|
||||
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
|
||||
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
|
||||
@@ -259,7 +259,7 @@ where
|
||||
};
|
||||
let response = match child_info.and_then(|child_info| {
|
||||
self.client.read_child_proof(
|
||||
&block,
|
||||
block,
|
||||
&child_info,
|
||||
&mut request.keys.iter().map(AsRef::as_ref),
|
||||
)
|
||||
|
||||
@@ -332,7 +332,7 @@ where
|
||||
let hash = header.hash();
|
||||
let parent_hash = *header.parent_hash();
|
||||
let justifications =
|
||||
if get_justification { self.client.justifications(&hash)? } else { None };
|
||||
if get_justification { self.client.justifications(hash)? } else { None };
|
||||
|
||||
let (justifications, justification, is_empty_justification) =
|
||||
if support_multiple_justifications {
|
||||
@@ -361,7 +361,7 @@ where
|
||||
};
|
||||
|
||||
let body = if get_body {
|
||||
match self.client.block_body(&hash)? {
|
||||
match self.client.block_body(hash)? {
|
||||
Some(mut extrinsics) =>
|
||||
extrinsics.iter_mut().map(|extrinsic| extrinsic.encode()).collect(),
|
||||
None => {
|
||||
@@ -374,7 +374,7 @@ where
|
||||
};
|
||||
|
||||
let indexed_body = if get_indexed_body {
|
||||
match self.client.block_indexed_body(&hash)? {
|
||||
match self.client.block_indexed_body(hash)? {
|
||||
Some(transactions) => transactions,
|
||||
None => {
|
||||
log::trace!(
|
||||
|
||||
@@ -3201,7 +3201,7 @@ mod test {
|
||||
|
||||
let finalized_block = blocks[MAX_BLOCKS_TO_LOOK_BACKWARDS as usize * 2 - 1].clone();
|
||||
let just = (*b"TEST", Vec::new());
|
||||
client.finalize_block(&finalized_block.hash(), Some(just)).unwrap();
|
||||
client.finalize_block(finalized_block.hash(), Some(just)).unwrap();
|
||||
sync.update_chain_info(&info.best_hash, info.best_number);
|
||||
|
||||
let peer_id1 = PeerId::random();
|
||||
@@ -3333,7 +3333,7 @@ mod test {
|
||||
|
||||
let finalized_block = blocks[MAX_BLOCKS_TO_LOOK_BACKWARDS as usize * 2 - 1].clone();
|
||||
let just = (*b"TEST", Vec::new());
|
||||
client.finalize_block(&finalized_block.hash(), Some(just)).unwrap();
|
||||
client.finalize_block(finalized_block.hash(), Some(just)).unwrap();
|
||||
sync.update_chain_info(&info.best_hash, info.best_number);
|
||||
|
||||
let peer_id1 = PeerId::random();
|
||||
|
||||
@@ -205,14 +205,14 @@ where
|
||||
|
||||
if !request.no_proof {
|
||||
let (proof, _count) = self.client.read_proof_collection(
|
||||
&block,
|
||||
block,
|
||||
request.start.as_slice(),
|
||||
MAX_RESPONSE_BYTES,
|
||||
)?;
|
||||
response.proof = proof.encode();
|
||||
} else {
|
||||
let entries = self.client.storage_collection(
|
||||
&block,
|
||||
block,
|
||||
request.start.as_slice(),
|
||||
MAX_RESPONSE_BYTES,
|
||||
)?;
|
||||
|
||||
@@ -40,7 +40,7 @@ fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>)
|
||||
|
||||
let (hash, number) = (client.block_hash(1).unwrap().unwrap(), 1);
|
||||
let header = client.header(&BlockId::Number(1)).unwrap();
|
||||
let justifications = client.justifications(&hash).unwrap();
|
||||
let justifications = client.justifications(hash).unwrap();
|
||||
let peer_id = PeerId::random();
|
||||
(
|
||||
client,
|
||||
|
||||
@@ -173,12 +173,12 @@ impl PeersClient {
|
||||
Some(header) => header,
|
||||
None => return false,
|
||||
};
|
||||
self.backend.have_state_at(&header.hash(), *header.number())
|
||||
self.backend.have_state_at(header.hash(), *header.number())
|
||||
}
|
||||
|
||||
pub fn justifications(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
) -> ClientResult<Option<Justifications>> {
|
||||
self.client.justifications(hash)
|
||||
}
|
||||
@@ -193,7 +193,7 @@ impl PeersClient {
|
||||
|
||||
pub fn finalize_block(
|
||||
&self,
|
||||
hash: &<Block as BlockT>::Hash,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> ClientResult<()> {
|
||||
@@ -535,14 +535,14 @@ where
|
||||
self.verifier.failed_verifications.lock().clone()
|
||||
}
|
||||
|
||||
pub fn has_block(&self, hash: &H256) -> bool {
|
||||
pub fn has_block(&self, hash: H256) -> bool {
|
||||
self.backend
|
||||
.as_ref()
|
||||
.map(|backend| backend.blockchain().header(BlockId::hash(*hash)).unwrap().is_some())
|
||||
.map(|backend| backend.blockchain().header(BlockId::hash(hash)).unwrap().is_some())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn has_body(&self, hash: &H256) -> bool {
|
||||
pub fn has_body(&self, hash: H256) -> bool {
|
||||
self.backend
|
||||
.as_ref()
|
||||
.map(|backend| backend.blockchain().body(hash).unwrap().is_some())
|
||||
@@ -1124,7 +1124,7 @@ impl JustificationImport<Block> for ForceFinalized {
|
||||
justification: Justification,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.0
|
||||
.finalize_block(&hash, Some(justification), true)
|
||||
.finalize_block(hash, Some(justification), true)
|
||||
.map_err(|_| ConsensusError::InvalidJustification)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,23 +252,14 @@ fn sync_justifications() {
|
||||
let hashof20 = backend.blockchain().expect_block_hash_from_id(&BlockId::Number(20)).unwrap();
|
||||
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(0).client().justifications(hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(hashof10).unwrap(), None);
|
||||
|
||||
// we finalize block #10, #15 and #20 for peer 0 with a justification
|
||||
let just = (*b"FRNK", Vec::new());
|
||||
net.peer(0)
|
||||
.client()
|
||||
.finalize_block(&hashof10, Some(just.clone()), true)
|
||||
.unwrap();
|
||||
net.peer(0)
|
||||
.client()
|
||||
.finalize_block(&hashof15, Some(just.clone()), true)
|
||||
.unwrap();
|
||||
net.peer(0)
|
||||
.client()
|
||||
.finalize_block(&hashof20, Some(just.clone()), true)
|
||||
.unwrap();
|
||||
net.peer(0).client().finalize_block(hashof10, Some(just.clone()), true).unwrap();
|
||||
net.peer(0).client().finalize_block(hashof15, Some(just.clone()), true).unwrap();
|
||||
net.peer(0).client().finalize_block(hashof20, Some(just.clone()), true).unwrap();
|
||||
|
||||
let hashof10 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap().hash();
|
||||
let hashof15 = net.peer(1).client().header(&BlockId::Number(15)).unwrap().unwrap().hash();
|
||||
@@ -283,12 +274,12 @@ fn sync_justifications() {
|
||||
net.poll(cx);
|
||||
|
||||
for hash in [hashof10, hashof15, hashof20] {
|
||||
if net.peer(0).client().justifications(&hash).unwrap() !=
|
||||
if net.peer(0).client().justifications(hash).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
}
|
||||
if net.peer(1).client().justifications(&hash).unwrap() !=
|
||||
if net.peer(1).client().justifications(hash).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
@@ -314,7 +305,7 @@ fn sync_justifications_across_forks() {
|
||||
net.block_until_sync();
|
||||
|
||||
let just = (*b"FRNK", Vec::new());
|
||||
net.peer(0).client().finalize_block(&f1_best, Some(just), true).unwrap();
|
||||
net.peer(0).client().finalize_block(f1_best, Some(just), true).unwrap();
|
||||
|
||||
net.peer(1).request_justification(&f1_best, 10);
|
||||
net.peer(1).request_justification(&f2_best, 11);
|
||||
@@ -322,9 +313,9 @@ fn sync_justifications_across_forks() {
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
|
||||
if net.peer(0).client().justifications(&f1_best).unwrap() ==
|
||||
if net.peer(0).client().justifications(f1_best).unwrap() ==
|
||||
Some(Justifications::from((*b"FRNK", Vec::new()))) &&
|
||||
net.peer(1).client().justifications(&f1_best).unwrap() ==
|
||||
net.peer(1).client().justifications(f1_best).unwrap() ==
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
Poll::Ready(())
|
||||
@@ -369,10 +360,10 @@ fn syncs_all_forks() {
|
||||
|
||||
net.block_until_sync();
|
||||
// Check that all peers have all of the branches.
|
||||
assert!(net.peer(0).has_block(&b1));
|
||||
assert!(net.peer(0).has_block(&b2));
|
||||
assert!(net.peer(1).has_block(&b1));
|
||||
assert!(net.peer(1).has_block(&b2));
|
||||
assert!(net.peer(0).has_block(b1));
|
||||
assert!(net.peer(0).has_block(b2));
|
||||
assert!(net.peer(1).has_block(b1));
|
||||
assert!(net.peer(1).has_block(b2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -555,7 +546,7 @@ fn syncs_header_only_forks() {
|
||||
net.peer(1).push_blocks(4, false);
|
||||
|
||||
// Peer 1 will sync the small fork even though common block state is missing
|
||||
while !net.peer(1).has_block(&small_hash) {
|
||||
while !net.peer(1).has_block(small_hash) {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
@@ -657,13 +648,13 @@ fn can_sync_to_peers_with_wrong_common_block() {
|
||||
|
||||
// both peers re-org to the same fork without notifying each other
|
||||
let just = Some((*b"FRNK", Vec::new()));
|
||||
net.peer(0).client().finalize_block(&fork_hash, just.clone(), true).unwrap();
|
||||
net.peer(1).client().finalize_block(&fork_hash, just, true).unwrap();
|
||||
net.peer(0).client().finalize_block(fork_hash, just.clone(), true).unwrap();
|
||||
net.peer(1).client().finalize_block(fork_hash, just, true).unwrap();
|
||||
let final_hash = net.peer(0).push_blocks(1, false);
|
||||
|
||||
net.block_until_sync();
|
||||
|
||||
assert!(net.peer(1).has_block(&final_hash));
|
||||
assert!(net.peer(1).has_block(final_hash));
|
||||
}
|
||||
|
||||
/// Returns `is_new_best = true` for each validated announcement.
|
||||
@@ -724,7 +715,7 @@ fn sync_blocks_when_block_announce_validator_says_it_is_new_best() {
|
||||
ForkChoiceStrategy::Custom(false),
|
||||
);
|
||||
|
||||
while !net.peer(2).has_block(&block_hash) {
|
||||
while !net.peer(2).has_block(block_hash) {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
@@ -767,7 +758,7 @@ fn wait_until_deferred_block_announce_validation_is_ready() {
|
||||
ForkChoiceStrategy::Custom(false),
|
||||
);
|
||||
|
||||
while !net.peer(1).has_block(&block_hash) {
|
||||
while !net.peer(1).has_block(block_hash) {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
@@ -788,7 +779,7 @@ fn sync_to_tip_requires_that_sync_protocol_is_informed_about_best_block() {
|
||||
net.block_until_idle();
|
||||
|
||||
// The peer should not have synced the block.
|
||||
assert!(!net.peer(1).has_block(&block_hash));
|
||||
assert!(!net.peer(1).has_block(block_hash));
|
||||
|
||||
// Make sync protocol aware of the best block
|
||||
net.peer(0).network_service().new_best_block_imported(block_hash, 3);
|
||||
@@ -802,7 +793,7 @@ fn sync_to_tip_requires_that_sync_protocol_is_informed_about_best_block() {
|
||||
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
if net.peer(2).has_block(&block_hash) {
|
||||
if net.peer(2).has_block(block_hash) {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
Poll::Pending
|
||||
@@ -810,7 +801,7 @@ fn sync_to_tip_requires_that_sync_protocol_is_informed_about_best_block() {
|
||||
}));
|
||||
|
||||
// However peer 1 should still not have the block.
|
||||
assert!(!net.peer(1).has_block(&block_hash));
|
||||
assert!(!net.peer(1).has_block(block_hash));
|
||||
}
|
||||
|
||||
/// Ensures that if we as a syncing node sync to the tip while we are connected to another peer
|
||||
@@ -831,10 +822,10 @@ fn sync_to_tip_when_we_sync_together_with_multiple_peers() {
|
||||
net.block_until_connected();
|
||||
net.block_until_idle();
|
||||
|
||||
assert!(!net.peer(2).has_block(&block_hash));
|
||||
assert!(!net.peer(2).has_block(block_hash));
|
||||
|
||||
net.peer(0).network_service().new_best_block_imported(block_hash, 10_000);
|
||||
while !net.peer(2).has_block(&block_hash) && !net.peer(1).has_block(&block_hash) {
|
||||
while !net.peer(2).has_block(block_hash) && !net.peer(1).has_block(block_hash) {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
@@ -895,7 +886,7 @@ fn block_announce_data_is_propagated() {
|
||||
let block_hash = net.peer(0).push_blocks_at_without_announcing(BlockId::Number(0), 1, true);
|
||||
net.peer(0).announce_block(block_hash, Some(vec![137]));
|
||||
|
||||
while !net.peer(1).has_block(&block_hash) || !net.peer(2).has_block(&block_hash) {
|
||||
while !net.peer(1).has_block(block_hash) || !net.peer(2).has_block(block_hash) {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
@@ -939,7 +930,7 @@ fn continue_to_sync_after_some_block_announcement_verifications_failed() {
|
||||
let block_hash = net.peer(0).push_blocks(500, true);
|
||||
|
||||
net.block_until_sync();
|
||||
assert!(net.peer(1).has_block(&block_hash));
|
||||
assert!(net.peer(1).has_block(block_hash));
|
||||
}
|
||||
|
||||
/// When being spammed by the same request of a peer, we ban this peer. However, we should only ban
|
||||
@@ -956,8 +947,8 @@ fn multiple_requests_are_accepted_as_long_as_they_are_not_fulfilled() {
|
||||
let hashof10 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap().hash();
|
||||
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(0).client().justifications(hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(hashof10).unwrap(), None);
|
||||
|
||||
// Let's assume block 10 was finalized, but we still need the justification from the network.
|
||||
net.peer(1).request_justification(&hashof10, 10);
|
||||
@@ -982,13 +973,13 @@ fn multiple_requests_are_accepted_as_long_as_they_are_not_fulfilled() {
|
||||
// Finalize the block and make the justification available.
|
||||
net.peer(0)
|
||||
.client()
|
||||
.finalize_block(&hashof10, Some((*b"FRNK", Vec::new())), true)
|
||||
.finalize_block(hashof10, Some((*b"FRNK", Vec::new())), true)
|
||||
.unwrap();
|
||||
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
|
||||
if net.peer(1).client().justifications(&hashof10).unwrap() !=
|
||||
if net.peer(1).client().justifications(hashof10).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
@@ -1110,7 +1101,7 @@ fn syncs_state() {
|
||||
.blockchain()
|
||||
.expect_block_hash_from_id(&BlockId::Number(60))
|
||||
.unwrap();
|
||||
net.peer(1).client().finalize_block(&hashof60, Some(just), true).unwrap();
|
||||
net.peer(1).client().finalize_block(hashof60, Some(just), true).unwrap();
|
||||
// Wait for state sync.
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
@@ -1165,14 +1156,14 @@ fn syncs_indexed_blocks() {
|
||||
.peer(0)
|
||||
.client()
|
||||
.as_client()
|
||||
.indexed_transaction(&indexed_key)
|
||||
.indexed_transaction(indexed_key)
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(net
|
||||
.peer(1)
|
||||
.client()
|
||||
.as_client()
|
||||
.indexed_transaction(&indexed_key)
|
||||
.indexed_transaction(indexed_key)
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
@@ -1181,7 +1172,7 @@ fn syncs_indexed_blocks() {
|
||||
.peer(1)
|
||||
.client()
|
||||
.as_client()
|
||||
.indexed_transaction(&indexed_key)
|
||||
.indexed_transaction(indexed_key)
|
||||
.unwrap()
|
||||
.is_some());
|
||||
}
|
||||
@@ -1210,7 +1201,7 @@ fn warp_sync() {
|
||||
// Wait for peer 1 download block history
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
if net.peer(3).has_body(&gap_end) && net.peer(3).has_body(&target) {
|
||||
if net.peer(3).has_body(gap_end) && net.peer(3).has_body(target) {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
Poll::Pending
|
||||
|
||||
Reference in New Issue
Block a user