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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/macaroons/bake.go
1
package macaroons
2

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

7
        "golang.org/x/net/context"
8
        "gopkg.in/macaroon-bakery.v2/bakery"
9
        "gopkg.in/macaroon.v2"
10
)
11

12
// inMemoryRootKeyStore is a simple implementation of bakery.RootKeyStore that
13
// stores a single root key in memory.
14
type inMemoryRootKeyStore struct {
15
        rootKey []byte
16
}
17

18
// A compile-time check to ensure that inMemoryRootKeyStore implements
19
// bakery.RootKeyStore.
20
var _ bakery.RootKeyStore = (*inMemoryRootKeyStore)(nil)
21

22
// Get returns the root key for the given id. If the item is not there, it
23
// returns ErrNotFound.
24
func (s *inMemoryRootKeyStore) Get(_ context.Context, id []byte) ([]byte,
25
        error) {
×
26

×
27
        if !bytes.Equal(id, DefaultRootKeyID) {
×
28
                return nil, bakery.ErrNotFound
×
29
        }
×
30

31
        return s.rootKey, nil
×
32
}
33

34
// RootKey returns the root key to be used for making a new macaroon, and an id
35
// that can be used to look it up later with the Get method.
36
func (s *inMemoryRootKeyStore) RootKey(context.Context) ([]byte, []byte,
UNCOV
37
        error) {
×
UNCOV
38

×
UNCOV
39
        return s.rootKey, DefaultRootKeyID, nil
×
UNCOV
40
}
×
41

42
// BakeFromRootKey creates a new macaroon that is derived from the given root
43
// key and permissions.
44
func BakeFromRootKey(rootKey []byte,
UNCOV
45
        permissions []bakery.Op) (*macaroon.Macaroon, error) {
×
UNCOV
46

×
UNCOV
47
        if len(rootKey) != RootKeyLen {
×
48
                return nil, fmt.Errorf("root key must be %d bytes, is %d",
×
49
                        RootKeyLen, len(rootKey))
×
50
        }
×
51

UNCOV
52
        rootKeyStore := &inMemoryRootKeyStore{
×
UNCOV
53
                rootKey: rootKey,
×
UNCOV
54
        }
×
UNCOV
55

×
UNCOV
56
        service, err := NewService(rootKeyStore, "lnd", false)
×
UNCOV
57
        if err != nil {
×
58
                return nil, fmt.Errorf("unable to create service: %w", err)
×
59
        }
×
60

UNCOV
61
        ctx := context.Background()
×
UNCOV
62
        mac, err := service.NewMacaroon(ctx, DefaultRootKeyID, permissions...)
×
UNCOV
63
        if err != nil {
×
64
                return nil, fmt.Errorf("unable to create macaroon: %w", err)
×
65
        }
×
66

UNCOV
67
        return mac.M(), nil
×
68
}
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