lnd: make closechannel send an instant empty update when no_wait set

We do things this way to keep behavior consistent across REST, gRPC
and CLI consistent. This was done to not alter the way we handle
Recv calls from the streams.
This commit is contained in:
Keagan McClelland committed 2024-01-23 12:25:01 -08:00
1 parent ec55831229
commit 804dabb4ea
5 files changed
+3270 -3147

No files matched your search

+4
View File
@@ -921,6 +921,10 @@ func executeChannelClose(ctxc context.Context, client lnrpc.LightningClient,
}
switch update := resp.Update.(type) {
case *lnrpc.CloseStatusUpdate_CloseInstant:
if req.NoWait {
return nil
}
case *lnrpc.CloseStatusUpdate_ClosePending:
closingHash := update.ClosePending.Txid
txid, err := chainhash.NewHash(closingHash)
+3227 -3143
View File
File diff suppressed because it is too large. Load diff
+9
View File
@@ -2046,12 +2046,18 @@ message CloseChannelRequest {
//
// NOTE: This field is only respected if we're the initiator of the channel.
uint64 max_fee_per_vbyte = 7;
// If true, then the rpc call will not block while it awaits a closing txid.
// Consequently this RPC call will not return a closing txid if this value
// is set.
bool no_wait = 8;
}
message CloseStatusUpdate {
oneof update {
PendingUpdate close_pending = 1;
ChannelCloseUpdate chan_close = 3;
InstantUpdate close_instant = 4;
}
}
@@ -2060,6 +2066,9 @@ message PendingUpdate {
uint32 output_index = 2;
}
message InstantUpdate {
}
message ReadyForPsbtFunding {
/*
The P2WSH address of the channel funding multisig address that the below
+13
View File
@@ -866,6 +866,13 @@
"required": false,
"type": "string",
"format": "uint64"
},
{
"name": "no_wait",
"description": "If true, then the rpc call will not block while it awaits a closing txid.\nConsequently this RPC call will not return a closing txid if this value\nis set.",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
@@ -4367,6 +4374,9 @@
},
"chan_close": {
"$ref": "#/definitions/lnrpcChannelCloseUpdate"
},
"close_instant": {
"$ref": "#/definitions/lnrpcInstantUpdate"
}
}
},
@@ -5236,6 +5246,9 @@
],
"default": "INITIATOR_UNKNOWN"
},
"lnrpcInstantUpdate": {
"type": "object"
},
"lnrpcInterceptFeedback": {
"type": "object",
"properties": {
+17 -4
View File
@@ -2643,10 +2643,10 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
rpcsLog.Debugf("Target sat/kw for closing transaction: %v",
int64(feeRate))
// Before we attempt the cooperative channel closure, we'll
// examine the channel to ensure that it doesn't have a
// lingering HTLC.
if len(channel.ActiveHtlcs()) != 0 {
// If the user hasn't specified NoWait, then before we attempt
// to close the channel we ensure there are no active HTLCs on
// the link.
if !in.NoWait && len(channel.ActiveHtlcs()) != 0 {
return fmt.Errorf("cannot co-op close channel " +
"with active htlcs")
}
@@ -2690,6 +2690,19 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
maxFee, deliveryScript,
)
}
// If the user doesn't want to wait for the txid to come back then we
// will send an empty update to kick off the stream.
if in.NoWait {
rpcsLog.Trace("[closechannel] sending instant update")
if err := updateStream.Send(
&lnrpc.CloseStatusUpdate{
Update: &lnrpc.CloseStatusUpdate_CloseInstant{},
},
); err != nil {
return err
}
}
out:
for {
select {