From 91f32ad270078e682d926ad078f293edefe83c32 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 13 Jan 2022 15:05:48 -0800 Subject: [PATCH 1/2] contractcourt: catch error when no historical bucket exists For older nodes, this bucket was never created, so we'll get an error if we try and query it. In this commit, we catch this error like we do when a given channel doesn't have the information (but the bucket actually exists). Fixes #6155 --- channeldb/db.go | 1 + channeldb/db_test.go | 7 ++++--- contractcourt/channel_arbitrator.go | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/channeldb/db.go b/channeldb/db.go index 92a49c2f8..1079cfd4c 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -329,6 +329,7 @@ var dbTopLevelBuckets = [][]byte{ metaBucket, closeSummaryBucket, outpointBucket, + historicalChannelBucket, } // Wipe completely deletes all saved state within all used buckets within the diff --git a/channeldb/db_test.go b/channeldb/db_test.go index c0b9bd79c..2773437f1 100644 --- a/channeldb/db_test.go +++ b/channeldb/db_test.go @@ -717,10 +717,11 @@ func TestFetchHistoricalChannel(t *testing.T) { // Create a an open channel in the database. channel := createTestChannel(t, cdb, openChannelOption()) - // First, try to lookup a channel when the bucket does not - // exist. + // First, try to lookup a channel when nothing is in the bucket. As the + // bucket is auto-created (on start up), we'll get a channel not found + // error. _, err = cdb.FetchHistoricalChannel(&channel.FundingOutpoint) - if err != ErrNoHistoricalBucket { + if err != ErrChannelNotFound { t.Fatalf("expected no bucket, got: %v", err) } diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index cc4c83ba6..4dadfa950 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -618,6 +618,8 @@ func (c *ChannelArbitrator) relaunchResolvers(commitSet *CommitSet, // If we don't find this channel, then it may be the case that it // was closed before we started to retain the final state // information for open channels. + case err == channeldb.ErrNoHistoricalBucket: + fallthrough case err == channeldb.ErrChannelNotFound: log.Warnf("ChannelArbitrator(%v): unable to fetch historical "+ "state", c.cfg.ChanPoint) @@ -1947,6 +1949,8 @@ func (c *ChannelArbitrator) prepContractResolutions( // If we don't find this channel, then it may be the case that it // was closed before we started to retain the final state // information for open channels. + case err == channeldb.ErrNoHistoricalBucket: + fallthrough case err == channeldb.ErrChannelNotFound: log.Warnf("ChannelArbitrator(%v): unable to fetch historical "+ "state", c.cfg.ChanPoint) From 957a0a513849202388532b65bb25408cbde04b79 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 13 Jan 2022 15:11:04 -0800 Subject: [PATCH 2/2] docs/release-notes: add entry for historical chan bucket check --- docs/release-notes/release-notes-0.14.2.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/release-notes-0.14.2.md b/docs/release-notes/release-notes-0.14.2.md index 2eba7fd6b..db9fd70a3 100644 --- a/docs/release-notes/release-notes-0.14.2.md +++ b/docs/release-notes/release-notes-0.14.2.md @@ -69,7 +69,9 @@ connection from the watch-only node. * [Fix duplicate db connection close](https://github.com/lightningnetwork/lnd/pull/6140) -* [Fix a memory leak introduced by the new ping-header p2p enhancement](https://github.com/lightningnetwork/lnd/pull/6144] +* [Fix a memory leak introduced by the new ping-header p2p enhancement](https://github.com/lightningnetwork/lnd/pull/6144) + +* [Fix an issue that would prevent very old nodes from starting up due to lack of a historical channel bucket](https://github.com/lightningnetwork/lnd/pull/6159) ## RPC Server