Skip to content

Commit

Permalink
[RFC] Minimize confusing authority errors (MystenLabs#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Apr 29, 2022
1 parent b92eef1 commit 53c0452
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,13 @@ impl AuthorityState {
}
}

/// Initiate a new transaction.
pub async fn handle_transaction(
async fn handle_transaction_impl(
&self,
transaction: Transaction,
transaction_digest: TransactionDigest,
) -> Result<TransactionInfoResponse, SuiError> {
// Check the sender's signature.
transaction.check_signature()?;
let transaction_digest = transaction.digest();

// Ensure an idempotent answer.
if self._database.transaction_exists(&transaction_digest)?
|| self._database.effects_exists(&transaction_digest)?
{
if self._database.transaction_exists(&transaction_digest)? {
let transaction_info = self.make_transaction_info(&transaction_digest).await?;
return Ok(transaction_info);
}
Expand Down Expand Up @@ -228,6 +222,32 @@ impl AuthorityState {
self.make_transaction_info(&transaction_digest).await
}

/// Initiate a new transaction.
pub async fn handle_transaction(
&self,
transaction: Transaction,
) -> Result<TransactionInfoResponse, SuiError> {
// Check the sender's signature.
transaction.check_signature()?;
let transaction_digest = transaction.digest();

let response = self
.handle_transaction_impl(transaction, transaction_digest)
.await;
match response {
Ok(r) => Ok(r),
// If we see an error, it is possible that a certificate has already been processed.
// In that case, we could still return Ok to avoid showing confusing errors.
Err(err) => {
if self._database.effects_exists(&transaction_digest)? {
Ok(self.make_transaction_info(&transaction_digest).await?)
} else {
Err(err)
}
}
}
}

/// Confirm a transfer.
pub async fn handle_confirmation_transaction(
&self,
Expand Down

0 comments on commit 53c0452

Please sign in to comment.