Skip to content

Commit

Permalink
Add handle_consensus_transaction to AuthorityAPI and call it from gat…
Browse files Browse the repository at this point in the history
…eway (MystenLabs#1637)
  • Loading branch information
lxfind authored Apr 29, 2022
1 parent 53c0452 commit 5812127
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
.map_err(serde::de::Error::custom)?
.next_port()
.ok_or_else(|| serde::de::Error::custom("No available port."))?;
socket_addr_from_hostport("localhost", port)
socket_addr_from_hostport("127.0.0.1", port)
};

Ok(AuthorityPrivateInfo {
Expand Down
2 changes: 1 addition & 1 deletion sui/tests/shared_objects_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async fn call_shared_object_contract() {
let configs = test_authority_configs();
let _handles = spawn_test_authorities(gas_objects.clone(), &configs).await;

// Publish the move package to all authorities and get the new pacakge ref.
// Publish the move package to all authorities and get the new package ref.
tokio::task::yield_now().await;
let transaction = publish_move_package_transaction(gas_objects.pop().unwrap());
let replies = submit_single_owner_transaction(transaction, &configs).await;
Expand Down
8 changes: 7 additions & 1 deletion sui_core/src/authority_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ where
?timeout_after_quorum,
"Broadcasting certificate to authorities"
);
let contains_shared_object = certificate.transaction.contains_shared_object();

let state = self
.quorum_map_then_reduce_with_timeout(
Expand All @@ -961,10 +962,15 @@ where
// - we try to update the authority with the cert, and on error return Err.
// - we try to re-process the certificate and return the result.

let res = client
let handle = if contains_shared_object {
client.handle_consensus_transaction(ConsensusTransaction::UserTransaction(cert_ref.clone()))
} else {
client
.handle_confirmation_transaction(ConfirmationTransaction::new(
cert_ref.clone(),
))
};
let res = handle
.instrument(tracing::trace_span!("handle_cert", authority =? _name))
.await;

Expand Down
24 changes: 24 additions & 0 deletions sui_core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ pub trait AuthorityAPI {
transaction: ConfirmationTransaction,
) -> Result<TransactionInfoResponse, SuiError>;

/// Processes consensus request.
async fn handle_consensus_transaction(
&self,
transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError>;

/// Handle Account information requests for this account.
async fn handle_account_info_request(
&self,
Expand Down Expand Up @@ -100,6 +106,17 @@ impl AuthorityAPI for NetworkAuthorityClient {
deserialize_transaction_info(response)
}

async fn handle_consensus_transaction(
&self,
transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError> {
let response = self
.0
.send_recv_bytes(serialize_consensus_transaction(&transaction))
.await?;
deserialize_transaction_info(response)
}

async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
Expand Down Expand Up @@ -213,6 +230,13 @@ impl AuthorityAPI for LocalAuthorityClient {
result
}

async fn handle_consensus_transaction(
&self,
_transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError> {
unimplemented!("LocalAuthorityClient does not support consensus transaction");
}

async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
Expand Down
10 changes: 10 additions & 0 deletions sui_core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ where
Ok(transaction_info)
}

async fn handle_consensus_transaction(
&self,
transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError> {
// TODO: Add safety checks on the response.
self.authority_client
.handle_consensus_transaction(transaction)
.await
}

async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
Expand Down
26 changes: 24 additions & 2 deletions sui_core/src/unit_tests/batch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use std::sync::Arc;
use std::{env, io};
use sui_types::messages::{
AccountInfoRequest, AccountInfoResponse, BatchInfoRequest, BatchInfoResponseItem,
ConfirmationTransaction, ObjectInfoRequest, ObjectInfoResponse, Transaction,
TransactionInfoRequest, TransactionInfoResponse,
ConfirmationTransaction, ConsensusTransaction, ObjectInfoRequest, ObjectInfoResponse,
Transaction, TransactionInfoRequest, TransactionInfoResponse,
};
use sui_types::object::Object;

Expand Down Expand Up @@ -443,6 +443,17 @@ impl AuthorityAPI for TrustworthyAuthorityClient {
})
}

async fn handle_consensus_transaction(
&self,
_transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError> {
Ok(TransactionInfoResponse {
signed_transaction: None,
certified_transaction: None,
signed_effects: None,
})
}

async fn handle_account_info_request(
&self,
_request: AccountInfoRequest,
Expand Down Expand Up @@ -551,6 +562,17 @@ impl AuthorityAPI for ByzantineAuthorityClient {
})
}

async fn handle_consensus_transaction(
&self,
_transaction: ConsensusTransaction,
) -> Result<TransactionInfoResponse, SuiError> {
Ok(TransactionInfoResponse {
signed_transaction: None,
certified_transaction: None,
signed_effects: None,
})
}

async fn handle_account_info_request(
&self,
_request: AccountInfoRequest,
Expand Down

0 comments on commit 5812127

Please sign in to comment.