rpc: properly interpret and parse cltvDelta from payreqs (if exists)
This commit is contained in:
parent
25614f67f8
commit
a29210f089
27
rpcserver.go
27
rpcserver.go
@ -1400,9 +1400,10 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer)
|
|||||||
// For each payment we need to know the msat amount, the destination
|
// For each payment we need to know the msat amount, the destination
|
||||||
// public key, and the payment hash.
|
// public key, and the payment hash.
|
||||||
type payment struct {
|
type payment struct {
|
||||||
msat lnwire.MilliSatoshi
|
msat lnwire.MilliSatoshi
|
||||||
dest []byte
|
dest []byte
|
||||||
pHash []byte
|
pHash []byte
|
||||||
|
cltvDelta uint16
|
||||||
}
|
}
|
||||||
payChan := make(chan *payment)
|
payChan := make(chan *payment)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
@ -1510,6 +1511,7 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer)
|
|||||||
}
|
}
|
||||||
p.msat = *payReq.MilliSat
|
p.msat = *payReq.MilliSat
|
||||||
p.pHash = payReq.PaymentHash[:]
|
p.pHash = payReq.PaymentHash[:]
|
||||||
|
p.cltvDelta = uint16(payReq.MinFinalCLTVExpiry())
|
||||||
} else {
|
} else {
|
||||||
// If the payment request field was not
|
// If the payment request field was not
|
||||||
// specified, construct the payment from
|
// specified, construct the payment from
|
||||||
@ -1593,6 +1595,9 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer)
|
|||||||
Amount: p.msat,
|
Amount: p.msat,
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
}
|
}
|
||||||
|
if p.cltvDelta != 0 {
|
||||||
|
payment.FinalCLTVDelta = &p.cltvDelta
|
||||||
|
}
|
||||||
preImage, route, err := r.server.chanRouter.SendPayment(payment)
|
preImage, route, err := r.server.chanRouter.SendPayment(payment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we receive payment error than,
|
// If we receive payment error than,
|
||||||
@ -1654,9 +1659,10 @@ func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
destPub *btcec.PublicKey
|
destPub *btcec.PublicKey
|
||||||
amtMSat lnwire.MilliSatoshi
|
amtMSat lnwire.MilliSatoshi
|
||||||
rHash [32]byte
|
rHash [32]byte
|
||||||
|
cltvDelta uint16
|
||||||
)
|
)
|
||||||
|
|
||||||
// If the proto request has an encoded payment request, then we we'll
|
// If the proto request has an encoded payment request, then we we'll
|
||||||
@ -1680,6 +1686,7 @@ func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
|||||||
}
|
}
|
||||||
amtMSat = *payReq.MilliSat
|
amtMSat = *payReq.MilliSat
|
||||||
rHash = *payReq.PaymentHash
|
rHash = *payReq.PaymentHash
|
||||||
|
cltvDelta = uint16(payReq.MinFinalCLTVExpiry())
|
||||||
|
|
||||||
// Otherwise, the payment conditions have been manually
|
// Otherwise, the payment conditions have been manually
|
||||||
// specified in the proto.
|
// specified in the proto.
|
||||||
@ -1724,11 +1731,15 @@ func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
|||||||
// Finally, send a payment request to the channel router. If the
|
// Finally, send a payment request to the channel router. If the
|
||||||
// payment succeeds, then the returned route will be that was used
|
// payment succeeds, then the returned route will be that was used
|
||||||
// successfully within the payment.
|
// successfully within the payment.
|
||||||
preImage, route, err := r.server.chanRouter.SendPayment(&routing.LightningPayment{
|
payment := &routing.LightningPayment{
|
||||||
Target: destPub,
|
Target: destPub,
|
||||||
Amount: amtMSat,
|
Amount: amtMSat,
|
||||||
PaymentHash: rHash,
|
PaymentHash: rHash,
|
||||||
})
|
}
|
||||||
|
if cltvDelta != 0 {
|
||||||
|
payment.FinalCLTVDelta = &cltvDelta
|
||||||
|
}
|
||||||
|
preImage, route, err := r.server.chanRouter.SendPayment(payment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -491,11 +491,9 @@ func (invoice *Invoice) Expiry() time.Duration {
|
|||||||
// current height and the expiry height of the HTLC extended in the last hop.
|
// current height and the expiry height of the HTLC extended in the last hop.
|
||||||
func (invoice *Invoice) MinFinalCLTVExpiry() uint64 {
|
func (invoice *Invoice) MinFinalCLTVExpiry() uint64 {
|
||||||
if invoice.minFinalCLTVExpiry != nil {
|
if invoice.minFinalCLTVExpiry != nil {
|
||||||
fmt.Println("USING SET CLTV")
|
|
||||||
return *invoice.minFinalCLTVExpiry
|
return *invoice.minFinalCLTVExpiry
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("USING DEFAULT CLTV")
|
|
||||||
return routing.DefaultFinalCLTVDelta
|
return routing.DefaultFinalCLTVDelta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user