channeldb: wipe all forwarding pkgs when close channel
This commit is contained in:
2 files changed
+33
No files matched your search
@@ -2862,6 +2862,12 @@ func (c *OpenChannel) CloseChannel(summary *ChannelCloseSummary,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete all the forwarding packages stored for this particular
|
||||||
|
// channel.
|
||||||
|
if err = chanState.Packager.Wipe(tx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Now that the index to this channel has been deleted, purge
|
// Now that the index to this channel has been deleted, purge
|
||||||
// the remaining channel metadata from the database.
|
// the remaining channel metadata from the database.
|
||||||
err = deleteOpenChannel(chanBucket)
|
err = deleteOpenChannel(chanBucket)
|
||||||
|
|||||||
@@ -130,6 +130,25 @@ func remoteHtlcsOption(htlcs []HTLC) testChannelOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadFwdPkgs is a helper method that reads all forwarding packages for a
|
||||||
|
// particular packager.
|
||||||
|
func loadFwdPkgs(t *testing.T, db kvdb.Backend,
|
||||||
|
packager FwdPackager) []*FwdPkg {
|
||||||
|
|
||||||
|
var (
|
||||||
|
fwdPkgs []*FwdPkg
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
err = kvdb.View(db, func(tx kvdb.RTx) error {
|
||||||
|
fwdPkgs, err = packager.LoadFwdPkgs(tx)
|
||||||
|
return err
|
||||||
|
}, func() {})
|
||||||
|
require.NoError(t, err, "unable to load fwd pkgs")
|
||||||
|
|
||||||
|
return fwdPkgs
|
||||||
|
}
|
||||||
|
|
||||||
// localShutdownOption is an option which sets the local upfront shutdown
|
// localShutdownOption is an option which sets the local upfront shutdown
|
||||||
// script for the channel.
|
// script for the channel.
|
||||||
func localShutdownOption(addr lnwire.DeliveryAddress) testChannelOption {
|
func localShutdownOption(addr lnwire.DeliveryAddress) testChannelOption {
|
||||||
@@ -822,6 +841,10 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
t.Fatalf("revocation state was not synced")
|
t.Fatalf("revocation state was not synced")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, we should have 2 forwarding packages added.
|
||||||
|
fwdPkgs := loadFwdPkgs(t, cdb, channel.Packager)
|
||||||
|
require.Len(t, fwdPkgs, 2, "wrong number of forwarding packages")
|
||||||
|
|
||||||
// Now attempt to delete the channel from the database.
|
// Now attempt to delete the channel from the database.
|
||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: channel.FundingOutpoint,
|
ChanPoint: channel.FundingOutpoint,
|
||||||
@@ -852,6 +875,10 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("revocation log search should have failed")
|
t.Fatal("revocation log search should have failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All forwarding packages of this channel has been deleted too.
|
||||||
|
fwdPkgs = loadFwdPkgs(t, cdb, channel.Packager)
|
||||||
|
require.Empty(t, fwdPkgs, "no forwarding packages should exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchPendingChannels(t *testing.T) {
|
func TestFetchPendingChannels(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user