Merge pull request #4140 from carlaKC/lnrpc-pendingchannelinitiator
lnrpc: use initiator enum for pending channel open initiator
This commit is contained in:
5 files changed
+849
-833
No files matched your search
+792
-791
File diff suppressed because it is too large.
Load diff
+9
-9
@@ -1483,6 +1483,13 @@ message ListChannelsResponse {
|
|||||||
repeated Channel channels = 11;
|
repeated Channel channels = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Initiator {
|
||||||
|
INITIATOR_UNKNOWN = 0;
|
||||||
|
INITIATOR_LOCAL = 1;
|
||||||
|
INITIATOR_REMOTE = 2;
|
||||||
|
INITIATOR_BOTH = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message ChannelCloseSummary {
|
message ChannelCloseSummary {
|
||||||
/// The outpoint (txid:index) of the funding transaction.
|
/// The outpoint (txid:index) of the funding transaction.
|
||||||
string channel_point = 1;
|
string channel_point = 1;
|
||||||
@@ -1523,13 +1530,6 @@ message ChannelCloseSummary {
|
|||||||
/// Details on how the channel was closed.
|
/// Details on how the channel was closed.
|
||||||
ClosureType close_type = 10;
|
ClosureType close_type = 10;
|
||||||
|
|
||||||
enum Initiator {
|
|
||||||
UNKNOWN = 0;
|
|
||||||
LOCAL = 1;
|
|
||||||
REMOTE = 2;
|
|
||||||
BOTH = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open initiator is the party that initiated opening the channel. Note that
|
Open initiator is the party that initiated opening the channel. Note that
|
||||||
this value may be unknown if the channel was closed before we migrated to
|
this value may be unknown if the channel was closed before we migrated to
|
||||||
@@ -2093,8 +2093,8 @@ message PendingChannelsResponse {
|
|||||||
*/
|
*/
|
||||||
int64 remote_chan_reserve_sat = 7;
|
int64 remote_chan_reserve_sat = 7;
|
||||||
|
|
||||||
// True if we initiated opening the channel.
|
// The party that initiated opening the channel.
|
||||||
bool initiator = 8;
|
Initiator initiator = 8;
|
||||||
|
|
||||||
/// The commitment type used by this channel.
|
/// The commitment type used by this channel.
|
||||||
CommitmentType commitment_type = 9;
|
CommitmentType commitment_type = 9;
|
||||||
|
|||||||
+14
-15
@@ -1513,16 +1513,6 @@
|
|||||||
],
|
],
|
||||||
"default": "COOPERATIVE_CLOSE"
|
"default": "COOPERATIVE_CLOSE"
|
||||||
},
|
},
|
||||||
"ChannelCloseSummaryInitiator": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"UNKNOWN",
|
|
||||||
"LOCAL",
|
|
||||||
"REMOTE",
|
|
||||||
"BOTH"
|
|
||||||
],
|
|
||||||
"default": "UNKNOWN"
|
|
||||||
},
|
|
||||||
"ChannelEventUpdateUpdateType": {
|
"ChannelEventUpdateUpdateType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -1743,9 +1733,8 @@
|
|||||||
"description": "*\nThe minimum satoshis the other node is required to reserve in its\nbalance."
|
"description": "*\nThe minimum satoshis the other node is required to reserve in its\nbalance."
|
||||||
},
|
},
|
||||||
"initiator": {
|
"initiator": {
|
||||||
"type": "boolean",
|
"$ref": "#/definitions/lnrpcInitiator",
|
||||||
"format": "boolean",
|
"description": "The party that initiated opening the channel."
|
||||||
"description": "True if we initiated opening the channel."
|
|
||||||
},
|
},
|
||||||
"commitment_type": {
|
"commitment_type": {
|
||||||
"$ref": "#/definitions/lnrpcCommitmentType",
|
"$ref": "#/definitions/lnrpcCommitmentType",
|
||||||
@@ -2233,11 +2222,11 @@
|
|||||||
"description": "/ Details on how the channel was closed."
|
"description": "/ Details on how the channel was closed."
|
||||||
},
|
},
|
||||||
"open_initiator": {
|
"open_initiator": {
|
||||||
"$ref": "#/definitions/ChannelCloseSummaryInitiator",
|
"$ref": "#/definitions/lnrpcInitiator",
|
||||||
"description": "*\nOpen initiator is the party that initiated opening the channel. Note that\nthis value may be unknown if the channel was closed before we migrated to\nstore open channel information after close."
|
"description": "*\nOpen initiator is the party that initiated opening the channel. Note that\nthis value may be unknown if the channel was closed before we migrated to\nstore open channel information after close."
|
||||||
},
|
},
|
||||||
"close_initiator": {
|
"close_initiator": {
|
||||||
"$ref": "#/definitions/ChannelCloseSummaryInitiator",
|
"$ref": "#/definitions/lnrpcInitiator",
|
||||||
"description": "*\nClose initiator indicates which party initiated the close. This value will\nbe unknown for channels that were cooperatively closed before we started\ntracking cooperative close initiators. Note that this indicates which party\ninitiated a close, and it is possible for both to initiate cooperative or\nforce closes, although only one party's close will be confirmed on chain."
|
"description": "*\nClose initiator indicates which party initiated the close. This value will\nbe unknown for channels that were cooperatively closed before we started\ntracking cooperative close initiators. Note that this indicates which party\ninitiated a close, and it is possible for both to initiate cooperative or\nforce closes, although only one party's close will be confirmed on chain."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3183,6 +3172,16 @@
|
|||||||
"lnrpcInitWalletResponse": {
|
"lnrpcInitWalletResponse": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"lnrpcInitiator": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"INITIATOR_UNKNOWN",
|
||||||
|
"INITIATOR_LOCAL",
|
||||||
|
"INITIATOR_REMOTE",
|
||||||
|
"INITIATOR_BOTH"
|
||||||
|
],
|
||||||
|
"default": "INITIATOR_UNKNOWN"
|
||||||
|
},
|
||||||
"lnrpcInvoice": {
|
"lnrpcInvoice": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -6715,7 +6715,7 @@ func subscribeChannelNotifications(ctxb context.Context, t *harnessTest,
|
|||||||
// expected type.
|
// expected type.
|
||||||
func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
||||||
closeType lnrpc.ChannelCloseSummary_ClosureType,
|
closeType lnrpc.ChannelCloseSummary_ClosureType,
|
||||||
closeInitiator lnrpc.ChannelCloseSummary_Initiator) error {
|
closeInitiator lnrpc.Initiator) error {
|
||||||
|
|
||||||
// We should receive one inactive and one closed notification
|
// We should receive one inactive and one closed notification
|
||||||
// for each channel.
|
// for each channel.
|
||||||
@@ -6859,7 +6859,7 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
|||||||
// receive the correct channel updates in order.
|
// receive the correct channel updates in order.
|
||||||
verifyCloseUpdatesReceived := func(sub channelSubscription,
|
verifyCloseUpdatesReceived := func(sub channelSubscription,
|
||||||
forceType lnrpc.ChannelCloseSummary_ClosureType,
|
forceType lnrpc.ChannelCloseSummary_ClosureType,
|
||||||
closeInitiator lnrpc.ChannelCloseSummary_Initiator) error {
|
closeInitiator lnrpc.Initiator) error {
|
||||||
|
|
||||||
// Ensure one inactive and one closed notification is received for each
|
// Ensure one inactive and one closed notification is received for each
|
||||||
// closed channel.
|
// closed channel.
|
||||||
@@ -6905,7 +6905,7 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
|||||||
// close initiator because Alice closed the channels.
|
// close initiator because Alice closed the channels.
|
||||||
if err := verifyCloseUpdatesReceived(bobChanSub,
|
if err := verifyCloseUpdatesReceived(bobChanSub,
|
||||||
lnrpc.ChannelCloseSummary_REMOTE_FORCE_CLOSE,
|
lnrpc.ChannelCloseSummary_REMOTE_FORCE_CLOSE,
|
||||||
lnrpc.ChannelCloseSummary_REMOTE); err != nil {
|
lnrpc.Initiator_INITIATOR_REMOTE); err != nil {
|
||||||
t.Fatalf("errored verifying close updates: %v", err)
|
t.Fatalf("errored verifying close updates: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6915,7 +6915,7 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
|
|||||||
// close initiator because Alice closed the channels.
|
// close initiator because Alice closed the channels.
|
||||||
if err := verifyCloseUpdatesReceived(aliceChanSub,
|
if err := verifyCloseUpdatesReceived(aliceChanSub,
|
||||||
lnrpc.ChannelCloseSummary_LOCAL_FORCE_CLOSE,
|
lnrpc.ChannelCloseSummary_LOCAL_FORCE_CLOSE,
|
||||||
lnrpc.ChannelCloseSummary_LOCAL); err != nil {
|
lnrpc.Initiator_INITIATOR_LOCAL); err != nil {
|
||||||
t.Fatalf("errored verifying close updates: %v", err)
|
t.Fatalf("errored verifying close updates: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-14
@@ -2646,6 +2646,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
|
|
||||||
resp := &lnrpc.PendingChannelsResponse{}
|
resp := &lnrpc.PendingChannelsResponse{}
|
||||||
|
|
||||||
|
// rpcInitiator returns the correct lnrpc initiator for channels where
|
||||||
|
// we have a record of the opening channel.
|
||||||
|
rpcInitiator := func(isInitiator bool) lnrpc.Initiator {
|
||||||
|
if isInitiator {
|
||||||
|
return lnrpc.Initiator_INITIATOR_LOCAL
|
||||||
|
}
|
||||||
|
|
||||||
|
return lnrpc.Initiator_INITIATOR_REMOTE
|
||||||
|
}
|
||||||
|
|
||||||
// First, we'll populate the response with all the channels that are
|
// First, we'll populate the response with all the channels that are
|
||||||
// soon to be opened. We can easily fetch this data from the database
|
// soon to be opened. We can easily fetch this data from the database
|
||||||
// and map the db struct to the proto response.
|
// and map the db struct to the proto response.
|
||||||
@@ -2680,7 +2690,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
RemoteBalance: int64(localCommitment.RemoteBalance.ToSatoshis()),
|
RemoteBalance: int64(localCommitment.RemoteBalance.ToSatoshis()),
|
||||||
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
|
LocalChanReserveSat: int64(pendingChan.LocalChanCfg.ChanReserve),
|
||||||
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
|
RemoteChanReserveSat: int64(pendingChan.RemoteChanCfg.ChanReserve),
|
||||||
Initiator: pendingChan.IsInitiator,
|
Initiator: rpcInitiator(pendingChan.IsInitiator),
|
||||||
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
||||||
},
|
},
|
||||||
CommitWeight: commitWeight,
|
CommitWeight: commitWeight,
|
||||||
@@ -2707,12 +2717,18 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
// needed regardless of how this channel was closed.
|
// needed regardless of how this channel was closed.
|
||||||
pub := pendingClose.RemotePub.SerializeCompressed()
|
pub := pendingClose.RemotePub.SerializeCompressed()
|
||||||
chanPoint := pendingClose.ChanPoint
|
chanPoint := pendingClose.ChanPoint
|
||||||
|
|
||||||
|
// Create the pending channel. If this channel was closed before
|
||||||
|
// we started storing historical channel data, we will not know
|
||||||
|
// who initiated the channel, so we set the initiator field to
|
||||||
|
// unknown.
|
||||||
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
|
channel := &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||||
RemoteNodePub: hex.EncodeToString(pub),
|
RemoteNodePub: hex.EncodeToString(pub),
|
||||||
ChannelPoint: chanPoint.String(),
|
ChannelPoint: chanPoint.String(),
|
||||||
Capacity: int64(pendingClose.Capacity),
|
Capacity: int64(pendingClose.Capacity),
|
||||||
LocalBalance: int64(pendingClose.SettledBalance),
|
LocalBalance: int64(pendingClose.SettledBalance),
|
||||||
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
|
CommitmentType: lnrpc.CommitmentType_UNKNOWN_COMMITMENT_TYPE,
|
||||||
|
Initiator: lnrpc.Initiator_INITIATOR_UNKNOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup the channel in the historical channel bucket to obtain
|
// Lookup the channel in the historical channel bucket to obtain
|
||||||
@@ -2730,7 +2746,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
case channeldb.ErrChannelNotFound:
|
case channeldb.ErrChannelNotFound:
|
||||||
|
|
||||||
case nil:
|
case nil:
|
||||||
channel.Initiator = historical.IsInitiator
|
channel.Initiator = rpcInitiator(historical.IsInitiator)
|
||||||
channel.CommitmentType = rpcCommitmentType(
|
channel.CommitmentType = rpcCommitmentType(
|
||||||
historical.ChanType,
|
historical.ChanType,
|
||||||
)
|
)
|
||||||
@@ -2860,7 +2876,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
|||||||
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
|
RemoteBalance: int64(waitingClose.LocalCommitment.RemoteBalance.ToSatoshis()),
|
||||||
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
|
LocalChanReserveSat: int64(waitingClose.LocalChanCfg.ChanReserve),
|
||||||
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
|
RemoteChanReserveSat: int64(waitingClose.RemoteChanCfg.ChanReserve),
|
||||||
Initiator: waitingClose.IsInitiator,
|
Initiator: rpcInitiator(waitingClose.IsInitiator),
|
||||||
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
|
CommitmentType: rpcCommitmentType(waitingClose.ChanType),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3352,8 +3368,8 @@ func (r *rpcServer) createRPCClosedChannel(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
closeType lnrpc.ChannelCloseSummary_ClosureType
|
closeType lnrpc.ChannelCloseSummary_ClosureType
|
||||||
openInit lnrpc.ChannelCloseSummary_Initiator
|
openInit lnrpc.Initiator
|
||||||
closeInitiator lnrpc.ChannelCloseSummary_Initiator
|
closeInitiator lnrpc.Initiator
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -3404,12 +3420,12 @@ func (r *rpcServer) createRPCClosedChannel(
|
|||||||
// channel is not present (which indicates that it was closed before we started
|
// channel is not present (which indicates that it was closed before we started
|
||||||
// writing channels to the historical close bucket).
|
// writing channels to the historical close bucket).
|
||||||
func (r *rpcServer) getInitiators(chanPoint *wire.OutPoint) (
|
func (r *rpcServer) getInitiators(chanPoint *wire.OutPoint) (
|
||||||
lnrpc.ChannelCloseSummary_Initiator,
|
lnrpc.Initiator,
|
||||||
lnrpc.ChannelCloseSummary_Initiator, error) {
|
lnrpc.Initiator, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
openInitiator = lnrpc.ChannelCloseSummary_UNKNOWN
|
openInitiator = lnrpc.Initiator_INITIATOR_UNKNOWN
|
||||||
closeInitiator = lnrpc.ChannelCloseSummary_UNKNOWN
|
closeInitiator = lnrpc.Initiator_INITIATOR_UNKNOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
// To get the close initiator for cooperative closes, we need
|
// To get the close initiator for cooperative closes, we need
|
||||||
@@ -3434,9 +3450,9 @@ func (r *rpcServer) getInitiators(chanPoint *wire.OutPoint) (
|
|||||||
// If we successfully looked up the channel, determine initiator based
|
// If we successfully looked up the channel, determine initiator based
|
||||||
// on channels status.
|
// on channels status.
|
||||||
if histChan.IsInitiator {
|
if histChan.IsInitiator {
|
||||||
openInitiator = lnrpc.ChannelCloseSummary_LOCAL
|
openInitiator = lnrpc.Initiator_INITIATOR_LOCAL
|
||||||
} else {
|
} else {
|
||||||
openInitiator = lnrpc.ChannelCloseSummary_REMOTE
|
openInitiator = lnrpc.Initiator_INITIATOR_REMOTE
|
||||||
}
|
}
|
||||||
|
|
||||||
localInit := histChan.HasChanStatus(
|
localInit := histChan.HasChanStatus(
|
||||||
@@ -3452,13 +3468,13 @@ func (r *rpcServer) getInitiators(chanPoint *wire.OutPoint) (
|
|||||||
// We return the initiator as both in this case to provide full
|
// We return the initiator as both in this case to provide full
|
||||||
// information about the close.
|
// information about the close.
|
||||||
case localInit && remoteInit:
|
case localInit && remoteInit:
|
||||||
closeInitiator = lnrpc.ChannelCloseSummary_BOTH
|
closeInitiator = lnrpc.Initiator_INITIATOR_BOTH
|
||||||
|
|
||||||
case localInit:
|
case localInit:
|
||||||
closeInitiator = lnrpc.ChannelCloseSummary_LOCAL
|
closeInitiator = lnrpc.Initiator_INITIATOR_LOCAL
|
||||||
|
|
||||||
case remoteInit:
|
case remoteInit:
|
||||||
closeInitiator = lnrpc.ChannelCloseSummary_REMOTE
|
closeInitiator = lnrpc.Initiator_INITIATOR_REMOTE
|
||||||
}
|
}
|
||||||
|
|
||||||
return openInitiator, closeInitiator, nil
|
return openInitiator, closeInitiator, nil
|
||||||
|
|||||||
Reference in new issue
Block a user