33
44use chrono:: { TimeZone , Utc } ;
55use std:: {
6+ env,
67 mem:: size_of,
8+ path:: PathBuf ,
9+ process,
710 sync:: Arc ,
811 time:: { SystemTime , UNIX_EPOCH } ,
912} ;
@@ -30,62 +33,31 @@ use kaspad_lib::daemon::{get_app_dir, CONSENSUS_DB, DEFAULT_DATA_DIR, META_DB, U
3033fn main ( ) {
3134 kaspa_core:: log:: init_logger ( None , "" ) ;
3235 let network = NetworkId :: new ( NetworkType :: Mainnet ) ;
33- let app_dir = get_app_dir ( ) ;
34- let db_dir = app_dir. join ( network. to_prefixed ( ) ) . join ( DEFAULT_DATA_DIR ) ;
35- let consensus_db_dir = db_dir. join ( CONSENSUS_DB ) . join ( "consensus-002" ) ; // check your own index
36- // let utxoindex_db_dir = db_dir.join(UTXOINDEX_DB);
37- // let meta_db_dir = db_dir.join(META_DB);
36+ // Require a consensus DB path as the first argument. If not provided, print usage and exit.
37+ // Usage: cargo run --package rocknroll --bin rocknroll -- <path-to-consensus-db>
38+ let consensus_db_dir: PathBuf = match env:: args ( ) . nth ( 1 ) {
39+ Some ( p) => PathBuf :: from ( p) ,
40+ None => {
41+ let prog = env:: args ( ) . next ( ) . unwrap_or_else ( || "rocknroll" . to_string ( ) ) ;
42+ eprintln ! ( "Usage: {} <consensus-db-path>" , prog) ;
43+ eprintln ! ( "Example: {} /home/user/.rusty-kaspa/kaspa-mainnet/datadir/consensus/consensus-001" , prog) ;
44+ process:: exit ( 1 ) ;
45+ }
46+ } ;
3847
3948 let config = Arc :: new ( ConfigBuilder :: new ( network. into ( ) ) . adjust_perf_params_to_consensus_params ( ) . build ( ) ) ;
4049 let db =
4150 kaspa_database:: prelude:: ConnBuilder :: default ( ) . with_db_path ( consensus_db_dir) . with_files_limit ( 128 ) . build_readonly ( ) . unwrap ( ) ;
4251
4352 let storage = ConsensusStorage :: new ( db. clone ( ) , config. clone ( ) ) ;
44- let services = ConsensusServices :: new ( db, storage. clone ( ) , config, Default :: default ( ) , Default :: default ( ) ) ;
45-
46- let start_datetime = Utc . with_ymd_and_hms ( 2025 , 10 , 5 , 0 , 0 , 0 ) . unwrap ( ) ;
47- let end_datetime = Utc . with_ymd_and_hms ( 2025 , 10 , 6 , 0 , 0 , 0 ) . unwrap ( ) ;
48- let start: SystemTime = start_datetime. into ( ) ;
49- let end: SystemTime = end_datetime. into ( ) ;
5053
5154 let pp = storage. pruning_point_store . read ( ) . pruning_point ( ) . unwrap ( ) ;
5255 let sink = storage. lkg_virtual_state . load ( ) . ghostdag_data . selected_parent ;
56+ let retention_root = storage. pruning_point_store . read ( ) . retention_period_root ( ) . unwrap ( ) ;
5357
54- let ( start, end) =
55- ( start. duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_millis ( ) as u64 , end. duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_millis ( ) as u64 ) ;
56- let mut count = 0 ;
57-
58- let mut fee = 0 ;
59-
60- for cb in services. reachability_service . forward_chain_iterator ( pp, sink, false ) {
61- let timestamp = storage. headers_store . get_timestamp ( cb) . unwrap ( ) ;
62- if start <= timestamp && timestamp < end {
63- let ad = storage. acceptance_data_store . get ( cb) . unwrap ( ) ;
64- let ( cb_accepted_fees, mergeset_accepted_txs_count) = ad
65- . iter ( )
66- . map ( |d| {
67- let cb_accepted_fees = calc_fees_in_cb ( cb, d, ad. clone ( ) , storage. clone ( ) ) ;
68-
69- ( cb_accepted_fees, d. accepted_transactions . len ( ) )
70- } )
71- . reduce ( |( a, b) , ( c, d) | ( a + c, b + d) )
72- . unwrap ( ) ;
73-
74- fee += cb_accepted_fees;
75- count += mergeset_accepted_txs_count;
76- if ( count - mergeset_accepted_txs_count) / 10_000_000 != count / 10_000_000 {
77- info ! ( "Accepted txs in range: {}" , count) ;
78- info ! ( "Fees paid: {}" , fee) ;
79- }
80- }
81- }
82- info ! (
83- "\n =======================================\n \t Accepted txs in range {} - {}: {}\n =======================================" ,
84- start_datetime. format( "%d/%m/%Y %H:%M" ) ,
85- end_datetime. format( "%d/%m/%Y %H:%M" ) ,
86- count
87- ) ;
88- info ! ( "Fees paid: {}" , fee) ;
58+ println ! ( "Pruning Point: {}" , pp) ;
59+ println ! ( "Sink: {}" , sink) ;
60+ println ! ( "Retention Root: {}" , retention_root) ;
8961}
9062
9163fn calc_fees_in_cb (
0 commit comments