Skip to content

Commit

Permalink
Merge pull request lightningnetwork#8813 from hieblmi/chaninfo-per-ou…
Browse files Browse the repository at this point in the history
…tpoint

Allow for a channel point in `GetChanInfo`
  • Loading branch information
guggero authored Jun 6, 2024
2 parents 0fadf97 + cc902e3 commit 98c52df
Showing 7 changed files with 1,453 additions and 1,366 deletions.
27 changes: 21 additions & 6 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.18.1.md
Original file line number Diff line number Diff line change
@@ -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
2,722 changes: 1,367 additions & 1,355 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions lnrpc/lightning.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
@@ -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 {
7 changes: 7 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
@@ -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": [
35 changes: 30 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 98c52df

Please sign in to comment.