Skip to content

Commit

Permalink
rpc: remove support for protobuf from rest endpoints
Browse files Browse the repository at this point in the history
This patch removes support from the various rest endpoints where it was
previously added. Instead, to support clients who want a binary format,
a gRPC service will be added in a future patch.
  • Loading branch information
bmwill committed Dec 9, 2024
1 parent 3f90eef commit e586a7a
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 475 deletions.
58 changes: 7 additions & 51 deletions crates/sui-e2e-tests/tests/rpc/checkpoints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prost::Message;
use sui_macros::sim_test;
use sui_rpc_api::client::sdk::Client;
use sui_rpc_api::client::Client as CoreClient;
Expand Down Expand Up @@ -45,23 +44,9 @@ async fn list_checkpoint() {
.await
.unwrap();

// Make sure list works with protobuf
let bytes = client
.get(&url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _checkpoints = sui_rpc_api::proto::ListCheckpointResponse::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
//
// Make sure list works with BCS and the old format of only a SignedCheckpoint with no contents
let bytes = client
.get(&url)
Expand Down Expand Up @@ -106,23 +91,8 @@ async fn get_checkpoint() {
.await
.unwrap();

// Make sure it works with protobuf
let bytes = client
.get(&url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _checkpoints = sui_rpc_api::proto::GetCheckpointResponse::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(&url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand Down Expand Up @@ -160,23 +130,9 @@ async fn get_full_checkpoint() {
test_cluster.rpc_url(),
latest.checkpoint.sequence_number
);
// Make sure it works with protobuf
let bytes = client
.get(&url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _checkpoints = sui_rpc_api::proto::FullCheckpoint::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(&url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand Down
22 changes: 3 additions & 19 deletions crates/sui-e2e-tests/tests/rpc/committee.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prost::Message;
use sui_macros::sim_test;
use sui_rpc_api::client::sdk::Client;
use sui_sdk_types::types::ValidatorCommittee;
Expand Down Expand Up @@ -30,23 +29,8 @@ async fn get_committee() {
.await
.unwrap();

// Make sure it works with protobuf
let bytes = client
.get(url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _object = sui_rpc_api::proto::ValidatorCommittee::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand All @@ -56,7 +40,7 @@ async fn get_committee() {
.bytes()
.await
.unwrap();
let _object = bcs::from_bytes::<ValidatorCommittee>(&bytes).unwrap();
let _committee = bcs::from_bytes::<ValidatorCommittee>(&bytes).unwrap();
}

let url = format!("{}/v2/system/committee", test_cluster.rpc_url(),);
Expand Down
20 changes: 2 additions & 18 deletions crates/sui-e2e-tests/tests/rpc/objects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prost::Message;
use sui_macros::sim_test;
use sui_rpc_api::client::sdk::Client;
use sui_rpc_api::client::Client as CoreClient;
Expand Down Expand Up @@ -45,23 +44,8 @@ async fn get_object() {
.await
.unwrap();

// Make sure it works with protobuf
let bytes = client
.get(url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _object = sui_rpc_api::proto::GetObjectResponse::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand Down
39 changes: 4 additions & 35 deletions crates/sui-e2e-tests/tests/rpc/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prost::Message;
use sui_macros::sim_test;
use sui_rpc_api::client::sdk::Client;
use sui_rpc_api::rest::transactions::{ListTransactionsQueryParameters, TransactionResponse};
Expand Down Expand Up @@ -36,23 +35,8 @@ async fn get_transaction() {
.await
.unwrap();

// Make sure it works with protobuf
let bytes = client
.get(&url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _transaction = sui_rpc_api::proto::GetTransactionResponse::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(&url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand Down Expand Up @@ -94,23 +78,8 @@ async fn list_checkpoint() {
.await
.unwrap();

// Make sure it works with protobuf
let bytes = client
.get(&url)
.header(
reqwest::header::ACCEPT,
sui_rpc_api::rest::APPLICATION_PROTOBUF,
)
.send()
.await
.unwrap()
.bytes()
.await
.unwrap();
let _transactions = sui_rpc_api::proto::ListTransactionsResponse::decode(bytes).unwrap();

// TODO remove this once the BCS format is no longer accepted and clients have migrated to the
// protobuf version
// TODO remove this once the BCS format is no longer supported by the rest endpoint and clients
// wanting binary have migrated to grpc
let bytes = client
.get(&url)
.header(reqwest::header::ACCEPT, sui_rpc_api::rest::APPLICATION_BCS)
Expand Down
12 changes: 1 addition & 11 deletions crates/sui-rpc-api/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@
}
}
},
"application/bcs": {},
"application/x-protobuf": {}
"application/bcs": {}
}
},
"410": {
Expand Down Expand Up @@ -309,7 +308,6 @@
"$ref": "#/components/schemas/ObjectResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
},
Expand Down Expand Up @@ -357,7 +355,6 @@
"$ref": "#/components/schemas/ObjectResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
},
Expand Down Expand Up @@ -492,7 +489,6 @@
"$ref": "#/components/schemas/TransactionResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
},
Expand Down Expand Up @@ -557,7 +553,6 @@
}
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
},
Expand Down Expand Up @@ -632,7 +627,6 @@
"$ref": "#/components/schemas/TransactionExecutionResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
}
Expand Down Expand Up @@ -668,7 +662,6 @@
"$ref": "#/components/schemas/ValidatorCommittee"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
},
Expand All @@ -694,7 +687,6 @@
"$ref": "#/components/schemas/ValidatorCommittee"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
}
Expand Down Expand Up @@ -885,7 +877,6 @@
"$ref": "#/components/schemas/TransactionSimulationResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
}
Expand Down Expand Up @@ -963,7 +954,6 @@
"$ref": "#/components/schemas/ResolveTransactionResponse"
}
},
"application/x-protobuf": {},
"application/bcs": {}
}
}
Expand Down
34 changes: 0 additions & 34 deletions crates/sui-rpc-api/src/client/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,6 @@ impl Client {
let request = self.inner.get(url).query(parameters);

self.bcs(request).await
// self.protobuf::<crate::proto::ListCheckpointResponse>(request)
// .await?
// .try_map(|page| {
// page.checkpoints
// .into_iter()
// .map(TryInto::try_into)
// .collect()
// })
}

pub async fn get_full_checkpoint(
Expand All @@ -280,13 +272,6 @@ impl Client {
let request = self.inner.get(url);

self.bcs(request).await
// self.protobuf::<crate::proto::FullCheckpoint>(request)
// .await?
// // TODO make this more efficient and convert directly into the sui-sdk-types version
// .try_map(|proto| {
// sui_types::full_checkpoint_content::CheckpointData::try_from(proto)
// .and_then(TryInto::try_into)
// })
}

pub async fn get_transaction(
Expand Down Expand Up @@ -430,25 +415,6 @@ impl Client {
Err(e) => Err(Error::from_error(e).with_parts(parts)),
}
}

#[allow(unused)]
pub(super) async fn protobuf<T: prost::Message + std::default::Default>(
&self,
request: reqwest::RequestBuilder,
) -> Result<Response<T>> {
let response = request
.header(reqwest::header::ACCEPT, crate::rest::APPLICATION_PROTOBUF)
.send()
.await?;

let (response, parts) = self.check_response(response).await?;

let bytes = response.bytes().await?;
match T::decode(bytes) {
Ok(v) => Ok(Response::new(v, parts)),
Err(e) => Err(Error::from_error(e).with_parts(parts)),
}
}
}

#[derive(Debug)]
Expand Down
Loading

0 comments on commit e586a7a

Please sign in to comment.