Skip to content

Commit

Permalink
api: deprecate execute_transaction endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq committed Jan 6, 2023
1 parent 77d6d29 commit d27ae1d
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 447 deletions.
26 changes: 0 additions & 26 deletions crates/sui-json-rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use sui_types::base_types::{
ObjectID, SequenceNumber, SuiAddress, TransactionDigest, TxSequenceNumber,
};
use sui_types::committee::EpochId;
use sui_types::crypto::SignatureScheme;
use sui_types::event::EventID;
use sui_types::messages::CommitteeInfoResponse;
use sui_types::messages::ExecuteTransactionRequestType;
Expand Down Expand Up @@ -554,31 +553,6 @@ pub trait EventReadApi {
#[open_rpc(namespace = "sui", tag = "APIs to execute transactions.")]
#[rpc(server, client, namespace = "sui")]
pub trait TransactionExecutionApi {
/// Execute the transaction and wait for results if desired.
/// Request types:
/// 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.
// TODO(joyqvq): remove this and rename executeTransactionSerializedSig to executeTransaction
#[method(name = "executeTransaction")]
async fn execute_transaction(
&self,
/// BCS serialized transaction data bytes without its type tag, as base-64 encoded string.
tx_bytes: Base64,
/// Flag of the signature scheme that is used.
sig_scheme: SignatureScheme,
/// Signature committed to the intent message of the transaction data, as base-64 encoded string.
signature: Base64,
/// Signer's public key, as base-64 encoded string.
pub_key: Base64,
/// The request type.
request_type: ExecuteTransactionRequestType,
) -> RpcResult<SuiExecuteTransactionResponse>;

#[method(name = "executeTransactionSerializedSig")]
async fn execute_transaction_serialized_sig(
&self,
Expand Down
41 changes: 0 additions & 41 deletions crates/sui-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use sui_core::authority_client::NetworkAuthorityClient;
use sui_core::transaction_orchestrator::TransactiondOrchestrator;
use sui_json_rpc_types::SuiExecuteTransactionResponse;
use sui_open_rpc::Module;
use sui_types::crypto::SignatureScheme;
use sui_types::intent::Intent;
use sui_types::messages::{ExecuteTransactionRequest, ExecuteTransactionRequestType};
use sui_types::{crypto, messages::Transaction};
Expand All @@ -40,46 +39,6 @@ impl FullNodeTransactionExecutionApi {

#[async_trait]
impl TransactionExecutionApiServer for FullNodeTransactionExecutionApi {
async fn execute_transaction(
&self,
tx_bytes: Base64,
sig_scheme: SignatureScheme,
signature: Base64,
pub_key: Base64,
request_type: ExecuteTransactionRequestType,
) -> RpcResult<SuiExecuteTransactionResponse> {
let tx_data =
bcs::from_bytes(&tx_bytes.to_vec().map_err(|e| anyhow!(e))?).map_err(|e| anyhow!(e))?;
let flag = vec![sig_scheme.flag()];
let signature = crypto::Signature::from_bytes(
&[
&*flag,
&*signature.to_vec().map_err(|e| anyhow!(e))?,
&pub_key.to_vec().map_err(|e| anyhow!(e))?,
]
.concat(),
)
.map_err(|e| anyhow!(e))?;
let txn = Transaction::from_data(tx_data, Intent::default(), signature);

let transaction_orchestrator = self.transaction_orchestrator.clone();
let response = spawn_monitored_task!(transaction_orchestrator.execute_transaction(
ExecuteTransactionRequest {
transaction: txn,
request_type,
}
))
.await
.map_err(|e| anyhow!(e))? // for JoinError
.map_err(|e| anyhow!(e))?; // For Sui transaction execution error (SuiResult<ExecuteTransactionResponse>)

SuiExecuteTransactionResponse::from_execute_transaction_response(
response,
self.module_cache.as_ref(),
)
.map_err(jsonrpsee::core::Error::from)
}

async fn execute_transaction_serialized_sig(
&self,
tx_bytes: Base64,
Expand Down
24 changes: 9 additions & 15 deletions crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,12 @@ async fn test_get_metadata() -> Result<(), anyhow::Error> {
let keystore_path = cluster.swarm.dir().join(SUI_KEYSTORE_FILENAME);
let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
.execute_transaction_serialized_sig(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down Expand Up @@ -326,14 +324,12 @@ async fn test_get_total_supply() -> Result<(), anyhow::Error> {
let keystore_path = cluster.swarm.dir().join(SUI_KEYSTORE_FILENAME);
let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
.execute_transaction_serialized_sig(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down Expand Up @@ -406,14 +402,12 @@ async fn test_get_total_supply() -> Result<(), anyhow::Error> {
let tx = transaction_bytes.to_data()?;

let tx = to_sender_signed_transaction(tx, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
.execute_transaction_serialized_sig(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down
Loading

0 comments on commit d27ae1d

Please sign in to comment.