rpc: add zero-conf, alias information to {list,closed}channels

This commit is contained in:
eugene
2022-07-13 15:27:40 -04:00
parent 012c0d96f5
commit 48f270fe20
4 changed files with 2414 additions and 2250 deletions

View File

@@ -4029,12 +4029,17 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
// Extract the commitment type from the channel type flags.
commitmentType := rpcCommitmentType(dbChannel.ChanType)
dbScid := dbChannel.ShortChannelID
// Fetch the set of aliases for the channel.
channelAliases := r.server.aliasMgr.GetAliases(dbScid)
channel := &lnrpc.Channel{
Active: isActive,
Private: isPrivate(dbChannel),
RemotePubkey: nodeID,
ChannelPoint: chanPoint.String(),
ChanId: dbChannel.ShortChannelID.ToUint64(),
ChanId: dbScid.ToUint64(),
Capacity: int64(dbChannel.Capacity),
LocalBalance: int64(localBalance.ToSatoshis()),
RemoteBalance: int64(remoteBalance.ToSatoshis()),
@@ -4056,12 +4061,22 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
RemoteConstraints: createChannelConstraint(
&dbChannel.RemoteChanCfg,
),
AliasScids: make([]uint64, 0, len(channelAliases)),
ZeroConf: dbChannel.IsZeroConf(),
ZeroConfConfirmedScid: dbChannel.ZeroConfRealScid().ToUint64(),
// TODO: remove the following deprecated fields
CsvDelay: uint32(dbChannel.LocalChanCfg.CsvDelay),
LocalChanReserveSat: int64(dbChannel.LocalChanCfg.ChanReserve),
RemoteChanReserveSat: int64(dbChannel.RemoteChanCfg.ChanReserve),
}
// Populate the set of aliases.
for _, chanAlias := range channelAliases {
channel.AliasScids = append(
channel.AliasScids, chanAlias.ToUint64(),
)
}
for i, htlc := range localCommit.Htlcs {
var rHash [32]byte
copy(rHash[:], htlc.RHash[:])
@@ -4227,6 +4242,11 @@ func (r *rpcServer) createRPCClosedChannel(
closeType = lnrpc.ChannelCloseSummary_ABANDONED
}
dbScid := dbChannel.ShortChanID
// Fetch the set of aliases for this channel.
channelAliases := r.server.aliasMgr.GetAliases(dbScid)
channel := &lnrpc.ChannelCloseSummary{
Capacity: int64(dbChannel.Capacity),
RemotePubkey: nodeID,
@@ -4240,6 +4260,37 @@ func (r *rpcServer) createRPCClosedChannel(
ClosingTxHash: dbChannel.ClosingTXID.String(),
OpenInitiator: openInit,
CloseInitiator: closeInitiator,
AliasScids: make([]uint64, 0, len(channelAliases)),
}
// Populate the set of aliases.
for _, chanAlias := range channelAliases {
channel.AliasScids = append(
channel.AliasScids, chanAlias.ToUint64(),
)
}
// Populate any historical data that the summary needs.
histChan, err := r.server.chanStateDB.FetchHistoricalChannel(
&dbChannel.ChanPoint,
)
switch err {
// The channel was closed in a pre-historic version of lnd. Ignore the
// error.
case channeldb.ErrNoHistoricalBucket:
case channeldb.ErrChannelNotFound:
case nil:
if histChan.IsZeroConf() && histChan.ZeroConfConfirmed() {
// If the channel was zero-conf, it may have confirmed.
// Populate the confirmed SCID if so.
confirmedScid := histChan.ZeroConfRealScid().ToUint64()
channel.ZeroConfConfirmedScid = confirmedScid
}
// Non-nil error not due to older versions of lnd.
default:
return nil, err
}
reports, err := r.server.miscDB.FetchChannelReports(