mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 20:15:18 +02:00
cnct+htlcswitch+invoices: report circuit key to invoice registry
Currently the invoice registry cannot tell apart the htlcs that pay to an invoice. Because htlcs may also be replayed on startup, it isn't possible to determine the total amount paid to an invoice. This commit is a first step towards fixing that. It reports the circuit keys of htlcs to the invoice registry, which forms the basis for accurate invoice accounting.
This commit is contained in:
@@ -498,9 +498,7 @@ func (c *ChannelArbitrator) supplementResolver(resolver ContractResolver,
|
||||
return c.supplementSuccessResolver(r, htlcMap)
|
||||
|
||||
case *htlcIncomingContestResolver:
|
||||
return c.supplementSuccessResolver(
|
||||
&r.htlcSuccessResolver, htlcMap,
|
||||
)
|
||||
return c.supplementIncomingContestResolver(r, htlcMap)
|
||||
|
||||
case *htlcTimeoutResolver:
|
||||
return c.supplementTimeoutResolver(r, htlcMap)
|
||||
@@ -514,6 +512,30 @@ func (c *ChannelArbitrator) supplementResolver(resolver ContractResolver,
|
||||
return nil
|
||||
}
|
||||
|
||||
// supplementSuccessResolver takes a htlcIncomingContestResolver as it is
|
||||
// restored from the log and fills in missing data from the htlcMap.
|
||||
func (c *ChannelArbitrator) supplementIncomingContestResolver(
|
||||
r *htlcIncomingContestResolver,
|
||||
htlcMap map[wire.OutPoint]*channeldb.HTLC) error {
|
||||
|
||||
res := r.htlcResolution
|
||||
htlcPoint := res.HtlcPoint()
|
||||
htlc, ok := htlcMap[htlcPoint]
|
||||
if !ok {
|
||||
return errors.New(
|
||||
"htlc for incoming contest resolver unavailable",
|
||||
)
|
||||
}
|
||||
|
||||
r.htlcAmt = htlc.Amt
|
||||
r.circuitKey = channeldb.CircuitKey{
|
||||
ChanID: c.cfg.ShortChanID,
|
||||
HtlcID: htlc.HtlcIndex,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// supplementSuccessResolver takes a htlcSuccessResolver as it is restored from
|
||||
// the log and fills in missing data from the htlcMap.
|
||||
func (c *ChannelArbitrator) supplementSuccessResolver(r *htlcSuccessResolver,
|
||||
|
@@ -27,6 +27,9 @@ type htlcIncomingContestResolver struct {
|
||||
// successfully.
|
||||
htlcExpiry uint32
|
||||
|
||||
// circuitKey describes the incoming htlc that is being resolved.
|
||||
circuitKey channeldb.CircuitKey
|
||||
|
||||
// htlcSuccessResolver is the inner resolver that may be utilized if we
|
||||
// learn of the preimage.
|
||||
htlcSuccessResolver
|
||||
@@ -166,7 +169,7 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
|
||||
// identical to HTLC resolution in the link.
|
||||
event, err := h.Registry.NotifyExitHopHtlc(
|
||||
h.payHash, h.htlcAmt, h.htlcExpiry, currentHeight,
|
||||
hodlChan, nil,
|
||||
h.circuitKey, hodlChan, nil,
|
||||
)
|
||||
switch err {
|
||||
case channeldb.ErrInvoiceNotFound:
|
||||
|
@@ -22,7 +22,7 @@ type Registry interface {
|
||||
// the resolution is sent on the passed in hodlChan later.
|
||||
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
|
||||
expiry uint32, currentHeight int32,
|
||||
hodlChan chan<- interface{},
|
||||
circuitKey channeldb.CircuitKey, hodlChan chan<- interface{},
|
||||
eob []byte) (*invoices.HodlEvent, error)
|
||||
|
||||
// HodlUnsubscribeAll unsubscribes from all hodl events.
|
||||
|
@@ -23,7 +23,8 @@ type mockRegistry struct {
|
||||
|
||||
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
|
||||
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
|
||||
hodlChan chan<- interface{}, eob []byte) (*invoices.HodlEvent, error) {
|
||||
circuitKey channeldb.CircuitKey, hodlChan chan<- interface{},
|
||||
eob []byte) (*invoices.HodlEvent, error) {
|
||||
|
||||
r.notifyChan <- notifyExitHopData{
|
||||
hodlChan: hodlChan,
|
||||
|
Reference in New Issue
Block a user