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

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

Open
acheroncrypto opened this issue Dec 17, 2024 · 0 comments · May be fixed by #7596
Open

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

acheroncrypto opened this issue Dec 17, 2024 · 0 comments · May be fixed by #7596

Comments

@acheroncrypto
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant