Skip to content

Commit

Permalink
contractcourt: catch error when no historical bucket exists
Browse files Browse the repository at this point in the history
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 lightningnetwork#6155
  • Loading branch information
Roasbeef committed Jan 18, 2022
1 parent 2682ca3 commit 91f32ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ var dbTopLevelBuckets = [][]byte{
metaBucket,
closeSummaryBucket,
outpointBucket,
historicalChannelBucket,
}

// Wipe completely deletes all saved state within all used buckets within the
Expand Down
7 changes: 4 additions & 3 deletions channeldb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions contractcourt/channel_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 91f32ad

Please sign in to comment.