From 9e9b912d3a14cbe4727191988ada7b69ad54f19b Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 4 Nov 2019 15:10:32 -0800 Subject: [PATCH] multi: replace NotifyExitHopHtlc eob param with hop.Payload --- contractcourt/interfaces.go | 2 +- contractcourt/mock_registry_test.go | 2 +- htlcswitch/hop/payload.go | 6 ++++++ htlcswitch/interfaces.go | 2 +- htlcswitch/link.go | 7 +++---- htlcswitch/mock.go | 5 +++-- invoices/interface.go | 11 +++++++++++ invoices/invoiceregistry.go | 2 +- 8 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 invoices/interface.go diff --git a/contractcourt/interfaces.go b/contractcourt/interfaces.go index c928f428..c73a23a0 100644 --- a/contractcourt/interfaces.go +++ b/contractcourt/interfaces.go @@ -21,7 +21,7 @@ type Registry interface { NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32, circuitKey channeldb.CircuitKey, hodlChan chan<- interface{}, - eob []byte) (*invoices.HodlEvent, error) + payload invoices.Payload) (*invoices.HodlEvent, error) // HodlUnsubscribeAll unsubscribes from all hodl events. HodlUnsubscribeAll(subscriber chan<- interface{}) diff --git a/contractcourt/mock_registry_test.go b/contractcourt/mock_registry_test.go index e4502289..43195249 100644 --- a/contractcourt/mock_registry_test.go +++ b/contractcourt/mock_registry_test.go @@ -24,7 +24,7 @@ type mockRegistry struct { func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32, circuitKey channeldb.CircuitKey, hodlChan chan<- interface{}, - eob []byte) (*invoices.HodlEvent, error) { + payload invoices.Payload) (*invoices.HodlEvent, error) { r.notifyChan <- notifyExitHopData{ hodlChan: hodlChan, diff --git a/htlcswitch/hop/payload.go b/htlcswitch/hop/payload.go index ad164e28..e05b4ee9 100644 --- a/htlcswitch/hop/payload.go +++ b/htlcswitch/hop/payload.go @@ -233,3 +233,9 @@ func ValidateParsedPayloadTypes(parsedTypes tlv.TypeSet, return nil } + +// MultiPath returns the record corresponding the option_mpp parsed from the +// onion payload. +func (h *Payload) MultiPath() *record.MPP { + return h.MPP +} diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index cd050856..3b9ac6df 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -27,7 +27,7 @@ type InvoiceDatabase interface { NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32, circuitKey channeldb.CircuitKey, hodlChan chan<- interface{}, - eob []byte) (*invoices.HodlEvent, error) + payload invoices.Payload) (*invoices.HodlEvent, error) // CancelInvoice attempts to cancel the invoice corresponding to the // passed payment hash. diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 4593d042..4da9c0db 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2676,8 +2676,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, switch fwdInfo.NextHop { case hop.Exit: updated, err := l.processExitHop( - pd, obfuscator, fwdInfo, heightNow, - chanIterator.ExtraOnionBlob(), + pd, obfuscator, fwdInfo, heightNow, pld, ) if err != nil { l.fail(LinkFailureError{code: ErrInternalError}, @@ -2846,7 +2845,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, // returns a boolean indicating whether the commitment tx needs an update. func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor, obfuscator hop.ErrorEncrypter, fwdInfo hop.ForwardingInfo, - heightNow uint32, eob []byte) (bool, error) { + heightNow uint32, payload invoices.Payload) (bool, error) { // If hodl.ExitSettle is requested, we will not validate the final hop's // ADD, nor will we settle the corresponding invoice or respond with the @@ -2897,7 +2896,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor, event, err := l.cfg.Registry.NotifyExitHopHtlc( invoiceHash, pd.Amount, pd.Timeout, int32(heightNow), - circuitKey, l.hodlQueue.ChanIn(), eob, + circuitKey, l.hodlQueue.ChanIn(), payload, ) switch err { diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 7701846e..3dc1160d 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -814,10 +814,11 @@ func (i *mockInvoiceRegistry) SettleHodlInvoice(preimage lntypes.Preimage) error func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash, amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32, circuitKey channeldb.CircuitKey, hodlChan chan<- interface{}, - eob []byte) (*invoices.HodlEvent, error) { + payload invoices.Payload) (*invoices.HodlEvent, error) { event, err := i.registry.NotifyExitHopHtlc( - rhash, amt, expiry, currentHeight, circuitKey, hodlChan, eob, + rhash, amt, expiry, currentHeight, circuitKey, hodlChan, + payload, ) if err != nil { return nil, err diff --git a/invoices/interface.go b/invoices/interface.go new file mode 100644 index 00000000..8bbe2ec9 --- /dev/null +++ b/invoices/interface.go @@ -0,0 +1,11 @@ +package invoices + +import "github.com/lightningnetwork/lnd/record" + +// Payload abstracts access to any additional fields provided in the final hop's +// TLV onion payload. +type Payload interface { + // MultiPath returns the record corresponding the option_mpp parsed from + // the onion payload. + MultiPath() *record.MPP +} diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index 3f35954f..61f0feaf 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -429,7 +429,7 @@ func (i *InvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (channeldb.Invoice, func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash, amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32, circuitKey channeldb.CircuitKey, hodlChan chan<- interface{}, - eob []byte) (*HodlEvent, error) { + payload Payload) (*HodlEvent, error) { i.Lock() defer i.Unlock()