-
Notifications
You must be signed in to change notification settings - Fork 5
feat: update snapshot parser for mark/set/go #434
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| target | ||
| README.html | ||
| restore.sh | ||
| startup.sh | ||
| configuration/ | ||
| docker-compose.yaml | ||
|
|
||
| # Nix | ||
| result | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ bs58 = "0.5" | |||
| chrono = { workspace = true } | ||||
| crc = "3" | ||||
| hex = { workspace = true } | ||||
| log = "0.4" | ||||
|
||||
| log = "0.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I couldn't get it working with tracing. Needed log.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,15 +2,17 @@ | |||||||||||||
| // | ||||||||||||||
| // Usage: cargo run --example test_streaming_parser --release -- <snapshot_path> | ||||||||||||||
|
|
||||||||||||||
| use acropolis_common::snapshot::streaming_snapshot::{ | ||||||||||||||
| use acropolis_common::snapshot::{ | ||||||||||||||
| AccountState, DRepCallback, DRepInfo, GovernanceProposal, PoolCallback, PoolInfo, | ||||||||||||||
| ProposalCallback, SnapshotCallbacks, SnapshotMetadata, StakeCallback, StreamingSnapshotParser, | ||||||||||||||
| UtxoCallback, UtxoEntry, | ||||||||||||||
| ProposalCallback, RawSnapshotsContainer, SnapshotCallbacks, SnapshotMetadata, | ||||||||||||||
| SnapshotsCallback, StakeCallback, StreamingSnapshotParser, UtxoCallback, UtxoEntry, | ||||||||||||||
| }; | ||||||||||||||
| use anyhow::Result; | ||||||||||||||
| use std::env; | ||||||||||||||
| use std::time::Instant; | ||||||||||||||
|
|
||||||||||||||
| use env_logger::Env; | ||||||||||||||
|
|
||||||||||||||
| // Simple counter callback that doesn't store data in memory | ||||||||||||||
| #[derive(Default)] | ||||||||||||||
| struct CountingCallbacks { | ||||||||||||||
|
|
@@ -55,7 +57,7 @@ impl UtxoCallback for CountingCallbacks { | |||||||||||||
| impl PoolCallback for CountingCallbacks { | ||||||||||||||
| fn on_pools(&mut self, pools: Vec<PoolInfo>) -> Result<()> { | ||||||||||||||
| self.pool_count = pools.len(); | ||||||||||||||
| eprintln!("✓ Parsed {} stake pools", pools.len()); | ||||||||||||||
| eprintln!("Parsed {} stake pools", pools.len()); | ||||||||||||||
|
|
||||||||||||||
| // Show first 10 pools | ||||||||||||||
| for (i, pool) in pools.iter().take(10).enumerate() { | ||||||||||||||
|
|
@@ -79,7 +81,7 @@ impl StakeCallback for CountingCallbacks { | |||||||||||||
| fn on_accounts(&mut self, accounts: Vec<AccountState>) -> Result<()> { | ||||||||||||||
| self.account_count = accounts.len(); | ||||||||||||||
| if !accounts.is_empty() { | ||||||||||||||
| eprintln!("✓ Parsed {} stake accounts", accounts.len()); | ||||||||||||||
| eprintln!("Parsed {} stake accounts", accounts.len()); | ||||||||||||||
|
|
||||||||||||||
| // Show first 10 accounts | ||||||||||||||
| for (i, account) in accounts.iter().take(10).enumerate() { | ||||||||||||||
|
|
@@ -104,7 +106,7 @@ impl StakeCallback for CountingCallbacks { | |||||||||||||
| impl DRepCallback for CountingCallbacks { | ||||||||||||||
| fn on_dreps(&mut self, dreps: Vec<DRepInfo>) -> Result<()> { | ||||||||||||||
| self.drep_count = dreps.len(); | ||||||||||||||
| eprintln!("✓ Parsed {} DReps", self.drep_count); | ||||||||||||||
| eprintln!("Parsed {} DReps", self.drep_count); | ||||||||||||||
|
|
||||||||||||||
| // Show first 10 DReps | ||||||||||||||
| for (i, drep) in dreps.iter().take(10).enumerate() { | ||||||||||||||
|
|
@@ -136,7 +138,7 @@ impl ProposalCallback for CountingCallbacks { | |||||||||||||
| fn on_proposals(&mut self, proposals: Vec<GovernanceProposal>) -> Result<()> { | ||||||||||||||
| self.proposal_count = proposals.len(); | ||||||||||||||
| if !proposals.is_empty() { | ||||||||||||||
| eprintln!("✓ Parsed {} governance proposals", proposals.len()); | ||||||||||||||
| eprintln!("Parsed {} governance proposals", proposals.len()); | ||||||||||||||
|
|
||||||||||||||
| // Show first 10 proposals | ||||||||||||||
| for (i, proposal) in proposals.iter().take(10).enumerate() { | ||||||||||||||
|
|
@@ -159,22 +161,22 @@ impl ProposalCallback for CountingCallbacks { | |||||||||||||
|
|
||||||||||||||
| impl SnapshotCallbacks for CountingCallbacks { | ||||||||||||||
| fn on_metadata(&mut self, metadata: SnapshotMetadata) -> Result<()> { | ||||||||||||||
| eprintln!("📊 Snapshot Metadata:"); | ||||||||||||||
| eprintln!(" • Epoch: {}", metadata.epoch); | ||||||||||||||
| eprintln!("Snapshot Metadata:"); | ||||||||||||||
| eprintln!(" Epoch: {}", metadata.epoch); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " • Treasury: {} ADA", | ||||||||||||||
| " Treasury: {} ADA", | ||||||||||||||
| metadata.pot_balances.treasury as f64 / 1_000_000.0 | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " • Reserves: {} ADA", | ||||||||||||||
| " Reserves: {} ADA", | ||||||||||||||
| metadata.pot_balances.reserves as f64 / 1_000_000.0 | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " • Deposits: {} ADA", | ||||||||||||||
| " Deposits: {} ADA", | ||||||||||||||
| metadata.pot_balances.deposits as f64 / 1_000_000.0 | ||||||||||||||
| ); | ||||||||||||||
| if let Some(count) = metadata.utxo_count { | ||||||||||||||
| eprintln!(" • UTXO count: {}", count); | ||||||||||||||
| eprintln!(" UTXO count: {count}"); | ||||||||||||||
| } | ||||||||||||||
| // Calculate total blocks produced | ||||||||||||||
| let total_blocks_previous: u32 = | ||||||||||||||
|
|
@@ -183,19 +185,43 @@ impl SnapshotCallbacks for CountingCallbacks { | |||||||||||||
| metadata.blocks_current_epoch.iter().map(|p| p.block_count as u32).sum(); | ||||||||||||||
|
|
||||||||||||||
| eprintln!( | ||||||||||||||
| " • Block production previous epoch: {} pools produced {} blocks total", | ||||||||||||||
| " Block production previous epoch: {} pools produced {} blocks total", | ||||||||||||||
| metadata.blocks_previous_epoch.len(), | ||||||||||||||
| total_blocks_previous | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " • Block production current epoch: {} pools produced {} blocks total", | ||||||||||||||
| " Block production current epoch: {} pools produced {} blocks total", | ||||||||||||||
| metadata.blocks_current_epoch.len(), | ||||||||||||||
| total_blocks_current | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| // Show snapshots info if available | ||||||||||||||
| if let Some(snapshots_info) = &metadata.snapshots { | ||||||||||||||
| eprintln!(" Snapshots Info:"); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " Mark snapshot: {} sections", | ||||||||||||||
| snapshots_info.mark.sections_count | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " Set snapshot: {} sections", | ||||||||||||||
| snapshots_info.set.sections_count | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " Go snapshot: {} sections", | ||||||||||||||
| snapshots_info.go.sections_count | ||||||||||||||
| ); | ||||||||||||||
| eprintln!( | ||||||||||||||
| " Fee value: {} lovelace ({} ADA)", | ||||||||||||||
| snapshots_info.fee, | ||||||||||||||
| snapshots_info.fee as f64 / 1_000_000.0 | ||||||||||||||
| ); | ||||||||||||||
| } else { | ||||||||||||||
| eprintln!(" No snapshots data available"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Show top block producers if any | ||||||||||||||
| if !metadata.blocks_previous_epoch.is_empty() { | ||||||||||||||
| eprintln!(" 📦 Previous epoch top producers (first 3):"); | ||||||||||||||
| eprintln!(" Previous epoch top producers (first 3):"); | ||||||||||||||
| let mut sorted_previous = metadata.blocks_previous_epoch.clone(); | ||||||||||||||
| sorted_previous.sort_by(|a, b| b.block_count.cmp(&a.block_count)); | ||||||||||||||
| for (i, production) in sorted_previous.iter().take(3).enumerate() { | ||||||||||||||
|
|
@@ -216,7 +242,7 @@ impl SnapshotCallbacks for CountingCallbacks { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if !metadata.blocks_current_epoch.is_empty() { | ||||||||||||||
| eprintln!(" 📦 Current epoch top producers (first 3):"); | ||||||||||||||
| eprintln!(" Current epoch top producers (first 3):"); | ||||||||||||||
| let mut sorted_current = metadata.blocks_current_epoch.clone(); | ||||||||||||||
| sorted_current.sort_by(|a, b| b.block_count.cmp(&a.block_count)); | ||||||||||||||
| for (i, production) in sorted_current.iter().take(3).enumerate() { | ||||||||||||||
|
|
@@ -246,6 +272,35 @@ impl SnapshotCallbacks for CountingCallbacks { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl SnapshotsCallback for CountingCallbacks { | ||||||||||||||
| fn on_snapshots(&mut self, snapshots: RawSnapshotsContainer) -> Result<()> { | ||||||||||||||
| eprintln!("Raw Snapshots Data:"); | ||||||||||||||
|
|
||||||||||||||
| // Calculate total stakes and delegator counts from VMap data | ||||||||||||||
| let mark_total: i64 = snapshots.mark.0.iter().map(|(_, amount)| amount).sum(); | ||||||||||||||
| let set_total: i64 = snapshots.set.0.iter().map(|(_, amount)| amount).sum(); | ||||||||||||||
| let go_total: i64 = snapshots.go.0.iter().map(|(_, amount)| amount).sum(); | ||||||||||||||
|
Comment on lines
+280
to
+282
|
||||||||||||||
| let mark_total: i64 = snapshots.mark.0.iter().map(|(_, amount)| amount).sum(); | |
| let set_total: i64 = snapshots.set.0.iter().map(|(_, amount)| amount).sum(); | |
| let go_total: i64 = snapshots.go.0.iter().map(|(_, amount)| amount).sum(); | |
| let mark_total: i128 = snapshots.mark.0.iter().map(|(_, amount)| *amount as i128).sum(); | |
| let set_total: i128 = snapshots.set.0.iter().map(|(_, amount)| *amount as i128).sum(); | |
| let go_total: i128 = snapshots.go.0.iter().map(|(_, amount)| *amount as i128).sum(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems a bit overkill to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add rust logging (default is "info")