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

lightningnetwork / lnd / 14193549836

01 Apr 2025 10:40AM UTC coverage: 69.046% (+0.007%) from 69.039%
14193549836

Pull #9665

github

web-flow
Merge e8825f209 into b01f4e514
Pull Request #9665: kvdb: bump etcd libs to v3.5.12

133439 of 193262 relevant lines covered (69.05%)

22119.45 hits per line

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

79.59
/channeldb/migration12/migration.go
1
package migration12
2

3
import (
4
        "bytes"
5

6
        lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
var emptyFeatures = lnwire.NewFeatureVector(nil, nil)
11

12
// MigrateInvoiceTLV migrates all existing invoice bodies over to be serialized
13
// in a single TLV stream. In the process, we drop the Receipt field and add
14
// PaymentAddr and Features to the invoice Terms.
15
func MigrateInvoiceTLV(tx kvdb.RwTx) error {
3✔
16
        log.Infof("Migrating invoice bodies to TLV, " +
3✔
17
                "adding payment addresses and feature vectors.")
3✔
18

3✔
19
        invoiceB := tx.ReadWriteBucket(invoiceBucket)
3✔
20
        if invoiceB == nil {
4✔
21
                return nil
1✔
22
        }
1✔
23

24
        type keyedInvoice struct {
2✔
25
                key     []byte
2✔
26
                invoice Invoice
2✔
27
        }
2✔
28

2✔
29
        // Read in all existing invoices using the old format.
2✔
30
        var invoices []keyedInvoice
2✔
31
        err := invoiceB.ForEach(func(k, v []byte) error {
4✔
32
                if v == nil {
2✔
33
                        return nil
×
34
                }
×
35

36
                invoiceReader := bytes.NewReader(v)
2✔
37
                invoice, err := LegacyDeserializeInvoice(invoiceReader)
2✔
38
                if err != nil {
2✔
39
                        return err
×
40
                }
×
41

42
                // Insert an empty feature vector on all old payments.
43
                invoice.Terms.Features = emptyFeatures
2✔
44

2✔
45
                invoices = append(invoices, keyedInvoice{
2✔
46
                        key:     k,
2✔
47
                        invoice: invoice,
2✔
48
                })
2✔
49

2✔
50
                return nil
2✔
51
        })
52
        if err != nil {
2✔
53
                return err
×
54
        }
×
55

56
        // Write out each one under its original key using TLV.
57
        for _, ki := range invoices {
4✔
58
                var b bytes.Buffer
2✔
59
                err = SerializeInvoice(&b, &ki.invoice)
2✔
60
                if err != nil {
2✔
61
                        return err
×
62
                }
×
63

64
                err = invoiceB.Put(ki.key, b.Bytes())
2✔
65
                if err != nil {
2✔
66
                        return err
×
67
                }
×
68
        }
69

70
        log.Infof("Migration to TLV invoice bodies, " +
2✔
71
                "payment address, and features complete!")
2✔
72

2✔
73
        return nil
2✔
74
}
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