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:
Michal Kucharczyk
2022-11-07 22:42:16 +01:00
committed by GitHub
parent 7c4bfc9749
commit 1ed70004e7
49 changed files with 428 additions and 441 deletions
@@ -1352,7 +1352,7 @@ where
// ideally some handle to a synchronization oracle would be used
// to avoid unconditionally notifying.
client
.apply_finality(import_op, &hash, persisted_justification, true)
.apply_finality(import_op, hash, persisted_justification, true)
.map_err(|e| {
warn!(target: "afg", "Error applying finality to block {:?}: {}", (hash, number), e);
e
@@ -188,7 +188,7 @@ where
.expect_block_hash_from_id(&BlockId::Number(last_block_for_set))?;
let justification = if let Some(grandpa_justification) = backend
.blockchain()
.justifications(&last_block_for_set_id)?
.justifications(last_block_for_set_id)?
.and_then(|justifications| justifications.into_justification(GRANDPA_ENGINE_ID))
{
grandpa_justification
@@ -312,7 +312,7 @@ mod tests {
for block in to_finalize {
let hash = blocks[*block as usize - 1].hash();
client.finalize_block(&hash, None).unwrap();
client.finalize_block(hash, None).unwrap();
}
(client, backend, blocks)
}
@@ -492,7 +492,7 @@ mod tests {
let grandpa_just8 = GrandpaJustification::from_commit(&client, round, commit).unwrap();
client
.finalize_block(&block8.hash(), Some((ID, grandpa_just8.encode().clone())))
.finalize_block(block8.hash(), Some((ID, grandpa_just8.encode().clone())))
.unwrap();
// Authority set change at block 8, so the justification stored there will be used in the
@@ -424,8 +424,8 @@ where
}
/// Read current set id form a given state.
fn current_set_id(&self, hash: &Block::Hash) -> Result<SetId, ConsensusError> {
let id = &BlockId::hash(*hash);
fn current_set_id(&self, hash: Block::Hash) -> Result<SetId, ConsensusError> {
let id = &BlockId::hash(hash);
let runtime_version = self.inner.runtime_api().version(id).map_err(|e| {
ConsensusError::ClientImport(format!(
"Unable to retrieve current runtime version. {}",
@@ -480,7 +480,7 @@ where
.runtime_api()
.grandpa_authorities(&BlockId::hash(hash))
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?;
let set_id = self.current_set_id(&hash)?;
let set_id = self.current_set_id(hash)?;
let authority_set = AuthoritySet::new(
authorities.clone(),
set_id,
@@ -375,7 +375,7 @@ fn finalize_3_voters_no_observers() {
// normally there's no justification for finalized blocks
assert!(
net.lock().peer(0).client().justifications(&hashof20).unwrap().is_none(),
net.lock().peer(0).client().justifications(hashof20).unwrap().is_none(),
"Extra justification for block#1",
);
}
@@ -621,7 +621,7 @@ fn justification_is_generated_periodically() {
// when block#32 (justification_period) is finalized, justification
// is required => generated
for i in 0..3 {
assert!(net.lock().peer(i).client().justifications(&hashof32).unwrap().is_some());
assert!(net.lock().peer(i).client().justifications(hashof32).unwrap().is_some());
}
}
@@ -665,12 +665,12 @@ fn sync_justifications_on_change_blocks() {
// the first 3 peers are grandpa voters and therefore have already finalized
// block 21 and stored a justification
for i in 0..3 {
assert!(net.lock().peer(i).client().justifications(&hashof21).unwrap().is_some());
assert!(net.lock().peer(i).client().justifications(hashof21).unwrap().is_some());
}
// the last peer should get the justification by syncing from other peers
futures::executor::block_on(futures::future::poll_fn(move |cx| {
if net.lock().peer(3).client().justifications(&hashof21).unwrap().is_none() {
if net.lock().peer(3).client().justifications(hashof21).unwrap().is_none() {
net.lock().poll(cx);
Poll::Pending
} else {
@@ -1428,7 +1428,7 @@ fn grandpa_environment_respects_voting_rules() {
.as_client()
.expect_block_hash_from_id(&BlockId::Number(19))
.unwrap();
peer.client().finalize_block(&hashof19, None, false).unwrap();
peer.client().finalize_block(hashof19, None, false).unwrap();
// the 3/4 environment should propose block 21 for voting
assert_eq!(
@@ -1455,7 +1455,7 @@ fn grandpa_environment_respects_voting_rules() {
.as_client()
.expect_block_hash_from_id(&BlockId::Number(21))
.unwrap();
peer.client().finalize_block(&hashof21, None, false).unwrap();
peer.client().finalize_block(hashof21, None, false).unwrap();
// even though the default environment will always try to not vote on the
// best block, there's a hard rule that we can't cast any votes lower than
@@ -1666,7 +1666,7 @@ fn imports_justification_for_regular_blocks_on_import() {
);
// the justification should be imported and available from the client
assert!(client.justifications(&block_hash).unwrap().is_some());
assert!(client.justifications(block_hash).unwrap().is_some());
}
#[test]
@@ -130,7 +130,7 @@ impl<Block: BlockT> WarpSyncProof<Block> {
}
let justification = blockchain
.justifications(&header.hash())?
.justifications(header.hash())?
.and_then(|just| just.into_justification(GRANDPA_ENGINE_ID))
.expect(
"header is last in set and contains standard change signal; \
@@ -412,7 +412,7 @@ mod tests {
let justification = GrandpaJustification::from_commit(&client, 42, commit).unwrap();
client
.finalize_block(&target_hash, Some((GRANDPA_ENGINE_ID, justification.encode())))
.finalize_block(target_hash, Some((GRANDPA_ENGINE_ID, justification.encode())))
.unwrap();
authority_set_changes.push((current_set_id, n));