mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 17:38:02 +00:00
Fast/warp sync fixes (#10562)
* Fast sync fixes * Fix gap blocks validation * Updated test * Formatting * Networking test
This commit is contained in:
@@ -130,6 +130,8 @@ pub enum Error<E: fmt::Debug> {
|
||||
InvalidPruningMode(String),
|
||||
/// Too many unfinalized sibling blocks inserted.
|
||||
TooManySiblingBlocks,
|
||||
/// Trying to insert existing block.
|
||||
BlockAlreadyExists,
|
||||
}
|
||||
|
||||
/// Pinning error type.
|
||||
@@ -154,6 +156,7 @@ impl<E: fmt::Debug> fmt::Debug for Error<E> {
|
||||
Error::InvalidParent => write!(f, "Trying to insert block with unknown parent"),
|
||||
Error::InvalidPruningMode(e) => write!(f, "Expected pruning mode: {}", e),
|
||||
Error::TooManySiblingBlocks => write!(f, "Too many sibling blocks inserted"),
|
||||
Error::BlockAlreadyExists => write!(f, "Block already exists"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,9 +210,10 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
|
||||
insert_values(&mut values, record.inserted);
|
||||
trace!(
|
||||
target: "state-db",
|
||||
"Uncanonicalized journal entry {}.{} ({} inserted, {} deleted)",
|
||||
"Uncanonicalized journal entry {}.{} ({:?}) ({} inserted, {} deleted)",
|
||||
block,
|
||||
index,
|
||||
record.hash,
|
||||
overlay.inserted.len(),
|
||||
overlay.deleted.len()
|
||||
);
|
||||
@@ -296,6 +297,9 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
|
||||
if level.blocks.len() >= MAX_BLOCKS_PER_LEVEL as usize {
|
||||
return Err(Error::TooManySiblingBlocks)
|
||||
}
|
||||
if level.blocks.iter().any(|b| b.hash == *hash) {
|
||||
return Err(Error::BlockAlreadyExists)
|
||||
}
|
||||
|
||||
let index = level.available_index();
|
||||
let journal_key = to_journal_key(number, index);
|
||||
@@ -641,7 +645,7 @@ mod tests {
|
||||
use super::{to_journal_key, NonCanonicalOverlay};
|
||||
use crate::{
|
||||
test::{make_changeset, make_db},
|
||||
ChangeSet, CommitSet, MetaDb,
|
||||
ChangeSet, CommitSet, Error, MetaDb,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use std::io;
|
||||
@@ -710,6 +714,20 @@ mod tests {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_existing_fails() {
|
||||
let db = make_db(&[]);
|
||||
let h1 = H256::random();
|
||||
let mut overlay = NonCanonicalOverlay::<H256, H256>::new(&db).unwrap();
|
||||
overlay
|
||||
.insert::<io::Error>(&h1, 2, &H256::default(), ChangeSet::default())
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
overlay.insert::<io::Error>(&h1, 2, &H256::default(), ChangeSet::default()),
|
||||
Err(Error::BlockAlreadyExists)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn canonicalize_unknown_panics() {
|
||||
|
||||
Reference in New Issue
Block a user