mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-01 18:27:43 +02:00
cnct: store full htlc struct inside resolver
This change prepares for accessing the onion blob from a resolver.
This commit is contained in:
@@ -8,9 +8,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
)
|
||||
|
||||
@@ -39,9 +37,6 @@ type htlcSuccessResolver struct {
|
||||
// historical queries to the chain for spends/confirmations.
|
||||
broadcastHeight uint32
|
||||
|
||||
// payHash is the payment hash of the original HTLC extended to us.
|
||||
payHash lntypes.Hash
|
||||
|
||||
// sweepTx will be non-nil if we've already crafted a transaction to
|
||||
// sweep a direct HTLC output. This is only a concern if we're sweeping
|
||||
// from the commitment transaction of the remote party.
|
||||
@@ -49,25 +44,22 @@ type htlcSuccessResolver struct {
|
||||
// TODO(roasbeef): send off to utxobundler
|
||||
sweepTx *wire.MsgTx
|
||||
|
||||
// htlcAmt is the original amount of the htlc, not taking into
|
||||
// account any fees that may have to be paid if it goes on chain.
|
||||
htlcAmt lnwire.MilliSatoshi
|
||||
// htlc contains information on the htlc that we are resolving on-chain.
|
||||
htlc channeldb.HTLC
|
||||
|
||||
contractResolverKit
|
||||
}
|
||||
|
||||
// newSuccessResolver instanties a new htlc success resolver.
|
||||
func newSuccessResolver(res lnwallet.IncomingHtlcResolution,
|
||||
broadcastHeight uint32, payHash lntypes.Hash,
|
||||
htlcAmt lnwire.MilliSatoshi,
|
||||
broadcastHeight uint32, htlc channeldb.HTLC,
|
||||
resCfg ResolverConfig) *htlcSuccessResolver {
|
||||
|
||||
return &htlcSuccessResolver{
|
||||
contractResolverKit: *newContractResolverKit(resCfg),
|
||||
htlcResolution: res,
|
||||
broadcastHeight: broadcastHeight,
|
||||
payHash: payHash,
|
||||
htlcAmt: htlcAmt,
|
||||
htlc: htlc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +107,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
if h.sweepTx == nil {
|
||||
log.Infof("%T(%x): crafting sweep tx for "+
|
||||
"incoming+remote htlc confirmed", h,
|
||||
h.payHash[:])
|
||||
h.htlc.RHash[:])
|
||||
|
||||
// Before we can craft out sweeping transaction, we
|
||||
// need to create an input which contains all the items
|
||||
@@ -149,7 +141,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): crafted sweep tx=%v", h,
|
||||
h.payHash[:], spew.Sdump(h.sweepTx))
|
||||
h.htlc.RHash[:], spew.Sdump(h.sweepTx))
|
||||
|
||||
// With the sweep transaction signed, we'll now
|
||||
// Checkpoint our state.
|
||||
@@ -165,7 +157,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
err := h.PublishTx(h.sweepTx)
|
||||
if err != nil {
|
||||
log.Infof("%T(%x): unable to publish tx: %v",
|
||||
h, h.payHash[:], err)
|
||||
h, h.htlc.RHash[:], err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -181,7 +173,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): waiting for sweep tx (txid=%v) to be "+
|
||||
"confirmed", h, h.payHash[:], sweepTXID)
|
||||
"confirmed", h, h.htlc.RHash[:], sweepTXID)
|
||||
|
||||
select {
|
||||
case _, ok := <-confNtfn.Confirmed:
|
||||
@@ -200,7 +192,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): broadcasting second-layer transition tx: %v",
|
||||
h, h.payHash[:], spew.Sdump(h.htlcResolution.SignedSuccessTx))
|
||||
h, h.htlc.RHash[:], spew.Sdump(h.htlcResolution.SignedSuccessTx))
|
||||
|
||||
// We'll now broadcast the second layer transaction so we can kick off
|
||||
// the claiming process.
|
||||
@@ -216,7 +208,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
// done so.
|
||||
if !h.outputIncubating {
|
||||
log.Infof("%T(%x): incubating incoming htlc output",
|
||||
h, h.payHash[:])
|
||||
h, h.htlc.RHash[:])
|
||||
|
||||
err := h.IncubateOutputs(
|
||||
h.ChanPoint, nil, nil, &h.htlcResolution,
|
||||
@@ -246,7 +238,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
|
||||
}
|
||||
|
||||
log.Infof("%T(%x): waiting for second-level HTLC output to be spent "+
|
||||
"after csv_delay=%v", h, h.payHash[:], h.htlcResolution.CsvDelay)
|
||||
"after csv_delay=%v", h, h.htlc.RHash[:], h.htlcResolution.CsvDelay)
|
||||
|
||||
select {
|
||||
case _, ok := <-spendNtfn.Spend:
|
||||
@@ -299,7 +291,7 @@ func (h *htlcSuccessResolver) Encode(w io.Writer) error {
|
||||
if err := binary.Write(w, endian, h.broadcastHeight); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write(h.payHash[:]); err != nil {
|
||||
if _, err := w.Write(h.htlc.RHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -332,7 +324,7 @@ func newSuccessResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
||||
if err := binary.Read(r, endian, &h.broadcastHeight); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := io.ReadFull(r, h.payHash[:]); err != nil {
|
||||
if _, err := io.ReadFull(r, h.htlc.RHash[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -344,7 +336,7 @@ func newSuccessResolverFromReader(r io.Reader, resCfg ResolverConfig) (
|
||||
//
|
||||
// NOTE: Part of the htlcContractResolver interface.
|
||||
func (h *htlcSuccessResolver) Supplement(htlc channeldb.HTLC) {
|
||||
h.htlcAmt = htlc.Amt
|
||||
h.htlc = htlc
|
||||
}
|
||||
|
||||
// HtlcPoint returns the htlc's outpoint on the commitment tx.
|
||||
|
Reference in New Issue
Block a user