htlcswitch: add cleanStore method

That let us clean up handed off payment results, as they will never be
queried again.
This commit is contained in:
Johan T. Halseth committed 2020-10-06 10:46:03 +02:00
1 parent d1a118388d
commit b071278f07
2 files changed
+67 -1

No files matched your search

+22 -1
View File
@@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
// TestNetworkResultSerialization checks that NetworkResults are properly
@@ -180,7 +181,6 @@ func TestNetworkResultStore(t *testing.T) {
// Since we don't delete results from the store (yet), make sure we
// will get subscriptions for all of them.
// TODO(halseth): check deletion when we have reliable handoff.
for i := uint64(0); i < numResults; i++ {
sub, err := store.subscribeResult(i)
if err != nil {
@@ -193,4 +193,25 @@ func TestNetworkResultStore(t *testing.T) {
t.Fatalf("no result received")
}
}
// Clean the store keeping the first two results.
toKeep := map[uint64]struct{}{
0: {},
1: {},
}
// Finally, delete the result.
err = store.cleanStore(toKeep)
require.NoError(t, err)
// Payment IDs 0 and 1 should be found, 2 and 3 should be deleted.
for i := uint64(0); i < numResults; i++ {
_, err = store.getResult(i)
if i <= 1 {
require.NoError(t, err, "unable to get result")
}
if i >= 2 && err != ErrPaymentIDNotFound {
t.Fatalf("expected ErrPaymentIDNotFound, got %v", err)
}
}
}