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

lightningnetwork / lnd / 15628278788

13 Jun 2025 06:45AM UTC coverage: 68.511% (+10.2%) from 58.333%
15628278788

Pull #9945

github

web-flow
Merge e78253ccc into 35102e7c3
Pull Request #9945: Decayed log optional migration

104 of 128 new or added lines in 10 files covered. (81.25%)

42 existing lines in 10 files now uncovered.

134495 of 196311 relevant lines covered (68.51%)

22245.95 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 to way bigger changes to the
15
// codebase.
16
// Very likely most of the decayed log db will shrink significantly after this
17
// migration because the other bucket called `shared-secrets` is garbage
18
// collected continuously.
19

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

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

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

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

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

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

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

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

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

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

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

3✔
74
        return nil
3✔
75
}
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