-
Notifications
You must be signed in to change notification settings - Fork 108
feat(walrus-sui): skip JSON-RPC client when fully migrated to gRPC #3186
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ use tonic::service::interceptor::InterceptedService; | |
| use walrus_core::ensure; | ||
|
|
||
| use crate::{ | ||
| client::SuiClientError, | ||
| client::{SuiClientError, retry_client::retriable_sui_client::GrpcMigrationLevel}, | ||
| coin::Coin, | ||
| contracts::{AssociatedContractStruct, TypeOriginMap}, | ||
| }; | ||
|
|
@@ -96,17 +96,26 @@ pub(crate) struct CoinBatch { | |
|
|
||
| impl DualClient { | ||
| /// Create a new DualClient with the given RPC URL and optional request timeout. | ||
| /// | ||
| /// When `WALRUS_GRPC_MIGRATION_LEVEL` is at its maximum, the JSON-RPC SuiClient is not | ||
| /// created. This allows connecting to gRPC-only nodes (e.g. sui-forking). | ||
| pub async fn new( | ||
| rpc_url: impl AsRef<str>, | ||
| request_timeout: Option<Duration>, | ||
| ) -> Result<Self, SuiClientError> { | ||
| let mut client_builder = SuiClientBuilder::default(); | ||
| if let Some(request_timeout) = request_timeout { | ||
| client_builder = client_builder.request_timeout(request_timeout); | ||
| } | ||
| let rpc_url = rpc_url.as_ref(); | ||
| let sui_client = Some(client_builder.build(rpc_url).await?); | ||
| let grpc_client = GrpcClient::new(rpc_url).context("unable to create grpc client")?; | ||
|
|
||
| let sui_client = if GrpcMigrationLevel::default().is_fully_migrated() { | ||
| None | ||
| } else { | ||
| let mut client_builder = SuiClientBuilder::default(); | ||
| if let Some(request_timeout) = request_timeout { | ||
| client_builder = client_builder.request_timeout(request_timeout); | ||
| } | ||
| Some(client_builder.build(rpc_url).await?) | ||
| }; | ||
|
Comment on lines
+109
to
+117
|
||
|
|
||
| Ok(Self { | ||
| sui_client, | ||
| grpc_client, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -212,6 +212,14 @@ const GRPC_MIGRATION_LEVEL_BATCH_OBJECTS: GrpcMigrationLevel = GrpcMigrationLeve | |||||||||||||||||||||||||||
| const GRPC_MIGRATION_LEVEL_SELECT_COINS: GrpcMigrationLevel = GrpcMigrationLevel(3); | ||||||||||||||||||||||||||||
| const GRPC_MIGRATION_LEVEL_GET_BALANCE: GrpcMigrationLevel = GrpcMigrationLevel(4); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| impl GrpcMigrationLevel { | ||||||||||||||||||||||||||||
| /// Returns true if the migration level is high enough that all RPC calls use gRPC | ||||||||||||||||||||||||||||
| /// and the JSON-RPC SuiClient is not needed. | ||||||||||||||||||||||||||||
|
Comment on lines
+216
to
+217
|
||||||||||||||||||||||||||||
| /// Returns true if the migration level is high enough that all RPC calls use gRPC | |
| /// and the JSON-RPC SuiClient is not needed. | |
| /// Returns true if the migration level is high enough that balance-related RPC calls | |
| /// (including coin selection and balance retrieval) use gRPC. | |
| /// | |
| /// Note: This does *not* guarantee that all RPC calls have been migrated to gRPC. Some | |
| /// operations (for example, certain transaction queries or owned-object listing) may | |
| /// still rely on the JSON-RPC `SuiClient`. Callers MUST NOT use this helper to decide | |
| /// that a JSON-RPC client is unnecessary. | |
| #[deprecated( | |
| note = "is_fully_migrated only reflects that balance-related RPCs are on gRPC; \ | |
| do not use it to assume JSON-RPC is no longer required." | |
| )] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
GrpcMigrationLevelfromretry_client::retriable_sui_clientmakesdual_clientdepend on the retry-layer module that already depends onDualClient, increasing coupling and risking cyclic-module tangles. Consider movingGrpcMigrationLevel(and its env parsing) into a lower-level/shared module (e.g. underclient/root) and re-exporting it, so bothDualClientand retry code depend on the same shared definition.