Skip to content

feat: remove miden-rpc-proto crate and add miden-node-proto-build#723

Merged
Mirko-von-Leipzig merged 26 commits intonextfrom
tomasarrachea-remove-rpc
Mar 26, 2025
Merged

feat: remove miden-rpc-proto crate and add miden-node-proto-build#723
Mirko-von-Leipzig merged 26 commits intonextfrom
tomasarrachea-remove-rpc

Conversation

@TomasArrachea
Copy link
Copy Markdown
Collaborator

@TomasArrachea TomasArrachea commented Feb 27, 2025

Closes #658.

Removed the miden-rpc-proto crate.

Instead, added miden-node-proto-build, that exposes ProtoBuilder that makes the bindings generation easier. This crate has a "internal" feature. When set, the ProtoBuilder compile() function will generate all the bindings (rpc, block-producer, and store, including the clients). If the feature is not set, only the rpc component will be built.

@TomasArrachea TomasArrachea force-pushed the tomasarrachea-remove-rpc branch 2 times, most recently from d2e396e to 55baec6 Compare February 28, 2025 20:36
@TomasArrachea TomasArrachea changed the title WIP: remove rpc client feat: remove rpc client from rpc crate Feb 28, 2025
@TomasArrachea TomasArrachea changed the title feat: remove rpc client from rpc crate feat: remove ApiClient from rpc crate Feb 28, 2025
@TomasArrachea TomasArrachea marked this pull request as ready for review March 5, 2025 03:50
@TomasArrachea TomasArrachea requested a review from bobbinth March 10, 2025 17:30
@TomasArrachea TomasArrachea force-pushed the tomasarrachea-remove-rpc branch from 284f095 to db440c7 Compare March 13, 2025 16:58
@TomasArrachea TomasArrachea changed the title feat: remove ApiClient from rpc crate feat: remove ApiClient from rpc crate and refactor proto codegen Mar 13, 2025
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 review yet, but I wanted to understand the overall approach. The way I see it is as follows:

  • We still keep protobuf files in the proto directory in the root of the repo as the "source of truth".
  • These files are then copied to the miden-node-proto-build crate during the build process and are used to set the protobuf files for the tonic builder (which is passed-in externally).
    • I actually didn't see the code that copies the file from the root into the crate - but maybe I missed it.
  • Then, in miden-node-proto we import miden-node-proto-build as a dependency and use it to actually generate the bindings.
  • If someone wanted to use the protobuf files (e.g., miden-client) they would add miden-node-proto-build as a build dependency and this would allow them to generate the desired bindings.

Assuming this is roughly correct, I think it works (and is probably a cleaner design than what we had before) - but I don't think it addresses the original issue. That is, we still need to either remove the client code from the PRC crate or somehow simplify the support for TLS.

I also think that people will still probably try to use miden-node-rpc to access the RPC component as the client and maybe pointing them to miden-node-proto-build may be too much of a burden.

One solution is to add miden-node-rpc-client crate (which would basically replace the old miden-rpc-proto crate). This crate would expose bindings with TLS and other features configured. This crate can then be directly used in miden-client (i.e., no need to build anything).

Another option is to use a single miden-node-rpc crate but have client and server features. The server feature would be used by the node internally, and the client feature would be used externally (e.g., by the miden-client). This may be a bit more complicated to implement though.

@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

Thank you! Not a review yet, but I wanted to understand the overall approach. The way I see it is as follows:

  • We still keep protobuf files in the proto directory in the root of the repo as the "source of truth".

  • These files are then copied to the miden-node-proto-build crate during the build process and are used to set the protobuf files for the tonic builder (which is passed-in externally).

    • I actually didn't see the code that copies the file from the root into the crate - but maybe I missed it.
  • Then, in miden-node-proto we import miden-node-proto-build as a dependency and use it to actually generate the bindings.

  • If someone wanted to use the protobuf files (e.g., miden-client) they would add miden-node-proto-build as a build dependency and this would allow them to generate the desired bindings.

I was hoping to only have the proto files directly in the miden-node-proto-build. No more copies, only that single set. We would highlight their location in the readme and the docs if we're concerned about discoverability, or we could move this particular crate to the top level (instead of within ./crates) and could even keep the folder named proto.

Assuming this is roughly correct, I think it works (and is probably a cleaner design than what we had before) - but I don't think it addresses the original issue. That is, we still need to either remove the client code from the PRC crate or somehow simplify the support for TLS.

I also think that people will still probably try to use miden-node-rpc to access the RPC component as the client and maybe pointing them to miden-node-proto-build may be too much of a burden.

I agree they may still do this, but I think we can minimize this with a

Warning

This crate is intended for internal use only. For gRPC bindings please see the crate .

This crate does not support TLS and cannot be used as a client for the official RPC endpoints.

and a proper example in the <proto-build> crate and readme.

One solution is to add miden-node-rpc-client crate (which would basically replace the old miden-rpc-proto crate). This crate would expose bindings with TLS and other features configured. This crate can then be directly used in miden-client (i.e., no need to build anything).

Another option is to use a single miden-node-rpc crate but have client and server features. The server feature would be used by the node internally, and the client feature would be used externally (e.g., by the miden-client). This may be a bit more complicated to implement though.

My hope is really to push users to the builder only. They may need both client and server for RPC - the latter for testing, or to create a proxy. In this case I think having both exposed by default, along with a solid example, should suffice as a jumping off point for users.

The only suboptimal point for me is the lack of domain types - but tbh they shouldn't be relying on our "internal" types, that just shows a lack of documentation in our gRPC API.

@bobbinth
Copy link
Copy Markdown
Contributor

I was hoping to only have the proto files directly in the miden-node-proto-build. No more copies, only that single set. We would highlight their location in the readme and the docs if we're concerned about discoverability, or we could move this particular crate to the top level (instead of within ./crates) and could even keep the folder named proto.

Yeah, I was mostly concerned about discoverability. Adding this to docs could work - but it'll need to be pretty prominent otherwise those searching for proto files won't find them. Moving the crate to the root level may be better.

My hope is really to push users to the builder only. They may need both client and server for RPC - the latter for testing, or to create a proxy. In this case I think having both exposed by default, along with a solid example, should suffice as a jumping off point for users.

For testing, just RPC is not enough - right? They'd have to run the full node.

I think the builders could be for more sophisticated users and if we can provide the required functionality via a simple import (assuming it doesn't complicate things too much for us), that would be better. But maybe this can be a separate issue.


To summarize:

  • We move miden-node-proto-build to the root level (into the proto directory). I guess the actual protobuf files will end up in proto/proto directory - right?
    • We add a good example of how to set up a build script using the miden-node-proto crate.
  • We remove the client code from miden-node-rpc and add relevant sections to the readme to point to miden-node-proto-build.

@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

My hope is really to push users to the builder only. They may need both client and server for RPC - the latter for testing, or to create a proxy. In this case I think having both exposed by default, along with a solid example, should suffice as a jumping off point for users.

For testing, just RPC is not enough - right? They'd have to run the full node.

It depends on what they want or need to test. I imagine basic testing could be done with server stubs and would be how I do unit testing. Or maybe by using snapshots - create the snapshots by running a node once, then use the RPC server to serve the snapshots for actual testing and CI. Its a pattern I'd like to move towards as well for more complex setups especially if it involved proving or things like proof-of-work.

I think the builders could be for more sophisticated users and if we can provide the required functionality via a simple import (assuming it doesn't complicate things too much for us), that would be better. But maybe this can be a separate issue.

I'm not convinced we want/need this, but let's tackle that separately :)

To summarize:

  • We move miden-node-proto-build to the root level (into the proto directory). I guess the actual protobuf files will end up in proto/proto directory - right?

    • We add a good example of how to set up a build script using the miden-node-proto crate.
  • We remove the client code from miden-node-rpc and add relevant sections to the readme to point to miden-node-proto-build.

Correct yes.

@TomasArrachea
Copy link
Copy Markdown
Collaborator Author

TomasArrachea commented Mar 20, 2025

We remove the client code from miden-node-rpc and add relevant sections to the readme to point to miden-node-proto-build.

@bobbinth I am not sure if I am completely on the same page on this. In the rpc crate there is only a RpcApi server component, that is used on the node binary. Which client code do you mean?

@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

Mirko-von-Leipzig commented Mar 20, 2025

We remove the client code from miden-node-rpc and add relevant sections to the readme to point to miden-node-proto-build.

@bobbinth I am not sure if I am completely on the same page on this. In the rpc crate there is only a RpcApi server component, that is used on the node binary. Which client code do you mean?

He meant the client exposed from proto which is prebuilt. Or rather I guess I did because I wrote rpc in the original issue description, confusing the matter.

@TomasArrachea TomasArrachea changed the title feat: remove ApiClient from rpc crate and refactor proto codegen feat: remove ApiClient from proto crate and refactor proto codegen Mar 20, 2025
@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

The tonic_build compile_protos_with_config function receives both the file descriptors with compiled proto files (I think this is used for server reflexion), and the raw proto files. So we would need to distribute the proto files anyway. For this, I think we could just keep the old way of copying the files and let the users compile them.

There is the https://docs.rs/tonic-build/latest/tonic_build/struct.Builder.html#method.compile_fds_with_config which compiles using the file descriptors alone. I think the file descriptors fully describe the .proto files and are essentially just the parsed version of them used by tonic_build, but I could be wrong.

@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

  1. We should then remove the various proto build scripts and the generated code from being checked in ideally.

By this you mean to have the generated code stored in "OUT_DIR", instead of being tracked and commited with the source code on miden-node-proto? In that case, I think I would be a good idea to do that in a separate PR and discuss it there.

This discussion is also about this approach: 0xPolygonMiden/miden-base#994

I'll revive that discussion and we can discuss it there. Let's leave that suggestion out of this PR :)

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.

One other thing: we should still remove the ApiClient from the rpc crate, right?

@TomasArrachea
Copy link
Copy Markdown
Collaborator Author

TomasArrachea commented Mar 25, 2025

@bobbinth thanks! I addressed the comments.

One other thing: we should still remove the ApiClient from the rpc crate, right?

About this, I am still not sure if I understand which code you mean. Maybe you mean the rpc ApiClient from the miden-node-proto crate?

@TomasArrachea
Copy link
Copy Markdown
Collaborator Author

@bobbinth There is no ApiClient in the miden-node-rpc crate. Assuming you mean the rpc ApiClient from the proto crate, the problem with deleting it is that it's used by the faucet, as we discussed in the original issue. I understood that Mirko's view on this was to just push users to use the new proto-build crate, and leave the proto crate for internal use only. I added a warning in the crate's readme for this (ac049e3). I should also update this PR's title.

An alternative could be to add again a feature flag to the proto crate ("rpc-client"), that would allow the faucet to access it, but not be included by default. This would mean that we wouldn't be deleting the ApiClient, the generated files will stay as they are now.

To actually delete the ApiClient from the crate we need a different solution. It could be to add bindings generation for the faucet, though I think that would add too much unnecessary boilerplate. Or perhaps to move the rpc client into a separate new crate.

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 few more minor comments line.

There is no ApiClient in the miden-node-rpc crate.

I was going more from this statement from the original issue:

Some users are using the gRPC client from our rpc crate -- however this crate does not enable TLS because internally our infrastructure is still http only. This means users of this client need to additionally override tonic with the TLS features. This is obscure and the client errors aren't very helpful in pointing out the issue since its just a connection rejection.

But maybe this meant rpc-client, which we now have deleted? If so, then probably nothing else to do here.

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.

Thanks! I know this was quite the back and forth :)

There will likely be some follow-up items like creating an example, and refactoring our internal RPC crate, but that can probably be done in a separate PR.

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.

All looks good! Thank you!

@TomasArrachea TomasArrachea changed the title feat: remove ApiClient from proto crate and refactor proto codegen feat: remove miden-rpc-proto crate and add miden-node-proto-build Mar 26, 2025
@Mirko-von-Leipzig Mirko-von-Leipzig merged commit f48b32b into next Mar 26, 2025
3 checks passed
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the tomasarrachea-remove-rpc branch March 26, 2025 15:09
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.

4 participants