drift-labs / protocol-v2

On-chain perpetuals dex with multiple liquidity mechanisms
Apache License 2.0
216 stars 116 forks source link

Duplicate transaction sent in FastSingleTxSender and RetryTxSender #917

Open JakkuSakura opened 8 months ago

JakkuSakura commented 8 months ago

FastSingleTxSender should send the transaction only once.

class FastSingleTxSender {
    async sendRawTransaction(
        rawTransaction: Buffer | Uint8Array,
        opts: ConfirmOptions
    ): Promise<TxSigAndSlot> {
        let txid: TransactionSignature;
        try {
            txid = await this.connection.sendRawTransaction(rawTransaction, opts);
            this.sendToAdditionalConnections(rawTransaction, opts);
        } catch (e) {
            console.error(e);
            throw e;
        }

        this.connection.sendRawTransaction(rawTransaction, opts).catch((e) => {
            console.error(e);
        });
        this.sendToAdditionalConnections(rawTransaction, opts);
...
}

In RetryTxSender, there is no handling for This transaction has already been processed error, so it happens every time

SendTransactionError: failed to send transaction: Transaction simulation failed: This transaction has already been processed
    at Connection.sendEncodedTransaction (drift/js/node_modules/.pnpm/@solana+web3.js@1.90.0/node_modules/@solana/web3.js/src/connection.ts:5921:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (drift/js/node_modules/.pnpm/@solana+web3.js@1.90.0/node_modules/@solana/web3.js/src/connection.ts:5880:20) {
  logs: []
}
crispheaney commented 8 months ago

do you have a custom blockhashRefreshInterval set? i've noticed that happening when blockhash isn't updated frequently enough, we could increase the default

JakkuSakura commented 8 months ago

Hi, I noticed that if I use a RPC other than helium, it will happen. If I use helium, it's working fine