channeldb: final htlc resolution storage opt-in
This commit is contained in:
10 files changed
+85
-27
No files matched your search
+24
-15
@@ -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
|
||||
|
||||
@@ -1463,7 +1463,7 @@ func TestKeyLocatorEncoding(t *testing.T) {
|
||||
func TestFinalHtlcs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, err := MakeTestDB(t)
|
||||
fullDB, err := MakeTestDB(t, OptionStoreFinalHtlcResolutions(true))
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -307,6 +307,7 @@ type DB struct {
|
||||
clock clock.Clock
|
||||
dryRun bool
|
||||
keepFailedPaymentAttempts bool
|
||||
storeFinalHtlcResolutions bool
|
||||
}
|
||||
|
||||
// Open opens or creates channeldb. Any necessary schemas migrations due
|
||||
@@ -364,6 +365,7 @@ func CreateWithBackend(backend kvdb.Backend,
|
||||
clock: opts.clock,
|
||||
dryRun: opts.dryRun,
|
||||
keepFailedPaymentAttempts: opts.keepFailedPaymentAttempts,
|
||||
storeFinalHtlcResolutions: opts.storeFinalHtlcResolutions,
|
||||
}
|
||||
|
||||
// Set the parent pointer (only used in tests).
|
||||
@@ -1741,6 +1743,11 @@ func (c *ChannelStateDB) LookupFinalHtlc(chanID lnwire.ShortChannelID,
|
||||
func (c *ChannelStateDB) PutOnchainFinalHtlcOutcome(
|
||||
chanID lnwire.ShortChannelID, htlcID uint64, settled bool) error {
|
||||
|
||||
// Skip if the user did not opt in to storing final resolutions.
|
||||
if !c.parent.storeFinalHtlcResolutions {
|
||||
return nil
|
||||
}
|
||||
|
||||
return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
|
||||
finalHtlcsBucket, err := fetchFinalHtlcsBucketRw(tx, chanID)
|
||||
if err != nil {
|
||||
|
||||
@@ -74,6 +74,10 @@ type Options struct {
|
||||
// keepFailedPaymentAttempts determines whether failed htlc attempts
|
||||
// are kept on disk or removed to save space.
|
||||
keepFailedPaymentAttempts bool
|
||||
|
||||
// storeFinalHtlcResolutions determines whether to persistently store
|
||||
// the final resolution of incoming htlcs.
|
||||
storeFinalHtlcResolutions bool
|
||||
}
|
||||
|
||||
// DefaultOptions returns an Options populated with default values.
|
||||
@@ -187,6 +191,16 @@ func OptionKeepFailedPaymentAttempts(keepFailedPaymentAttempts bool) OptionModif
|
||||
}
|
||||
}
|
||||
|
||||
// OptionStoreFinalHtlcResolutions controls whether to persistently store the
|
||||
// final resolution of incoming htlcs.
|
||||
func OptionStoreFinalHtlcResolutions(
|
||||
storeFinalHtlcResolutions bool) OptionModifier {
|
||||
|
||||
return func(o *Options) {
|
||||
o.storeFinalHtlcResolutions = storeFinalHtlcResolutions
|
||||
}
|
||||
}
|
||||
|
||||
// OptionPruneRevocationLog specifies whether the migration for pruning
|
||||
// revocation logs needs to be applied or not.
|
||||
func OptionPruneRevocationLog(prune bool) OptionModifier {
|
||||
|
||||
Reference in new issue
Block a user