Skip to content

refactor(validator): refactor gRPC server implementation#1959

Open
kkovaacs wants to merge 4 commits intonextfrom
krisztian/refactor-validator-grpc-server
Open

refactor(validator): refactor gRPC server implementation#1959
kkovaacs wants to merge 4 commits intonextfrom
krisztian/refactor-validator-grpc-server

Conversation

@kkovaacs
Copy link
Copy Markdown
Contributor

@kkovaacs kkovaacs commented Apr 20, 2026

As outlined in #1885, after having the build-time generation of related traits and blanket implementations (PR #1950) we can start moving our GRPC API implementations to the new framework.

This PR does this for the validator GRPC API. As suggested in the issue, each method is moved to its own file.

Closes #1970

Base automatically changed from krisztian/grpc-servers to next April 21, 2026 08:05
This commit refactors the gRPC server implementation in the validator
crate. The API implementation is now split into separate modules for
each endpoint.
@kkovaacs kkovaacs force-pushed the krisztian/refactor-validator-grpc-server branch from aa3a80b to 3da29dc Compare April 21, 2026 08:57
@kkovaacs kkovaacs marked this pull request as ready for review April 21, 2026 09:19
@kkovaacs kkovaacs requested a review from Copilot April 21, 2026 09:19
Copy link
Copy Markdown
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

Refactors the validator gRPC API implementation to the new per-method trait-based framework and splits each RPC method into its own module, aligning with the approach described in #1885.

Changes:

  • Migrated validator RPC method implementations to generated per-method traits (Status, SubmitProvenTransaction, SignBlock).
  • Split each validator RPC method into its own file under crates/validator/src/server/.
  • Added a changelog entry documenting the validator gRPC server refactor.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/validator/src/server/mod.rs Removes the direct api_server::Api impl and wires the server to rely on the new generated blanket implementation; adds per-method modules.
crates/validator/src/server/status.rs Implements the per-method Status trait for ValidatorServer.
crates/validator/src/server/submit_proven_transaction.rs Implements the per-method SubmitProvenTransaction trait, including decode/handle/encode split.
crates/validator/src/server/sign_block.rs Implements the per-method SignBlock trait, including decode/handle/encode split and semaphore serialization.
CHANGELOG.md Documents the validator gRPC API refactor.

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

Comment on lines +22 to +32
async fn handle(&self, _input: Self::Input) -> tonic::Result<Self::Output> {
unimplemented!()
}

fn decode(_request: ()) -> tonic::Result<Self::Input> {
unimplemented!()
}

fn encode(_output: Self::Output) -> tonic::Result<grpc::validator::ValidatorStatus> {
unimplemented!()
}
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

handle, decode, and encode are left as unimplemented!(), which will panic if these trait methods are ever used (e.g., if the generated blanket impl stops calling the overridden full, or if tests/helpers call handle directly). It would be safer to implement the intended decode/handle/encode flow and rely on the default full implementation (and adjust Input/Output types accordingly) rather than overriding full and leaving required methods unimplemented.

Copilot uses AI. Check for mistakes.
Comment thread crates/validator/src/server/sign_block.rs Outdated
Comment thread CHANGELOG.md Outdated
kkovaacs and others added 2 commits April 21, 2026 12:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

I didn't inspect the code too much with the assumption that its largely a copy-paste from the original.

Comment on lines +26 to +28
fn encode(output: Self::Output) -> tonic::Result<grpc::blockchain::BlockSignature> {
Ok(grpc::blockchain::BlockSignature { signature: output.to_bytes() })
}
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 suspect all of our encode calls are infallible.. Should we change the API to replace Result<T> with T? Maybe in the future we may need fallible encoding? Can't imagine why though..

Comment on lines +13 to +19
Ok(grpc::validator::ValidatorStatus {
version: env!("CARGO_PKG_VERSION").to_string(),
status: "OK".to_string(),
chain_tip: self.chain_tip.load(Ordering::Relaxed),
validated_transactions_count: self.validated_transactions_count.load(Ordering::Relaxed),
signed_blocks_count: self.signed_blocks_count.load(Ordering::Relaxed),
})
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.

We just need to be careful when we're adding instrumentation at the top level, that this doesn't override anything important.

@kkovaacs kkovaacs requested a review from sergerad April 21, 2026 14:38
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.

Migrate validator gRPC server to new codegen

3 participants