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