Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

spl-token transfer --no-wait still waits for transaction to confirm #7595

Open
@acheroncrypto

Description

@acheroncrypto

Problem

Running the transfer command with the --no-wait flag still waits for transaction confirmation.

Arg::with_name("no_wait")
.long("no-wait")
.takes_value(false)
.help("Return signature immediately after submitting the transaction, instead of waiting for confirmations"),

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:

self.client
.send_transaction(&transaction)

Later, this method eventually calls <ProgramRpcClientSendTransaction as SendTransactionRpc>::send, which actually calls client.send_and_confirm_transaction:

client
.send_and_confirm_transaction(transaction)

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:

RpcClientResponse::Signature(signature) => {
let blockhash = config.program_client.get_latest_blockhash().await?;
config
.rpc_client
.confirm_transaction_with_spinner(
signature,
&blockhash,
config.rpc_client.commitment(),
)
.await?;
Ok(TransactionReturnData::CliSignature(CliSignature {
signature: signature.to_string(),
}))
}

And if the user passes in --no-wait, then the transaction would only get confirmed once (during the initial send_and_confirm):

RpcClientResponse::Signature(signature) if no_wait => {
Ok(TransactionReturnData::CliSignature(CliSignature {
signature: signature.to_string(),
}))
}

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 to ProgramRpcClientSendAndConfirmTransaction
  • Add ProgramRpcClientSendTransaction that only sends the transaction in its SendTransactionRpc::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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions