multi: add TLV awareness to htlcswitch, pass extra EOB to the invoice registry

In this commit, we update the `HopIterator` to gain awareness of the new
TLV hop payload. The default `HopIterator` will now hide the details of
the TLV from the caller, and return the same `ForwardingInfo` struct in
a uniform manner. We also add a new method: `ExtraOnionBlob` to allow
the caller to obtain the raw EOB (the serialized TLV stream) to pass
around.

Within the link, we'll now pass the EOB information into the invoice
registry. This allows the registry to parse out any additional
information from the EOB that it needs to settle the payment, such as a
preimage shard in the AMP case.
This commit is contained in:
Olaoluwa Osuntokun
2019-07-30 21:52:17 -07:00
parent c78e3aaa9d
commit 23cc8389f2
10 changed files with 233 additions and 33 deletions

View File

@@ -489,7 +489,7 @@ func (i *InvoiceRegistry) checkHtlcParameters(invoice *channeldb.Invoice,
// prevent deadlock.
func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
hodlChan chan<- interface{}) (*HodlEvent, error) {
hodlChan chan<- interface{}, eob []byte) (*HodlEvent, error) {
i.Lock()
defer i.Unlock()

View File

@@ -119,7 +119,7 @@ func TestSettleInvoice(t *testing.T) {
// Settle invoice with a slightly higher amount.
amtPaid := lnwire.MilliSatoshi(100500)
_, err = registry.NotifyExitHopHtlc(
hash, amtPaid, testInvoiceExpiry, 0, hodlChan,
hash, amtPaid, testInvoiceExpiry, 0, hodlChan, nil,
)
if err != nil {
t.Fatal(err)
@@ -155,6 +155,7 @@ func TestSettleInvoice(t *testing.T) {
// restart.
event, err := registry.NotifyExitHopHtlc(
hash, amtPaid, testInvoiceExpiry, testCurrentHeight, hodlChan,
nil,
)
if err != nil {
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
@@ -168,7 +169,7 @@ func TestSettleInvoice(t *testing.T) {
// same. New HTLCs with a different amount should be rejected.
event, err = registry.NotifyExitHopHtlc(
hash, amtPaid+600, testInvoiceExpiry, testCurrentHeight,
hodlChan,
hodlChan, nil,
)
if err != nil {
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
@@ -181,7 +182,7 @@ func TestSettleInvoice(t *testing.T) {
// behaviour as settling with a higher amount.
event, err = registry.NotifyExitHopHtlc(
hash, amtPaid-600, testInvoiceExpiry, testCurrentHeight,
hodlChan,
hodlChan, nil,
)
if err != nil {
t.Fatalf("unexpected NotifyExitHopHtlc error: %v", err)
@@ -304,7 +305,7 @@ func TestCancelInvoice(t *testing.T) {
// succeed.
hodlChan := make(chan interface{})
event, err := registry.NotifyExitHopHtlc(
hash, amt, testInvoiceExpiry, testCurrentHeight, hodlChan,
hash, amt, testInvoiceExpiry, testCurrentHeight, hodlChan, nil,
)
if err != nil {
t.Fatal("expected settlement of a canceled invoice to succeed")
@@ -381,6 +382,7 @@ func TestHoldInvoice(t *testing.T) {
// should be possible.
event, err := registry.NotifyExitHopHtlc(
hash, amtPaid, testInvoiceExpiry, testCurrentHeight, hodlChan,
nil,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@@ -392,6 +394,7 @@ func TestHoldInvoice(t *testing.T) {
// Test idempotency.
event, err = registry.NotifyExitHopHtlc(
hash, amtPaid, testInvoiceExpiry, testCurrentHeight, hodlChan,
nil,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@@ -487,7 +490,7 @@ func TestUnknownInvoice(t *testing.T) {
hodlChan := make(chan interface{})
amt := lnwire.MilliSatoshi(100000)
_, err := registry.NotifyExitHopHtlc(
hash, amt, testInvoiceExpiry, testCurrentHeight, hodlChan,
hash, amt, testInvoiceExpiry, testCurrentHeight, hodlChan, nil,
)
if err != channeldb.ErrInvoiceNotFound {
t.Fatal("expected invoice not found error")