channeldb: final htlc resolution storage opt-in

This commit is contained in:
Joost Jager
2023-01-19 13:04:43 +01:00
parent b50d59ec2e
commit 7a785c74c4
10 changed files with 85 additions and 27 deletions

View File

@@ -1879,12 +1879,18 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment,
return err
}
// Get the bucket where settled htlcs are recorded.
finalHtlcsBucket, err := fetchFinalHtlcsBucketRw(
tx, c.ShortChannelID,
)
if err != nil {
return err
// Get the bucket where settled htlcs are recorded if the user
// opted in to storing this information.
var finalHtlcsBucket kvdb.RwBucket
if c.Db.parent.storeFinalHtlcResolutions {
bucket, err := fetchFinalHtlcsBucketRw(
tx, c.ShortChannelID,
)
if err != nil {
return err
}
finalHtlcsBucket = bucket
}
var unsignedUpdates []LogUpdate
@@ -1957,15 +1963,18 @@ func processFinalHtlc(finalHtlcsBucket walletdb.ReadWriteBucket, upd LogUpdate,
return nil
}
err := putFinalHtlc(
finalHtlcsBucket, id,
FinalHtlcInfo{
Settled: settled,
Offchain: true,
},
)
if err != nil {
return err
// Store the final resolution in the database if a bucket is provided.
if finalHtlcsBucket != nil {
err := putFinalHtlc(
finalHtlcsBucket, id,
FinalHtlcInfo{
Settled: settled,
Offchain: true,
},
)
if err != nil {
return err
}
}
finalHtlcs[id] = settled