spl-token transfer --no-wait
still waits for transaction to confirm #7595
Description
Problem
Running the transfer
command with the --no-wait
flag still waits for transaction confirmation.
solana-program-library/token/cli/src/clap_app.rs
Lines 1401 to 1404 in 9d467db
Given the above description, the expected behavior is to return the transaction signature immediately after sending the transaction.
Reproduction
The easiest way to reproduce this locally is to change the default commitment to finalized
before running the command. In ~/.config/solana/cli/config.yml
:
# ...
commitment: finalized
Details
After a long chain of calls, the command processor eventually calls the token.process_ixs
, which then calls client.send_transaction
:
solana-program-library/token/client/src/token.rs
Lines 726 to 727 in 9d467db
Later, this method eventually calls <ProgramRpcClientSendTransaction as SendTransactionRpc>::send
, which actually calls client.send_and_confirm_transaction
:
solana-program-library/token/client/src/client.rs
Lines 147 to 148 in 9d467db
Thus, the send
method both sends and confirms the transaction.
This also makes the spinner for confirming transactions never show up because the transaction has to be confirmed beforehand for that part of the code to execute.
Additionally, pretty much all commands seem to be calling the finish_tx
function with no_wait
argument as false
, which means they're confirming the transaction twice:
solana-program-library/token/cli/src/command.rs
Lines 4714 to 4728 in 9d467db
And if the user passes in --no-wait
, then the transaction would only get confirmed once (during the initial send_and_confirm
):
solana-program-library/token/cli/src/command.rs
Lines 4709 to 4713 in 9d467db
Solution
The simplest solution would be to change the client.send_and_confirm_transaction
call to client.send_transaction
, especially since the transactions are already being confirmed inside the finish_tx
function as mentioned earlier.
However, this would affect people who use the spl-token-client
and expect the methods of Token
to confirm transactions. For example, it may break local testing, including the tests in this repository. Considering this, an improved version of this solution would be to convert the ProgramRpcClientSendTransaction
struct to a named one and add a confirm
field to decide whether to also confirm the transaction inside its SendTransactionRpc
implementation.
Another solution would be to:
- Rename
ProgramRpcClientSendTransaction
toProgramRpcClientSendAndConfirmTransaction
- Add
ProgramRpcClientSendTransaction
that only sends the transaction in itsSendTransactionRpc::send
method
as mentioned in #3139 (review), but a downside of this solution is that it requires quite a bit more changes than the previous solution.