routing+rpcserver: move route querying+sending to SendPayment

This commit moves much of the logic for querying for a potential route,
constructing the HTLC including the Sphinx packet, and sending the
ultimate payment from the rpcServer to the ChannelRouter.

This movement paves the way for muilt-path path finding as well as
adding automatic retry logic to the ChannelRouter. Additionally, by
having the ChannelRouter construct the Sphinx packet, we’ll be able to
also include the proper time-lock and general per-hop-payload
information properly in the future.
This commit is contained in:
Olaoluwa Osuntokun
2017-02-01 18:29:46 -08:00
parent 4eebc7c994
commit 08f0d0fbea
3 changed files with 183 additions and 157 deletions

View File

@@ -17,11 +17,11 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/connmgr"
"github.com/roasbeef/btcutil"
"github.com/lightningnetwork/lnd/routing"
)
// server is the main server of the Lightning Network Daemon. The server houses
@@ -167,6 +167,17 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
Notifier: notifier,
Broadcast: s.broadcastMessage,
SendMessages: s.sendToPeer,
SendToSwitch: func(firstHop *btcec.PublicKey,
htlcAdd *lnwire.HTLCAddRequest) error {
firstHopPub := firstHop.SerializeCompressed()
destInterface := chainhash.Hash(fastsha256.Sum256(firstHopPub))
return s.htlcSwitch.SendHTLC(&htlcPacket{
dest: destInterface,
msg: htlcAdd,
})
},
})
if err != nil {
return nil, err
@@ -217,6 +228,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
// Send the persistent connection request to the connection
// manager, saving the request itself so we can cancel/restart
// the process as needed.
// TODO(roasbeef): use default addr
connReq := &connmgr.ConnReq{
Addr: lnAddr,
Permanent: true,