mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 19:11:04 +00:00
Run RustFmt as part of the CI (#37)
* Run RustFmt as part of the CI * Format repo * Run RustFmt before the default Travis build step Apparently if you override `script` you also need to make sure to `build` and `test` the code yourself. * Format repo
This commit is contained in:
committed by
Bastian Köcher
parent
d904a282c8
commit
e5f998d7d9
@@ -100,7 +100,13 @@ fn prepare_votes<S: Storage>(
|
||||
header: &Header,
|
||||
submitter: Option<&S::Submitter>,
|
||||
two_thirds_majority_transition: u64,
|
||||
) -> Result<(BTreeMap<Address, u64>, VecDeque<(H256, u64, Option<S::Submitter>, BTreeSet<Address>)>), Error> {
|
||||
) -> Result<
|
||||
(
|
||||
BTreeMap<Address, u64>,
|
||||
VecDeque<(H256, u64, Option<S::Submitter>, BTreeSet<Address>)>,
|
||||
),
|
||||
Error,
|
||||
> {
|
||||
// this fn can only work with single validators set
|
||||
if !validators.contains(&header.author) {
|
||||
return Err(Error::NotValidator);
|
||||
|
||||
@@ -36,10 +36,7 @@ use crate::validators::{Validators, ValidatorsConfiguration};
|
||||
use crate::verification::verify_aura_header;
|
||||
use crate::{AuraConfiguration, Storage};
|
||||
use primitives::{Header, Receipt, H256};
|
||||
use sp_std::{
|
||||
collections::btree_map::BTreeMap,
|
||||
prelude::*,
|
||||
};
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
/// Maximal number of headers behind best blocks that we are aiming to store. When there
|
||||
/// are too many unfinalized headers, it slows down finalization tracking significantly.
|
||||
@@ -89,7 +86,7 @@ pub fn import_headers<S: Storage>(
|
||||
}
|
||||
}
|
||||
useful += 1;
|
||||
},
|
||||
}
|
||||
Err(Error::AncientHeader) | Err(Error::KnownHeader) => useless += 1,
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
@@ -143,16 +140,14 @@ pub fn import_header<S: Storage>(
|
||||
let total_difficulty = import_context.total_difficulty() + header.difficulty;
|
||||
let is_best = total_difficulty > best_total_difficulty;
|
||||
let header_number = header.number;
|
||||
storage.insert_header(
|
||||
import_context.into_import_header(
|
||||
is_best,
|
||||
hash,
|
||||
header,
|
||||
total_difficulty,
|
||||
enacted_change,
|
||||
scheduled_change,
|
||||
),
|
||||
);
|
||||
storage.insert_header(import_context.into_import_header(
|
||||
is_best,
|
||||
hash,
|
||||
header,
|
||||
total_difficulty,
|
||||
enacted_change,
|
||||
scheduled_change,
|
||||
));
|
||||
|
||||
// now mark finalized headers && prune old headers
|
||||
storage.finalize_headers(
|
||||
@@ -300,18 +295,18 @@ mod tests {
|
||||
let mut latest_block_hash = Default::default();
|
||||
for i in 1..11 {
|
||||
let header = block_i(&storage, i, &validators);
|
||||
let (rolling_last_block_hash, finalized_blocks) =
|
||||
import_header(
|
||||
&mut storage,
|
||||
&kovan_aura_config(),
|
||||
&validators_config,
|
||||
10,
|
||||
Some(100),
|
||||
header,
|
||||
None,
|
||||
).unwrap();
|
||||
let (rolling_last_block_hash, finalized_blocks) = import_header(
|
||||
&mut storage,
|
||||
&kovan_aura_config(),
|
||||
&validators_config,
|
||||
10,
|
||||
Some(100),
|
||||
header,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
match i {
|
||||
2 ..= 10 => assert_eq!(
|
||||
2..=10 => assert_eq!(
|
||||
finalized_blocks,
|
||||
vec![(i - 1, block_i(&storage, i - 1, &validators).hash(), Some(100))],
|
||||
"At {}",
|
||||
@@ -341,7 +336,8 @@ mod tests {
|
||||
Some(vec![crate::validators::tests::validators_change_recept(
|
||||
latest_block_hash,
|
||||
)]),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
finalized_blocks,
|
||||
vec![(10, block_i(&storage, 10, &validators).hash(), Some(100))],
|
||||
@@ -366,20 +362,17 @@ mod tests {
|
||||
};
|
||||
let header = signed_header(&validators, header, step as _);
|
||||
expected_blocks.push((i, header.hash(), Some(102)));
|
||||
let (rolling_last_block_hash, finalized_blocks) =
|
||||
import_header(
|
||||
&mut storage,
|
||||
&kovan_aura_config(),
|
||||
&validators_config,
|
||||
10,
|
||||
Some(102),
|
||||
header,
|
||||
None,
|
||||
).unwrap();
|
||||
assert_eq!(
|
||||
finalized_blocks,
|
||||
vec![],
|
||||
);
|
||||
let (rolling_last_block_hash, finalized_blocks) = import_header(
|
||||
&mut storage,
|
||||
&kovan_aura_config(),
|
||||
&validators_config,
|
||||
10,
|
||||
Some(102),
|
||||
header,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(finalized_blocks, vec![],);
|
||||
latest_block_hash = rolling_last_block_hash;
|
||||
step += 3;
|
||||
}
|
||||
@@ -406,7 +399,8 @@ mod tests {
|
||||
Some(103),
|
||||
header,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(finalized_blocks, expected_blocks);
|
||||
assert_eq!(storage.oldest_unpruned_block(), 15);
|
||||
}
|
||||
|
||||
@@ -36,12 +36,7 @@ use codec::{Decode, Encode};
|
||||
use frame_support::{decl_module, decl_storage};
|
||||
use primitives::{Address, Header, Receipt, H256, U256};
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use sp_std::{
|
||||
prelude::*,
|
||||
cmp::Ord,
|
||||
collections::btree_map::BTreeMap,
|
||||
iter::from_fn,
|
||||
};
|
||||
use sp_std::{cmp::Ord, collections::btree_map::BTreeMap, iter::from_fn, prelude::*};
|
||||
use validators::{ValidatorsConfiguration, ValidatorsSource};
|
||||
|
||||
pub use import::{header_import_requires_receipts, import_header};
|
||||
@@ -481,7 +476,10 @@ impl<T: Trait> Storage for BridgeStorage<T> {
|
||||
// ensure that unfinalized headers we want to prune do not have scheduled changes
|
||||
if number > finalized_number {
|
||||
if let Some(ref blocks_at_number) = blocks_at_number {
|
||||
if blocks_at_number.iter().any(|block| ScheduledChanges::contains_key(block)) {
|
||||
if blocks_at_number
|
||||
.iter()
|
||||
.any(|block| ScheduledChanges::contains_key(block))
|
||||
{
|
||||
HeadersByNumber::insert(number, blocks_at_number);
|
||||
OldestUnprunedBlock::put(number);
|
||||
return;
|
||||
@@ -776,7 +774,9 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
fn header(&self, hash: &H256) -> Option<(Header, Option<Self::Submitter>)> {
|
||||
self.headers.get(hash).map(|header| (header.header.clone(), header.submitter.clone()))
|
||||
self.headers
|
||||
.get(hash)
|
||||
.map(|header| (header.header.clone(), header.submitter.clone()))
|
||||
}
|
||||
|
||||
fn import_context(
|
||||
|
||||
@@ -198,10 +198,7 @@ mod tests {
|
||||
empty_step
|
||||
}
|
||||
|
||||
fn verify_with_config(
|
||||
config: &AuraConfiguration,
|
||||
header: &Header,
|
||||
) -> Result<ImportContext<AccountId>, Error> {
|
||||
fn verify_with_config(config: &AuraConfiguration, header: &Header) -> Result<ImportContext<AccountId>, Error> {
|
||||
let storage = InMemoryStorage::new(genesis(), validators_addresses(3));
|
||||
verify_aura_header(&storage, &config, None, header)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user