From 7977b97227400005d4a83dc7b4c29944c032f9f4 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 23 Oct 2018 13:11:29 -0700 Subject: [PATCH] Surface AccountInUse to JSON RPC users so they know to retry the transaction --- doc/json-rpc.md | 1 + src/bank.rs | 1 + src/rpc.rs | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/json-rpc.md b/doc/json-rpc.md index 5091e4607f..9c54d79e7b 100644 --- a/doc/json-rpc.md +++ b/doc/json-rpc.md @@ -168,6 +168,7 @@ events. * `Confirmed` - Transaction was successful * `SignatureNotFound` - Unknown transaction * `ProgramRuntimeError` - An error occurred in the program that processed this Transaction + * `AccountInUse` - Another Transaction had a write lock one of the Accounts specified in this Transaction. The Transaction may succeed if retried * `GenericFailure` - Some other error occurred. **Note**: In the future new Transaction statuses may be added to this list. It's safe to assume that all new statuses will be more specific error conditions that previously presented as `GenericFailure` ##### Example: diff --git a/src/bank.rs b/src/bank.rs index 906d9edd77..94fd051742 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -302,6 +302,7 @@ impl Bank { if res[i] != Err(BankError::SignatureNotFound) { let status = match res[i] { Ok(_) => RpcSignatureStatus::Confirmed, + Err(BankError::AccountInUse) => RpcSignatureStatus::AccountInUse, Err(BankError::ProgramRuntimeError(_)) => { RpcSignatureStatus::ProgramRuntimeError } diff --git a/src/rpc.rs b/src/rpc.rs index b191d42cc9..45abbf3912 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -90,10 +90,11 @@ impl Metadata for Meta {} #[derive(Copy, Clone, PartialEq, Serialize, Debug)] pub enum RpcSignatureStatus { + AccountInUse, Confirmed, - SignatureNotFound, - ProgramRuntimeError, GenericFailure, + ProgramRuntimeError, + SignatureNotFound, } build_rpc_trait! { @@ -157,6 +158,7 @@ impl RpcSol for RpcSolImpl { Ok( match meta.request_processor.get_signature_status(signature) { Ok(_) => RpcSignatureStatus::Confirmed, + Err(BankError::AccountInUse) => RpcSignatureStatus::AccountInUse, Err(BankError::ProgramRuntimeError(_)) => RpcSignatureStatus::ProgramRuntimeError, Err(BankError::SignatureNotFound) => RpcSignatureStatus::SignatureNotFound, Err(err) => {