Skip to content

cleanup: Use CommitSemanticallyVerifiedBlockRequest in block verifier#10284

Open
arya2 wants to merge 10 commits intomainfrom
suggestion-for-cv-commit-state-error
Open

cleanup: Use CommitSemanticallyVerifiedBlockRequest in block verifier#10284
arya2 wants to merge 10 commits intomainfrom
suggestion-for-cv-commit-state-error

Conversation

@arya2
Copy link
Contributor

@arya2 arya2 commented Feb 6, 2026

Motivation

This is just minor cleanup, it simplifies some code and serves as an example for how to use the new MappedRequest trait.

PR Checklist

  • The PR name is suitable for the release notes.
  • The PR follows the contribution guidelines.
  • The library crate changelogs are up to date.
  • The solution is tested.
  • The documentation is up to date.

@arya2 arya2 self-assigned this Feb 6, 2026
@arya2 arya2 added C-enhancement Category: This is an improvement C-cleanup Category: This is a cleanup A-state Area: State / database changes C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG P-Optional ✨ labels Feb 6, 2026
Copy link

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 performs a small refactor across zebra-consensus and zebra-state to use the new MappedRequest-based request wrappers for committing blocks, and to simplify commit error handling by standardizing on CommitBlockError.

Changes:

  • Switch semantic block verification to commit via CommitSemanticallyVerifiedBlockRequest + MappedRequest helpers.
  • Unify commit request error types across finalized/non-finalized commit paths to use CommitBlockError.
  • Evolve MappedRequest to rely on Into<Request> + add helper mapping for tower-layer vs state errors.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
zebrad/tests/acceptance.rs Updates acceptance test to use CommitSemanticallyVerifiedBlockRequest::new(...).map_err(...).
zebra-state/src/service/queued_blocks.rs Standardizes queued-block result channel error type to CommitBlockError.
zebra-state/src/service/finalized_state/zebra_db/block.rs Switches finalized commit APIs to return CommitBlockError.
zebra-state/src/service/finalized_state.rs Propagates CommitBlockError through finalized-state commit APIs.
zebra-state/src/service.rs Updates state service request handling/comments to expect CommitBlockError.
zebra-state/src/request.rs Updates MappedRequest API, adds map_err, and refactors commit request wrappers to use Into<Request>.
zebra-state/src/lib.rs Changes public re-exports to expose LayeredStateError and removes older commit wrapper errors.
zebra-state/src/error.rs Removes commit wrapper error types, adds LayeredStateError, and adjusts conversions.
zebra-consensus/src/block.rs Uses CommitSemanticallyVerifiedBlockRequest in the block verifier and maps tower-layer errors into VerifyBlockError.
zebra-consensus/Cargo.toml Adds derive-new dependency for new constructor generation usage.
Cargo.lock Locks derive-new addition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 646 to 655
/// Accepts a state service to call, maps this request to a [`Request`], waits for the state to be ready,
/// calls the state with the mapped request, then maps the success or error response to the expected response
/// or error type for this request.
///
/// Returns a [`Result<MappedResponse, LayeredServicesError<RequestError>>`].
#[allow(async_fn_in_trait)]
async fn mapped_oneshot<State>(
async fn run<State>(
self,
state: &mut State,
s: &mut State,
) -> Result<Self::MappedResponse, LayeredStateError<Self::Error>>
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The rustdoc for MappedRequest::run still says it returns LayeredServicesError<...>, but the function now returns Result<_, LayeredStateError<Self::Error>>. Please update the doc comment (and the referenced type name) so it matches the actual signature/output error semantics.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was already wrong, so feel free to fix it now or not

Copy link
Collaborator

@conradoplg conradoplg 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, but I'd like to keep the MSRV 1.85 if possible

Comment on lines 646 to 655
/// Accepts a state service to call, maps this request to a [`Request`], waits for the state to be ready,
/// calls the state with the mapped request, then maps the success or error response to the expected response
/// or error type for this request.
///
/// Returns a [`Result<MappedResponse, LayeredServicesError<RequestError>>`].
#[allow(async_fn_in_trait)]
async fn mapped_oneshot<State>(
async fn run<State>(
self,
state: &mut State,
s: &mut State,
) -> Result<Self::MappedResponse, LayeredStateError<Self::Error>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was already wrong, so feel free to fix it now or not


/// Maps the expected [`Response`] variant for this request to the mapped response type.
fn map_response(response: Response) -> Self::MappedResponse;
fn map_rsp(response: Response) -> Self::MappedResponse;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional, but I'm not a fan of abbreviations

Cargo.toml Outdated
homepage = "https://zfnd.org/zebra/"
keywords = ["zebra", "zcash"]
rust-version = "1.85.0"
rust-version = "1.89.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're trying to keep the MSRV 1.85 for crates, unless absolutely necessary. Can this PR be changed to not require this bump?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code on main is already using Result::flatten(self) from 1.89.0, we could change it back but there was a TODO waiting for that feature to stabilize for years.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I know ☹️ but at the time we didn't realize that it would be better to keep a lower MSRV for the crates and we just bumped it down. I can work on this if you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. I'll set it back to 1.85.0 for now and wait until it can be bumped without disrupting any active use cases. The ZIP 213 PR will also need some updates.

@arya2 arya2 requested a review from conradoplg February 20, 2026 17:06
Copy link

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

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-state Area: State / database changes C-cleanup Category: This is a cleanup C-enhancement Category: This is an improvement C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG P-Low ❄️

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants