rpc: restore proper debug HTLC usage

In this commit, we fix a slight regression that happened when the
sendtoroute RPC call was implemented. As a result of the refactoring,
the debughtlc mode silently broke. In this commit, we fix this by
checking against the zero hash, rather than the length of the payment
hash, as since we use a fixed sized byte slice, it will always be zero.
This commit is contained in:
Olaoluwa Osuntokun 2018-06-30 17:13:14 -05:00
parent 9205720bea
commit b3bb65ea43
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -11,11 +11,11 @@ import (
"math"
"sort"
"strings"
"sync"
"time"
"gopkg.in/macaroon-bakery.v2/bakery"
"sync"
"sync/atomic"
"github.com/coreos/bbolt"
@ -51,6 +51,8 @@ const (
)
var (
zeroHash [32]byte
// maxPaymentMSat is the maximum allowed payment currently permitted as
// defined in BOLT-002. This value depends on which chain is active.
// It is set to the value under the Bitcoin chain as default.
@ -2061,9 +2063,10 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
payIntent.cltvDelta = uint16(rpcPayReq.FinalCltvDelta)
// If the user is manually specifying payment details, then the
// payment hash may be encoded as a string.
if rpcPayReq.PaymentHashString != "" {
// If the user is manually specifying payment details, then the payment
// hash may be encoded as a string.
switch {
case rpcPayReq.PaymentHashString != "":
paymentHash, err := hex.DecodeString(
rpcPayReq.PaymentHashString,
)
@ -2072,15 +2075,15 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
}
copy(payIntent.rHash[:], paymentHash)
} else {
copy(payIntent.rHash[:], rpcPayReq.PaymentHash)
}
// If we're in debug HTLC mode, then all outgoing HTLCs will pay to the
// same debug rHash. Otherwise, we pay to the rHash specified within
// the RPC request.
if cfg.DebugHTLC && len(payIntent.rHash) == 0 {
case cfg.DebugHTLC && bytes.Equal(payIntent.rHash[:], zeroHash[:]):
copy(payIntent.rHash[:], debugHash[:])
default:
copy(payIntent.rHash[:], rpcPayReq.PaymentHash)
}
// Currently, within the bootstrap phase of the network, we limit the