mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +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:
@@ -197,17 +197,6 @@ impl fmt::Display for MemorySize {
|
||||
}
|
||||
}
|
||||
|
||||
/// Memory statistics for state db.
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct StateDbMemoryInfo {
|
||||
/// Memory usage of the non-canonical overlay
|
||||
pub non_canonical: MemorySize,
|
||||
/// Memory usage of the pruning window.
|
||||
pub pruning: Option<MemorySize>,
|
||||
/// Memory usage of the pinned blocks.
|
||||
pub pinned: MemorySize,
|
||||
}
|
||||
|
||||
/// Memory statistics for client instance.
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct MemoryInfo {
|
||||
@@ -215,8 +204,6 @@ pub struct MemoryInfo {
|
||||
pub state_cache: MemorySize,
|
||||
/// Size of backend database cache.
|
||||
pub database_cache: MemorySize,
|
||||
/// Size of the state db.
|
||||
pub state_db: StateDbMemoryInfo,
|
||||
}
|
||||
|
||||
/// I/O statistics for client instance.
|
||||
@@ -264,13 +251,9 @@ impl fmt::Display for UsageInfo {
|
||||
write!(
|
||||
f,
|
||||
"caches: ({} state, {} db overlay), \
|
||||
state db: ({} non-canonical, {} pruning, {} pinned), \
|
||||
i/o: ({} tx, {} write, {} read, {} avg tx, {}/{} key cache reads/total, {} trie nodes writes)",
|
||||
self.memory.state_cache,
|
||||
self.memory.database_cache,
|
||||
self.memory.state_db.non_canonical,
|
||||
self.memory.state_db.pruning.unwrap_or_default(),
|
||||
self.memory.state_db.pinned,
|
||||
self.io.transactions,
|
||||
self.io.bytes_written,
|
||||
self.io.bytes_read,
|
||||
|
||||
@@ -17,9 +17,9 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = [
|
||||
"derive",
|
||||
] }
|
||||
hash-db = "0.15.2"
|
||||
kvdb = "0.12.0"
|
||||
kvdb-memorydb = "0.12.0"
|
||||
kvdb-rocksdb = { version = "0.16.0", optional = true }
|
||||
kvdb = "0.13.0"
|
||||
kvdb-memorydb = "0.13.0"
|
||||
kvdb-rocksdb = { version = "0.17.0", optional = true }
|
||||
linked-hash-map = "0.5.4"
|
||||
log = "0.4.17"
|
||||
parity-db = "0.4.2"
|
||||
@@ -36,7 +36,7 @@ sp-trie = { version = "7.0.0", path = "../../primitives/trie" }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3.3"
|
||||
kvdb-rocksdb = "0.16.0"
|
||||
kvdb-rocksdb = "0.17.0"
|
||||
rand = "0.8.4"
|
||||
tempfile = "3.1.0"
|
||||
quickcheck = { version = "1.0.3", default-features = false }
|
||||
|
||||
@@ -2086,10 +2086,9 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
let state_cache = MemorySize::from_bytes(
|
||||
self.shared_trie_cache.as_ref().map_or(0, |c| c.used_memory_size()),
|
||||
);
|
||||
let state_db = self.storage.state_db.memory_info();
|
||||
|
||||
Some(UsageInfo {
|
||||
memory: MemoryInfo { state_cache, database_cache, state_db },
|
||||
memory: MemoryInfo { state_cache, database_cache },
|
||||
io: IoInfo {
|
||||
transactions: io_stats.transactions,
|
||||
bytes_read: io_stats.bytes_read,
|
||||
|
||||
@@ -59,15 +59,11 @@ pub struct Cache<B: BlockT> {
|
||||
|
||||
struct LRUMap<K, V>(LinkedHashMap<K, V>, usize, usize);
|
||||
|
||||
/// Internal trait similar to `heapsize` but using
|
||||
/// a simply estimation.
|
||||
/// Internal trait similar to `heapsize` but using a simple estimation.
|
||||
///
|
||||
/// This should not be made public, it is implementation
|
||||
/// detail trait. If it need to become public please
|
||||
/// consider using `malloc_size_of`.
|
||||
/// This should not be made public, it is an implementation detail trait.
|
||||
trait EstimateSize {
|
||||
/// Return a size estimation of additional size needed
|
||||
/// to cache this struct (in bytes).
|
||||
/// Return a size estimation of the additional size needed to cache this struct (in bytes).
|
||||
fn estimate_size(&self) -> usize;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ ansi_term = "0.12.1"
|
||||
futures = "0.3.21"
|
||||
futures-timer = "3.0.1"
|
||||
log = "0.4.17"
|
||||
parity-util-mem = { version = "0.12.0", default-features = false, features = ["primitive-types"] }
|
||||
sc-client-api = { version = "4.0.0-dev", path = "../api" }
|
||||
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
|
||||
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../transaction-pool/api" }
|
||||
|
||||
@@ -22,10 +22,8 @@ use ansi_term::Colour;
|
||||
use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use log::{debug, info, trace};
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use sc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use sc_network_common::service::NetworkStatusProvider;
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use sp_runtime::traits::{Block as BlockT, Header};
|
||||
use std::{collections::VecDeque, fmt::Display, sync::Arc, time::Duration};
|
||||
@@ -53,16 +51,11 @@ impl Default for OutputFormat {
|
||||
}
|
||||
|
||||
/// Builds the informant and returns a `Future` that drives the informant.
|
||||
pub async fn build<B: BlockT, C, N, P>(
|
||||
client: Arc<C>,
|
||||
network: N,
|
||||
pool: Arc<P>,
|
||||
format: OutputFormat,
|
||||
) where
|
||||
pub async fn build<B: BlockT, C, N>(client: Arc<C>, network: N, format: OutputFormat)
|
||||
where
|
||||
N: NetworkStatusProvider<B>,
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
P: TransactionPool + MallocSizeOf,
|
||||
{
|
||||
let mut display = display::InformantDisplay::new(format.clone());
|
||||
|
||||
@@ -83,11 +76,6 @@ pub async fn build<B: BlockT, C, N, P>(
|
||||
"Usage statistics not displayed as backend does not provide it",
|
||||
)
|
||||
}
|
||||
trace!(
|
||||
target: "usage",
|
||||
"Subsystems memory [txpool: {} kB]",
|
||||
parity_util_mem::malloc_size(&*pool) / 1024,
|
||||
);
|
||||
display.display(&info, net_status);
|
||||
future::ready(())
|
||||
});
|
||||
|
||||
@@ -80,9 +80,6 @@ sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
|
||||
sc-sysinfo = { version = "6.0.0-dev", path = "../sysinfo" }
|
||||
tracing = "0.1.29"
|
||||
tracing-futures = { version = "0.2.4" }
|
||||
parity-util-mem = { version = "0.12.0", default-features = false, features = [
|
||||
"primitive-types",
|
||||
] }
|
||||
async-trait = "0.1.57"
|
||||
tokio = { version = "1.22.0", features = ["time", "rt-multi-thread", "parking_lot"] }
|
||||
tempfile = "3.1.0"
|
||||
|
||||
@@ -436,9 +436,7 @@ where
|
||||
TBl::Hash: Unpin,
|
||||
TBl::Header: Unpin,
|
||||
TBackend: 'static + sc_client_api::backend::Backend<TBl> + Send,
|
||||
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash>
|
||||
+ parity_util_mem::MallocSizeOf
|
||||
+ 'static,
|
||||
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static,
|
||||
{
|
||||
let SpawnTasksParams {
|
||||
mut config,
|
||||
@@ -540,12 +538,7 @@ where
|
||||
spawn_handle.spawn(
|
||||
"informant",
|
||||
None,
|
||||
sc_informant::build(
|
||||
client.clone(),
|
||||
network,
|
||||
transaction_pool.clone(),
|
||||
config.informant_output_format,
|
||||
),
|
||||
sc_informant::build(client.clone(), network, config.informant_output_format),
|
||||
);
|
||||
|
||||
task_manager.keep_alive((config.base_path, rpc));
|
||||
|
||||
@@ -43,7 +43,6 @@ struct PrometheusMetrics {
|
||||
// I/O
|
||||
database_cache: Gauge<U64>,
|
||||
state_cache: Gauge<U64>,
|
||||
state_db: GaugeVec<U64>,
|
||||
}
|
||||
|
||||
impl PrometheusMetrics {
|
||||
@@ -117,13 +116,6 @@ impl PrometheusMetrics {
|
||||
Gauge::new("substrate_state_cache_bytes", "State cache size in bytes")?,
|
||||
registry,
|
||||
)?,
|
||||
state_db: register(
|
||||
GaugeVec::new(
|
||||
Opts::new("substrate_state_db_cache_bytes", "State DB cache in bytes"),
|
||||
&["subtype"],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -254,18 +246,6 @@ impl MetricsService {
|
||||
if let Some(info) = info.usage.as_ref() {
|
||||
metrics.database_cache.set(info.memory.database_cache.as_bytes() as u64);
|
||||
metrics.state_cache.set(info.memory.state_cache.as_bytes() as u64);
|
||||
|
||||
metrics
|
||||
.state_db
|
||||
.with_label_values(&["non_canonical"])
|
||||
.set(info.memory.state_db.non_canonical.as_bytes() as u64);
|
||||
if let Some(pruning) = info.memory.state_db.pruning {
|
||||
metrics.state_db.with_label_values(&["pruning"]).set(pruning.as_bytes() as u64);
|
||||
}
|
||||
metrics
|
||||
.state_db
|
||||
.with_label_values(&["pinned"])
|
||||
.set(info.memory.state_db.pinned.as_bytes() as u64);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
|
||||
log = "0.4.17"
|
||||
parity-util-mem = { version = "0.12.0", default-features = false, features = ["primitive-types"] }
|
||||
parity-util-mem-derive = "0.1.0"
|
||||
parking_lot = "0.12.1"
|
||||
sc-client-api = { version = "4.0.0-dev", path = "../api" }
|
||||
sp-core = { version = "7.0.0", path = "../../primitives/core" }
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -30,7 +30,6 @@ pub(crate) const LAST_CANONICAL: &[u8] = b"last_canonical";
|
||||
const MAX_BLOCKS_PER_LEVEL: u64 = 32;
|
||||
|
||||
/// See module documentation.
|
||||
#[derive(parity_util_mem_derive::MallocSizeOf)]
|
||||
pub struct NonCanonicalOverlay<BlockHash: Hash, Key: Hash> {
|
||||
last_canonicalized: Option<(BlockHash, u64)>,
|
||||
levels: VecDeque<OverlayLevel<BlockHash, Key>>,
|
||||
@@ -41,7 +40,6 @@ pub struct NonCanonicalOverlay<BlockHash: Hash, Key: Hash> {
|
||||
pinned_insertions: HashMap<BlockHash, (Vec<Key>, u32)>,
|
||||
}
|
||||
|
||||
#[derive(parity_util_mem_derive::MallocSizeOf)]
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
struct OverlayLevel<BlockHash: Hash, Key: Hash> {
|
||||
blocks: Vec<BlockOverlay<BlockHash, Key>>,
|
||||
@@ -81,7 +79,6 @@ fn to_journal_key(block: u64, index: u64) -> Vec<u8> {
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
#[derive(parity_util_mem_derive::MallocSizeOf)]
|
||||
struct BlockOverlay<BlockHash: Hash, Key: Hash> {
|
||||
hash: BlockHash,
|
||||
journal_index: u64,
|
||||
|
||||
@@ -36,7 +36,6 @@ pub(crate) const LAST_PRUNED: &[u8] = b"last_pruned";
|
||||
const PRUNING_JOURNAL: &[u8] = b"pruning_journal";
|
||||
|
||||
/// See module documentation.
|
||||
#[derive(parity_util_mem_derive::MallocSizeOf)]
|
||||
pub struct RefWindow<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
/// A queue of blocks keep tracking keys that should be deleted for each block in the
|
||||
/// pruning window.
|
||||
@@ -50,7 +49,6 @@ pub struct RefWindow<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
/// blocks in memory, and keep track of re-inserted keys to not delete them when pruning
|
||||
/// - `DbBacked`, used when the backend database supports reference counting, only keep
|
||||
/// a few number of blocks in memory and load more blocks on demand
|
||||
#[derive(parity_util_mem_derive::MallocSizeOf)]
|
||||
enum DeathRowQueue<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
Mem {
|
||||
/// A queue of keys that should be deleted for each block in the pruning window.
|
||||
@@ -60,7 +58,6 @@ enum DeathRowQueue<BlockHash: Hash, Key: Hash, D: MetaDb> {
|
||||
},
|
||||
DbBacked {
|
||||
// The backend database
|
||||
#[ignore_malloc_size_of = "Shared data"]
|
||||
db: D,
|
||||
/// A queue of keys that should be deleted for each block in the pruning window.
|
||||
/// Only caching the first few blocks of the pruning window, blocks inside are
|
||||
@@ -251,7 +248,7 @@ fn load_death_row_from_db<BlockHash: Hash, Key: Hash, D: MetaDb>(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, parity_util_mem_derive::MallocSizeOf)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
struct DeathRow<BlockHash: Hash, Key: Hash> {
|
||||
hash: BlockHash,
|
||||
deleted: HashSet<Key>,
|
||||
@@ -345,10 +342,6 @@ impl<BlockHash: Hash, Key: Hash, D: MetaDb> RefWindow<BlockHash, Key, D> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn mem_used(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.window_size() == 0
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ futures = "0.3.21"
|
||||
futures-timer = "3.0.2"
|
||||
linked-hash-map = "0.5.4"
|
||||
log = "0.4.17"
|
||||
parity-util-mem = { version = "0.12.0", default-features = false, features = ["primitive-types"] }
|
||||
parking_lot = "0.12.1"
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
thiserror = "1.0.30"
|
||||
|
||||
@@ -84,7 +84,7 @@ pub struct PruneStatus<Hash, Ex> {
|
||||
|
||||
/// Immutable transaction
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
#[derive(PartialEq, Eq, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct Transaction<Hash, Extrinsic> {
|
||||
/// Raw extrinsic representing that transaction.
|
||||
pub data: Extrinsic,
|
||||
@@ -207,7 +207,7 @@ const RECENTLY_PRUNED_TAGS: usize = 2;
|
||||
/// as-is for the second time will fail or produce unwanted results.
|
||||
/// Most likely it is required to revalidate them and recompute set of
|
||||
/// required tags.
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct BasePool<Hash: hash::Hash + Eq, Ex> {
|
||||
reject_future_transactions: bool,
|
||||
future: FutureTransactions<Hash, Ex>,
|
||||
@@ -796,27 +796,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_track_heap_size() {
|
||||
let mut pool = pool();
|
||||
pool.import(Transaction {
|
||||
data: vec![5u8; 1024],
|
||||
hash: 5,
|
||||
provides: vec![vec![0], vec![4]],
|
||||
..DEFAULT_TX.clone()
|
||||
})
|
||||
.expect("import 1 should be ok");
|
||||
pool.import(Transaction {
|
||||
data: vec![3u8; 1024],
|
||||
hash: 7,
|
||||
provides: vec![vec![2], vec![7]],
|
||||
..DEFAULT_TX.clone()
|
||||
})
|
||||
.expect("import 2 should be ok");
|
||||
|
||||
assert!(parity_util_mem::malloc_size(&pool) > 5000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_remove_invalid_transactions() {
|
||||
// given
|
||||
|
||||
@@ -28,7 +28,6 @@ use std::time::Instant;
|
||||
|
||||
use super::base_pool::Transaction;
|
||||
|
||||
#[derive(parity_util_mem::MallocSizeOf)]
|
||||
/// Transaction with partially satisfied dependencies.
|
||||
pub struct WaitingTransaction<Hash, Ex> {
|
||||
/// Transaction details.
|
||||
@@ -108,7 +107,7 @@ impl<Hash, Ex> WaitingTransaction<Hash, Ex> {
|
||||
///
|
||||
/// Contains transactions that are still awaiting for some other transactions that
|
||||
/// could provide a tag that they require.
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct FutureTransactions<Hash: hash::Hash + Eq, Ex> {
|
||||
/// tags that are not yet provided by any transaction and we await for them
|
||||
wanted_tags: HashMap<Tag, HashSet<Hash>>,
|
||||
@@ -251,33 +250,3 @@ impl<Hash: hash::Hash + Eq + Clone, Ex> FutureTransactions<Hash, Ex> {
|
||||
self.waiting.values().fold(0, |acc, tx| acc + tx.transaction.bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::transaction_validity::TransactionSource;
|
||||
|
||||
#[test]
|
||||
fn can_track_heap_size() {
|
||||
let mut future = FutureTransactions::default();
|
||||
future.import(WaitingTransaction {
|
||||
transaction: Transaction {
|
||||
data: vec![0u8; 1024],
|
||||
bytes: 1,
|
||||
hash: 1,
|
||||
priority: 1,
|
||||
valid_till: 2,
|
||||
requires: vec![vec![1], vec![2]],
|
||||
provides: vec![vec![3], vec![4]],
|
||||
propagate: true,
|
||||
source: TransactionSource::External,
|
||||
}
|
||||
.into(),
|
||||
missing_tags: vec![vec![1u8], vec![2u8]].into_iter().collect(),
|
||||
imported_at: std::time::Instant::now(),
|
||||
});
|
||||
|
||||
// data is at least 1024!
|
||||
assert!(parity_util_mem::malloc_size(&future) > 1024);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,15 +144,6 @@ pub struct Pool<B: ChainApi> {
|
||||
validated_pool: Arc<ValidatedPool<B>>,
|
||||
}
|
||||
|
||||
impl<B: ChainApi> parity_util_mem::MallocSizeOf for Pool<B>
|
||||
where
|
||||
ExtrinsicFor<B>: parity_util_mem::MallocSizeOf,
|
||||
{
|
||||
fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize {
|
||||
self.validated_pool.size_of(ops)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: ChainApi> Pool<B> {
|
||||
/// Create a new transaction pool.
|
||||
pub fn new(options: Options, is_validator: IsValidator, api: Arc<B>) -> Self {
|
||||
|
||||
@@ -37,7 +37,7 @@ use super::{
|
||||
/// An in-pool transaction reference.
|
||||
///
|
||||
/// Should be cheap to clone.
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct TransactionRef<Hash, Ex> {
|
||||
/// The actual transaction data.
|
||||
pub transaction: Arc<Transaction<Hash, Ex>>,
|
||||
@@ -74,7 +74,7 @@ impl<Hash, Ex> PartialEq for TransactionRef<Hash, Ex> {
|
||||
}
|
||||
impl<Hash, Ex> Eq for TransactionRef<Hash, Ex> {}
|
||||
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct ReadyTx<Hash, Ex> {
|
||||
/// A reference to a transaction
|
||||
pub transaction: TransactionRef<Hash, Ex>,
|
||||
@@ -105,7 +105,7 @@ qed
|
||||
"#;
|
||||
|
||||
/// Validated transactions that are block ready with all their dependencies met.
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct ReadyTransactions<Hash: hash::Hash + Eq, Ex> {
|
||||
/// Next free insertion id (used to indicate when a transaction was inserted into the pool).
|
||||
insertion_id: u64,
|
||||
@@ -742,25 +742,6 @@ mod tests {
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_report_heap_size() {
|
||||
let mut ready = ReadyTransactions::default();
|
||||
let tx = Transaction {
|
||||
data: vec![5],
|
||||
bytes: 1,
|
||||
hash: 5,
|
||||
priority: 1,
|
||||
valid_till: u64::MAX, // use the max here for testing.
|
||||
requires: vec![],
|
||||
provides: vec![],
|
||||
propagate: true,
|
||||
source: Source::External,
|
||||
};
|
||||
import(&mut ready, tx).unwrap();
|
||||
|
||||
assert!(parity_util_mem::malloc_size(&ready) > 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_order_refs() {
|
||||
let mut id = 1;
|
||||
|
||||
@@ -33,7 +33,7 @@ pub trait Size {
|
||||
/// Map with size tracking.
|
||||
///
|
||||
/// Size reported might be slightly off and only approximately true.
|
||||
#[derive(Debug, parity_util_mem::MallocSizeOf)]
|
||||
#[derive(Debug)]
|
||||
pub struct TrackedMap<K, V> {
|
||||
index: Arc<RwLock<HashMap<K, V>>>,
|
||||
bytes: AtomicIsize,
|
||||
|
||||
@@ -110,16 +110,6 @@ pub struct ValidatedPool<B: ChainApi> {
|
||||
rotator: PoolRotator<ExtrinsicHash<B>>,
|
||||
}
|
||||
|
||||
impl<B: ChainApi> parity_util_mem::MallocSizeOf for ValidatedPool<B>
|
||||
where
|
||||
ExtrinsicFor<B>: parity_util_mem::MallocSizeOf,
|
||||
{
|
||||
fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize {
|
||||
// other entries insignificant or non-primary references
|
||||
self.pool.size_of(ops)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: ChainApi> ValidatedPool<B> {
|
||||
/// Create a new transaction pool.
|
||||
pub fn new(options: Options, is_validator: IsValidator, api: Arc<B>) -> Self {
|
||||
|
||||
@@ -135,17 +135,6 @@ impl<T, Block: BlockT> ReadyPoll<T, Block> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<PoolApi, Block> parity_util_mem::MallocSizeOf for BasicPool<PoolApi, Block>
|
||||
where
|
||||
PoolApi: graph::ChainApi<Block = Block>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize {
|
||||
// other entries insignificant or non-primary references
|
||||
self.pool.size_of(ops)
|
||||
}
|
||||
}
|
||||
|
||||
/// Type of revalidation.
|
||||
pub enum RevalidationType {
|
||||
/// Light revalidation type.
|
||||
|
||||
@@ -440,17 +440,6 @@ fn should_push_watchers_during_maintenance() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_track_heap_size() {
|
||||
let (pool, _api, _guard) = maintained_pool();
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).expect("1. Imported");
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 210))).expect("1. Imported");
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 211))).expect("1. Imported");
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 212))).expect("1. Imported");
|
||||
|
||||
assert!(parity_util_mem::malloc_size(&pool) > 3000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finalization() {
|
||||
let xt = uxt(Alice, 209);
|
||||
|
||||
Reference in New Issue
Block a user