lnd.xprv/watchtower/lookout/punisher.go
Wilmer Paulino 7946d0a256
multi: remove ErrDoubleSpend check for PublishTransaction
In this commit, we address a lingering issue within some subsystems that
are responsible for broadcasting transactions. Previously,
ErrDoubleSpend indicated that a transaction was already included in the
mempool/chain. This error was then modified to actually be returned for
conflicting transactions, but its callers were not modified accordingly.
This would lead to conflicting transactions to be interpreted as valid,
when they shouldn't be.
2019-03-13 17:57:19 -07:00

58 lines
1.6 KiB
Go

package lookout
import (
"github.com/btcsuite/btcd/wire"
)
// PunisherConfig houses the resources required by the Punisher.
type PunisherConfig struct {
// PublishTx provides the ability to send a signed transaction to the
// network.
PublishTx func(*wire.MsgTx) error
// TODO(conner) add DB tracking and spend ntfn registration to see if
// ours confirmed or not
}
// BreachPunisher handles the responsibility of constructing and broadcasting
// justice transactions. Justice transactions are constructed from previously
// accepted state updates uploaded by the watchtower's clients.
type BreachPunisher struct {
cfg *PunisherConfig
}
// NewBreachPunisher constructs a new BreachPunisher given a PunisherConfig.
func NewBreachPunisher(cfg *PunisherConfig) *BreachPunisher {
return &BreachPunisher{
cfg: cfg,
}
}
// Punish constructs a justice transaction given a JusticeDescriptor and
// publishes is it to the network.
func (p *BreachPunisher) Punish(desc *JusticeDescriptor, quit <-chan struct{}) error {
justiceTxn, err := desc.CreateJusticeTxn()
if err != nil {
log.Errorf("Unable to create justice txn for "+
"client=%s with breach-txid=%s: %v",
desc.SessionInfo.ID, desc.BreachedCommitTx.TxHash(), err)
return err
}
log.Infof("Publishing justice transaction for client=%s with txid=%s",
desc.SessionInfo.ID, justiceTxn.TxHash())
err = p.cfg.PublishTx(justiceTxn)
if err != nil {
log.Errorf("Unable to publish justice txn for client=%s"+
"with breach-txid=%s: %v",
desc.SessionInfo.ID, desc.BreachedCommitTx.TxHash(), err)
return err
}
// TODO(conner): register for spend and remove from db after
// confirmation
return nil
}