Merge pull request #8813 from hieblmi/chaninfo-per-outpoint

Allow for a channel point in `GetChanInfo`
This commit is contained in:
Oliver Gugger 2024-06-06 14:47:31 +02:00 committed by GitHub
commit 98c52df4d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1459 additions and 1372 deletions

View file

@ -1787,8 +1787,16 @@ var getChanInfoCommand = cli.Command{
ArgsUsage: "chan_id",
Flags: []cli.Flag{
cli.Uint64Flag{
Name: "chan_id",
Usage: "the 8-byte compact channel ID to query for",
Name: "chan_id",
Usage: "The 8-byte compact channel ID to query for. " +
"If this is set the chan_point param is " +
"ignored.",
},
cli.StringFlag{
Name: "chan_point",
Usage: "The channel point in format txid:index. If " +
"the chan_id param is set this param is " +
"ignored.",
},
},
Action: actionDecorator(getChanInfo),
@ -1800,24 +1808,31 @@ func getChanInfo(ctx *cli.Context) error {
defer cleanUp()
var (
chanID uint64
err error
chanID uint64
chanPoint string
err error
)
switch {
case ctx.IsSet("chan_id"):
chanID = ctx.Uint64("chan_id")
case ctx.Args().Present():
chanID, err = strconv.ParseUint(ctx.Args().First(), 10, 64)
if err != nil {
return fmt.Errorf("error parsing chan_id: %w", err)
}
case ctx.IsSet("chan_point"):
chanPoint = ctx.String("chan_point")
default:
return fmt.Errorf("chan_id argument missing")
return fmt.Errorf("chan_id or chan_point argument missing")
}
req := &lnrpc.ChanInfoRequest{
ChanId: chanID,
ChanId: chanID,
ChanPoint: chanPoint,
}
chanInfo, err := client.GetChanInfo(ctxc, req)

View file

@ -35,10 +35,16 @@
* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
now accepts `0` failure amounts.
* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
adds support for channel points.
## lncli Updates
* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
`0` failure amounts.
* [`getchaninfo`](https://github.com/lightningnetwork/lnd/pull/8813) now accepts
a channel outpoint besides a channel id.
## Code Health
## Breaking Changes

File diff suppressed because it is too large Load diff

View file

@ -1555,6 +1555,10 @@ func local_request_Lightning_GetNodeMetrics_0(ctx context.Context, marshaler run
}
var (
filter_Lightning_GetChanInfo_0 = &utilities.DoubleArray{Encoding: map[string]int{"chan_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)
func request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ChanInfoRequest
var metadata runtime.ServerMetadata
@ -1576,6 +1580,13 @@ func request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtime.Mars
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_GetChanInfo_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetChanInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
@ -1602,6 +1613,13 @@ func local_request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtim
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_GetChanInfo_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetChanInfo(ctx, &protoReq)
return msg, metadata, err

View file

@ -3443,6 +3443,10 @@ message ChanInfoRequest {
output index for the channel.
*/
uint64 chan_id = 1 [jstype = JS_STRING];
// The channel point of the channel in format funding_txid:output_index. If
// chan_id is specified, this field is ignored.
string chan_point = 2;
}
message NetworkInfoRequest {

View file

@ -1204,6 +1204,13 @@
"required": true,
"type": "string",
"format": "uint64"
},
{
"name": "chan_point",
"description": "The channel point of the channel in format funding_txid:output_index. If\nchan_id is specified, this field is ignored.",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [

View file

@ -6295,15 +6295,40 @@ func (r *rpcServer) GetNodeMetrics(ctx context.Context,
}
// GetChanInfo returns the latest authenticated network announcement for the
// given channel identified by its channel ID: an 8-byte integer which uniquely
// identifies the location of transaction's funding output within the block
// chain.
func (r *rpcServer) GetChanInfo(ctx context.Context,
// given channel identified by either its channel ID or a channel outpoint. Both
// uniquely identify the location of transaction's funding output within the
// blockchain. The former is an 8-byte integer, while the latter is a string
// formatted as funding_txid:output_index.
func (r *rpcServer) GetChanInfo(_ context.Context,
in *lnrpc.ChanInfoRequest) (*lnrpc.ChannelEdge, error) {
graph := r.server.graphDB
edgeInfo, edge1, edge2, err := graph.FetchChannelEdgesByID(in.ChanId)
var (
edgeInfo *models.ChannelEdgeInfo
edge1, edge2 *models.ChannelEdgePolicy
err error
)
switch {
case in.ChanId != 0:
edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByID(
in.ChanId,
)
case in.ChanPoint != "":
var chanPoint *wire.OutPoint
chanPoint, err = wire.NewOutPointFromString(in.ChanPoint)
if err != nil {
return nil, err
}
edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByOutpoint(
chanPoint,
)
default:
return nil, fmt.Errorf("specify either chan_id or chan_point")
}
if err != nil {
return nil, err
}