From 449c3d533eb61247fefcf7cb60578a6b0166ac9b Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 9 Feb 2019 16:27:37 +0100 Subject: [PATCH] contractcourt: add access to full invoice registry from resolvers Previously a function pointer was passed to chain arbitrator to avoid a circular dependency. Now that the routetypes package exists, we can pass the full invoice registry to chain arbitrator. This is a preparation to be able to use other invoice registry methods in contract resolvers. --- contractcourt/chain_arbitrator.go | 9 ++++----- contractcourt/channel_arbitrator_test.go | 4 ---- contractcourt/htlc_success_resolver.go | 4 ++-- server.go | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 696ddeb26..9bdc68d0b 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -12,7 +12,7 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/input" - "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/sweep" @@ -137,10 +137,9 @@ type ChainArbitratorConfig struct { // Sweeper allows resolvers to sweep their final outputs. Sweeper *sweep.UtxoSweeper - // SettleInvoice attempts to settle an existing invoice on-chain with - // the given payment hash. ErrInvoiceNotFound is returned if an invoice - // is not found. - SettleInvoice func(lntypes.Hash, lnwire.MilliSatoshi) error + // Registry is the invoice database that is used by resolvers to lookup + // preimages and settle invoices. + Registry *invoices.InvoiceRegistry // NotifyClosedChannel is a function closure that the ChainArbitrator // will use to notify the ChannelNotifier about a newly closed channel. diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 5e89aef0a..ed64c2035 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -11,7 +11,6 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "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" ) @@ -177,9 +176,6 @@ func createTestChannelArbitrator(log ArbitratorLog) (*ChannelArbitrator, *lnwallet.IncomingHtlcResolution, uint32) error { return nil }, - SettleInvoice: func(lntypes.Hash, lnwire.MilliSatoshi) error { - return nil - }, } // We'll use the resolvedChan to synchronize on call to diff --git a/contractcourt/htlc_success_resolver.go b/contractcourt/htlc_success_resolver.go index abad34b4a..a8c774f7f 100644 --- a/contractcourt/htlc_success_resolver.go +++ b/contractcourt/htlc_success_resolver.go @@ -179,7 +179,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { // With the HTLC claimed, we can attempt to settle its // corresponding invoice if we were the original destination. - err = h.SettleInvoice(h.payHash, h.htlcAmt) + err = h.Registry.SettleInvoice(h.payHash, h.htlcAmt) if err != nil && err != channeldb.ErrInvoiceNotFound { log.Errorf("Unable to settle invoice with payment "+ "hash %x: %v", h.payHash, err) @@ -252,7 +252,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { // With the HTLC claimed, we can attempt to settle its corresponding // invoice if we were the original destination. - err = h.SettleInvoice(h.payHash, h.htlcAmt) + err = h.Registry.SettleInvoice(h.payHash, h.htlcAmt) if err != nil && err != channeldb.ErrInvoiceNotFound { log.Errorf("Unable to settle invoice with payment "+ "hash %x: %v", h.payHash, err) diff --git a/server.go b/server.go index dbe2512f0..71723acfc 100644 --- a/server.go +++ b/server.go @@ -778,7 +778,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, }, DisableChannel: s.chanStatusMgr.RequestDisable, Sweeper: s.sweeper, - SettleInvoice: s.invoices.SettleInvoice, + Registry: s.invoices, NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent, }, chanDB)