Skip to content

Tip to depth#39

Open
arminsabouri wants to merge 7 commits intomasterfrom
tip-to-depth
Open

Tip to depth#39
arminsabouri wants to merge 7 commits intomasterfrom
tip-to-depth

Conversation

@arminsabouri
Copy link
Copy Markdown
Collaborator

@arminsabouri arminsabouri commented Apr 1, 2026

This Pr just focuses on index building from the tip to some desired depth by first identifying the best block and working backwards to the depth and parsing from there. Everything in the dense id system work as is, treating the nth block at if it was genesis. i.e everything is stil the ith order just relative to the depth at which we sync at.

@arminsabouri arminsabouri force-pushed the block-indexer branch 2 times, most recently from b8c0e1c to bc9d6c7 Compare April 3, 2026 14:17
Base automatically changed from block-indexer to master April 3, 2026 14:53
@arminsabouri arminsabouri marked this pull request as ready for review April 3, 2026 15:09
@arminsabouri arminsabouri force-pushed the tip-to-depth branch 3 times, most recently from f7af22b to 9bcd4be Compare April 3, 2026 20:37
@arminsabouri arminsabouri force-pushed the tip-to-depth branch 3 times, most recently from 837d9b5 to fb32de4 Compare April 8, 2026 01:38
Comment thread src/crates/block-index/src/lib.rs
@@ -0,0 +1,4 @@
Recovered manifest with next_file=5 manifest_num=4 log_num=3 prev_log_num=0 last_seq=0
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do we need these files? I dont think so. only .log blobs. Undo files may also be not needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since tx-indexer indexes txs but does not maintain the state of the UTXO set, I don't think it needs rev*dat (undo/reorg). LOG and LOG.old seems not needed either

@arminsabouri
Copy link
Copy Markdown
Collaborator Author

Need more review before merging.

@bc1cindy
Copy link
Copy Markdown
Contributor

bc1cindy commented Apr 8, 2026

Need more review before merging.

im doing it rn

Copy link
Copy Markdown
Contributor

@bc1cindy bc1cindy left a comment

Choose a reason for hiding this comment

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

overall looks great!

Comment thread src/crates/primitives/src/blk_file.rs Outdated
/// every blk file with it (cycling the key by absolute byte position). This struct reads
/// the key once on construction and applies it transparently in all read operations.
/// When `xor.dat` is absent or all-zero the reads are pass-through.
pub struct BlkFileStore {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it worth to align with lib.rs for consistency? pub(crate) there and pub here

@@ -0,0 +1,4 @@
Recovered manifest with next_file=5 manifest_num=4 log_num=3 prev_log_num=0 last_seq=0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since tx-indexer indexes txs but does not maintain the state of the UTXO set, I don't think it needs rev*dat (undo/reorg). LOG and LOG.old seems not needed either

let obfuscation_key = db
.get(OBFUSCATE_KEY_KEY)
.map(|b| b.to_vec())
.map(|b| b[1..].to_vec())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if b is empty? would It be better to add guards?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If the result is empty there is not much we can do. Panic here seems appropriate bc it suggests level DB is serving corrupt keys (?)

Comment thread examples/indexer.rs Outdated
.expect("failed to open sled DB")
.spk_db()
.expect("failed to open spk_db tree");
// 1. Build indices into a temp directory (or user-specified index-dir)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: update the comment

maybe just Build indices into a temp directory is enough

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

}
file_hints.push((file_no, info.height_first, info.height_last));
}
Err(_) => continue,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can silent skip produce an incomplete index?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yup great catch


let spec = DenseBuildSpec {
blocks_dir,
range: start_height..end_height + 1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still new to codebase so just asking

Should this dense range start at start_height without adjusting the block height accessors too? Once the storage is offset from genesis block_of_tx() returns global heights but tx_range_for_block() still indexes block_tx_index as if the first stored block were height 0 so tx_range_for_block(block_of_tx(...)) will panic for tip windows.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes your intuition is correct

And getting block info from some block to some depth
by iterating the chain backwards
Add multi-file parser support and sync_from_tip entry point that uses BlockIndex to find the tip, walks back depth blocks, and indexes forward into dense storage.
We should passing input datadir, where we want the data to go
and depth. Everything else can be abstract away in the internal methods
If requested depth exceeds chain length return a specific error
instead of key not found.
Ensure we can parse multiple blk files.
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