mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-07 05:49:59 +02:00
multi: add height-based invoice expiry
This commit adds height-based invoice expiry for hodl invoices that have active htlcs. This allows us to cancel our intentionally held htlcs before channels are force closed. We only add this for hodl invoices because we expect regular invoices to automatically be resolved. We still keep hodl invoices in the time-based expiry queue, because we want to expire open invoices that reach their timeout before any htlcs are added. Since htlcs are added after the invoice is created, we add new htlcs as they arrive in the invoice registry. In this commit, we allow adding of duplicate entries for an invoice to be added to the expiry queue as each htlc arrives to keep implementation simple. Our cancellation logic can already handle the case where an entry is already canceled, so this is ok.
This commit is contained in:
@ -797,6 +797,20 @@ type mockInvoiceRegistry struct {
|
||||
cleanup func()
|
||||
}
|
||||
|
||||
type mockChainNotifier struct {
|
||||
chainntnfs.ChainNotifier
|
||||
}
|
||||
|
||||
// RegisterBlockEpochNtfn mocks a successful call to register block
|
||||
// notifications.
|
||||
func (m *mockChainNotifier) RegisterBlockEpochNtfn(*chainntnfs.BlockEpoch) (
|
||||
*chainntnfs.BlockEpochEvent, error) {
|
||||
|
||||
return &chainntnfs.BlockEpochEvent{
|
||||
Cancel: func() {},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
|
||||
cdb, cleanup, err := newDB()
|
||||
if err != nil {
|
||||
@ -805,7 +819,10 @@ func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
|
||||
|
||||
registry := invoices.NewRegistry(
|
||||
cdb,
|
||||
invoices.NewInvoiceExpiryWatcher(clock.NewDefaultClock()),
|
||||
invoices.NewInvoiceExpiryWatcher(
|
||||
clock.NewDefaultClock(), 0, 0, nil,
|
||||
&mockChainNotifier{},
|
||||
),
|
||||
&invoices.RegistryConfig{
|
||||
FinalCltvRejectDelta: 5,
|
||||
},
|
||||
|
Reference in New Issue
Block a user