Skip to content

Commit

Permalink
fix: TransactionStatus::status should not be waiting for Final (#379)
Browse files Browse the repository at this point in the history
The `TransactionStatus::status` call should not be waiting for `Final`
inclusion of the transaction as it is supposed to only be checking the
status of the transaction on chain and not wait for it to completely
complete. Also, this does not take away any feature as
`TransactionStatus::wait` already does the full wait
  • Loading branch information
ChaoticTempest authored Oct 18, 2024
1 parent 2c478e2 commit 87c5ae5
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions workspaces/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use near_primitives::transaction::{
Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction,
DeployContractAction, FunctionCallAction, StakeAction, TransferAction,
};
use near_primitives::views::FinalExecutionOutcomeView;
use near_primitives::views::{FinalExecutionOutcomeView, TxExecutionStatus};
use std::convert::TryInto;
use std::fmt;
use std::future::IntoFuture;
Expand Down Expand Up @@ -513,30 +513,44 @@ impl TransactionStatus {
/// is in an unexpected state. The error should have further context. Otherwise, if an
/// `Ok` value with [`Poll::Pending`] is returned, then the transaction has not finished.
pub async fn status(&self) -> Result<Poll<ExecutionFinalResult>> {
let result = self
let rpc_resp = self
.worker
.client()
.tx_async_status(
&self.sender_id,
near_primitives::hash::CryptoHash(self.hash.0),
near_primitives::views::TxExecutionStatus::Final,
TxExecutionStatus::Included,
)
.await
.map(|o| {
o.final_execution_outcome
.map(|e| ExecutionFinalResult::from_view(e.into_outcome()))
});

match result {
Ok(Some(result)) => Ok(Poll::Ready(result)),
Ok(None) => Ok(Poll::Pending),
.await;

let rpc_resp = match rpc_resp {
Ok(rpc_resp) => rpc_resp,
Err(err) => match err {
JsonRpcError::ServerError(JsonRpcServerError::HandlerError(
RpcTransactionError::UnknownTransaction { .. },
)) => Ok(Poll::Pending),
other => Err(RpcErrorCode::BroadcastTxFailure.custom(other)),
)) => return Ok(Poll::Pending),
other => return Err(RpcErrorCode::BroadcastTxFailure.custom(other)),
},
};

if matches!(rpc_resp.final_execution_status, TxExecutionStatus::Included) {
return Ok(Poll::Pending);
}

let Some(final_outcome) = rpc_resp.final_execution_outcome else {
// final execution outcome is not available yet.
return Ok(Poll::Pending);
};

let outcome = final_outcome.into_outcome();

match outcome.status {
near_primitives::views::FinalExecutionStatus::NotStarted => return Ok(Poll::Pending),
near_primitives::views::FinalExecutionStatus::Started => return Ok(Poll::Pending),
_ => (),
}

Ok(Poll::Ready(ExecutionFinalResult::from_view(outcome)))
}

/// Wait until the completion of the transaction by polling [`TransactionStatus::status`].
Expand Down

0 comments on commit 87c5ae5

Please sign in to comment.