multi: use wire records on payment and intercept flows
This commit is contained in:
1 parent
aa86020b84
commit
878f964a33
10 files changed
+108
-75
No files matched your search
@@ -25,12 +25,13 @@ var ErrPaymentLifecycleExiting = errors.New("payment lifecycle exiting")
|
||||
// paymentLifecycle holds all information about the current state of a payment
|
||||
// needed to resume if from any point.
|
||||
type paymentLifecycle struct {
|
||||
router *ChannelRouter
|
||||
feeLimit lnwire.MilliSatoshi
|
||||
identifier lntypes.Hash
|
||||
paySession PaymentSession
|
||||
shardTracker shards.ShardTracker
|
||||
currentHeight int32
|
||||
router *ChannelRouter
|
||||
feeLimit lnwire.MilliSatoshi
|
||||
identifier lntypes.Hash
|
||||
paySession PaymentSession
|
||||
shardTracker shards.ShardTracker
|
||||
currentHeight int32
|
||||
firstHopCustomRecords lnwire.CustomRecords
|
||||
|
||||
// quit is closed to signal the sub goroutines of the payment lifecycle
|
||||
// to stop.
|
||||
@@ -52,18 +53,19 @@ type paymentLifecycle struct {
|
||||
// newPaymentLifecycle initiates a new payment lifecycle and returns it.
|
||||
func newPaymentLifecycle(r *ChannelRouter, feeLimit lnwire.MilliSatoshi,
|
||||
identifier lntypes.Hash, paySession PaymentSession,
|
||||
shardTracker shards.ShardTracker,
|
||||
currentHeight int32) *paymentLifecycle {
|
||||
shardTracker shards.ShardTracker, currentHeight int32,
|
||||
firstHopCustomRecords lnwire.CustomRecords) *paymentLifecycle {
|
||||
|
||||
p := &paymentLifecycle{
|
||||
router: r,
|
||||
feeLimit: feeLimit,
|
||||
identifier: identifier,
|
||||
paySession: paySession,
|
||||
shardTracker: shardTracker,
|
||||
currentHeight: currentHeight,
|
||||
quit: make(chan struct{}),
|
||||
resultCollected: make(chan error, 1),
|
||||
router: r,
|
||||
feeLimit: feeLimit,
|
||||
identifier: identifier,
|
||||
paySession: paySession,
|
||||
shardTracker: shardTracker,
|
||||
currentHeight: currentHeight,
|
||||
quit: make(chan struct{}),
|
||||
resultCollected: make(chan error, 1),
|
||||
firstHopCustomRecords: firstHopCustomRecords,
|
||||
}
|
||||
|
||||
// Mount the result collector.
|
||||
@@ -677,9 +679,10 @@ func (p *paymentLifecycle) sendAttempt(
|
||||
// this packet will be used to route the payment through the network,
|
||||
// starting with the first-hop.
|
||||
htlcAdd := &lnwire.UpdateAddHTLC{
|
||||
Amount: rt.TotalAmount,
|
||||
Expiry: rt.TotalTimeLock,
|
||||
PaymentHash: *attempt.Hash,
|
||||
Amount: rt.TotalAmount,
|
||||
Expiry: rt.TotalTimeLock,
|
||||
PaymentHash: *attempt.Hash,
|
||||
CustomRecords: p.firstHopCustomRecords,
|
||||
}
|
||||
|
||||
// Generate the raw encoded sphinx packet to be included along
|
||||
|
||||
@@ -89,7 +89,7 @@ func newTestPaymentLifecycle(t *testing.T) (*paymentLifecycle, *mockers) {
|
||||
// Create a test payment lifecycle with no fee limit and no timeout.
|
||||
p := newPaymentLifecycle(
|
||||
rt, noFeeLimit, paymentHash, mockPaymentSession,
|
||||
mockShardTracker, 0,
|
||||
mockShardTracker, 0, nil,
|
||||
)
|
||||
|
||||
// Create a mock payment which is returned from mockControlTower.
|
||||
|
||||
+15
-4
@@ -865,6 +865,11 @@ type LightningPayment struct {
|
||||
// fail.
|
||||
DestCustomRecords record.CustomSet
|
||||
|
||||
// FirstHopCustomRecords are the TLV records that are to be sent to the
|
||||
// first hop of this payment. These records will be transmitted via the
|
||||
// wire message and therefore do not affect the onion payload size.
|
||||
FirstHopCustomRecords lnwire.CustomRecords
|
||||
|
||||
// MaxParts is the maximum number of partial payments that may be used
|
||||
// to complete the full amount.
|
||||
MaxParts uint32
|
||||
@@ -948,6 +953,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte,
|
||||
return r.sendPayment(
|
||||
context.Background(), payment.FeeLimit, payment.Identifier(),
|
||||
payment.PayAttemptTimeout, paySession, shardTracker,
|
||||
payment.FirstHopCustomRecords,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -968,6 +974,7 @@ func (r *ChannelRouter) SendPaymentAsync(ctx context.Context,
|
||||
_, _, err := r.sendPayment(
|
||||
ctx, payment.FeeLimit, payment.Identifier(),
|
||||
payment.PayAttemptTimeout, ps, st,
|
||||
payment.FirstHopCustomRecords,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Payment %x failed: %v",
|
||||
@@ -1141,7 +1148,9 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
||||
// - nil payment session (since we already have a route).
|
||||
// - no payment timeout.
|
||||
// - no current block height.
|
||||
p := newPaymentLifecycle(r, 0, paymentIdentifier, nil, shardTracker, 0)
|
||||
p := newPaymentLifecycle(
|
||||
r, 0, paymentIdentifier, nil, shardTracker, 0, nil,
|
||||
)
|
||||
|
||||
// We found a route to try, create a new HTLC attempt to try.
|
||||
//
|
||||
@@ -1237,7 +1246,9 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
||||
func (r *ChannelRouter) sendPayment(ctx context.Context,
|
||||
feeLimit lnwire.MilliSatoshi, identifier lntypes.Hash,
|
||||
paymentAttemptTimeout time.Duration, paySession PaymentSession,
|
||||
shardTracker shards.ShardTracker) ([32]byte, *route.Route, error) {
|
||||
shardTracker shards.ShardTracker,
|
||||
firstHopCustomRecords lnwire.CustomRecords) ([32]byte, *route.Route,
|
||||
error) {
|
||||
|
||||
// If the user provides a timeout, we will additionally wrap the context
|
||||
// in a deadline.
|
||||
@@ -1262,7 +1273,7 @@ func (r *ChannelRouter) sendPayment(ctx context.Context,
|
||||
// can resume the payment from the current state.
|
||||
p := newPaymentLifecycle(
|
||||
r, feeLimit, identifier, paySession, shardTracker,
|
||||
currentHeight,
|
||||
currentHeight, firstHopCustomRecords,
|
||||
)
|
||||
|
||||
return p.resumePayment(ctx)
|
||||
@@ -1465,7 +1476,7 @@ func (r *ChannelRouter) resumePayments() error {
|
||||
noTimeout := time.Duration(0)
|
||||
_, _, err := r.sendPayment(
|
||||
context.Background(), 0, payHash, noTimeout, paySession,
|
||||
shardTracker,
|
||||
shardTracker, nil,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Resuming payment %v failed: %v", payHash,
|
||||
|
||||
Reference in new issue
Block a user