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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

93.02
/routing/shards/shard_tracker.go
1
package shards
2

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

7
        "github.com/lightningnetwork/lnd/lntypes"
8
        "github.com/lightningnetwork/lnd/record"
9
)
10

11
// PaymentShard is an interface representing a shard tracked by the
12
// ShardTracker. It contains options that are specific to the given shard that
13
// might differ from the overall payment.
14
type PaymentShard interface {
15
        // Hash returns the hash used for the HTLC representing this shard.
16
        Hash() lntypes.Hash
17

18
        // MPP returns any extra MPP records that should be set for the final
19
        // hop on the route used by this shard.
20
        MPP() *record.MPP
21

22
        // AMP returns any extra AMP records that should be set for the final
23
        // hop on the route used by this shard.
24
        AMP() *record.AMP
25
}
26

27
// ShardTracker is an interface representing a tracker that keeps track of the
28
// inflight shards of a payment, and is able to assign new shards the correct
29
// options such as hash and extra records.
30
type ShardTracker interface {
31
        // NewShard registers a new attempt with the ShardTracker and returns a
32
        // new shard representing this attempt. This attempt's shard should be
33
        // canceled if it ends up not being used by the overall payment, i.e.
34
        // if the attempt fails.
35
        NewShard(uint64, bool) (PaymentShard, error)
36

37
        // CancelShard cancel's the shard corresponding to the given attempt
38
        // ID. This lets the ShardTracker free up any slots used by this shard,
39
        // and in case of AMP payments return the share used by this shard to
40
        // the root share.
41
        CancelShard(uint64) error
42

43
        // GetHash retrieves the hash used by the shard of the given attempt
44
        // ID. This will return an error if the attempt ID is unknown.
45
        GetHash(uint64) (lntypes.Hash, error)
46
}
47

48
// Shard is a struct used for simple shards where we only need to keep map it
49
// to a single hash.
50
type Shard struct {
51
        hash lntypes.Hash
52
}
53

54
// Hash returns the hash used for the HTLC representing this shard.
55
func (s *Shard) Hash() lntypes.Hash {
3✔
56
        return s.hash
3✔
57
}
3✔
58

59
// MPP returns any extra MPP records that should be set for the final hop on
60
// the route used by this shard.
61
func (s *Shard) MPP() *record.MPP {
3✔
62
        return nil
3✔
63
}
3✔
64

65
// AMP returns any extra AMP records that should be set for the final hop on
66
// the route used by this shard.
67
func (s *Shard) AMP() *record.AMP {
3✔
68
        return nil
3✔
69
}
3✔
70

71
// SimpleShardTracker is an implementation of the ShardTracker interface that
72
// simply maps attempt IDs to hashes. New shards will be given a static payment
73
// hash. This should be used for regular and MPP payments, in addition to
74
// resumed payments where all the attempt's hashes have already been created.
75
type SimpleShardTracker struct {
76
        hash   lntypes.Hash
77
        shards map[uint64]lntypes.Hash
78
        sync.Mutex
79
}
80

81
// A compile time check to ensure SimpleShardTracker implements the
82
// ShardTracker interface.
83
var _ ShardTracker = (*SimpleShardTracker)(nil)
84

85
// NewSimpleShardTracker creates a new instance of the SimpleShardTracker with
86
// the given payment hash and existing attempts.
87
func NewSimpleShardTracker(paymentHash lntypes.Hash,
88
        shards map[uint64]lntypes.Hash) ShardTracker {
3✔
89

3✔
90
        if shards == nil {
6✔
91
                shards = make(map[uint64]lntypes.Hash)
3✔
92
        }
3✔
93

94
        return &SimpleShardTracker{
3✔
95
                hash:   paymentHash,
3✔
96
                shards: shards,
3✔
97
        }
3✔
98
}
99

100
// NewShard registers a new attempt with the ShardTracker and returns a
101
// new shard representing this attempt. This attempt's shard should be canceled
102
// if it ends up not being used by the overall payment, i.e. if the attempt
103
// fails.
104
func (m *SimpleShardTracker) NewShard(id uint64, _ bool) (PaymentShard, error) {
3✔
105
        m.Lock()
3✔
106
        m.shards[id] = m.hash
3✔
107
        m.Unlock()
3✔
108

3✔
109
        return &Shard{
3✔
110
                hash: m.hash,
3✔
111
        }, nil
3✔
112
}
3✔
113

114
// CancelShard cancel's the shard corresponding to the given attempt ID.
115
func (m *SimpleShardTracker) CancelShard(id uint64) error {
3✔
116
        m.Lock()
3✔
117
        delete(m.shards, id)
3✔
118
        m.Unlock()
3✔
119

3✔
120
        return nil
3✔
121
}
3✔
122

123
// GetHash retrieves the hash used by the shard of the given attempt ID. This
124
// will return an error if the attempt ID is unknown.
125
func (m *SimpleShardTracker) GetHash(id uint64) (lntypes.Hash, error) {
3✔
126
        m.Lock()
3✔
127
        hash, ok := m.shards[id]
3✔
128
        m.Unlock()
3✔
129
        if !ok {
3✔
130
                return lntypes.Hash{}, fmt.Errorf("hash for attempt id %v "+
×
131
                        "not found", id)
×
132
        }
×
133

134
        return hash, nil
3✔
135
}
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