Skip to content

Conversation

@kobi-lizard
Copy link

Problem

Hash type is ubiquitous and a bit abused. For example, sometimes there's a comment next to some argument clarifying the the Hash type means slice merkle root. This makes it hard to introduce the double merkle block id and check for correctness.

Summary of Changes

Distinguish slice merkle roots with a new type.
Simplified the way the merkle tree implementation is indexed.

@kobi-lizard
Copy link
Author

Obviously it's unfinished 🐸 struggling with cyclic dependencies right now.

@akhi3030 akhi3030 force-pushed the kobi-merkle-root-type branch from dff580a to cca4098 Compare October 7, 2025 14:13
use solana_hash::Hash;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct SliceRoot(pub Hash);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub struct SliceRoot(pub Hash);
pub struct SliceRoot(Hash);

It will be cleaner to not make the internal field pub. And to have a constructor with appropriate visibility to ensure that "valid" SliceRoots can be constructed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an advantage to using a struct here rather than a type alias?

Copy link
Contributor

Choose a reason for hiding this comment

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

a type alias serves just as documentation and doesn't offer actual type safety. It is still possible to accidentally pass in the wrong type and the compiler will not complain.

Copy link
Author

Choose a reason for hiding this comment

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

Right, type alias would be like the mentioned comment that says "this argument means this". I want to make sure and trace correct methods get/return SliceRoot or AlpenglowBlockId and Rust to guide my hand. Is it just me or this is how it should be? 😅

Copy link
Author

@kobi-lizard kobi-lizard Oct 7, 2025

Choose a reason for hiding this comment

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

With this codebase I will get a stroke without Rust holding my hand lol

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's fine, i'm cool with the struct approach

@@ -0,0 +1,7 @@
use solana_hash::Hash;
Copy link
Contributor

Choose a reason for hiding this comment

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

To reviewers, this crate introduced to break the cyclic dependency. Once, the work here is done, the type definition ca be moved to solana-sdk which is probably the right place for defining SliceRoot.

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally SDK represents types that will be used on chain, perhaps it would make sense for this to live in votor-messages or ledger/src/shred.rs instead

Copy link
Author

Choose a reason for hiding this comment

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

Tried shred.rs, there's a cyclic dep with runtime.
Can try votor-messages, but pretty sure there's a cyclic dependency :(

Copy link
Contributor

Choose a reason for hiding this comment

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

votor-messages is designed to be a lightweight leaf crate for types that everyone can depend on. AFAIK it shouldn't depend on any non SDK crates, maybe give it a try?

@AshwinSekar
Copy link
Contributor

Thought about this some more, since the majority of the Double Merkle work will be in code outside of agave-votor it would be best to do this first upstream in Agave and then cherry-pick it back here if needed.

We're almost done upstreaming votor, and the size of the divergence is growing each day so best to work directly on agave every chance we can get. Also will make it easier to get reviews from the code owners for each of the parts, networking team for shreds & steve for blockstore.

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