Merge pull request #2671 from wpaulino/tx-broadcast-err-handling
lnwallet/btcwallet: remove invalid transactions from the wallet when broadcast fails
This commit is contained in:
commit
c1228ae15f
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
@ -148,7 +147,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
|||||||
// constructed, we'll broadcast the sweep transaction to the
|
// constructed, we'll broadcast the sweep transaction to the
|
||||||
// network.
|
// network.
|
||||||
err := h.PublishTx(h.sweepTx)
|
err := h.PublishTx(h.sweepTx)
|
||||||
if err != nil && err != lnwallet.ErrDoubleSpend {
|
if err != nil {
|
||||||
log.Infof("%T(%x): unable to publish tx: %v",
|
log.Infof("%T(%x): unable to publish tx: %v",
|
||||||
h, h.payHash[:], err)
|
h, h.payHash[:], err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -200,7 +199,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): after changing sighashes send to tx bundler
|
// TODO(roasbeef): after changing sighashes send to tx bundler
|
||||||
err := h.PublishTx(h.htlcResolution.SignedSuccessTx)
|
err := h.PublishTx(h.htlcResolution.SignedSuccessTx)
|
||||||
if err != nil && err != lnwallet.ErrDoubleSpend {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ func (f *fundingManager) Start() error {
|
|||||||
channel.IsInitiator {
|
channel.IsInitiator {
|
||||||
|
|
||||||
err := f.cfg.PublishTransaction(channel.FundingTxn)
|
err := f.cfg.PublishTransaction(channel.FundingTxn)
|
||||||
if err != nil && err != lnwallet.ErrDoubleSpend {
|
if err != nil {
|
||||||
fndgLog.Errorf("Unable to rebroadcast funding "+
|
fndgLog.Errorf("Unable to rebroadcast funding "+
|
||||||
"tx for ChannelPoint(%v): %v",
|
"tx for ChannelPoint(%v): %v",
|
||||||
channel.FundingOutpoint, err)
|
channel.FundingOutpoint, err)
|
||||||
|
@ -384,28 +384,13 @@ func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32) (
|
|||||||
|
|
||||||
// PublishTransaction performs cursory validation (dust checks, etc), then
|
// PublishTransaction performs cursory validation (dust checks, etc), then
|
||||||
// finally broadcasts the passed transaction to the Bitcoin network. If
|
// finally broadcasts the passed transaction to the Bitcoin network. If
|
||||||
// publishing the transaction fails, an error describing the reason is
|
// publishing the transaction fails, an error describing the reason is returned
|
||||||
// returned (currently ErrDoubleSpend). If the transaction is already
|
// (currently ErrDoubleSpend). If the transaction is already published to the
|
||||||
// published to the network (either in the mempool or chain) no error
|
// network (either in the mempool or chain) no error will be returned.
|
||||||
// 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) {
|
switch b.chain.(type) {
|
||||||
case *chain.RPCClient:
|
case *chain.RPCClient:
|
||||||
if strings.Contains(err.Error(), "already have") {
|
|
||||||
// Transaction was already in the mempool, do
|
|
||||||
// not treat as an error. We do this to mimic
|
|
||||||
// the behaviour of bitcoind, which will not
|
|
||||||
// return an error if a transaction in the
|
|
||||||
// mempool is sent again using the
|
|
||||||
// sendrawtransaction RPC call.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already exists") {
|
|
||||||
// Transaction was already mined, we don't
|
|
||||||
// consider this an error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already spent") {
|
if strings.Contains(err.Error(), "already spent") {
|
||||||
// Output was already spent.
|
// Output was already spent.
|
||||||
return lnwallet.ErrDoubleSpend
|
return lnwallet.ErrDoubleSpend
|
||||||
@ -421,19 +406,6 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *chain.BitcoindClient:
|
case *chain.BitcoindClient:
|
||||||
if strings.Contains(err.Error(), "txn-already-in-mempool") {
|
|
||||||
// Transaction in mempool, treat as non-error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "txn-already-known") {
|
|
||||||
// Transaction in mempool, treat as non-error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already in block") {
|
|
||||||
// Transaction was already mined, we don't
|
|
||||||
// consider this an error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "txn-mempool-conflict") {
|
if strings.Contains(err.Error(), "txn-mempool-conflict") {
|
||||||
// Output was spent by other transaction
|
// Output was spent by other transaction
|
||||||
// already in the mempool.
|
// already in the mempool.
|
||||||
@ -450,16 +422,6 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *chain.NeutrinoClient:
|
case *chain.NeutrinoClient:
|
||||||
if strings.Contains(err.Error(), "already have") {
|
|
||||||
// Transaction was already in the mempool, do
|
|
||||||
// not treat as an error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already exists") {
|
|
||||||
// Transaction was already mined, we don't
|
|
||||||
// consider this an error.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "already spent") {
|
if strings.Contains(err.Error(), "already spent") {
|
||||||
// Output was already spent.
|
// Output was already spent.
|
||||||
return lnwallet.ErrDoubleSpend
|
return lnwallet.ErrDoubleSpend
|
||||||
|
@ -894,7 +894,7 @@ func (u *utxoNursery) sweepCribOutput(classHeight uint32, baby *babyOutput) erro
|
|||||||
// We'll now broadcast the HTLC transaction, then wait for it to be
|
// We'll now broadcast the HTLC transaction, then wait for it to be
|
||||||
// confirmed before transitioning it to kindergarten.
|
// confirmed before transitioning it to kindergarten.
|
||||||
err := u.cfg.PublishTransaction(baby.timeoutTx)
|
err := u.cfg.PublishTransaction(baby.timeoutTx)
|
||||||
if err != nil && err != lnwallet.ErrDoubleSpend {
|
if err != nil {
|
||||||
utxnLog.Errorf("Unable to broadcast baby tx: "+
|
utxnLog.Errorf("Unable to broadcast baby tx: "+
|
||||||
"%v, %v", err, spew.Sdump(baby.timeoutTx))
|
"%v, %v", err, spew.Sdump(baby.timeoutTx))
|
||||||
return err
|
return err
|
||||||
|
@ -2,7 +2,6 @@ package lookout
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PunisherConfig houses the resources required by the Punisher.
|
// PunisherConfig houses the resources required by the Punisher.
|
||||||
@ -44,7 +43,7 @@ func (p *BreachPunisher) Punish(desc *JusticeDescriptor, quit <-chan struct{}) e
|
|||||||
desc.SessionInfo.ID, justiceTxn.TxHash())
|
desc.SessionInfo.ID, justiceTxn.TxHash())
|
||||||
|
|
||||||
err = p.cfg.PublishTx(justiceTxn)
|
err = p.cfg.PublishTx(justiceTxn)
|
||||||
if err != nil && err != lnwallet.ErrDoubleSpend {
|
if err != nil {
|
||||||
log.Errorf("Unable to publish justice txn for client=%s"+
|
log.Errorf("Unable to publish justice txn for client=%s"+
|
||||||
"with breach-txid=%s: %v",
|
"with breach-txid=%s: %v",
|
||||||
desc.SessionInfo.ID, desc.BreachedCommitTx.TxHash(), err)
|
desc.SessionInfo.ID, desc.BreachedCommitTx.TxHash(), err)
|
||||||
|
Loading…
Reference in New Issue
Block a user