From 39c9dfb9e4ad1995acf9004ac847a9ea9446064b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Sep 2016 12:03:38 -0700 Subject: [PATCH] config: add a new --debughtlc config parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new configuration parameter to the deamon: ‘DebugHTLC’. When true, all outgoing HTLC’s sent via the RPC interface will be sent paying to a special rHash value which all lnd nodes also with the flag activated know the preimage to. Therefore all payments sent to a 1-hop node will immediately be settled by that node. By default, this flag is false, it it only intended to be used to exercise local changes to 1-hop behavior manually. --- config.go | 1 + rpcserver.go | 12 +++++++++++- server.go | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index ecd448bf3..cdf36c86a 100644 --- a/config.go +++ b/config.go @@ -68,6 +68,7 @@ type config struct { TestNet3 bool `long:"testnet" description:"Use the test network"` SimNet bool `long:"simnet" description:"Use the simulation test network"` SegNet bool `long:"segnet" description:"Use the segragated witness test network"` + DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLC's sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."` } // loadConfig initializes and parses the config using a config file and command diff --git a/rpcserver.go b/rpcserver.go index 3130f0334..3824016c4 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -458,12 +458,22 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer) return err } + // If we're in debug HTLC mode, then all outgoing + // HTLC's will pay to the same debug rHash. Otherwise, + // we pay to the rHash specified within the RPC + // request. + var rHash [32]byte + if cfg.DebugHTLC { + rHash = debugHash + } else { + copy(rHash[:], nextPayment.PaymentHash) + } // Craft an HTLC packet to send to the routing sub-system. The // meta-data within this packet will be used to route the // payment through the network. htlcAdd := &lnwire.HTLCAddRequest{ Amount: lnwire.CreditsAmount(nextPayment.Amt), - RedemptionHashes: [][32]byte{debugHash}, + RedemptionHashes: [][32]byte{rHash}, } destAddr, err := wire.NewShaHash(nextPayment.Dest) if err != nil { diff --git a/server.go b/server.go index 4d8dd6c4c..af289a432 100644 --- a/server.go +++ b/server.go @@ -104,6 +104,15 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier, quit: make(chan struct{}), } + // If the debug HTLC flag is on, then we invoice a "master debug" + // invoice which all outgoing payments will be sent and all incoming + // HTLC's with the debug R-Hash immediately settled. + if cfg.DebugHTLC { + kiloCoin := btcutil.Amount(btcutil.SatoshiPerBitcoin * 1000) + s.invoices.AddDebugInvoice(kiloCoin, *debugPre) + srvrLog.Debugf("Debug HTLC invoice inserted, preimage=%x, hash=%x", + debugPre[:], debugHash[:]) + } s.utxoNursery = newUtxoNursery(notifier, wallet)