mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 17:08:00 +00:00
Fast/warp sync fixes (#10562)
* Fast sync fixes * Fix gap blocks validation * Updated test * Formatting * Networking test
This commit is contained in:
@@ -477,7 +477,6 @@ impl<Block: BlockT> BlockchainDb<Block> {
|
||||
let mut meta = self.meta.write();
|
||||
if number.is_zero() {
|
||||
meta.genesis_hash = hash;
|
||||
meta.finalized_hash = hash;
|
||||
}
|
||||
|
||||
if is_best {
|
||||
@@ -1347,11 +1346,6 @@ impl<Block: BlockT> Backend<Block> {
|
||||
}
|
||||
|
||||
if number.is_zero() {
|
||||
transaction.set_from_vec(
|
||||
columns::META,
|
||||
meta_keys::FINALIZED_BLOCK,
|
||||
lookup_key.clone(),
|
||||
);
|
||||
transaction.set(columns::META, meta_keys::GENESIS_HASH, hash.as_ref());
|
||||
|
||||
if operation.commit_state {
|
||||
@@ -1447,14 +1441,15 @@ impl<Block: BlockT> Backend<Block> {
|
||||
let finalized = number_u64 == 0 || pending_block.leaf_state.is_final();
|
||||
finalized
|
||||
} else {
|
||||
number.is_zero() || pending_block.leaf_state.is_final()
|
||||
(number.is_zero() && last_finalized_num.is_zero()) ||
|
||||
pending_block.leaf_state.is_final()
|
||||
};
|
||||
|
||||
let header = &pending_block.header;
|
||||
let is_best = pending_block.leaf_state.is_best();
|
||||
debug!(target: "db",
|
||||
"DB Commit {:?} ({}), best={}, state={}, existing={}",
|
||||
hash, number, is_best, operation.commit_state, existing_header,
|
||||
"DB Commit {:?} ({}), best={}, state={}, existing={}, finalized={}",
|
||||
hash, number, is_best, operation.commit_state, existing_header, finalized,
|
||||
);
|
||||
|
||||
self.state_usage.merge_sm(operation.old_state.usage_info());
|
||||
@@ -2295,6 +2290,7 @@ pub(crate) mod tests {
|
||||
extrinsics_root: H256,
|
||||
) -> H256 {
|
||||
insert_block(backend, number, parent_hash, changes, extrinsics_root, Vec::new(), None)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn insert_block(
|
||||
@@ -2305,7 +2301,7 @@ pub(crate) mod tests {
|
||||
extrinsics_root: H256,
|
||||
body: Vec<ExtrinsicWrapper<u64>>,
|
||||
transaction_index: Option<Vec<IndexOperation>>,
|
||||
) -> H256 {
|
||||
) -> Result<H256, sp_blockchain::Error> {
|
||||
use sp_runtime::testing::Digest;
|
||||
|
||||
let digest = Digest::default();
|
||||
@@ -2329,9 +2325,9 @@ pub(crate) mod tests {
|
||||
if let Some(index) = transaction_index {
|
||||
op.update_transaction_index(index).unwrap();
|
||||
}
|
||||
backend.commit_operation(op).unwrap();
|
||||
backend.commit_operation(op)?;
|
||||
|
||||
header_hash
|
||||
Ok(header_hash)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3019,7 +3015,6 @@ pub(crate) mod tests {
|
||||
{
|
||||
let header = backend.blockchain().header(BlockId::Hash(hash1)).unwrap().unwrap();
|
||||
let mut op = backend.begin_operation().unwrap();
|
||||
backend.begin_state_operation(&mut op, BlockId::Hash(hash0)).unwrap();
|
||||
op.set_block_data(header, None, None, None, NewBlockState::Best).unwrap();
|
||||
backend.commit_operation(op).unwrap();
|
||||
}
|
||||
@@ -3063,7 +3058,8 @@ pub(crate) mod tests {
|
||||
Default::default(),
|
||||
vec![i.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
blocks.push(hash);
|
||||
prev_hash = hash;
|
||||
}
|
||||
@@ -3100,7 +3096,8 @@ pub(crate) mod tests {
|
||||
Default::default(),
|
||||
vec![i.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
blocks.push(hash);
|
||||
prev_hash = hash;
|
||||
}
|
||||
@@ -3114,7 +3111,8 @@ pub(crate) mod tests {
|
||||
sp_core::H256::random(),
|
||||
vec![2.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
insert_block(
|
||||
&backend,
|
||||
3,
|
||||
@@ -3123,7 +3121,8 @@ pub(crate) mod tests {
|
||||
H256::random(),
|
||||
vec![3.into(), 11.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
let mut op = backend.begin_operation().unwrap();
|
||||
backend.begin_state_operation(&mut op, BlockId::Hash(blocks[4])).unwrap();
|
||||
op.mark_head(BlockId::Hash(blocks[4])).unwrap();
|
||||
@@ -3172,7 +3171,8 @@ pub(crate) mod tests {
|
||||
Default::default(),
|
||||
vec![i.into()],
|
||||
Some(index),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
blocks.push(hash);
|
||||
prev_hash = hash;
|
||||
}
|
||||
@@ -3206,7 +3206,8 @@ pub(crate) mod tests {
|
||||
Default::default(),
|
||||
vec![i.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
blocks.push(hash);
|
||||
prev_hash = hash;
|
||||
}
|
||||
@@ -3220,7 +3221,8 @@ pub(crate) mod tests {
|
||||
sp_core::H256::random(),
|
||||
vec![42.into()],
|
||||
None,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
assert!(backend.remove_leaf_block(&best_hash).is_err());
|
||||
assert!(backend.have_state_at(&prev_hash, 1));
|
||||
backend.remove_leaf_block(&prev_hash).unwrap();
|
||||
@@ -3290,4 +3292,21 @@ pub(crate) mod tests {
|
||||
|
||||
assert_eq!(backend.blockchain().info().finalized_hash, block1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_import_existing_state_fails() {
|
||||
let backend: Backend<Block> = Backend::new_test(10, 10);
|
||||
let genesis =
|
||||
insert_block(&backend, 0, Default::default(), None, Default::default(), vec![], None)
|
||||
.unwrap();
|
||||
|
||||
insert_block(&backend, 1, genesis, None, Default::default(), vec![], None).unwrap();
|
||||
let err = insert_block(&backend, 1, genesis, None, Default::default(), vec![], None)
|
||||
.err()
|
||||
.unwrap();
|
||||
match err {
|
||||
sp_blockchain::Error::StateDatabase(m) if m == "Block already exists" => (),
|
||||
e @ _ => panic!("Unexpected error {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user