Use connectors utxos from swept rounds (#167)

* use connectors utxos from swept rounds

* revert docker-compose.regtest.yml

* add gitignore

* fix integration tests
This commit is contained in:
Louis Singer
2024-05-29 14:34:35 +02:00
committed by GitHub
parent dca302df69
commit b5bac540ef
16 changed files with 167 additions and 76 deletions

View File

@@ -382,7 +382,14 @@ func (s *service) startFinalization() {
return
}
unsignedPoolTx, tree, connectorAddress, err := s.builder.BuildPoolTx(s.pubkey, payments, s.minRelayFee)
sweptRounds, err := s.repoManager.Rounds().GetSweptRounds(ctx)
if err != nil {
changes = round.Fail(fmt.Errorf("failed to retrieve swept rounds: %s", err))
log.WithError(err).Warn("failed to retrieve swept rounds")
return
}
unsignedPoolTx, tree, connectorAddress, err := s.builder.BuildPoolTx(s.pubkey, payments, s.minRelayFee, sweptRounds)
if err != nil {
changes = round.Fail(fmt.Errorf("failed to create pool tx: %s", err))
log.WithError(err).Warn("failed to create pool tx")
@@ -619,7 +626,12 @@ func (s *service) listenToScannerNotifications() {
continue
}
signedForfeitTx, err := s.wallet.SignConnectorInput(ctx, forfeitTx, []int{0}, false)
if err := s.wallet.LockConnectorUtxos(ctx, []ports.TxOutpoint{txOutpoint{connectorTxid, connectorVout}}); err != nil {
log.WithError(err).Warn("failed to lock connector utxos")
continue
}
signedForfeitTx, err := s.wallet.SignPset(ctx, forfeitTx, false)
if err != nil {
log.WithError(err).Warn("failed to sign connector input in forfeit tx")
continue
@@ -697,8 +709,14 @@ func (s *service) getNextConnector(
for _, i := range pset.Inputs {
if chainhash.Hash(i.PreviousTxid).String() == u.GetTxid() && i.PreviousTxIndex == u.GetIndex() {
connectorOutpoint := newOutpointFromPsetInput(pset.Inputs[0])
if err := s.wallet.LockConnectorUtxos(ctx, []ports.TxOutpoint{connectorOutpoint}); err != nil {
return "", 0, err
}
// sign & broadcast the connector tx
signedConnectorTx, err := s.wallet.SignConnectorInput(ctx, b64, []int{0}, true)
signedConnectorTx, err := s.wallet.SignPset(ctx, b64, true)
if err != nil {
return "", 0, err
}
@@ -1015,3 +1033,23 @@ func findForfeitTx(
return "", fmt.Errorf("forfeit tx not found")
}
type txOutpoint struct {
txid string
vout uint32
}
func newOutpointFromPsetInput(input psetv2.Input) txOutpoint {
return txOutpoint{
txid: chainhash.Hash(input.PreviousTxid).String(),
vout: input.PreviousTxIndex,
}
}
func (outpoint txOutpoint) GetTxid() string {
return outpoint.txid
}
func (outpoint txOutpoint) GetIndex() uint32 {
return outpoint.vout
}

View File

@@ -3,6 +3,7 @@ package application
import (
"context"
"fmt"
"strings"
"time"
"github.com/ark-network/ark/common/tree"
@@ -227,7 +228,7 @@ func (s *sweeper) createTask(
err = nil
txid := ""
// retry until the tx is broadcasted or the error is not BIP68 final
for len(txid) == 0 && (err == nil || err == fmt.Errorf("non-BIP68-final")) {
for len(txid) == 0 && (err == nil || strings.Contains(err.Error(), "non-BIP68-final")) {
if err != nil {
log.Debugln("sweep tx not BIP68 final, retrying in 5 seconds")
time.Sleep(5 * time.Second)