Skip to content

Conversation

@buddhisthead
Copy link
Collaborator

This PR updates the snapshot_bootstrapper module to read and parse an Amaru/Haskell node snapshot file, providing the initial structure of the process. It includes the parser and placeholder callback implementation for the streaming snapshot parser and also the pub/sub top-level message sequence.

Some features:

  • Progress Tracking: Logs every million UTXOs processed
  • Comprehensive Logging: Detailed statistics and metadata logging
  • Error Handling: Proper Result types and error propagation
  • Async Architecture: Non-blocking operation with proper context management
  • Message Publishing: Publishes GenesisComplete message to trigger next phase

TESTING
Nothing yet. But cargo test shouldn't be broken.

Copilot AI review requested due to automatic review settings October 22, 2025 19:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a streaming snapshot parser for Cardano node snapshots, replacing the previous ledger state directory loading approach. The changes establish a callback-based architecture for processing snapshot data asynchronously and publishing completion messages to coordinate with downstream modules.

Key Changes:

  • Replaced LedgerState::from_directory() with a streaming parser using callback handlers for UTXOs, pools, stakes, DReps, and governance proposals
  • Introduced SnapshotHandler struct to accumulate snapshot data and build blockchain state information
  • Added progress tracking with logging every million UTXOs and comprehensive statistics reporting

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs Core implementation of streaming snapshot parser with callback handlers and message publishing
common/src/messages.rs Added BootupCompleteMessage type and clarified SnapshotComplete comment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 67 to 78

// Create a synthetic BlockInfo representing the snapshot state
// This represents the last block included in the snapshot
Ok(BlockInfo {
status: BlockStatus::Immutable, // Snapshot blocks are immutable
slot: 0, // TODO: Extract from snapshot metadata if available
number: 0, // TODO: Extract from snapshot metadata if available
hash: BlockHash::default(), // TODO: Extract from snapshot metadata if available
epoch: metadata.epoch,
epoch_slot: 0, // TODO: Extract from snapshot metadata if available
new_epoch: false, // Not necessarily a new epoch
timestamp: 0, // TODO: Extract from snapshot metadata if available
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using zero values and default hash for critical block identification fields (slot, number, hash, epoch_slot, timestamp) will cause issues with downstream consumers expecting valid block identifiers. These fields should either be extracted from the snapshot metadata or the code should validate that metadata contains these values before proceeding.

Suggested change
// Create a synthetic BlockInfo representing the snapshot state
// This represents the last block included in the snapshot
Ok(BlockInfo {
status: BlockStatus::Immutable, // Snapshot blocks are immutable
slot: 0, // TODO: Extract from snapshot metadata if available
number: 0, // TODO: Extract from snapshot metadata if available
hash: BlockHash::default(), // TODO: Extract from snapshot metadata if available
epoch: metadata.epoch,
epoch_slot: 0, // TODO: Extract from snapshot metadata if available
new_epoch: false, // Not necessarily a new epoch
timestamp: 0, // TODO: Extract from snapshot metadata if available
// Validate and extract critical block identification fields from metadata
let slot = metadata.slot;
let number = metadata.number;
let hash = metadata.hash.clone();
let epoch_slot = metadata.epoch_slot;
let timestamp = metadata.timestamp;
if slot == 0 {
return Err(anyhow::anyhow!("Invalid slot value in snapshot metadata"));
}
if number == 0 {
return Err(anyhow::anyhow!("Invalid block number in snapshot metadata"));
}
if hash == BlockHash::default() {
return Err(anyhow::anyhow!("Invalid block hash in snapshot metadata"));
}
if epoch_slot == 0 {
return Err(anyhow::anyhow!("Invalid epoch_slot value in snapshot metadata"));
}
if timestamp == 0 {
return Err(anyhow::anyhow!("Invalid timestamp value in snapshot metadata"));
}
// Create a BlockInfo representing the snapshot state
Ok(BlockInfo {
status: BlockStatus::Immutable, // Snapshot blocks are immutable
slot,
number,
hash,
epoch: metadata.epoch,
epoch_slot,
new_epoch: false, // Not necessarily a new epoch
timestamp,

Copilot uses AI. Check for mistakes.
epoch_slot: 0, // TODO: Extract from snapshot metadata if available
new_epoch: false, // Not necessarily a new epoch
timestamp: 0, // TODO: Extract from snapshot metadata if available
era: Era::Conway, // TODO: Determine from snapshot or config
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding Era::Conway assumes all snapshots are from the Conway era, which may not be true for historical snapshots or other network configurations. The era should be determined from the snapshot metadata or configuration.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sandtreader
Copy link
Collaborator

Looks a great start - @buddhisthead did you want this merged or is it still WIP?

@buddhisthead
Copy link
Collaborator Author

I don't have any good tests for it yet, which I'd like to add. I can probably hack on this a little tomorrow and try to wrap it up. I'd love to get some messages flowing to the DRepState before I call it good.

@sandtreader sandtreader marked this pull request as draft October 28, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants