routing: take Vertex types as path finding source and target nodes
Currently public keys are represented either as a 33-byte array (Vertex) or as a btcec.PublicKey struct. The latter isn't useable as index into maps and cannot be used easily in compares. Therefore the 33-byte array representation is used predominantly throughout the code base. This commit converts the argument types of source and target nodes for path finding to Vertex. Path finding executes no crypto operations and using Vertex simplifies the code. Additionally, it prepares for the path finding source parameter to be exposed over rpc in a follow up commit without requiring conversion back and forth between Vertex and btcec.PublicKey.
This commit is contained in:
7 files changed
+198
-171
No files matched your search
+18
-20
@@ -2764,7 +2764,7 @@ func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
|
||||
type rpcPaymentIntent struct {
|
||||
msat lnwire.MilliSatoshi
|
||||
feeLimit lnwire.MilliSatoshi
|
||||
dest *btcec.PublicKey
|
||||
dest routing.Vertex
|
||||
rHash [32]byte
|
||||
cltvDelta uint16
|
||||
routeHints [][]routing.HopHint
|
||||
@@ -2778,7 +2778,6 @@ type rpcPaymentIntent struct {
|
||||
// three ways a client can specify their payment details: a payment request,
|
||||
// via manual details, or via a complete route.
|
||||
func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error) {
|
||||
var err error
|
||||
payIntent := rpcPaymentIntent{}
|
||||
|
||||
// If a route was specified, then we can use that directly.
|
||||
@@ -2849,7 +2848,8 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
)
|
||||
|
||||
copy(payIntent.rHash[:], payReq.PaymentHash[:])
|
||||
payIntent.dest = payReq.Destination
|
||||
destKey := payReq.Destination.SerializeCompressed()
|
||||
copy(payIntent.dest[:], destKey)
|
||||
payIntent.cltvDelta = uint16(payReq.MinFinalCLTVExpiry())
|
||||
payIntent.routeHints = payReq.RouteHints
|
||||
|
||||
@@ -2859,24 +2859,20 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
// At this point, a destination MUST be specified, so we'll convert it
|
||||
// into the proper representation now. The destination will either be
|
||||
// encoded as raw bytes, or via a hex string.
|
||||
var pubBytes []byte
|
||||
if len(rpcPayReq.Dest) != 0 {
|
||||
payIntent.dest, err = btcec.ParsePubKey(
|
||||
rpcPayReq.Dest, btcec.S256(),
|
||||
)
|
||||
if err != nil {
|
||||
return payIntent, err
|
||||
}
|
||||
|
||||
pubBytes = rpcPayReq.Dest
|
||||
} else {
|
||||
pubBytes, err := hex.DecodeString(rpcPayReq.DestString)
|
||||
if err != nil {
|
||||
return payIntent, err
|
||||
}
|
||||
payIntent.dest, err = btcec.ParsePubKey(pubBytes, btcec.S256())
|
||||
var err error
|
||||
pubBytes, err = hex.DecodeString(rpcPayReq.DestString)
|
||||
if err != nil {
|
||||
return payIntent, err
|
||||
}
|
||||
}
|
||||
if len(pubBytes) != 33 {
|
||||
return payIntent, errors.New("invalid key length")
|
||||
}
|
||||
copy(payIntent.dest[:], pubBytes)
|
||||
|
||||
// Otherwise, If the payment request field was not specified
|
||||
// (and a custom route wasn't specified), construct the payment
|
||||
@@ -4001,17 +3997,19 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||
func (r *rpcServer) QueryRoutes(ctx context.Context,
|
||||
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
|
||||
|
||||
// First parse the hex-encoded public key into a full public key object
|
||||
// we can properly manipulate.
|
||||
|
||||
pubKeyBytes, err := hex.DecodeString(in.PubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pubKey, err := btcec.ParsePubKey(pubKeyBytes, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
if len(pubKeyBytes) != 33 {
|
||||
return nil, errors.New("invalid key length")
|
||||
}
|
||||
|
||||
var pubKey routing.Vertex
|
||||
copy(pubKey[:], pubKeyBytes)
|
||||
|
||||
// Currently, within the bootstrap phase of the network, we limit the
|
||||
// largest payment size allotted to (2^32) - 1 mSAT or 4.29 million
|
||||
// satoshis.
|
||||
|
||||
Reference in new issue
Block a user