mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 19:11:04 +00:00
paritydb support for parachains db. (#4838)
* parity db subsystem without cache and no splitted column * fmt * fix path (auto from parity-db fail) * lru cache for db column with cache * Revert "lru cache for db column with cache" This reverts commit ae177bc5e107a075eff6a21f651218ada6599b74. * Write_lock mutex * theoric code for bridges * revert changes * Revert bridge changes * fix spec_version * update parity db * test purge-db * Use specific ordered collection with paritydb. * Revert "Use specific ordered collection with paritydb." This reverts commit 8b66d0a4ae914cba1af0f44050d45dd6d9327c6b. * fix chain selection tests. * remove patch * fix auto. * Remove useless exists directory method * purge chain without parity-db removal * spellcheck * renamings and filtering. * fix assertion * format * update parity-db and fmt * Auto keep using rocksdb when it exists. * Revert "Auto keep using rocksdb when it exists." This reverts commit cea49b32ae590bdce31fed5c45f3c028ae0c7564. * Update kvdb version.
This commit is contained in:
@@ -28,8 +28,8 @@ use std::{
|
||||
|
||||
use futures::{channel::oneshot, future, select, FutureExt};
|
||||
use futures_timer::Delay;
|
||||
use kvdb::{DBTransaction, KeyValueDB};
|
||||
use parity_scale_codec::{Decode, Encode, Error as CodecError, Input};
|
||||
use polkadot_node_subsystem_util::database::{DBTransaction, Database};
|
||||
|
||||
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
|
||||
use polkadot_node_primitives::{AvailableData, ErasureChunk};
|
||||
@@ -152,7 +152,7 @@ struct CandidateMeta {
|
||||
}
|
||||
|
||||
fn query_inner<D: Decode>(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
column: u32,
|
||||
key: &[u8],
|
||||
) -> Result<Option<D>, Error> {
|
||||
@@ -181,7 +181,7 @@ fn write_available_data(
|
||||
}
|
||||
|
||||
fn load_available_data(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
config: &Config,
|
||||
hash: &CandidateHash,
|
||||
) -> Result<Option<AvailableData>, Error> {
|
||||
@@ -197,7 +197,7 @@ fn delete_available_data(tx: &mut DBTransaction, config: &Config, hash: &Candida
|
||||
}
|
||||
|
||||
fn load_chunk(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
config: &Config,
|
||||
candidate_hash: &CandidateHash,
|
||||
chunk_index: ValidatorIndex,
|
||||
@@ -231,7 +231,7 @@ fn delete_chunk(
|
||||
}
|
||||
|
||||
fn load_meta(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
config: &Config,
|
||||
hash: &CandidateHash,
|
||||
) -> Result<Option<CandidateMeta>, Error> {
|
||||
@@ -443,7 +443,7 @@ impl Clock for SystemClock {
|
||||
pub struct AvailabilityStoreSubsystem {
|
||||
pruning_config: PruningConfig,
|
||||
config: Config,
|
||||
db: Arc<dyn KeyValueDB>,
|
||||
db: Arc<dyn Database>,
|
||||
known_blocks: KnownUnfinalizedBlocks,
|
||||
finalized_number: Option<BlockNumber>,
|
||||
metrics: Metrics,
|
||||
@@ -452,7 +452,7 @@ pub struct AvailabilityStoreSubsystem {
|
||||
|
||||
impl AvailabilityStoreSubsystem {
|
||||
/// Create a new `AvailabilityStoreSubsystem` with a given config on disk.
|
||||
pub fn new(db: Arc<dyn KeyValueDB>, config: Config, metrics: Metrics) -> Self {
|
||||
pub fn new(db: Arc<dyn Database>, config: Config, metrics: Metrics) -> Self {
|
||||
Self::with_pruning_config_and_clock(
|
||||
db,
|
||||
config,
|
||||
@@ -464,7 +464,7 @@ impl AvailabilityStoreSubsystem {
|
||||
|
||||
/// Create a new `AvailabilityStoreSubsystem` with a given config on disk.
|
||||
fn with_pruning_config_and_clock(
|
||||
db: Arc<dyn KeyValueDB>,
|
||||
db: Arc<dyn Database>,
|
||||
config: Config,
|
||||
pruning_config: PruningConfig,
|
||||
clock: Box<dyn Clock>,
|
||||
@@ -661,7 +661,7 @@ where
|
||||
|
||||
async fn process_new_head<Context>(
|
||||
ctx: &mut Context,
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
db_transaction: &mut DBTransaction,
|
||||
config: &Config,
|
||||
pruning_config: &PruningConfig,
|
||||
@@ -711,7 +711,7 @@ where
|
||||
}
|
||||
|
||||
fn note_block_backed(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
db_transaction: &mut DBTransaction,
|
||||
config: &Config,
|
||||
pruning_config: &PruningConfig,
|
||||
@@ -740,7 +740,7 @@ fn note_block_backed(
|
||||
}
|
||||
|
||||
fn note_block_included(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
db_transaction: &mut DBTransaction,
|
||||
config: &Config,
|
||||
pruning_config: &PruningConfig,
|
||||
@@ -1128,7 +1128,7 @@ fn process_message(
|
||||
|
||||
// Ok(true) on success, Ok(false) on failure, and Err on internal error.
|
||||
fn store_chunk(
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
db: &Arc<dyn Database>,
|
||||
config: &Config,
|
||||
candidate_hash: CandidateHash,
|
||||
chunk: ErasureChunk,
|
||||
@@ -1222,7 +1222,7 @@ fn store_available_data(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prune_all(db: &Arc<dyn KeyValueDB>, config: &Config, clock: &dyn Clock) -> Result<(), Error> {
|
||||
fn prune_all(db: &Arc<dyn Database>, config: &Config, clock: &dyn Clock) -> Result<(), Error> {
|
||||
let now = clock.now()?;
|
||||
let (range_start, range_end) = pruning_range(now);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ use ::test_helpers::TestCandidateBuilder;
|
||||
use parking_lot::Mutex;
|
||||
use polkadot_node_primitives::{AvailableData, BlockData, PoV, Proof};
|
||||
use polkadot_node_subsystem_test_helpers as test_helpers;
|
||||
use polkadot_node_subsystem_util::TimeoutExt;
|
||||
use polkadot_node_subsystem_util::{database::Database, TimeoutExt};
|
||||
use polkadot_primitives::v1::{
|
||||
CandidateHash, CandidateReceipt, CoreIndex, GroupIndex, HeadData, Header,
|
||||
PersistedValidationData, ValidatorId,
|
||||
@@ -107,7 +107,7 @@ impl Default for TestState {
|
||||
|
||||
fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||
state: TestState,
|
||||
store: Arc<dyn KeyValueDB>,
|
||||
store: Arc<dyn Database>,
|
||||
test: impl FnOnce(VirtualOverseer) -> T,
|
||||
) {
|
||||
let _ = env_logger::builder()
|
||||
@@ -180,7 +180,7 @@ async fn overseer_signal(overseer: &mut VirtualOverseer, signal: OverseerSignal)
|
||||
.expect(&format!("{:?} is more than enough for sending signals.", TIMEOUT));
|
||||
}
|
||||
|
||||
fn with_tx(db: &Arc<impl KeyValueDB>, f: impl FnOnce(&mut DBTransaction)) {
|
||||
fn with_tx(db: &Arc<impl Database + ?Sized>, f: impl FnOnce(&mut DBTransaction)) {
|
||||
let mut tx = DBTransaction::new();
|
||||
f(&mut tx);
|
||||
db.write(tx).unwrap();
|
||||
@@ -195,9 +195,17 @@ fn candidate_included(receipt: CandidateReceipt) -> CandidateEvent {
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_store() -> Arc<dyn Database> {
|
||||
let db = kvdb_memorydb::create(columns::NUM_COLUMNS);
|
||||
let db =
|
||||
polkadot_node_subsystem_util::database::kvdb_impl::DbAdapter::new(db, &[columns::META]);
|
||||
Arc::new(db)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_api_error_does_not_stop_the_subsystem() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
|
||||
test_harness(TestState::default(), store, |mut virtual_overseer| async move {
|
||||
let new_leaf = Hash::repeat_byte(0x01);
|
||||
@@ -270,7 +278,8 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
|
||||
|
||||
#[test]
|
||||
fn store_chunk_works() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
|
||||
test_harness(TestState::default(), store.clone(), |mut virtual_overseer| async move {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = ValidatorIndex(5);
|
||||
@@ -317,7 +326,8 @@ fn store_chunk_works() {
|
||||
|
||||
#[test]
|
||||
fn store_chunk_does_nothing_if_no_entry_already() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
|
||||
test_harness(TestState::default(), store.clone(), |mut virtual_overseer| async move {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = ValidatorIndex(5);
|
||||
@@ -348,7 +358,8 @@ fn store_chunk_does_nothing_if_no_entry_already() {
|
||||
|
||||
#[test]
|
||||
fn query_chunk_checks_meta() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
|
||||
test_harness(TestState::default(), store.clone(), |mut virtual_overseer| async move {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = ValidatorIndex(5);
|
||||
@@ -395,7 +406,7 @@ fn query_chunk_checks_meta() {
|
||||
|
||||
#[test]
|
||||
fn store_block_works() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
|
||||
@@ -445,7 +456,7 @@ fn store_block_works() {
|
||||
|
||||
#[test]
|
||||
fn store_pov_and_query_chunk_works() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
@@ -487,7 +498,7 @@ fn store_pov_and_query_chunk_works() {
|
||||
|
||||
#[test]
|
||||
fn query_all_chunks_works() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
@@ -582,7 +593,7 @@ fn query_all_chunks_works() {
|
||||
|
||||
#[test]
|
||||
fn stored_but_not_included_data_is_pruned() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
@@ -626,7 +637,7 @@ fn stored_but_not_included_data_is_pruned() {
|
||||
|
||||
#[test]
|
||||
fn stored_data_kept_until_finalized() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
@@ -719,7 +730,7 @@ fn stored_data_kept_until_finalized() {
|
||||
|
||||
#[test]
|
||||
fn we_dont_miss_anything_if_import_notifications_are_missed() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
@@ -843,7 +854,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
|
||||
|
||||
#[test]
|
||||
fn forkfullness_works() {
|
||||
let store = Arc::new(kvdb_memorydb::create(columns::NUM_COLUMNS));
|
||||
let store = test_store();
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
|
||||
|
||||
Reference in New Issue
Block a user