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

lightningnetwork / lnd / 15858991938

24 Jun 2025 06:51PM UTC coverage: 55.808% (-2.4%) from 58.173%
15858991938

Pull #9148

github

web-flow
Merge 0e921d6a5 into 29ff13d83
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

232 of 267 new or added lines in 5 files covered. (86.89%)

24606 existing lines in 281 files now uncovered.

108380 of 194201 relevant lines covered (55.81%)

22488.12 hits per line

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

0.0
/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.
UNCOV
39
func (c *MigrationConfigImpl) GetDecayedLog() kvdb.Backend {
×
UNCOV
40
        return c.DecayedLog
×
UNCOV
41
}
×
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.
UNCOV
48
func MigrateDecayedLog(db kvdb.Backend, cfg MigrationConfig) error {
×
UNCOV
49
        decayedLog := cfg.GetDecayedLog()
×
UNCOV
50

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

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

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

×
UNCOV
66
                return nil
×
UNCOV
67
        }, func() {})
×
68

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

UNCOV
73
        log.Info("Decayed log migrated successfully")
×
UNCOV
74

×
UNCOV
75
        return nil
×
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