Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utxo counts #422

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3bceedf
start
D-Stacks Jan 26, 2024
7fb5814
Merge branch 'master' into utxo-counts
D-Stacks Jan 26, 2024
5d28c8c
clippy lints
D-Stacks Jan 26, 2024
9f1eade
fmt
D-Stacks Jan 26, 2024
5eb2e7a
fmt
D-Stacks Jan 26, 2024
2e5e4b7
updated some namings .
D-Stacks Jan 27, 2024
7ef67a5
better logs some more.
D-Stacks Jan 27, 2024
5e8c5f3
better new store init.
D-Stacks Jan 27, 2024
77b28bc
some more betterments.
D-Stacks Jan 27, 2024
2bc46c6
some fixes + sanity checks.
D-Stacks Jan 28, 2024
27b902a
some fixes + commented out sanity checks.
D-Stacks Jan 28, 2024
849df8a
fmt
D-Stacks Jan 28, 2024
e844731
fix output with batch size.
D-Stacks Jan 28, 2024
d0fdaf9
renable sanity checks and filter for dups with same daa.
D-Stacks Feb 1, 2024
a06906b
renable sanity checks and filter for dups with same daa.
D-Stacks Feb 1, 2024
aec9712
fmt
D-Stacks Feb 1, 2024
281e20c
simplify.
D-Stacks Feb 1, 2024
1f77d9f
fix sanity tests to read from db, not cache.
D-Stacks Feb 16, 2024
5bee211
add sanity check every 10k resolve virtuals.
D-Stacks Feb 16, 2024
463efaa
clean-up, better init code, add to rpc.
D-Stacks Feb 17, 2024
b99ed79
feat: import golang-based wallet account (#413)
biryukovmaxim Feb 15, 2024
374ee2f
fix lints. (#421)
D-Stacks Feb 15, 2024
d7a9a6b
rename to count, more clean up, make start-up sanity optional.
D-Stacks Feb 17, 2024
95cbbda
rename to count, more clean up, make start-up sanity optional.
D-Stacks Feb 17, 2024
b268f30
one more clean-up.
D-Stacks Feb 17, 2024
6719344
Merge branch 'master' into utxo-counts
D-Stacks Feb 17, 2024
651b723
fmt.
D-Stacks Feb 17, 2024
c4a1f24
Be explicit about supply in sompi, to avoid confustion.
D-Stacks Feb 17, 2024
f6ba55e
Merge branch 'master' into utxo-counts
D-Stacks Mar 12, 2024
cb4857c
Merge branch 'master' into utxo-counts
D-Stacks Mar 20, 2024
bca388c
Merge branch 'master' into utxo-counts
D-Stacks Mar 21, 2024
d24b2c1
Merge branch 'master' into utxo-counts
D-Stacks Mar 26, 2024
44b6a68
Merge branch 'master' into utxo-counts
D-Stacks Apr 23, 2024
b8546de
Merge branch 'master' into utxo-counts
D-Stacks May 30, 2024
ff29b23
Merge branch 'master' into utxo-counts
D-Stacks Jul 1, 2024
85bc7f2
Merge branch 'dev' of https://github.com/kaspanet/rusty-kaspa into ut…
D-Stacks Aug 28, 2024
32741f1
add to wrpc versioning thing.
D-Stacks Aug 28, 2024
72f54c8
fix tests, and lints.
D-Stacks Aug 28, 2024
e0ff029
fix lints again.
D-Stacks Aug 28, 2024
a23209a
Merge branch 'dev' into utxo-counts
D-Stacks Sep 1, 2024
ca1e550
Merge branch 'dev' into utxo-counts
D-Stacks Sep 2, 2024
8be0e84
Merge branch 'dev' into utxo-counts
D-Stacks Sep 2, 2024
a1f3726
Merge branch 'dev' into utxo-counts
D-Stacks Sep 10, 2024
29a52bd
Merge branch 'dev' into utxo-counts
D-Stacks Sep 11, 2024
18e06e3
Merge branch 'master' into utxo-counts
D-Stacks Sep 11, 2024
2224327
Merge branch 'master' into utxo-counts
D-Stacks Sep 12, 2024
124bd80
Merge branch 'master' into utxo-counts
D-Stacks Sep 15, 2024
c2794ff
Merge branch 'master' into utxo-counts
D-Stacks Sep 26, 2024
cd271a1
Merge branch 'master' into utxo-counts
D-Stacks Sep 30, 2024
e7873b6
Merge branch 'master' into utxo-counts
D-Stacks Oct 8, 2024
b23932b
Merge branch 'master' into utxo-counts
D-Stacks Oct 15, 2024
558d718
Merge branch 'master' into utxo-counts
D-Stacks Oct 22, 2024
f254784
Merge branch 'master' into utxo-counts
D-Stacks Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,36 @@ impl KaspaCli {
.join(" "),
)
}
SyncState::UtxoSync { total, .. } => {
Some([style("SYNC UTXO").red().to_string(), style(total.separated_string()).dim().to_string()].join(" "))
SyncState::PruningPointUTXOs { processed, total } => {
let progress = (*processed as f64 / *total as f64).round() as u64;
Some(
[
style("SYNC IBD Pruning Point UTXOs ").red().to_string(),
style(format!("{} ({}%)", processed.separated_string(), progress)).dim().to_string(),
]
.join(" "),
)
}
SyncState::VirtualUTXOs { processed, total } => {
let progress = (*processed as f64 / *total as f64).round() as u64;
Some(
[
style("SYNC Virtual UTXOs").red().to_string(),
style(format!("{} ({}%)", processed.separated_string(), progress)).dim().to_string(),
]
.join(" "),
)
}
SyncState::UtxoIndexUTXOs { processed, total } => {
let progress = (*processed as f64 / *total as f64).round() as u64;
Some(
[
style("SYNC UtxoIndex UTXOs").red().to_string(),
style(format!("{} ({}%)", processed.separated_string(), progress)).dim().to_string(),
]
.join(" "),
)
}
SyncState::UtxoResync => Some([style("SYNC").red().to_string(), style("UTXO").black().to_string()].join(" ")),
SyncState::NotSynced => Some([style("SYNC").red().to_string(), style("...").black().to_string()].join(" ")),
SyncState::Synced { .. } => None,
}
Expand Down
8 changes: 8 additions & 0 deletions components/consensusmanager/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ impl ConsensusSessionOwned {
self.clone().spawn_blocking(move |c| c.get_virtual_utxos(from_outpoint, chunk_size, skip_first)).await
}

pub async fn async_get_virtual_utxoset_count(&self) -> u64 {
self.clone().spawn_blocking(|c| c.get_virtual_utxoset_count()).await
}

pub async fn async_get_tips(&self) -> Vec<Hash> {
self.clone().spawn_blocking(|c| c.get_tips()).await
}
Expand Down Expand Up @@ -409,6 +413,10 @@ impl ConsensusSessionOwned {
.await
}

pub async fn async_get_pruning_point_utxoset_count(&self) -> u64 {
self.clone().spawn_blocking(|c| c.get_pruning_point_utxoset_count()).await
}

pub async fn async_get_missing_block_body_hashes(&self, high: Hash) -> ConsensusResult<Vec<Hash>> {
self.clone().spawn_blocking(move |c| c.get_missing_block_body_hashes(high)).await
}
Expand Down
8 changes: 8 additions & 0 deletions consensus/core/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pub trait ConsensusApi: Send + Sync {
unimplemented!()
}

fn get_virtual_utxoset_count(&self) -> u64 {
unimplemented!()
}

fn get_tips(&self) -> Vec<Hash> {
unimplemented!()
}
Expand Down Expand Up @@ -324,6 +328,10 @@ pub trait ConsensusApi: Send + Sync {
unimplemented!()
}

fn get_pruning_point_utxoset_count(&self) -> u64 {
unimplemented!()
}

fn get_missing_block_body_hashes(&self, high: Hash) -> ConsensusResult<Vec<Hash>> {
unimplemented!()
}
Expand Down
8 changes: 8 additions & 0 deletions consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ impl ConsensusApi for Consensus {
iter.map(|item| item.unwrap()).collect()
}

fn get_virtual_utxoset_count(&self) -> u64 {
self.virtual_stores.read().utxo_set.num_of_entries().unwrap()
}

fn get_tips(&self) -> Vec<Hash> {
self.body_tips_store.read().get().unwrap().read().iter().copied().collect_vec()
}
Expand Down Expand Up @@ -748,6 +752,10 @@ impl ConsensusApi for Consensus {
Ok(utxos)
}

fn get_pruning_point_utxoset_count(&self) -> u64 {
self.pruning_utxoset_stores.read().utxo_set.num_of_entries().unwrap()
}

fn modify_coinbase_payload(&self, payload: Vec<u8>, miner_data: &MinerData) -> CoinbaseResult<Vec<u8>> {
self.services.coinbase_manager.modify_coinbase_payload(payload, miner_data)
}
Expand Down
30 changes: 30 additions & 0 deletions consensus/src/consensus/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
tips::DbTipsStore,
utxo_diffs::DbUtxoDiffsStore,
utxo_multisets::DbUtxoMultisetsStore,
utxo_set::{self, UtxoSetStoreReader},
virtual_state::{LkgVirtualState, VirtualStores},
DB,
},
Expand All @@ -28,6 +29,7 @@ use crate::{
use super::cache_policy_builder::CachePolicyBuilder as PolicyBuilder;
use itertools::Itertools;
use kaspa_consensus_core::{blockstatus::BlockStatus, BlockHashSet};
use kaspa_core::info;
use kaspa_database::registry::DatabaseStorePrefixes;
use kaspa_hashes::Hash;
use parking_lot::RwLock;
Expand Down Expand Up @@ -231,6 +233,34 @@ impl ConsensusStorage {
reachability::init(reachability_store.write().deref_mut()).unwrap();
relations::init(reachability_relations_store.write().deref_mut());

// Ensure that the the `num_of_entries`` cached items are initialized for the utxo set stores.
// TODO: below inits should be removable with the next HF, a once off init should suffice.
if utxo_set::init(&mut pruning_utxoset_stores.write().utxo_set).unwrap() {
info!(
"Initialized the `num_of_entries` cached item db for the pruning utxoset with {0} entries",
pruning_utxoset_stores.write().utxo_set.num_of_entries().unwrap()
);
}

if utxo_set::init(&mut virtual_stores.write().utxo_set).unwrap() {
info!(
"Initialized the `num_of_entries` cached item db for the virtual utxoset with {0} entries",
virtual_stores.write().utxo_set.num_of_entries().unwrap()
);
}

// Sanity checks:
if config.enable_sanity_checks {
info!("Running sanity checks on the consensus storage, this may take a while...");
assert_eq!(
pruning_utxoset_stores.read().utxo_set.num_of_entries().unwrap(),
pruning_utxoset_stores.read().utxo_set.iterator().count() as u64
);
assert_eq!(
virtual_stores.read().utxo_set.num_of_entries().unwrap(),
virtual_stores.read().utxo_set.iterator().count() as u64
);
}
Arc::new(Self {
db,
statuses_store,
Expand Down
7 changes: 6 additions & 1 deletion consensus/src/model/stores/pruning_utxoset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ pub struct PruningUtxosetStores {
impl PruningUtxosetStores {
pub fn new(db: Arc<DB>, utxoset_cache_policy: CachePolicy) -> Self {
Self {
utxo_set: DbUtxoSetStore::new(db.clone(), utxoset_cache_policy, DatabaseStorePrefixes::PruningUtxoset.into()),
utxo_set: DbUtxoSetStore::new(
db.clone(),
utxoset_cache_policy,
DatabaseStorePrefixes::PruningUtxoset.into(),
DatabaseStorePrefixes::PruningUtxosetCount.into(),
),
utxoset_position_access: CachedDbItem::new(db, DatabaseStorePrefixes::PruningUtxosetPosition.into()),
}
}
Expand Down
Loading