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.
This commit is contained in:
Joost Jager 2019-02-09 16:27:37 +01:00
parent 2be1051fb6
commit 449c3d533e
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
4 changed files with 7 additions and 12 deletions

@ -12,7 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/sweep" "github.com/lightningnetwork/lnd/sweep"
@ -137,10 +137,9 @@ type ChainArbitratorConfig struct {
// Sweeper allows resolvers to sweep their final outputs. // Sweeper allows resolvers to sweep their final outputs.
Sweeper *sweep.UtxoSweeper Sweeper *sweep.UtxoSweeper
// SettleInvoice attempts to settle an existing invoice on-chain with // Registry is the invoice database that is used by resolvers to lookup
// the given payment hash. ErrInvoiceNotFound is returned if an invoice // preimages and settle invoices.
// is not found. Registry *invoices.InvoiceRegistry
SettleInvoice func(lntypes.Hash, lnwire.MilliSatoshi) error
// NotifyClosedChannel is a function closure that the ChainArbitrator // NotifyClosedChannel is a function closure that the ChainArbitrator
// will use to notify the ChannelNotifier about a newly closed channel. // will use to notify the ChannelNotifier about a newly closed channel.

@ -11,7 +11,6 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -177,9 +176,6 @@ func createTestChannelArbitrator(log ArbitratorLog) (*ChannelArbitrator,
*lnwallet.IncomingHtlcResolution, uint32) error { *lnwallet.IncomingHtlcResolution, uint32) error {
return nil return nil
}, },
SettleInvoice: func(lntypes.Hash, lnwire.MilliSatoshi) error {
return nil
},
} }
// We'll use the resolvedChan to synchronize on call to // We'll use the resolvedChan to synchronize on call to

@ -179,7 +179,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
// With the HTLC claimed, we can attempt to settle its // With the HTLC claimed, we can attempt to settle its
// corresponding invoice if we were the original destination. // 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 { if err != nil && err != channeldb.ErrInvoiceNotFound {
log.Errorf("Unable to settle invoice with payment "+ log.Errorf("Unable to settle invoice with payment "+
"hash %x: %v", h.payHash, err) "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 // With the HTLC claimed, we can attempt to settle its corresponding
// invoice if we were the original destination. // 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 { if err != nil && err != channeldb.ErrInvoiceNotFound {
log.Errorf("Unable to settle invoice with payment "+ log.Errorf("Unable to settle invoice with payment "+
"hash %x: %v", h.payHash, err) "hash %x: %v", h.payHash, err)

@ -778,7 +778,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
}, },
DisableChannel: s.chanStatusMgr.RequestDisable, DisableChannel: s.chanStatusMgr.RequestDisable,
Sweeper: s.sweeper, Sweeper: s.sweeper,
SettleInvoice: s.invoices.SettleInvoice, Registry: s.invoices,
NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent, NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent,
}, chanDB) }, chanDB)