rpcserver: allow targeting open channels via global lightning ID
This commit adds the ability to open channels according a node’s “global” lightning ID in addition to the local relative peer ID.
This commit is contained in:
parent
7aaa46d7ff
commit
6c83f53206
11
rpcserver.go
11
rpcserver.go
@ -196,18 +196,17 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
|
||||
|
||||
localFundingAmt := btcutil.Amount(in.LocalFundingAmount)
|
||||
remoteFundingAmt := btcutil.Amount(in.RemoteFundingAmount)
|
||||
target := in.TargetPeerId
|
||||
numConfs := in.NumConfs
|
||||
updateChan, errChan := r.server.OpenChannel(target, localFundingAmt,
|
||||
remoteFundingAmt, numConfs)
|
||||
updateChan, errChan := r.server.OpenChannel(in.TargetPeerId,
|
||||
in.TargetNode, localFundingAmt, remoteFundingAmt, in.NumConfs)
|
||||
|
||||
var outpoint wire.OutPoint
|
||||
out:
|
||||
for {
|
||||
select {
|
||||
case err := <-errChan:
|
||||
rpcsLog.Errorf("unable to open channel to peerid(%v): %v",
|
||||
target, err)
|
||||
rpcsLog.Errorf("unable to open channel to "+
|
||||
"lightningID(%v) nor peerID(%v): %v",
|
||||
in.TargetNode, in.TargetPeerId, err)
|
||||
return err
|
||||
case fundingUpdate := <-updateChan:
|
||||
rpcsLog.Tracef("[openchannel] sending update: %v",
|
||||
|
30
server.go
30
server.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
@ -248,11 +249,11 @@ type listPeersMsg struct {
|
||||
}
|
||||
|
||||
// openChanReq is a message sent to the server in order to request the
|
||||
// initiation of a channel funding workflow to the peer with the specified
|
||||
// node ID.
|
||||
// initiation of a channel funding workflow to the peer with either the specified
|
||||
// relative peer ID, or a global lightning ID.
|
||||
type openChanReq struct {
|
||||
targetNodeID int32
|
||||
targetNode *lndc.LNAdr
|
||||
targetPeerID int32
|
||||
targetNodeID [32]byte
|
||||
|
||||
// TODO(roasbeef): make enums in lnwire
|
||||
channelType uint8
|
||||
@ -409,18 +410,19 @@ func (s *server) handleConnectPeer(msg *connectPeerMsg) {
|
||||
func (s *server) handleOpenChanReq(req *openChanReq) {
|
||||
// First attempt to locate the target peer to open a channel with, if
|
||||
// we're unable to locate the peer then this request will fail.
|
||||
target := req.targetNodeID
|
||||
var targetPeer *peer
|
||||
for _, peer := range s.peers { // TODO(roasbeef): threadsafe api
|
||||
// We found the the target
|
||||
if target == peer.id {
|
||||
if req.targetPeerID == peer.id ||
|
||||
bytes.Equal(req.targetNodeID[:], peer.lightningID[:]) {
|
||||
targetPeer = peer
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetPeer == nil {
|
||||
req.err <- fmt.Errorf("unable to find peer %v", target)
|
||||
req.err <- fmt.Errorf("unable to find peer lightningID(%v), "+
|
||||
"peerID(%v)", req.targetNodeID, req.targetPeerID)
|
||||
return
|
||||
}
|
||||
|
||||
@ -446,21 +448,23 @@ func (s *server) ConnectToPeer(addr *lndc.LNAdr) (int32, error) {
|
||||
|
||||
// OpenChannel sends a request to the server to open a channel to the specified
|
||||
// peer identified by ID with the passed channel funding paramters.
|
||||
func (s *server) OpenChannel(nodeID int32, localAmt, remoteAmt btcutil.Amount,
|
||||
func (s *server) OpenChannel(peerID int32, nodeID []byte, localAmt, remoteAmt btcutil.Amount,
|
||||
numConfs uint32) (chan *lnrpc.OpenStatusUpdate, chan error) {
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
updateChan := make(chan *lnrpc.OpenStatusUpdate, 1)
|
||||
|
||||
s.queries <- &openChanReq{
|
||||
targetNodeID: nodeID,
|
||||
req := &openChanReq{
|
||||
targetPeerID: peerID,
|
||||
localFundingAmt: localAmt,
|
||||
remoteFundingAmt: remoteAmt,
|
||||
numConfs: numConfs,
|
||||
|
||||
updates: updateChan,
|
||||
err: errChan,
|
||||
updates: updateChan,
|
||||
err: errChan,
|
||||
}
|
||||
copy(req.targetNodeID[:], nodeID)
|
||||
|
||||
s.queries <- req
|
||||
|
||||
return updateChan, errChan
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user