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