Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TransactionStatus::status should not be waiting for Final #379

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, final is not needed, but looking at the implementation, it feels that you actually need ExecutedOptimistic since the function needs to return the transaction outcome, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, this is just polling the transaction status, so ExecutedOptimistic would have the transaction already be slightly completed. This function should just be returning immediately where ExecutedOptimistic would take some time to resolve

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misinterpreted Poll<> part in the function signature. I thought about it as part of the native Rust futures polling, but it is not.

)
.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
Loading