mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
invoices: add RegistryConfig struct
This commit is contained in:
parent
56282db30a
commit
499f2b16cf
@ -790,9 +790,12 @@ func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
finalCltvRejectDelta := int32(5)
|
registry := invoices.NewRegistry(
|
||||||
|
cdb,
|
||||||
registry := invoices.NewRegistry(cdb, finalCltvRejectDelta)
|
&invoices.RegistryConfig{
|
||||||
|
FinalCltvRejectDelta: 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
registry.Start()
|
registry.Start()
|
||||||
|
|
||||||
return &mockInvoiceRegistry{
|
return &mockInvoiceRegistry{
|
||||||
|
@ -41,6 +41,16 @@ type HodlEvent struct {
|
|||||||
AcceptHeight int32
|
AcceptHeight int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegistryConfig contains the configuration parameters for invoice registry.
|
||||||
|
type RegistryConfig struct {
|
||||||
|
// FinalCltvRejectDelta defines the number of blocks before the expiry
|
||||||
|
// of the htlc where we no longer settle it as an exit hop and instead
|
||||||
|
// cancel it back. Normally this value should be lower than the cltv
|
||||||
|
// expiry of any invoice we create and the code effectuating this should
|
||||||
|
// not be hit.
|
||||||
|
FinalCltvRejectDelta int32
|
||||||
|
}
|
||||||
|
|
||||||
// InvoiceRegistry is a central registry of all the outstanding invoices
|
// InvoiceRegistry is a central registry of all the outstanding invoices
|
||||||
// created by the daemon. The registry is a thin wrapper around a map in order
|
// created by the daemon. The registry is a thin wrapper around a map in order
|
||||||
// to ensure that all updates/reads are thread safe.
|
// to ensure that all updates/reads are thread safe.
|
||||||
@ -49,6 +59,9 @@ type InvoiceRegistry struct {
|
|||||||
|
|
||||||
cdb *channeldb.DB
|
cdb *channeldb.DB
|
||||||
|
|
||||||
|
// cfg contains the registry's configuration parameters.
|
||||||
|
cfg *RegistryConfig
|
||||||
|
|
||||||
clientMtx sync.Mutex
|
clientMtx sync.Mutex
|
||||||
nextClientID uint32
|
nextClientID uint32
|
||||||
notificationClients map[uint32]*InvoiceSubscription
|
notificationClients map[uint32]*InvoiceSubscription
|
||||||
@ -69,13 +82,6 @@ type InvoiceRegistry struct {
|
|||||||
// subscriber. This is used to unsubscribe from all hashes efficiently.
|
// subscriber. This is used to unsubscribe from all hashes efficiently.
|
||||||
hodlReverseSubscriptions map[chan<- interface{}]map[channeldb.CircuitKey]struct{}
|
hodlReverseSubscriptions map[chan<- interface{}]map[channeldb.CircuitKey]struct{}
|
||||||
|
|
||||||
// finalCltvRejectDelta defines the number of blocks before the expiry
|
|
||||||
// of the htlc where we no longer settle it as an exit hop and instead
|
|
||||||
// cancel it back. Normally this value should be lower than the cltv
|
|
||||||
// expiry of any invoice we create and the code effectuating this should
|
|
||||||
// not be hit.
|
|
||||||
finalCltvRejectDelta int32
|
|
||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
@ -84,7 +90,7 @@ type InvoiceRegistry struct {
|
|||||||
// wraps the persistent on-disk invoice storage with an additional in-memory
|
// wraps the persistent on-disk invoice storage with an additional in-memory
|
||||||
// layer. The in-memory layer is in place such that debug invoices can be added
|
// layer. The in-memory layer is in place such that debug invoices can be added
|
||||||
// which are volatile yet available system wide within the daemon.
|
// which are volatile yet available system wide within the daemon.
|
||||||
func NewRegistry(cdb *channeldb.DB, finalCltvRejectDelta int32) *InvoiceRegistry {
|
func NewRegistry(cdb *channeldb.DB, cfg *RegistryConfig) *InvoiceRegistry {
|
||||||
|
|
||||||
return &InvoiceRegistry{
|
return &InvoiceRegistry{
|
||||||
cdb: cdb,
|
cdb: cdb,
|
||||||
@ -95,7 +101,7 @@ func NewRegistry(cdb *channeldb.DB, finalCltvRejectDelta int32) *InvoiceRegistry
|
|||||||
invoiceEvents: make(chan interface{}, 100),
|
invoiceEvents: make(chan interface{}, 100),
|
||||||
hodlSubscriptions: make(map[channeldb.CircuitKey]map[chan<- interface{}]struct{}),
|
hodlSubscriptions: make(map[channeldb.CircuitKey]map[chan<- interface{}]struct{}),
|
||||||
hodlReverseSubscriptions: make(map[chan<- interface{}]map[channeldb.CircuitKey]struct{}),
|
hodlReverseSubscriptions: make(map[chan<- interface{}]map[channeldb.CircuitKey]struct{}),
|
||||||
finalCltvRejectDelta: finalCltvRejectDelta,
|
cfg: cfg,
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,7 +448,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
|||||||
amtPaid: amtPaid,
|
amtPaid: amtPaid,
|
||||||
expiry: expiry,
|
expiry: expiry,
|
||||||
currentHeight: currentHeight,
|
currentHeight: currentHeight,
|
||||||
finalCltvRejectDelta: i.finalCltvRejectDelta,
|
finalCltvRejectDelta: i.cfg.FinalCltvRejectDelta,
|
||||||
customRecords: payload.CustomRecords(),
|
customRecords: payload.CustomRecords(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,10 @@ func newTestContext(t *testing.T) *testContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate and start the invoice ctx.registry.
|
// Instantiate and start the invoice ctx.registry.
|
||||||
registry := NewRegistry(cdb, testFinalCltvRejectDelta)
|
cfg := RegistryConfig{
|
||||||
|
FinalCltvRejectDelta: testFinalCltvRejectDelta,
|
||||||
|
}
|
||||||
|
registry := NewRegistry(cdb, &cfg)
|
||||||
|
|
||||||
err = registry.Start()
|
err = registry.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -390,7 +393,10 @@ func TestSettleHoldInvoice(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// Instantiate and start the invoice ctx.registry.
|
// Instantiate and start the invoice ctx.registry.
|
||||||
registry := NewRegistry(cdb, testFinalCltvRejectDelta)
|
cfg := RegistryConfig{
|
||||||
|
FinalCltvRejectDelta: testFinalCltvRejectDelta,
|
||||||
|
}
|
||||||
|
registry := NewRegistry(cdb, &cfg)
|
||||||
|
|
||||||
err = registry.Start()
|
err = registry.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -558,7 +564,10 @@ func TestCancelHoldInvoice(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// Instantiate and start the invoice ctx.registry.
|
// Instantiate and start the invoice ctx.registry.
|
||||||
registry := NewRegistry(cdb, testFinalCltvRejectDelta)
|
cfg := RegistryConfig{
|
||||||
|
FinalCltvRejectDelta: testFinalCltvRejectDelta,
|
||||||
|
}
|
||||||
|
registry := NewRegistry(cdb, &cfg)
|
||||||
|
|
||||||
err = registry.Start()
|
err = registry.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -378,6 +378,10 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registryConfig := invoices.RegistryConfig{
|
||||||
|
FinalCltvRejectDelta: defaultFinalCltvRejectDelta,
|
||||||
|
}
|
||||||
|
|
||||||
s := &server{
|
s := &server{
|
||||||
chanDB: chanDB,
|
chanDB: chanDB,
|
||||||
cc: cc,
|
cc: cc,
|
||||||
@ -386,9 +390,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
readPool: readPool,
|
readPool: readPool,
|
||||||
chansToRestore: chansToRestore,
|
chansToRestore: chansToRestore,
|
||||||
|
|
||||||
invoices: invoices.NewRegistry(
|
invoices: invoices.NewRegistry(chanDB, ®istryConfig),
|
||||||
chanDB, defaultFinalCltvRejectDelta,
|
|
||||||
),
|
|
||||||
|
|
||||||
channelNotifier: channelnotifier.New(chanDB),
|
channelNotifier: channelnotifier.New(chanDB),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user