Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rpc-alt] add write apis #21153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[rpc-alt] add write apis #21153

wants to merge 1 commit into from

Conversation

emmazzz
Copy link
Contributor

@emmazzz emmazzz commented Feb 10, 2025

Description

This PR adds transaction execution and dry run APIs to indexer alt jsonrpc, which is basically a wrapper of the fullnode rpc.

Test plan

Added a test.


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Feb 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 9:01am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 9:01am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 9:01am

@emmazzz emmazzz temporarily deployed to sui-typescript-aws-kms-test-env February 10, 2025 08:54 — with GitHub Actions Inactive
#[tokio::test]
async fn test_execution_and_dry_run() {
// Set up a test cluster so we have some accounts and a fullnode RPC URL to connect to.
let test_cluster = TestClusterBuilder::new()
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 thought about adding support for txn execution via rpc in transactional test runner but I figured this way is easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this next to the other E2E tests? (see #21161 for what I mean).

@@ -76,6 +84,7 @@ impl RpcService {
let RpcArgs {
rpc_listen_address,
max_rpc_connections,
..
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a sign that fullnode_rpc_url doesn't belong on this struct -- imagine that this module is similar to Indexer and IndexerArgs (part of an RPC service framework).

Can you create a separate clap Args struct for the WriteArgs, in the write module, instead? Then you can flatten that struct into the rpc sub-command's list of fields. That way you can keep RpcArgs as just the flags passed to initialise the core of the RPC service, but still accept the fullnode URL as a command-line argument.

use super::rpc_module::RpcModule;

#[open_rpc(namespace = "sui", tag = "Write API")]
#[rpc(server, client, namespace = "sui")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Generating the client based on this trait is neat

Comment on lines +22 to +28
/// 1. WaitForEffectsCert: waits for TransactionEffectsCert and then return to client.
/// This mode is a proxy for transaction finality.
/// 2. WaitForLocalExecution: waits for TransactionEffectsCert and make sure the node
/// executed the transaction locally before returning the client. The local execution
/// makes sure this node is aware of this transaction when client fires subsequent queries.
/// However if the node fails to execute the transaction locally in a timely manner,
/// a bool type in the response is set to false to indicated the case.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the latest on deprecating WaitForLocalExecution? Should we be supporting different request types? Does WaitForLocalExecution still have meaning for us, given "local" means the fullnode, and not this RPC service? We can no longer guarantee that the RPC will return a response that is consistent with the effects of this transaction, after executeTransactionBlock(..., WaitForLocalExecution) returns.

.0
.execute_transaction_block(tx_bytes, signatures, opts, request_type)
.await
.map_err(internal_error_object)?)
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this means that any error, including user errors, transient errors, etc from the fullnode will turn into internal errors here. That seems wrong -- we should be passing the errors on transparently.

@@ -185,6 +194,7 @@ impl Default for RpcArgs {
Self {
rpc_listen_address: "0.0.0.0:6000".parse().unwrap(),
max_rpc_connections: 100,
fullnode_rpc_url: "http://localhost:9000".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about this default -- what are your thoughts on making this flag optional, and only adding the write module if it exists? It gets around the tricky issue of coming up with a default URL.


/// The URL of the fullnode RPC we connect to for executing transactions.
#[clap(long, default_value_t = Self::default().fullnode_rpc_url)]
pub fullnode_rpc_url: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use Url for this, so we get some input validation. The type implements AsRef<str> so it can be passed to HttpClientBuilder::build.

// Set up the rpc server that we want to test.
let (_rpc_server_handle, rpc_url) = set_up_rpc_server(fullnode_rpc_url, cancel.clone()).await;

// Coonstruct a transaction to execute.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Coonstruct a transaction to execute.
// Construct a transaction to execute.

const DEFAULT_GAS_AMOUNT: u64 = 1_000_000_000;

#[tokio::test]
async fn test_execution_and_dry_run() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add some tests for various error cases, and make sure the error codes get reported faithfully.

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.

2 participants