mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 09:45:25 +02:00
lnwallet/btcwallet: check publication error types, handle replacement
error Since btcwallet will return typed errors now, we can simplify the matching logic in order to return ErrDoubleSpend. In case a transaction cannot be published since it did not satisfy the requirements for a valid replacement, return ErrDoubleSpend to indicate it was not propagated.
This commit is contained in:
parent
96ebce6842
commit
61e1b48f57
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -429,47 +428,25 @@ func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32) (
|
|||||||
// network (either in the mempool or chain) no error will be returned.
|
// network (either in the mempool or chain) no error will be returned.
|
||||||
func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
|
func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
|
||||||
if err := b.wallet.PublishTransaction(tx); err != nil {
|
if err := b.wallet.PublishTransaction(tx); err != nil {
|
||||||
switch b.chain.(type) {
|
|
||||||
case *chain.RPCClient:
|
|
||||||
if strings.Contains(err.Error(), "already spent") {
|
|
||||||
// Output was already spent.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already been spent") {
|
|
||||||
// Output was already spent.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "orphan transaction") {
|
|
||||||
// Transaction is spending either output that
|
|
||||||
// is missing or already spent.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
|
|
||||||
case *chain.BitcoindClient:
|
// If we failed to publish the transaction, check whether we
|
||||||
if strings.Contains(err.Error(), "txn-mempool-conflict") {
|
// got an error of known type.
|
||||||
// Output was spent by other transaction
|
switch err.(type) {
|
||||||
// already in the mempool.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "insufficient fee") {
|
|
||||||
// RBF enabled transaction did not have enough fee.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "Missing inputs") {
|
|
||||||
// Transaction is spending either output that
|
|
||||||
// is missing or already spent.
|
|
||||||
return lnwallet.ErrDoubleSpend
|
|
||||||
}
|
|
||||||
|
|
||||||
case *chain.NeutrinoClient:
|
// If the wallet reports a double spend, convert it to our
|
||||||
if strings.Contains(err.Error(), "already spent") {
|
// internal ErrDoubleSpend and return.
|
||||||
// Output was already spent.
|
case *base.ErrDoubleSpend:
|
||||||
return lnwallet.ErrDoubleSpend
|
return lnwallet.ErrDoubleSpend
|
||||||
}
|
|
||||||
|
// If the wallet reports a replacement error, return
|
||||||
|
// ErrDoubleSpend, as we currently are never attempting to
|
||||||
|
// replace transactions.
|
||||||
|
case *base.ErrReplacement:
|
||||||
|
return lnwallet.ErrDoubleSpend
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user