From 6c2b73ff6b02ea6228c803754ea86cce1f73aecb Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 10 May 2024 15:26:43 +0200 Subject: [PATCH] fix: add retry for Bitcoin signing --- e2e/runner/bitcoin.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 5f9895023f..b393b5c0f0 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -240,13 +240,10 @@ func (runner *E2ERunner) SendToTSSFromDeployerWithMemo( } } - stx, signed, err := btcRPC.SignRawTransactionWithWallet2(tx, inputsForSign) + stx, err := signRawTransactionWithWallet2WithRetry(btcRPC, tx, inputsForSign) if err != nil { panic(err) } - if !signed { - panic("btc transaction not signed") - } txid, err := btcRPC.SendRawTransaction(stx, true) if err != nil { panic(err) @@ -407,3 +404,23 @@ func (runner *E2ERunner) ProveBTCTransaction(txHash *chainhash.Hash) { } runner.Logger.Info("OK: txProof verified for inTx: %s", txHash.String()) } + +// SignRawTransactionWithWallet2WithRetry signs a raw transaction with wallet2 and retries if it's not signed +func signRawTransactionWithWallet2WithRetry( + btcRPC *rpcclient.Client, + tx *wire.MsgTx, + inputsForSign []btcjson.RawTxWitnessInput, +) (*wire.MsgTx, error) { + for i := 0; i < 5; i++ { + stx, signed, err := btcRPC.SignRawTransactionWithWallet2(tx, inputsForSign) + if err != nil { + return nil, err + } + if signed { + return stx, nil + } + time.Sleep(2 * time.Second) + } + + return nil, fmt.Errorf("signRawTransactionWithWallet2WithRetry: not signed") +}