Skip to content

feat: include genesis block's commitment in Status#1181

Merged
bobbinth merged 7 commits into0xMiden:nextfrom
varun-doshi:varun/status
Aug 28, 2025
Merged

feat: include genesis block's commitment in Status#1181
bobbinth merged 7 commits into0xMiden:nextfrom
varun-doshi:varun/status

Conversation

@varun-doshi
Copy link
Copy Markdown
Contributor

Fixes #1088

Copy link
Copy Markdown
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

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

Looks good in terms of code, but I think we should look into caching the genesis commitment. Generally, this commitment will be decided at the start of the chain and would never change, so going to the store every time seems unnecessary.

When the Rpc component starts serving (ie, on Rpc::serve), we are already retrieving the genesis commitment to setup the accept header tonic layer, so maybe we could take the chance and somehow set this metadata for the status endpoint to use later.

Comment thread crates/rpc/src/server/api.rs Outdated
@varun-doshi
Copy link
Copy Markdown
Contributor Author

When the Rpc component starts serving (ie, on Rpc::serve), we are already retrieving the genesis commitment to setup the accept header tonic layer, so maybe we could take the chance and somehow set this metadata for the status endpoint to use later.

Would it be acceptable to save it in a new field in RpcService ?

Comment thread crates/rpc/src/server/api.rs Outdated
Comment on lines +80 to +84
pub fn set_genesis_commitment(&self, commitment: Word) -> anyhow::Result<()> {
self.genesis_commitment
.set(commitment)
.map_err(|_| anyhow::anyhow!("Genesis commitment already set"))?;
Ok(())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be set on the struct initialization? cc @igamigo

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think ideally you would set this on construction, but I'm not sure this is doable right now without changing the semantics a bit. Basically you would need to change new to be async and also it would not return until the store was up and running (so that get_genesis_header_with_retry returns).
The current way is not as clean and adds some (very manageable) complexity, but can't think of a better way without refactoring other sections too much.

Copy link
Copy Markdown
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

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

LGTM. As mentioned in the comments, not sure if there is a better way to set this up without refactoring some other pieces of code, but overall the added complexity seems low enough that this is a good tradeoff (and we could add a TODO or an issue to revisit this). Would be nice to see if @sergerad has any opinions on this as well.

Comment thread crates/rpc/src/server/api.rs Outdated
pub fn set_genesis_commitment(&self, commitment: Word) -> anyhow::Result<()> {
self.genesis_commitment
.set(commitment)
.map_err(|_| anyhow::anyhow!("Genesis commitment already set"))?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.map_err(|_| anyhow::anyhow!("Genesis commitment already set"))?;
.map_err(|_| anyhow::anyhow!("genesis commitment already set"))?;

Comment thread crates/rpc/src/server/api.rs Outdated

let genesis_commitment = self.genesis_commitment.get().ok_or({
tracing::warn!(target: COMPONENT, "Failed to fetch genesis header");
Status::internal("failed to fetch genesis header")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Status::internal("failed to fetch genesis header")
Status::failed_precondition("genesis header was not set")

Comment thread crates/rpc/src/server/api.rs Outdated
Comment on lines +80 to +84
pub fn set_genesis_commitment(&self, commitment: Word) -> anyhow::Result<()> {
self.genesis_commitment
.set(commitment)
.map_err(|_| anyhow::anyhow!("Genesis commitment already set"))?;
Ok(())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think ideally you would set this on construction, but I'm not sure this is doable right now without changing the semantics a bit. Basically you would need to change new to be async and also it would not return until the store was up and running (so that get_genesis_header_with_retry returns).
The current way is not as clean and adds some (very manageable) complexity, but can't think of a better way without refactoring other sections too much.

Comment thread crates/rpc/src/server/api.rs Outdated
}
}

pub fn set_genesis_commitment(&self, commitment: Word) -> anyhow::Result<()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's add some doc comments to mention what this function does and why it's needed.

@igamigo igamigo requested a review from sergerad August 26, 2025 14:27
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a couple of small comments/questions inline.

Comment thread proto/proto/rpc.proto Outdated
Comment thread crates/rpc/src/server/api.rs Outdated
Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

Its a bit hacky but works for now.

I think we take this as is, and then refactor it later such that the store and block-producer clients are created in the serve function. This can be trivially done once we have a general way to auto-retry tonic requests e.g. store.get_genesis_header().retry_on_transport_error().await.

Comment thread crates/rpc/src/server/api.rs Outdated
pub struct RpcService {
store: StoreRpcClient,
block_producer: Option<BlockProducerClient>,
genesis_commitment: Word,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I made a PR to your branch to move this to option also

varun-doshi#1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged!

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@bobbinth bobbinth merged commit f6603d3 into 0xMiden:next Aug 28, 2025
4 checks passed
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.

Include genesis block's commitment in Status

6 participants