multi: remove internal peer_id usage

This commit is contained in:
MeshCollider authored and Olaoluwa Osuntokun committed 2018-02-19 17:48:39 -08:00
1 parent 4ed5ba0d26
commit 915c4201b9
6 files changed
+36 -75

No files matched your search

+25 -31
View File
@@ -668,8 +668,8 @@ func (r *rpcServer) DisconnectPeer(ctx context.Context,
func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
updateStream lnrpc.Lightning_OpenChannelServer) error {
rpcsLog.Tracef("[openchannel] request to peerid(%v) "+
"allocation(us=%v, them=%v)", in.TargetPeerId,
rpcsLog.Tracef("[openchannel] request to identityPub(%v) "+
"allocation(us=%v, them=%v)", in.NodePubkeyString,
in.LocalFundingAmount, in.PushSat)
if !r.server.Started() {
@@ -720,24 +720,21 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
// TODO(roasbeef): also return channel ID?
// If the node key is set, then we'll parse the raw bytes into a pubkey
// object so we can easily manipulate it. If this isn't set, then we
// expected the TargetPeerId to be set accordingly.
if len(in.NodePubkey) != 0 {
nodePubKey, err = btcec.ParsePubKey(in.NodePubkey, btcec.S256())
if err != nil {
return err
}
// Making a channel to ourselves wouldn't be of any use, so we
// explicitly disallow them.
if nodePubKey.IsEqual(r.server.identityPriv.PubKey()) {
return fmt.Errorf("cannot open channel to self")
}
nodePubKeyBytes = nodePubKey.SerializeCompressed()
// Parse the raw bytes of the node key into a pubkey object so we
// can easily manipulate it.
nodePubKey, err = btcec.ParsePubKey(in.NodePubkey, btcec.S256())
if err != nil {
return err
}
// Making a channel to ourselves wouldn't be of any use, so we
// explicitly disallow them.
if nodePubKey.IsEqual(r.server.identityPriv.PubKey()) {
return fmt.Errorf("cannot open channel to self")
}
nodePubKeyBytes = nodePubKey.SerializeCompressed()
// Based on the passed fee related parameters, we'll determine an
// appropriate fee rate for the funding transaction.
feePerByte, err := determineFeePerByte(
@@ -754,7 +751,7 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
// open a new channel. A stream is returned in place, this stream will
// be used to consume updates of the state of the pending channel.
updateChan, errChan := r.server.OpenChannel(
in.TargetPeerId, nodePubKey, localFundingAmt,
nodePubKey, localFundingAmt,
lnwire.NewMSatFromSatoshis(remoteInitialBalance),
minHtlc, feePerByte, in.Private,
)
@@ -764,9 +761,8 @@ out:
for {
select {
case err := <-errChan:
rpcsLog.Errorf("unable to open channel to "+
"identityPub(%x) nor peerID(%v): %v",
nodePubKeyBytes, in.TargetPeerId, err)
rpcsLog.Errorf("unable to open channel to identityPub(%x): %v",
nodePubKeyBytes, err)
return err
case fundingUpdate := <-updateChan:
rpcsLog.Tracef("[openchannel] sending update: %v",
@@ -802,8 +798,8 @@ out:
}
}
rpcsLog.Tracef("[openchannel] success peerid(%v), ChannelPoint(%v)",
in.TargetPeerId, outpoint)
rpcsLog.Tracef("[openchannel] success identityPub(%x), ChannelPoint(%v)",
nodePubKeyBytes, outpoint)
return nil
}
@@ -814,8 +810,8 @@ out:
func (r *rpcServer) OpenChannelSync(ctx context.Context,
in *lnrpc.OpenChannelRequest) (*lnrpc.ChannelPoint, error) {
rpcsLog.Tracef("[openchannel] request to peerid(%v) "+
"allocation(us=%v, them=%v)", in.TargetPeerId,
rpcsLog.Tracef("[openchannel] request to identityPub(%v) "+
"allocation(us=%v, them=%v)", in.NodePubkeyString,
in.LocalFundingAmount, in.PushSat)
// We don't allow new channels to be open while the server is still
@@ -874,7 +870,7 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
int64(feePerByte))
updateChan, errChan := r.server.OpenChannel(
in.TargetPeerId, nodepubKey, localFundingAmt,
nodepubKey, localFundingAmt,
lnwire.NewMSatFromSatoshis(remoteInitialBalance),
minHtlc, feePerByte, in.Private,
)
@@ -882,9 +878,8 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
select {
// If an error occurs them immediately return the error to the client.
case err := <-errChan:
rpcsLog.Errorf("unable to open channel to "+
"identityPub(%x) nor peerID(%v): %v",
nodepubKey, in.TargetPeerId, err)
rpcsLog.Errorf("unable to open channel to identityPub(%x): %v",
nodepubKey, err)
return nil, err
// Otherwise, wait for the first channel update. The first update sent
@@ -1237,7 +1232,6 @@ func (r *rpcServer) ListPeers(ctx context.Context,
nodePub := serverPeer.addr.IdentityKey.SerializeCompressed()
peer := &lnrpc.Peer{
PubKey: hex.EncodeToString(nodePub),
PeerId: serverPeer.id,
Address: serverPeer.conn.RemoteAddr().String(),
Inbound: !serverPeer.inbound, // Flip for display
BytesRecv: atomic.LoadUint64(&serverPeer.bytesReceived),