mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
New database trait (#5549)
* Introduce trait * The trait * Generic * Basic impls. * Remove unneeded bounds * Minor changes * Switch over to the new DB trait * Integrated parity-db and added CLI for db selection * Default impl. * Fix logs. * Started integrating subdb * Apply suggestions from code review Co-Authored-By: Cecile Tonglet <cecile@parity.io> * Apply suggestions from code review Co-Authored-By: Nikolay Volf <nikvolf@gmail.com> * Enable subdb * Bump parity-db * Fixed CLI macro * Fixed browser build * Fixed features * Sort out features * Use parity-db from crates.io * Typo Co-authored-by: arkpar <arkady.paronyan@gmail.com> Co-authored-by: Cecile Tonglet <cecile@parity.io> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ use sp_blockchain::{
|
||||
use sc_client_api::{BlockchainEvents, BlockImportNotification, FinalityNotifications, ImportNotifications, FinalityNotification, backend::{TransactionFor, AuxStore, Backend, Finalizer}, BlockBackend};
|
||||
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
|
||||
use sc_client::LongestChain;
|
||||
use sc_client::blockchain::HeaderBackend;
|
||||
use sc_network::config::Role;
|
||||
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
|
||||
use sp_consensus::import_queue::{
|
||||
@@ -359,13 +360,9 @@ impl<D> Peer<D> {
|
||||
|
||||
/// Test helper to compare the blockchain state of multiple (networked)
|
||||
/// clients.
|
||||
/// Potentially costly, as it creates in-memory copies of both blockchains in order
|
||||
/// to compare them. If you have easier/softer checks that are sufficient, e.g.
|
||||
/// by using .info(), you should probably use it instead of this.
|
||||
pub fn blockchain_canon_equals(&self, other: &Self) -> bool {
|
||||
if let (Some(mine), Some(others)) = (self.backend.clone(), other.backend.clone()) {
|
||||
mine.as_in_memory().blockchain()
|
||||
.canon_equals_to(others.as_in_memory().blockchain())
|
||||
mine.blockchain().info().best_hash == others.blockchain().info().best_hash
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@@ -374,7 +371,7 @@ impl<D> Peer<D> {
|
||||
/// Count the total number of imported blocks.
|
||||
pub fn blocks_count(&self) -> u64 {
|
||||
self.backend.as_ref().map(
|
||||
|backend| backend.blocks_count()
|
||||
|backend| backend.blockchain().info().best_number
|
||||
).unwrap_or(0)
|
||||
}
|
||||
|
||||
@@ -382,6 +379,12 @@ impl<D> Peer<D> {
|
||||
pub fn failed_verifications(&self) -> HashMap<<Block as BlockT>::Hash, String> {
|
||||
self.verifier.failed_verifications.lock().clone()
|
||||
}
|
||||
|
||||
pub fn has_block(&self, hash: &H256) -> bool {
|
||||
self.backend.as_ref().map(
|
||||
|backend| backend.blockchain().header(BlockId::hash(*hash)).unwrap().is_some()
|
||||
).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements `BlockImport` for any `Transaction`. Internally the transaction is
|
||||
|
||||
@@ -339,13 +339,15 @@ fn syncs_all_forks() {
|
||||
net.peer(0).push_blocks(2, false);
|
||||
net.peer(1).push_blocks(2, false);
|
||||
|
||||
net.peer(0).push_blocks(2, true);
|
||||
net.peer(1).push_blocks(4, false);
|
||||
let b1 = net.peer(0).push_blocks(2, true);
|
||||
let b2 = net.peer(1).push_blocks(4, false);
|
||||
|
||||
net.block_until_sync();
|
||||
// Check that all peers have all of the blocks.
|
||||
assert_eq!(9, net.peer(0).blocks_count());
|
||||
assert_eq!(9, net.peer(1).blocks_count());
|
||||
// Check that all peers have all of the branches.
|
||||
assert!(net.peer(0).has_block(&b1));
|
||||
assert!(net.peer(0).has_block(&b2));
|
||||
assert!(net.peer(1).has_block(&b1));
|
||||
assert!(net.peer(1).has_block(&b2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -587,24 +589,11 @@ fn syncs_header_only_forks() {
|
||||
|
||||
net.peer(0).push_blocks(2, true);
|
||||
let small_hash = net.peer(0).client().info().best_hash;
|
||||
let small_number = net.peer(0).client().info().best_number;
|
||||
net.peer(1).push_blocks(4, false);
|
||||
|
||||
net.block_until_sync();
|
||||
// Peer 1 will sync the small fork even though common block state is missing
|
||||
assert_eq!(9, net.peer(0).blocks_count());
|
||||
assert_eq!(9, net.peer(1).blocks_count());
|
||||
|
||||
// Request explicit header-only sync request for the ancient fork.
|
||||
let first_peer_id = net.peer(0).id();
|
||||
net.peer(1).set_sync_fork_request(vec![first_peer_id], small_hash, small_number);
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
if net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_none() {
|
||||
return Poll::Pending
|
||||
}
|
||||
Poll::Ready(())
|
||||
}));
|
||||
assert!(net.peer(1).has_block(&small_hash));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user