Skip to content

chore(proto): refactor messages structure#1045

Merged
bobbinth merged 50 commits intonextfrom
santiagopittella-refactor-proto-messages
Jul 27, 2025
Merged

chore(proto): refactor messages structure#1045
bobbinth merged 50 commits intonextfrom
santiagopittella-refactor-proto-messages

Conversation

@SantiagoPittella
Copy link
Copy Markdown
Collaborator

closes: #993

This PR aims to refactor the structure of the proto files and some messages. I split the common messages into three files: primitives (with the merkle tree and digest messages), accounts (account headers, info, notes), and blockchain (block headers, transactions).

The services remain as top-level "modules" (as Mirko suggested in the issue), and the messages specific to them were placed inside each one of them. Some messages are shared between services, so I introduced a "shared.proto" file with those.

Also, I removed the Request/Response suffixes. In some cases, due to the same name on both messages without the suffix, I used the suffix Result. I don't really love this last part, any suggestion on this would be appreciated.

The next step is to use this new names from the generated code in our domain. I'll do this in this PR, but opened it anyways to start discussing the new message's structure.

@SantiagoPittella
Copy link
Copy Markdown
Collaborator Author

  1. In the first commit is the initial migration, where I use the Result suffix in some messages.
  2. In the second commit I replaced the old rust code with the new generated one.
  3. After that, each commit is a removal of the Result suffix in a message.

@SantiagoPittella SantiagoPittella requested a review from bobbinth July 4, 2025 18:36
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.

Thank you! Not a full review but I left some comments inline.

Overall, I don't think this is much of an improvement over existing layout (and in some ways more confusing). A few things I've highlighted in the comments:

  • I would not use action verbs to for message naming.
  • If we are removing Request/Response suffixes, we shouldn't just keep the previous names. For example, ApplyBlockResponse is OK as a message name but ApplyBlock is probably not. And I think sometimes it is OK to keep Request suffix to make things clear.
  • I'm not sure we need the shared.proto file. Most of these messages could either go into other files under types or go into individual service files.
  • I think it should be OK to import messages from other service files. For example, in rpc.proto we could import messages from block_producer.proto and store.proto.

Comment thread proto/proto/remote_prover.proto Outdated
Comment thread proto/proto/remote_prover.proto Outdated
Comment thread proto/proto/remote_prover.proto Outdated
Comment thread proto/proto/remote_prover.proto Outdated
Comment thread proto/proto/block_producer.proto Outdated
Comment thread proto/proto/ntx_builder.proto Outdated
Comment thread proto/proto/types/account.proto Outdated
Comment thread proto/proto/store.proto Outdated
Comment thread proto/proto/types/shared.proto Outdated
Comment thread proto/proto/store.proto Outdated
@SantiagoPittella
Copy link
Copy Markdown
Collaborator Author

@bobbinth answering your comments:

  1. I replaced some messages basically re-adding the Request/Response suffixes in the cases were I wasn't able to remove the action verbs (e.g. ProofRequest, GetTransactionInputsRequest) and used the basic types messages whenever it was possible (e.g. GetNotesById now receives a NoteIds which is just a vector of IDs).
  2. Added section separator for each request/response message in the services file.
  3. Removed the shared.proto file in favor of moving the messages to the services. I left only the RpcStatus message in the rpc.proto file, moved almost all of the shared messages to store.proto and some of them to block_producer.proto.

I'm now working on renaming the Rust generated structs.

lmk what do you think of this approach.

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.

Thank you! I think this structure works much better. This is not a full review yet - but I left a few comments inline.

Comment thread proto/proto/rpc.proto Outdated
Comment thread proto/proto/store.proto Outdated
Comment thread proto/proto/store.proto Outdated
Comment thread proto/proto/types/note.proto Outdated
Comment thread proto/proto/types/note.proto Outdated
Comment thread proto/proto/store/shared.proto
Comment thread proto/proto/store/shared.proto
Comment thread proto/proto/store/block_producer.proto Outdated
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 some comments inline - mostly about using namespaces to prefix protobuf types (i.e., instead of ProtoMyType doing something like proto::MyType) - let's try to use this approach consistently throughout.

Also, I think #1045 (comment) still needs to be addressed.

Comment thread bin/faucet/src/rpc_client.rs Outdated
Comment thread bin/faucet/src/rpc_client.rs Outdated
Comment thread bin/faucet/src/rpc_client.rs Outdated
Comment thread bin/remote-prover/src/api/prover.rs Outdated
Comment thread bin/remote-prover/src/api/prover.rs Outdated
}

// Represents the result of syncing notes request.
message SyncNotesResponse {
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.

Part of me wants to strive for fully replacing the request/response suffixes. Mainly because that naming tends to be less expressive than the alternative. Understood that sometimes it may be very difficult to think of an appropriate / expressive name in the context.

Taking this as an example. What would we rename SyncNotesResponse to? Perhaps NoteSyncRecordsByTag or ..ByTagAndBlock which gets verbose but you get the idea.

LMK what you think. cc @bobbinth

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.

We tried to do that where new names were unambiguous - but for a few, I'm not sure there are good alternatives. For example, we could rename SyncNotesRequest into something like BlockNumberAndNoteTagList - but I think this may actually be more confusing then SyncNotesRequest.

Similar with the SyncNotesResponse - though, here maybe something like NoteSyncRecords or maybe BlockNoteSyncRecords would actually be an improvement (though, I don't think by much).

// ================================================================================================

// Request to subscribe to mempool events.
message MempoolSubscriptionRequest {
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.

Even just MempoolSubscription would make sense to me here.

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.

I'm not sure MempoolSubscription is a better option here - it implies that the message carries a subscription while it is actually a request for a subscription.

Comment thread proto/proto/store/block_producer.proto Outdated
// ================================================================================================

// Returns data required to prove the next block.
message GetBlockInputsRequest {
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.

BlockInputRequirements or BlockInputFields or similar?

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.

Or *Parameters for messages that specify parameters like this?

Copy link
Copy Markdown
Collaborator

@sergerad sergerad Jul 21, 2025

Choose a reason for hiding this comment

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

would make more sense in the code:
Request<BlockInputsParameters>

rather than
Request<GetBlockInputsRequest>.

@bobbinth

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth Jul 22, 2025

Choose a reason for hiding this comment

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

"InputsParameters" sounds somewhat redundant - but I do think we can improve the naming here by at least getting rid of the Get prefix - e.g.:

  • GetBlockInputsRequest -> BlockInputsRequest
  • GetBatchInputsRequest -> BatchInputsRequest
  • GetTransactionInputsRequest -> TransactionInputsRequest

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.

I just pushed this changes, and removed an alias that I missed before.

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.

"InputsParameters" sounds somewhat redundant

The parameters refers to the fields in the request that result the block inputs returned. Although I could be confused about these endpoints I'm not super familiar.

Removing Get prefix is definitely an improvement. I still have the nit of disliking Request<SomethingRequest> in the code (2x "request" in the type). But its not a problem for readability.

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'm sure we can rename/reshuffle things a bit more, but given the footprint of this PR, I'd prefer merge it sooner rather than later. If there are specific things we want to address, we can do this in follow-up PR/issues.

But would be good to get 1 or 2 more people look through it.

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.

Some minor comments you can ignore; this looks like a really good step forward imo. Thank you!

Comment thread proto/proto/types/primitives.proto Outdated
message SmtLeaf {
oneof leaf {
// An empty leaf.
uint64 empty = 1;
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.

This could probably be the empty type google.proto.Empty (or whatever it actually is).

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.

I think that we still want the leaf index (that's what the empty represents here). Probably it is better to just rename it

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.

done

Comment thread proto/build.rs
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 don't think we need to separate the file descriptors by service, especially for the store.

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.

It was my suggestion to separate them. My thinking was that this file has gotten very big and it was difficult to parse through.

There may be better ways to split it up though (rather than by service) - but maybe that could be a separate task.

@bobbinth
Copy link
Copy Markdown
Contributor

After I merged #1097, there are some more merge conflicts. Sorry about that!

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 e9afc2f into next Jul 27, 2025
8 checks passed
@bobbinth bobbinth deleted the santiagopittella-refactor-proto-messages branch July 27, 2025 21:37
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.

gRPC: refactor schemas

4 participants