rpcserver: ensure OpenChannel+OpenChannelSync parse NodePubkey

This commit is contained in:
Conner Fromknecht 2020-03-30 16:56:12 -07:00
parent 1823840ed6
commit 303d441d4d
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

View File

@ -1666,13 +1666,10 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
return err
}
var (
nodePubKey *btcec.PublicKey
nodePubKeyBytes []byte
)
// TODO(roasbeef): also return channel ID?
var nodePubKey *btcec.PublicKey
// Ensure that the NodePubKey is set before attempting to use it
if len(in.NodePubkey) == 0 {
return fmt.Errorf("NodePubKey is not set")
@ -1691,8 +1688,6 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
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.
satPerKw := chainfee.SatPerKVByte(in.SatPerByte * 1000).FeePerKWeight()
@ -1780,7 +1775,7 @@ out:
select {
case err := <-errChan:
rpcsLog.Errorf("unable to open channel to NodeKey(%x): %v",
nodePubKeyBytes, err)
nodePubKey.SerializeCompressed(), err)
return err
case fundingUpdate := <-updateChan:
rpcsLog.Tracef("[openchannel] sending update: %v",
@ -1812,7 +1807,7 @@ out:
}
rpcsLog.Tracef("[openchannel] success NodeKey(%x), ChannelPoint(%v)",
nodePubKeyBytes, outpoint)
nodePubKey.SerializeCompressed(), outpoint)
return nil
}
@ -1845,16 +1840,31 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
"wallet is fully synced")
}
// Decode the provided target node's public key, parsing it into a pub
// key object. For all sync call, byte slices are expected to be
// encoded as hex strings.
keyBytes, err := hex.DecodeString(in.NodePubkeyString)
if err != nil {
return nil, err
}
nodepubKey, err := btcec.ParsePubKey(keyBytes, btcec.S256())
if err != nil {
return nil, err
var nodePubKey *btcec.PublicKey
// Parse the remote pubkey the NodePubkey field of the request. If it's
// not present, we'll fallback to the deprecated version that parses the
// key from a hex string.
if len(in.NodePubkey) > 0 {
// 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 nil, err
}
} else {
// Decode the provided target node's public key, parsing it into
// a pub key object. For all sync call, byte slices are expected
// to be encoded as hex strings.
keyBytes, err := hex.DecodeString(in.NodePubkeyString)
if err != nil {
return nil, err
}
nodePubKey, err = btcec.ParsePubKey(keyBytes, btcec.S256())
if err != nil {
return nil, err
}
}
localFundingAmt := btcutil.Amount(in.LocalFundingAmount)
@ -1916,7 +1926,7 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
}
req := &openChanReq{
targetPubkey: nodepubKey,
targetPubkey: nodePubKey,
chainHash: *activeNetParams.GenesisHash,
localFundingAmt: localFundingAmt,
pushAmt: lnwire.NewMSatFromSatoshis(remoteInitialBalance),
@ -1933,7 +1943,7 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
// If an error occurs them immediately return the error to the client.
case err := <-errChan:
rpcsLog.Errorf("unable to open channel to NodeKey(%x): %v",
nodepubKey, err)
nodePubKey.SerializeCompressed(), err)
return nil, err
// Otherwise, wait for the first channel update. The first update sent