mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-23 12:13:50 +02:00
rpc: add zero-conf, alias information to {list,closed}channels
This commit is contained in:
53
rpcserver.go
53
rpcserver.go
@@ -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(
|
||||
|
Reference in New Issue
Block a user