From b3bb65ea43ba3d48605c1aadd082f6945b2dd5bf Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 30 Jun 2018 17:13:14 -0500 Subject: [PATCH] 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. --- rpcserver.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 99de1e34..98241511 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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