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

lightningnetwork / lnd / 13593508312

28 Feb 2025 05:41PM UTC coverage: 58.287% (-10.4%) from 68.65%
13593508312

Pull #9458

github

web-flow
Merge d40067c0c into f1182e433
Pull Request #9458: multi+server.go: add initial permissions for some peers

346 of 548 new or added lines in 10 files covered. (63.14%)

27412 existing lines in 442 files now uncovered.

94709 of 162488 relevant lines covered (58.29%)

1.81 hits per line

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

0.0
/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.
UNCOV
15
func MigrateInvoiceTLV(tx kvdb.RwTx) error {
×
UNCOV
16
        log.Infof("Migrating invoice bodies to TLV, " +
×
UNCOV
17
                "adding payment addresses and feature vectors.")
×
UNCOV
18

×
UNCOV
19
        invoiceB := tx.ReadWriteBucket(invoiceBucket)
×
UNCOV
20
        if invoiceB == nil {
×
UNCOV
21
                return nil
×
UNCOV
22
        }
×
23

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

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

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

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

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

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

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

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

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

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