mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
protocol: rename clearing to shutdown.
As per lightning-rfc e277023be40f0dcc7ff7e818cef1e0d23547cb8c. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
bb28bbd470
commit
fd650ba79d
@ -227,12 +227,12 @@ void queue_pkt_err(struct peer *peer, Pkt *err)
|
||||
queue_raw_pkt(peer, err);
|
||||
}
|
||||
|
||||
void queue_pkt_close_clearing(struct peer *peer)
|
||||
void queue_pkt_close_shutdown(struct peer *peer)
|
||||
{
|
||||
u8 *redeemscript;
|
||||
CloseClearing *c = tal(peer, CloseClearing);
|
||||
CloseShutdown *c = tal(peer, CloseShutdown);
|
||||
|
||||
close_clearing__init(c);
|
||||
close_shutdown__init(c);
|
||||
redeemscript = bitcoin_redeem_single(c, peer->dstate->secpctx,
|
||||
&peer->local.finalkey);
|
||||
peer->closing.our_script = scriptpubkey_p2sh(peer, redeemscript);
|
||||
@ -243,7 +243,7 @@ void queue_pkt_close_clearing(struct peer *peer)
|
||||
0);
|
||||
c->scriptpubkey.len = tal_count(c->scriptpubkey.data);
|
||||
|
||||
queue_pkt(peer, PKT__PKT_CLOSE_CLEARING, c);
|
||||
queue_pkt(peer, PKT__PKT_CLOSE_SHUTDOWN, c);
|
||||
}
|
||||
|
||||
void queue_pkt_close_signature(struct peer *peer)
|
||||
@ -509,9 +509,9 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt)
|
||||
Pkt *accept_pkt_close_shutdown(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
const CloseClearing *c = pkt->close_clearing;
|
||||
const CloseShutdown *c = pkt->close_shutdown;
|
||||
|
||||
/* FIXME: Filter for non-standardness? */
|
||||
peer->closing.their_script = tal_dup_arr(peer, u8,
|
||||
|
@ -21,7 +21,7 @@ void queue_pkt_commit(struct peer *peer);
|
||||
void queue_pkt_revocation(struct peer *peer,
|
||||
const struct sha256 *preimage,
|
||||
const struct sha256 *next_hash);
|
||||
void queue_pkt_close_clearing(struct peer *peer);
|
||||
void queue_pkt_close_shutdown(struct peer *peer);
|
||||
void queue_pkt_close_signature(struct peer *peer);
|
||||
|
||||
Pkt *pkt_err(struct peer *peer, const char *msg, ...);
|
||||
@ -53,6 +53,6 @@ Pkt *accept_pkt_commit(struct peer *peer, const Pkt *pkt,
|
||||
|
||||
Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt);
|
||||
|
||||
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt);
|
||||
Pkt *accept_pkt_close_shutdown(struct peer *peer, const Pkt *pkt);
|
||||
|
||||
#endif /* LIGHTNING_DAEMON_PACKETS_H */
|
||||
|
@ -728,7 +728,7 @@ static bool closing_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* We can get update_commit in both normal and clearing states. */
|
||||
/* We can get update_commit in both normal and shutdown states. */
|
||||
static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
Pkt *err;
|
||||
@ -941,22 +941,22 @@ static void peer_calculate_close_fee(struct peer *peer)
|
||||
assert(!(peer->closing.our_fee & 1));
|
||||
}
|
||||
|
||||
/* This is the io loop while we're clearing. */
|
||||
static bool clearing_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
/* This is the io loop while we're shutdown. */
|
||||
static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
Pkt *err = NULL;
|
||||
|
||||
assert(peer->state == STATE_CLEARING
|
||||
|| peer->state == STATE_CLEARING_COMMITTING);
|
||||
assert(peer->state == STATE_SHUTDOWN
|
||||
|| peer->state == STATE_SHUTDOWN_COMMITTING);
|
||||
|
||||
switch (pkt->pkt_case) {
|
||||
case PKT__PKT_UPDATE_REVOCATION:
|
||||
if (peer->state == STATE_CLEARING)
|
||||
if (peer->state == STATE_SHUTDOWN)
|
||||
err = pkt_err_unexpected(peer, pkt);
|
||||
else {
|
||||
err = handle_pkt_revocation(peer, pkt);
|
||||
if (!err) {
|
||||
set_peer_state(peer, STATE_CLEARING, __func__);
|
||||
set_peer_state(peer, STATE_SHUTDOWN, __func__);
|
||||
peer_update_complete(peer);
|
||||
}
|
||||
}
|
||||
@ -966,21 +966,21 @@ static bool clearing_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node MUST NOT send a `update_add_htlc` after a
|
||||
* `close_clearing` */
|
||||
* `close_shutdown` */
|
||||
if (peer->closing.their_script)
|
||||
err = pkt_err(peer, "Update during clearing");
|
||||
err = pkt_err(peer, "Update during shutdown");
|
||||
else
|
||||
err = handle_pkt_htlc_add(peer, pkt);
|
||||
break;
|
||||
|
||||
case PKT__PKT_CLOSE_CLEARING:
|
||||
case PKT__PKT_CLOSE_SHUTDOWN:
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node... MUST NOT send more than one `close_clearing`. */
|
||||
* A node... MUST NOT send more than one `close_shutdown`. */
|
||||
if (peer->closing.their_script)
|
||||
err = pkt_err_unexpected(peer, pkt);
|
||||
else
|
||||
err = accept_pkt_close_clearing(peer, pkt);
|
||||
err = accept_pkt_close_shutdown(peer, pkt);
|
||||
break;
|
||||
|
||||
case PKT__PKT_UPDATE_FULFILL_HTLC:
|
||||
@ -1020,10 +1020,10 @@ static bool clearing_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void peer_start_clearing(struct peer *peer)
|
||||
static void peer_start_shutdown(struct peer *peer)
|
||||
{
|
||||
assert(peer->state == STATE_CLEARING
|
||||
|| peer->state == STATE_CLEARING_COMMITTING);
|
||||
assert(peer->state == STATE_SHUTDOWN
|
||||
|| peer->state == STATE_SHUTDOWN_COMMITTING);
|
||||
|
||||
/* If they started close, we might not have sent ours. */
|
||||
if (!peer->closing.our_script) {
|
||||
@ -1035,10 +1035,10 @@ static void peer_start_clearing(struct peer *peer)
|
||||
tal_free(redeemscript);
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node SHOULD send a `close_clearing` (if it has
|
||||
* not already) after receiving `close_clearing`.
|
||||
* A node SHOULD send a `close_shutdown` (if it has
|
||||
* not already) after receiving `close_shutdown`.
|
||||
*/
|
||||
queue_pkt_close_clearing(peer);
|
||||
queue_pkt_close_shutdown(peer);
|
||||
}
|
||||
|
||||
/* Catch case where we've exchanged and had no HTLCs anyway. */
|
||||
@ -1075,19 +1075,19 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
err = handle_pkt_commit(peer, pkt);
|
||||
break;
|
||||
|
||||
case PKT_CLOSE_CLEARING:
|
||||
err = accept_pkt_close_clearing(peer, pkt);
|
||||
case PKT_CLOSE_SHUTDOWN:
|
||||
err = accept_pkt_close_shutdown(peer, pkt);
|
||||
if (err)
|
||||
break;
|
||||
if (peer->state == STATE_NORMAL)
|
||||
set_peer_state(peer, STATE_CLEARING, __func__);
|
||||
set_peer_state(peer, STATE_SHUTDOWN, __func__);
|
||||
else {
|
||||
assert(peer->state == STATE_NORMAL_COMMITTING);
|
||||
set_peer_state(peer, STATE_CLEARING_COMMITTING,
|
||||
set_peer_state(peer, STATE_SHUTDOWN_COMMITTING,
|
||||
__func__);
|
||||
}
|
||||
|
||||
peer_start_clearing(peer);
|
||||
peer_start_shutdown(peer);
|
||||
return true;
|
||||
|
||||
case PKT_UPDATE_REVOCATION:
|
||||
@ -1405,8 +1405,8 @@ static struct io_plan *pkt_in(struct io_conn *conn, struct peer *peer)
|
||||
keep_going = true;
|
||||
else if (state_is_normal(peer->state))
|
||||
keep_going = normal_pkt_in(peer, peer->inpkt);
|
||||
else if (state_is_clearing(peer->state))
|
||||
keep_going = clearing_pkt_in(peer, peer->inpkt);
|
||||
else if (state_is_shutdown(peer->state))
|
||||
keep_going = shutdown_pkt_in(peer, peer->inpkt);
|
||||
else if (peer->state == STATE_MUTUAL_CLOSING)
|
||||
keep_going = closing_pkt_in(peer, peer->inpkt);
|
||||
else {
|
||||
@ -1541,8 +1541,8 @@ static void do_commit(struct peer *peer, struct command *jsoncmd)
|
||||
peer_add_their_commit(peer, &ci->txid, ci->commit_num);
|
||||
|
||||
queue_pkt_commit(peer);
|
||||
if (peer->state == STATE_CLEARING) {
|
||||
set_peer_state(peer, STATE_CLEARING_COMMITTING, __func__);
|
||||
if (peer->state == STATE_SHUTDOWN) {
|
||||
set_peer_state(peer, STATE_SHUTDOWN_COMMITTING, __func__);
|
||||
} else {
|
||||
assert(peer->state == STATE_NORMAL);
|
||||
set_peer_state(peer, STATE_NORMAL_COMMITTING, __func__);
|
||||
@ -2580,7 +2580,7 @@ static void resolve_mutual_close(struct peer *peer)
|
||||
*
|
||||
* A node doesn't need to do anything else as it has already agreed to
|
||||
* the output, which is sent to its specified scriptpubkey (see BOLT
|
||||
* #2 "4.1: Closing initiation: close_clearing").
|
||||
* #2 "4.1: Closing initiation: close_shutdown").
|
||||
*/
|
||||
for (i = 0; i < peer->onchain.tx->output_count; i++)
|
||||
peer->onchain.resolved[i] = irrevocably_resolved(peer);
|
||||
@ -3496,10 +3496,10 @@ static void json_close(struct command *cmd,
|
||||
}
|
||||
|
||||
if (peer->state == STATE_NORMAL_COMMITTING)
|
||||
set_peer_state(peer, STATE_CLEARING_COMMITTING, __func__);
|
||||
set_peer_state(peer, STATE_SHUTDOWN_COMMITTING, __func__);
|
||||
else
|
||||
set_peer_state(peer, STATE_CLEARING, __func__);
|
||||
peer_start_clearing(peer);
|
||||
set_peer_state(peer, STATE_SHUTDOWN, __func__);
|
||||
peer_start_shutdown(peer);
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
|
@ -699,13 +699,13 @@ if [ -n "$CLOSE_WITH_HTLCS" ]; then
|
||||
lcli1 close $ID2
|
||||
|
||||
# They should be waiting for it to clear up.
|
||||
check_peerstate lcli1 STATE_CLEARING
|
||||
check_peerstate lcli2 STATE_CLEARING
|
||||
check_peerstate lcli1 STATE_SHUTDOWN
|
||||
check_peerstate lcli2 STATE_SHUTDOWN
|
||||
|
||||
# Fail one, still waiting.
|
||||
lcli2 failhtlc $ID1 $HTLCID
|
||||
check_peerstate lcli1 STATE_CLEARING
|
||||
check_peerstate lcli2 STATE_CLEARING
|
||||
check_peerstate lcli1 STATE_SHUTDOWN
|
||||
check_peerstate lcli2 STATE_SHUTDOWN
|
||||
|
||||
# Fulfill the other causes them to actually complete the close.
|
||||
lcli1 fulfillhtlc $ID2 $HTLCID2 $SECRET2
|
||||
|
@ -910,47 +910,47 @@ void update_revocation__free_unpacked
|
||||
assert(message->base.descriptor == &update_revocation__descriptor);
|
||||
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
|
||||
}
|
||||
void close_clearing__init
|
||||
(CloseClearing *message)
|
||||
void close_shutdown__init
|
||||
(CloseShutdown *message)
|
||||
{
|
||||
static CloseClearing init_value = CLOSE_CLEARING__INIT;
|
||||
static CloseShutdown init_value = CLOSE_SHUTDOWN__INIT;
|
||||
*message = init_value;
|
||||
}
|
||||
size_t close_clearing__get_packed_size
|
||||
(const CloseClearing *message)
|
||||
size_t close_shutdown__get_packed_size
|
||||
(const CloseShutdown *message)
|
||||
{
|
||||
assert(message->base.descriptor == &close_clearing__descriptor);
|
||||
assert(message->base.descriptor == &close_shutdown__descriptor);
|
||||
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
|
||||
}
|
||||
size_t close_clearing__pack
|
||||
(const CloseClearing *message,
|
||||
size_t close_shutdown__pack
|
||||
(const CloseShutdown *message,
|
||||
uint8_t *out)
|
||||
{
|
||||
assert(message->base.descriptor == &close_clearing__descriptor);
|
||||
assert(message->base.descriptor == &close_shutdown__descriptor);
|
||||
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
|
||||
}
|
||||
size_t close_clearing__pack_to_buffer
|
||||
(const CloseClearing *message,
|
||||
size_t close_shutdown__pack_to_buffer
|
||||
(const CloseShutdown *message,
|
||||
ProtobufCBuffer *buffer)
|
||||
{
|
||||
assert(message->base.descriptor == &close_clearing__descriptor);
|
||||
assert(message->base.descriptor == &close_shutdown__descriptor);
|
||||
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
|
||||
}
|
||||
CloseClearing *
|
||||
close_clearing__unpack
|
||||
CloseShutdown *
|
||||
close_shutdown__unpack
|
||||
(ProtobufCAllocator *allocator,
|
||||
size_t len,
|
||||
const uint8_t *data)
|
||||
{
|
||||
return (CloseClearing *)
|
||||
protobuf_c_message_unpack (&close_clearing__descriptor,
|
||||
return (CloseShutdown *)
|
||||
protobuf_c_message_unpack (&close_shutdown__descriptor,
|
||||
allocator, len, data);
|
||||
}
|
||||
void close_clearing__free_unpacked
|
||||
(CloseClearing *message,
|
||||
void close_shutdown__free_unpacked
|
||||
(CloseShutdown *message,
|
||||
ProtobufCAllocator *allocator)
|
||||
{
|
||||
assert(message->base.descriptor == &close_clearing__descriptor);
|
||||
assert(message->base.descriptor == &close_shutdown__descriptor);
|
||||
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
|
||||
}
|
||||
void close_signature__init
|
||||
@ -2354,7 +2354,7 @@ const ProtobufCMessageDescriptor update_revocation__descriptor =
|
||||
(ProtobufCMessageInit) update_revocation__init,
|
||||
NULL,NULL,NULL /* reserved[123] */
|
||||
};
|
||||
static const ProtobufCFieldDescriptor close_clearing__field_descriptors[1] =
|
||||
static const ProtobufCFieldDescriptor close_shutdown__field_descriptors[1] =
|
||||
{
|
||||
{
|
||||
"scriptPubkey",
|
||||
@ -2362,34 +2362,34 @@ static const ProtobufCFieldDescriptor close_clearing__field_descriptors[1] =
|
||||
PROTOBUF_C_LABEL_REQUIRED,
|
||||
PROTOBUF_C_TYPE_BYTES,
|
||||
0, /* quantifier_offset */
|
||||
offsetof(CloseClearing, scriptpubkey),
|
||||
offsetof(CloseShutdown, scriptpubkey),
|
||||
NULL,
|
||||
NULL,
|
||||
0, /* flags */
|
||||
0,NULL,NULL /* reserved1,reserved2, etc */
|
||||
},
|
||||
};
|
||||
static const unsigned close_clearing__field_indices_by_name[] = {
|
||||
static const unsigned close_shutdown__field_indices_by_name[] = {
|
||||
0, /* field[0] = scriptPubkey */
|
||||
};
|
||||
static const ProtobufCIntRange close_clearing__number_ranges[1 + 1] =
|
||||
static const ProtobufCIntRange close_shutdown__number_ranges[1 + 1] =
|
||||
{
|
||||
{ 1, 0 },
|
||||
{ 0, 1 }
|
||||
};
|
||||
const ProtobufCMessageDescriptor close_clearing__descriptor =
|
||||
const ProtobufCMessageDescriptor close_shutdown__descriptor =
|
||||
{
|
||||
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
||||
"close_clearing",
|
||||
"CloseClearing",
|
||||
"CloseClearing",
|
||||
"close_shutdown",
|
||||
"CloseShutdown",
|
||||
"CloseShutdown",
|
||||
"",
|
||||
sizeof(CloseClearing),
|
||||
sizeof(CloseShutdown),
|
||||
1,
|
||||
close_clearing__field_descriptors,
|
||||
close_clearing__field_indices_by_name,
|
||||
1, close_clearing__number_ranges,
|
||||
(ProtobufCMessageInit) close_clearing__init,
|
||||
close_shutdown__field_descriptors,
|
||||
close_shutdown__field_indices_by_name,
|
||||
1, close_shutdown__number_ranges,
|
||||
(ProtobufCMessageInit) close_shutdown__init,
|
||||
NULL,NULL,NULL /* reserved[123] */
|
||||
};
|
||||
static const ProtobufCFieldDescriptor close_signature__field_descriptors[2] =
|
||||
@ -2592,13 +2592,13 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[14] =
|
||||
0,NULL,NULL /* reserved1,reserved2, etc */
|
||||
},
|
||||
{
|
||||
"close_clearing",
|
||||
"close_shutdown",
|
||||
30,
|
||||
PROTOBUF_C_LABEL_OPTIONAL,
|
||||
PROTOBUF_C_TYPE_MESSAGE,
|
||||
offsetof(Pkt, pkt_case),
|
||||
offsetof(Pkt, close_clearing),
|
||||
&close_clearing__descriptor,
|
||||
offsetof(Pkt, close_shutdown),
|
||||
&close_shutdown__descriptor,
|
||||
NULL,
|
||||
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
|
||||
0,NULL,NULL /* reserved1,reserved2, etc */
|
||||
@ -2654,7 +2654,7 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[14] =
|
||||
};
|
||||
static const unsigned pkt__field_indices_by_name[] = {
|
||||
12, /* field[12] = auth */
|
||||
9, /* field[9] = close_clearing */
|
||||
9, /* field[9] = close_shutdown */
|
||||
10, /* field[10] = close_signature */
|
||||
11, /* field[11] = error */
|
||||
5, /* field[5] = open */
|
||||
|
@ -36,7 +36,7 @@ typedef struct _FailReason FailReason;
|
||||
typedef struct _UpdateFailHtlc UpdateFailHtlc;
|
||||
typedef struct _UpdateCommit UpdateCommit;
|
||||
typedef struct _UpdateRevocation UpdateRevocation;
|
||||
typedef struct _CloseClearing CloseClearing;
|
||||
typedef struct _CloseShutdown CloseShutdown;
|
||||
typedef struct _CloseSignature CloseSignature;
|
||||
typedef struct _Error Error;
|
||||
typedef struct _Pkt Pkt;
|
||||
@ -471,7 +471,7 @@ struct _UpdateRevocation
|
||||
/*
|
||||
* Start clearing out the channel HTLCs so we can close it
|
||||
*/
|
||||
struct _CloseClearing
|
||||
struct _CloseShutdown
|
||||
{
|
||||
ProtobufCMessage base;
|
||||
/*
|
||||
@ -479,8 +479,8 @@ struct _CloseClearing
|
||||
*/
|
||||
ProtobufCBinaryData scriptpubkey;
|
||||
};
|
||||
#define CLOSE_CLEARING__INIT \
|
||||
{ PROTOBUF_C_MESSAGE_INIT (&close_clearing__descriptor) \
|
||||
#define CLOSE_SHUTDOWN__INIT \
|
||||
{ PROTOBUF_C_MESSAGE_INIT (&close_shutdown__descriptor) \
|
||||
, {0,NULL} }
|
||||
|
||||
|
||||
@ -527,7 +527,7 @@ typedef enum {
|
||||
PKT__PKT_UPDATE_FAIL_HTLC = 4,
|
||||
PKT__PKT_UPDATE_COMMIT = 5,
|
||||
PKT__PKT_UPDATE_REVOCATION = 6,
|
||||
PKT__PKT_CLOSE_CLEARING = 30,
|
||||
PKT__PKT_CLOSE_SHUTDOWN = 30,
|
||||
PKT__PKT_CLOSE_SIGNATURE = 31,
|
||||
PKT__PKT_ERROR = 40,
|
||||
} Pkt__PktCase;
|
||||
@ -563,7 +563,7 @@ struct _Pkt
|
||||
/*
|
||||
* Closing
|
||||
*/
|
||||
CloseClearing *close_clearing;
|
||||
CloseShutdown *close_shutdown;
|
||||
CloseSignature *close_signature;
|
||||
/*
|
||||
* Unexpected issue.
|
||||
@ -975,24 +975,24 @@ UpdateRevocation *
|
||||
void update_revocation__free_unpacked
|
||||
(UpdateRevocation *message,
|
||||
ProtobufCAllocator *allocator);
|
||||
/* CloseClearing methods */
|
||||
void close_clearing__init
|
||||
(CloseClearing *message);
|
||||
size_t close_clearing__get_packed_size
|
||||
(const CloseClearing *message);
|
||||
size_t close_clearing__pack
|
||||
(const CloseClearing *message,
|
||||
/* CloseShutdown methods */
|
||||
void close_shutdown__init
|
||||
(CloseShutdown *message);
|
||||
size_t close_shutdown__get_packed_size
|
||||
(const CloseShutdown *message);
|
||||
size_t close_shutdown__pack
|
||||
(const CloseShutdown *message,
|
||||
uint8_t *out);
|
||||
size_t close_clearing__pack_to_buffer
|
||||
(const CloseClearing *message,
|
||||
size_t close_shutdown__pack_to_buffer
|
||||
(const CloseShutdown *message,
|
||||
ProtobufCBuffer *buffer);
|
||||
CloseClearing *
|
||||
close_clearing__unpack
|
||||
CloseShutdown *
|
||||
close_shutdown__unpack
|
||||
(ProtobufCAllocator *allocator,
|
||||
size_t len,
|
||||
const uint8_t *data);
|
||||
void close_clearing__free_unpacked
|
||||
(CloseClearing *message,
|
||||
void close_shutdown__free_unpacked
|
||||
(CloseShutdown *message,
|
||||
ProtobufCAllocator *allocator);
|
||||
/* CloseSignature methods */
|
||||
void close_signature__init
|
||||
@ -1116,8 +1116,8 @@ typedef void (*UpdateCommit_Closure)
|
||||
typedef void (*UpdateRevocation_Closure)
|
||||
(const UpdateRevocation *message,
|
||||
void *closure_data);
|
||||
typedef void (*CloseClearing_Closure)
|
||||
(const CloseClearing *message,
|
||||
typedef void (*CloseShutdown_Closure)
|
||||
(const CloseShutdown *message,
|
||||
void *closure_data);
|
||||
typedef void (*CloseSignature_Closure)
|
||||
(const CloseSignature *message,
|
||||
@ -1156,7 +1156,7 @@ extern const ProtobufCMessageDescriptor fail_reason__descriptor;
|
||||
extern const ProtobufCMessageDescriptor update_fail_htlc__descriptor;
|
||||
extern const ProtobufCMessageDescriptor update_commit__descriptor;
|
||||
extern const ProtobufCMessageDescriptor update_revocation__descriptor;
|
||||
extern const ProtobufCMessageDescriptor close_clearing__descriptor;
|
||||
extern const ProtobufCMessageDescriptor close_shutdown__descriptor;
|
||||
extern const ProtobufCMessageDescriptor close_signature__descriptor;
|
||||
extern const ProtobufCMessageDescriptor error__descriptor;
|
||||
extern const ProtobufCMessageDescriptor pkt__descriptor;
|
||||
|
@ -193,7 +193,7 @@ message update_revocation {
|
||||
}
|
||||
|
||||
// Start clearing out the channel HTLCs so we can close it
|
||||
message close_clearing {
|
||||
message close_shutdown {
|
||||
// Output script for mutual close tx.
|
||||
required bytes scriptPubkey = 1;
|
||||
}
|
||||
@ -230,7 +230,7 @@ message pkt {
|
||||
update_revocation update_revocation = 6;
|
||||
|
||||
// Closing
|
||||
close_clearing close_clearing = 30;
|
||||
close_shutdown close_shutdown = 30;
|
||||
close_signature close_signature = 31;
|
||||
|
||||
// Unexpected issue.
|
||||
|
32
state.c
32
state.c
@ -213,9 +213,9 @@ enum state state(struct peer *peer,
|
||||
}
|
||||
return next_state(peer, input,
|
||||
STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR);
|
||||
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
||||
goto accept_clearing;
|
||||
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
|
||||
goto accept_shutdown;
|
||||
} else if (input_is_pkt(input)) {
|
||||
peer_open_complete(peer, "unexpected packet");
|
||||
goto unexpected_pkt;
|
||||
@ -245,9 +245,9 @@ enum state state(struct peer *peer,
|
||||
}
|
||||
return next_state(peer, input,
|
||||
STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR);
|
||||
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
||||
goto accept_clearing;
|
||||
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
|
||||
goto accept_shutdown;
|
||||
} else if (input_is_pkt(input)) {
|
||||
peer_open_complete(peer, "unexpected packet");
|
||||
goto unexpected_pkt;
|
||||
@ -259,9 +259,9 @@ enum state state(struct peer *peer,
|
||||
/* Ready for business! */
|
||||
peer_open_complete(peer, NULL);
|
||||
return next_state(peer, input, STATE_NORMAL);
|
||||
} else if (input_is(input, PKT_CLOSE_CLEARING)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_CLEARING");
|
||||
goto accept_clearing;
|
||||
} else if (input_is(input, PKT_CLOSE_SHUTDOWN)) {
|
||||
peer_open_complete(peer, "Received PKT_CLOSE_SHUTDOWN");
|
||||
goto accept_shutdown;
|
||||
} else if (input_is_pkt(input)) {
|
||||
peer_open_complete(peer, "unexpected packet");
|
||||
goto unexpected_pkt;
|
||||
@ -277,8 +277,8 @@ enum state state(struct peer *peer,
|
||||
case STATE_ERR_BREAKDOWN:
|
||||
case STATE_CLOSED:
|
||||
case STATE_MAX:
|
||||
case STATE_CLEARING:
|
||||
case STATE_CLEARING_COMMITTING:
|
||||
case STATE_SHUTDOWN:
|
||||
case STATE_SHUTDOWN_COMMITTING:
|
||||
case STATE_MUTUAL_CLOSING:
|
||||
case STATE_CLOSE_ONCHAIN_CHEATED:
|
||||
case STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL:
|
||||
@ -305,13 +305,13 @@ err_breakdown:
|
||||
breakdown:
|
||||
return next_state(peer, input, STATE_ERR_BREAKDOWN);
|
||||
|
||||
accept_clearing:
|
||||
err = accept_pkt_close_clearing(peer, pkt);
|
||||
accept_shutdown:
|
||||
err = accept_pkt_close_shutdown(peer, pkt);
|
||||
if (err)
|
||||
goto err_breakdown;
|
||||
|
||||
/* If we've sent commit, we're still waiting for it when clearing. */
|
||||
/* If we've sent commit, we're still waiting for it when shutdown. */
|
||||
if (peer->state == STATE_NORMAL_COMMITTING)
|
||||
return next_state(peer, input, STATE_CLEARING_COMMITTING);
|
||||
return next_state(peer, input, STATE_CLEARING);
|
||||
return next_state(peer, input, STATE_SHUTDOWN_COMMITTING);
|
||||
return next_state(peer, input, STATE_SHUTDOWN);
|
||||
}
|
||||
|
10
state.h
10
state.h
@ -19,9 +19,9 @@ static inline bool state_is_error(enum state s)
|
||||
return s >= STATE_ERR_BREAKDOWN && s <= STATE_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
static inline bool state_is_clearing(enum state s)
|
||||
static inline bool state_is_shutdown(enum state s)
|
||||
{
|
||||
return s == STATE_CLEARING || s == STATE_CLEARING_COMMITTING;
|
||||
return s == STATE_SHUTDOWN || s == STATE_SHUTDOWN_COMMITTING;
|
||||
}
|
||||
|
||||
static inline bool state_is_onchain(enum state s)
|
||||
@ -53,12 +53,12 @@ static inline bool state_can_io(enum state s)
|
||||
|
||||
static inline bool state_can_commit(enum state s)
|
||||
{
|
||||
return s == STATE_NORMAL || s == STATE_CLEARING;
|
||||
return s == STATE_NORMAL || s == STATE_SHUTDOWN;
|
||||
}
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node MUST NOT send a `update_add_htlc` after a `close_clearing`
|
||||
* A node MUST NOT send a `update_add_htlc` after a `close_shutdown`
|
||||
*/
|
||||
static inline bool state_can_add_htlc(enum state s)
|
||||
{
|
||||
@ -67,7 +67,7 @@ static inline bool state_can_add_htlc(enum state s)
|
||||
|
||||
static inline bool state_can_remove_htlc(enum state s)
|
||||
{
|
||||
return state_is_normal(s) || state_is_clearing(s);
|
||||
return state_is_normal(s) || state_is_shutdown(s);
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,8 +30,8 @@ enum state {
|
||||
/*
|
||||
* Closing (handled outside state machine).
|
||||
*/
|
||||
STATE_CLEARING,
|
||||
STATE_CLEARING_COMMITTING,
|
||||
STATE_SHUTDOWN,
|
||||
STATE_SHUTDOWN_COMMITTING,
|
||||
STATE_MUTUAL_CLOSING,
|
||||
|
||||
/* Four states to represent closing onchain (for getpeers) */
|
||||
@ -79,7 +79,7 @@ enum state_input {
|
||||
PKT_UPDATE_REVOCATION = PKT__PKT_UPDATE_REVOCATION,
|
||||
|
||||
/* If they want to close. */
|
||||
PKT_CLOSE_CLEARING = PKT__PKT_CLOSE_CLEARING,
|
||||
PKT_CLOSE_SHUTDOWN = PKT__PKT_CLOSE_SHUTDOWN,
|
||||
|
||||
/* Something unexpected went wrong. */
|
||||
PKT_ERROR = PKT__PKT_ERROR,
|
||||
|
Loading…
Reference in New Issue
Block a user