• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15837191368

23 Jun 2025 11:17PM UTC coverage: 68.172% (+0.001%) from 68.171%
15837191368

push

github

web-flow
Merge pull request #9945 from ziggie1984/optional-migration

Decayed log optional migration

90 of 116 new or added lines in 7 files covered. (77.59%)

82 existing lines in 22 files now uncovered.

134699 of 197588 relevant lines covered (68.17%)

22153.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/channeldb/migration34/migration.go
1
package migration34
2

3
import (
4
        "errors"
5
        "fmt"
6

7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
// Migration34 is an optional migration that garbage collects the decayed log
11
// in particular the `batch-replay` bucket. However we did choose to use an
12
// optional migration which defaults to true because the decayed log db is
13
// separate from the channeldb and if we would have implemented it as a
14
// required migration, then it would have required a bigger change to the
15
// codebase.
16
//
17
// Most of the decayed log db will shrink significantly after this migration
18
// because the other bucket called `shared-secrets` is garbage collected
19
// continuously and the `batch-replay` bucket will be deleted.
20

21
var (
22
        // batchReplayBucket is a bucket that maps batch identifiers to
23
        // serialized ReplaySets. This is used to give idempotency in the event
24
        // that a batch is processed more than once.
25
        batchReplayBucket = []byte("batch-replay")
26
)
27

28
// MigrationConfig is the interface for the migration configuration.
29
type MigrationConfig interface {
30
        GetDecayedLog() kvdb.Backend
31
}
32

33
// MigrationConfigImpl is the implementation of the migration configuration.
34
type MigrationConfigImpl struct {
35
        DecayedLog kvdb.Backend
36
}
37

38
// GetDecayedLog returns the decayed log backend.
39
func (c *MigrationConfigImpl) GetDecayedLog() kvdb.Backend {
3✔
40
        return c.DecayedLog
3✔
41
}
3✔
42

43
// MigrateDecayedLog migrates the decayed log. The migration deletes the
44
// `batch-replay` bucket, which is no longer used.
45
//
46
// NOTE: This migration is idempotent. If the bucket does not exist, then this
47
// migration is a no-op.
48
func MigrateDecayedLog(db kvdb.Backend, cfg MigrationConfig) error {
3✔
49
        decayedLog := cfg.GetDecayedLog()
3✔
50

3✔
51
        // Make sure we have a reference to the decayed log.
3✔
52
        if decayedLog == nil {
3✔
NEW
53
                return fmt.Errorf("decayed log backend is not available")
×
NEW
54
        }
×
55

56
        log.Info("Migrating decayed log...")
3✔
57
        err := decayedLog.Update(func(tx kvdb.RwTx) error {
6✔
58
                err := tx.DeleteTopLevelBucket(batchReplayBucket)
3✔
59
                if err != nil && !errors.Is(err, kvdb.ErrBucketNotFound) {
3✔
NEW
60
                        return fmt.Errorf("deleting top level bucket %s: %w",
×
NEW
61
                                batchReplayBucket, err)
×
NEW
62
                }
×
63

64
                log.Debugf("top level bucket %s deleted", batchReplayBucket)
3✔
65

3✔
66
                return nil
3✔
67
        }, func() {})
3✔
68

69
        if err != nil {
3✔
NEW
70
                return fmt.Errorf("failed to migrate decayed log: %w", err)
×
NEW
71
        }
×
72

73
        log.Info("Decayed log migrated successfully")
3✔
74

3✔
75
        return nil
3✔
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc