Skip to content

Commit

Permalink
fix: add retry for Bitcoin signing
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed May 10, 2024
1 parent 7458093 commit 6c2b73f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}

0 comments on commit 6c2b73f

Please sign in to comment.