mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -39,19 +39,20 @@
|
||||
use log::{trace, warn};
|
||||
use std::sync::Arc;
|
||||
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use sc_client_api::backend::Backend;
|
||||
use sp_blockchain::{Backend as BlockchainBackend, HeaderBackend};
|
||||
use sp_finality_grandpa::GRANDPA_ENGINE_ID;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{NumberFor, Block as BlockT, Header as HeaderT, One},
|
||||
traits::{Block as BlockT, Header as HeaderT, NumberFor, One},
|
||||
};
|
||||
use sc_client_api::backend::Backend;
|
||||
|
||||
use crate::{
|
||||
SharedAuthoritySet, best_justification,
|
||||
authorities::{AuthoritySetChangeId, AuthoritySetChanges},
|
||||
best_justification,
|
||||
justification::GrandpaJustification,
|
||||
SharedAuthoritySet,
|
||||
};
|
||||
|
||||
const MAX_UNKNOWN_HEADERS: usize = 100_000;
|
||||
@@ -76,10 +77,7 @@ where
|
||||
backend: Arc<B>,
|
||||
shared_authority_set: Option<SharedAuthoritySet<Block::Hash, NumberFor<Block>>>,
|
||||
) -> Self {
|
||||
FinalityProofProvider {
|
||||
backend,
|
||||
shared_authority_set,
|
||||
}
|
||||
FinalityProofProvider { backend, shared_authority_set }
|
||||
}
|
||||
|
||||
/// Create new finality proof provider for the service using:
|
||||
@@ -113,14 +111,10 @@ where
|
||||
{
|
||||
changes
|
||||
} else {
|
||||
return Ok(None);
|
||||
return Ok(None)
|
||||
};
|
||||
|
||||
prove_finality(
|
||||
&*self.backend,
|
||||
authority_set_changes,
|
||||
block,
|
||||
)
|
||||
prove_finality(&*self.backend, authority_set_changes, block)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,11 +160,10 @@ where
|
||||
if info.finalized_number < block {
|
||||
let err = format!(
|
||||
"Requested finality proof for descendant of #{} while we only have finalized #{}.",
|
||||
block,
|
||||
info.finalized_number,
|
||||
block, info.finalized_number,
|
||||
);
|
||||
trace!(target: "afg", "{}", &err);
|
||||
return Err(FinalityProofError::BlockNotYetFinalized);
|
||||
return Err(FinalityProofError::BlockNotYetFinalized)
|
||||
}
|
||||
|
||||
let (justification, just_block) = match authority_set_changes.get_set_id(block) {
|
||||
@@ -185,9 +178,9 @@ where
|
||||
"No justification found for the latest finalized block. \
|
||||
Returning empty proof.",
|
||||
);
|
||||
return Ok(None);
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
},
|
||||
AuthoritySetChangeId::Set(_, last_block_for_set) => {
|
||||
let last_block_for_set_id = BlockId::Number(last_block_for_set);
|
||||
let justification = if let Some(grandpa_justification) = backend
|
||||
@@ -203,10 +196,10 @@ where
|
||||
Returning empty proof.",
|
||||
block,
|
||||
);
|
||||
return Ok(None);
|
||||
return Ok(None)
|
||||
};
|
||||
(justification, last_block_for_set)
|
||||
}
|
||||
},
|
||||
AuthoritySetChangeId::Unknown => {
|
||||
warn!(
|
||||
target: "afg",
|
||||
@@ -214,8 +207,8 @@ where
|
||||
You need to resync to populate AuthoritySetChanges properly.",
|
||||
block,
|
||||
);
|
||||
return Err(FinalityProofError::BlockNotInAuthoritySetChanges);
|
||||
}
|
||||
return Err(FinalityProofError::BlockNotInAuthoritySetChanges)
|
||||
},
|
||||
};
|
||||
|
||||
// Collect all headers from the requested block until the last block of the set
|
||||
@@ -224,7 +217,7 @@ where
|
||||
let mut current = block + One::one();
|
||||
loop {
|
||||
if current > just_block || headers.len() >= MAX_UNKNOWN_HEADERS {
|
||||
break;
|
||||
break
|
||||
}
|
||||
headers.push(backend.blockchain().expect_header(BlockId::Number(current))?);
|
||||
current += One::one();
|
||||
@@ -245,9 +238,7 @@ where
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
authorities::AuthoritySetChanges, BlockNumberOps, ClientError, SetId,
|
||||
};
|
||||
use crate::{authorities::AuthoritySetChanges, BlockNumberOps, ClientError, SetId};
|
||||
use futures::executor::block_on;
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sc_client_api::{apply_aux, LockImportRun};
|
||||
@@ -276,8 +267,9 @@ pub(crate) mod tests {
|
||||
let proof = super::FinalityProof::<Block::Header>::decode(&mut &remote_proof[..])
|
||||
.map_err(|_| ClientError::BadJustification("failed to decode finality proof".into()))?;
|
||||
|
||||
let justification: GrandpaJustification<Block> = Decode::decode(&mut &proof.justification[..])
|
||||
.map_err(|_| ClientError::JustificationDecode)?;
|
||||
let justification: GrandpaJustification<Block> =
|
||||
Decode::decode(&mut &proof.justification[..])
|
||||
.map_err(|_| ClientError::JustificationDecode)?;
|
||||
justification.verify(current_set_id, ¤t_authorities)?;
|
||||
|
||||
Ok(proof)
|
||||
@@ -321,13 +313,13 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
fn store_best_justification(client: &TestClient, just: &GrandpaJustification<Block>) {
|
||||
client.lock_import_and_run(|import_op| {
|
||||
crate::aux_schema::update_best_justification(
|
||||
just,
|
||||
|insert| apply_aux(import_op, insert, &[]),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
client
|
||||
.lock_import_and_run(|import_op| {
|
||||
crate::aux_schema::update_best_justification(just, |insert| {
|
||||
apply_aux(import_op, insert, &[])
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -336,11 +328,7 @@ pub(crate) mod tests {
|
||||
let authority_set_changes = AuthoritySetChanges::empty();
|
||||
|
||||
// The last finalized block is 4, so we cannot provide further justifications.
|
||||
let proof_of_5 = prove_finality(
|
||||
&*backend,
|
||||
authority_set_changes,
|
||||
5,
|
||||
);
|
||||
let proof_of_5 = prove_finality(&*backend, authority_set_changes, 5);
|
||||
assert!(matches!(proof_of_5, Err(FinalityProofError::BlockNotYetFinalized)));
|
||||
}
|
||||
|
||||
@@ -353,12 +341,7 @@ pub(crate) mod tests {
|
||||
|
||||
// Block 4 is finalized without justification
|
||||
// => we can't prove finality of 3
|
||||
let proof_of_3 = prove_finality(
|
||||
&*backend,
|
||||
authority_set_changes,
|
||||
3,
|
||||
)
|
||||
.unwrap();
|
||||
let proof_of_3 = prove_finality(&*backend, authority_set_changes, 3).unwrap();
|
||||
assert_eq!(proof_of_3, None);
|
||||
}
|
||||
|
||||
@@ -406,14 +389,15 @@ pub(crate) mod tests {
|
||||
1,
|
||||
vec![(AuthorityId::from_slice(&[3u8; 32]), 1u64)],
|
||||
finality_proof.encode(),
|
||||
).unwrap_err();
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
fn create_commit<S, Id>(
|
||||
block: Block,
|
||||
round: u64,
|
||||
set_id: SetId,
|
||||
auth: &[Ed25519Keyring]
|
||||
auth: &[Ed25519Keyring],
|
||||
) -> finality_grandpa::Commit<H256, u64, S, Id>
|
||||
where
|
||||
Id: From<sp_core::ed25519::Public>,
|
||||
@@ -481,11 +465,7 @@ pub(crate) mod tests {
|
||||
let mut authority_set_changes = AuthoritySetChanges::empty();
|
||||
authority_set_changes.append(1, 8);
|
||||
|
||||
let proof_of_6 = prove_finality(
|
||||
&*backend,
|
||||
authority_set_changes,
|
||||
6,
|
||||
);
|
||||
let proof_of_6 = prove_finality(&*backend, authority_set_changes, 6);
|
||||
assert!(matches!(proof_of_6, Err(FinalityProofError::BlockNotInAuthoritySetChanges)));
|
||||
}
|
||||
|
||||
@@ -499,11 +479,9 @@ pub(crate) mod tests {
|
||||
let commit = create_commit(block8.clone(), round, 1, &[Ed25519Keyring::Alice]);
|
||||
let grandpa_just8 = GrandpaJustification::from_commit(&client, round, commit).unwrap();
|
||||
|
||||
client.finalize_block(
|
||||
BlockId::Number(8),
|
||||
Some((ID, grandpa_just8.encode().clone()))
|
||||
)
|
||||
.unwrap();
|
||||
client
|
||||
.finalize_block(BlockId::Number(8), Some((ID, grandpa_just8.encode().clone())))
|
||||
.unwrap();
|
||||
|
||||
// Authority set change at block 8, so the justification stored there will be used in the
|
||||
// FinalityProof for block 6
|
||||
@@ -512,13 +490,7 @@ pub(crate) mod tests {
|
||||
authority_set_changes.append(1, 8);
|
||||
|
||||
let proof_of_6: FinalityProof = Decode::decode(
|
||||
&mut &prove_finality(
|
||||
&*backend,
|
||||
authority_set_changes.clone(),
|
||||
6,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap()[..],
|
||||
&mut &prove_finality(&*backend, authority_set_changes.clone(), 6).unwrap().unwrap()[..],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -540,10 +512,7 @@ pub(crate) mod tests {
|
||||
let mut authority_set_changes = AuthoritySetChanges::empty();
|
||||
authority_set_changes.append(0, 5);
|
||||
|
||||
assert!(matches!(
|
||||
prove_finality(&*backend, authority_set_changes, 6),
|
||||
Ok(None),
|
||||
));
|
||||
assert!(matches!(prove_finality(&*backend, authority_set_changes, 6), Ok(None),));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -563,13 +532,7 @@ pub(crate) mod tests {
|
||||
authority_set_changes.append(0, 5);
|
||||
|
||||
let proof_of_6: FinalityProof = Decode::decode(
|
||||
&mut &prove_finality(
|
||||
&*backend,
|
||||
authority_set_changes,
|
||||
6,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap()[..],
|
||||
&mut &prove_finality(&*backend, authority_set_changes, 6).unwrap().unwrap()[..],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user