mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Remove mem_info and references to parity-util-mem (#12795)
* Remove mem_info and some references to parity-util-mem * [Draft] Finish removing references to `parity-util-mem` * Upgrade dependencies * Update scripts/ci/deny.toml Co-authored-by: ordian <write@reusable.software> * Fix Cargo.lock (remove unwanted dependency changes) * Removed unused argument * Run cargo fmt (didn't have pre-commit set up) * Fix some CI errors * Fix another CI error * Remove unused dependency Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
@@ -49,10 +49,8 @@ mod test;
|
||||
use codec::Codec;
|
||||
use log::trace;
|
||||
use noncanonical::NonCanonicalOverlay;
|
||||
use parity_util_mem::{malloc_size, MallocSizeOf};
|
||||
use parking_lot::RwLock;
|
||||
use pruning::{HaveBlock, RefWindow};
|
||||
use sc_client_api::{MemorySize, StateDbMemoryInfo};
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
fmt,
|
||||
@@ -220,8 +218,6 @@ pub struct Constraints {
|
||||
/// Maximum blocks. Defaults to 0 when unspecified, effectively keeping only non-canonical
|
||||
/// states.
|
||||
pub max_blocks: Option<u32>,
|
||||
/// Maximum memory in the pruning overlay.
|
||||
pub max_mem: Option<usize>,
|
||||
}
|
||||
|
||||
/// Pruning mode.
|
||||
@@ -238,7 +234,7 @@ pub enum PruningMode {
|
||||
impl PruningMode {
|
||||
/// Create a mode that keeps given number of blocks.
|
||||
pub fn blocks_pruning(n: u32) -> PruningMode {
|
||||
PruningMode::Constrained(Constraints { max_blocks: Some(n), max_mem: None })
|
||||
PruningMode::Constrained(Constraints { max_blocks: Some(n) })
|
||||
}
|
||||
|
||||
/// Is this an archive (either ArchiveAll or ArchiveCanonical) pruning mode?
|
||||
@@ -276,7 +272,7 @@ impl Default for PruningMode {
|
||||
|
||||
impl Default for Constraints {
|
||||
fn default() -> Self {
|
||||
Self { max_blocks: Some(DEFAULT_MAX_BLOCK_CONSTRAINT), max_mem: None }
|
||||
Self { max_blocks: Some(DEFAULT_MAX_BLOCK_CONSTRAINT) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,9 +290,7 @@ pub struct StateDbSync<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
ref_counting: bool,
|
||||
}
|
||||
|
||||
impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
StateDbSync<BlockHash, Key, D>
|
||||
{
|
||||
impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDbSync<BlockHash, Key, D> {
|
||||
fn new(
|
||||
mode: PruningMode,
|
||||
ref_counting: bool,
|
||||
@@ -306,8 +300,7 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
|
||||
let non_canonical: NonCanonicalOverlay<BlockHash, Key> = NonCanonicalOverlay::new(&db)?;
|
||||
let pruning: Option<RefWindow<BlockHash, Key, D>> = match mode {
|
||||
PruningMode::Constrained(Constraints { max_mem: Some(_), .. }) => unimplemented!(),
|
||||
PruningMode::Constrained(Constraints { max_blocks, .. }) =>
|
||||
PruningMode::Constrained(Constraints { max_blocks }) =>
|
||||
Some(RefWindow::new(db, max_blocks.unwrap_or(0), ref_counting)?),
|
||||
PruningMode::ArchiveAll | PruningMode::ArchiveCanonical => None,
|
||||
};
|
||||
@@ -392,10 +385,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
break
|
||||
}
|
||||
|
||||
if constraints.max_mem.map_or(false, |m| pruning.mem_used() > m) {
|
||||
break
|
||||
}
|
||||
|
||||
let pinned = &self.pinned;
|
||||
match pruning.next_hash() {
|
||||
// the block record is temporary unavailable, break and try next time
|
||||
@@ -496,14 +485,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
}
|
||||
db.get(key.as_ref()).map_err(Error::Db)
|
||||
}
|
||||
|
||||
fn memory_info(&self) -> StateDbMemoryInfo {
|
||||
StateDbMemoryInfo {
|
||||
non_canonical: MemorySize::from_bytes(malloc_size(&self.non_canonical)),
|
||||
pruning: self.pruning.as_ref().map(|p| MemorySize::from_bytes(malloc_size(&p))),
|
||||
pinned: MemorySize::from_bytes(malloc_size(&self.pinned)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// State DB maintenance. See module description.
|
||||
@@ -512,9 +493,7 @@ pub struct StateDb<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
db: RwLock<StateDbSync<BlockHash, Key, D>>,
|
||||
}
|
||||
|
||||
impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
StateDb<BlockHash, Key, D>
|
||||
{
|
||||
impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDb<BlockHash, Key, D> {
|
||||
/// Create an instance of [`StateDb`].
|
||||
pub fn open(
|
||||
db: D,
|
||||
@@ -637,11 +616,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
|
||||
*state_db = StateDbSync::new(state_db.mode.clone(), state_db.ref_counting, db)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the current memory statistics of this instance.
|
||||
pub fn memory_info(&self) -> StateDbMemoryInfo {
|
||||
self.db.read().memory_info()
|
||||
}
|
||||
}
|
||||
|
||||
/// The result return by `StateDb::is_pruned`
|
||||
@@ -772,10 +746,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn block_record_unavailable() {
|
||||
let (mut db, state_db) = make_test_db(PruningMode::Constrained(Constraints {
|
||||
max_blocks: Some(1),
|
||||
max_mem: None,
|
||||
}));
|
||||
let (mut db, state_db) =
|
||||
make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(1) }));
|
||||
// import 2 blocks
|
||||
for i in &[5, 6] {
|
||||
db.commit(
|
||||
@@ -809,19 +781,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prune_window_0() {
|
||||
let (db, _) = make_test_db(PruningMode::Constrained(Constraints {
|
||||
max_blocks: Some(0),
|
||||
max_mem: None,
|
||||
}));
|
||||
let (db, _) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(0) }));
|
||||
assert!(db.data_eq(&make_db(&[21, 3, 922, 94])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prune_window_1() {
|
||||
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints {
|
||||
max_blocks: Some(1),
|
||||
max_mem: None,
|
||||
}));
|
||||
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(1) }));
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(0), 0), IsPruned::Pruned);
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(1), 1), IsPruned::Pruned);
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(21), 2), IsPruned::Pruned);
|
||||
@@ -831,10 +797,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prune_window_2() {
|
||||
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints {
|
||||
max_blocks: Some(2),
|
||||
max_mem: None,
|
||||
}));
|
||||
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(2) }));
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(0), 0), IsPruned::Pruned);
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(1), 1), IsPruned::Pruned);
|
||||
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(21), 2), IsPruned::NotPruned);
|
||||
@@ -858,7 +821,7 @@ mod tests {
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let new_mode = PruningMode::Constrained(Constraints { max_blocks: Some(2), max_mem: None });
|
||||
let new_mode = PruningMode::Constrained(Constraints { max_blocks: Some(2) });
|
||||
let state_db_open_result: Result<(_, StateDb<H256, H256, TestDb>), _> =
|
||||
StateDb::open(db.clone(), Some(new_mode), false, false);
|
||||
assert!(state_db_open_result.is_err());
|
||||
|
||||
Reference in New Issue
Block a user