Browse Source

protocol: rename routefail to fail.

It's a generic "I couldn't complete this" failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
4f67b59c26
  1. 15
      daemon/packets.c
  2. 2
      daemon/peer.c
  3. 74
      lightning.pb-c.c
  4. 46
      lightning.pb-c.h
  5. 6
      lightning.proto
  6. 18
      state.c
  7. 12
      state.h
  8. 4
      state_types.h
  9. 20
      test/test_state_coverage.c

15
daemon/packets.c

@ -175,17 +175,17 @@ Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct peer *peer,
return make_pkt(ctx, PKT__PKT_UPDATE_TIMEDOUT_HTLC, t); return make_pkt(ctx, PKT__PKT_UPDATE_TIMEDOUT_HTLC, t);
} }
Pkt *pkt_htlc_routefail(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_fail(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog) const struct htlc_progress *htlc_prog)
{ {
UpdateRoutefailHtlc *f = tal(ctx, UpdateRoutefailHtlc); UpdateFailHtlc *f = tal(ctx, UpdateFailHtlc);
update_routefail_htlc__init(f); update_fail_htlc__init(f);
f->revocation_hash = sha256_to_proto(f, &htlc_prog->our_revocation_hash); f->revocation_hash = sha256_to_proto(f, &htlc_prog->our_revocation_hash);
f->r_hash = sha256_to_proto(f, &htlc_prog->htlc->rhash); f->r_hash = sha256_to_proto(f, &htlc_prog->htlc->rhash);
return make_pkt(ctx, PKT__PKT_UPDATE_ROUTEFAIL_HTLC, f); return make_pkt(ctx, PKT__PKT_UPDATE_FAIL_HTLC, f);
} }
Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer) Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer)
@ -501,10 +501,9 @@ decline:
return NULL; return NULL;
}; };
Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, Pkt *accept_pkt_htlc_fail(const tal_t *ctx, struct peer *peer, const Pkt *pkt)
struct peer *peer, const Pkt *pkt)
{ {
const UpdateRoutefailHtlc *f = pkt->update_routefail_htlc; const UpdateFailHtlc *f = pkt->update_fail_htlc;
struct htlc_progress *cur = tal(peer, struct htlc_progress); struct htlc_progress *cur = tal(peer, struct htlc_progress);
Pkt *err; Pkt *err;
size_t i; size_t i;

2
daemon/peer.c

@ -1611,7 +1611,7 @@ static void do_failhtlc(struct peer *peer,
funding_remove_htlc(&cstate->b, i); funding_remove_htlc(&cstate->b, i);
set_htlc_command(peer, cstate, failhtlc->jsoncmd, htlc, set_htlc_command(peer, cstate, failhtlc->jsoncmd, htlc,
CMD_SEND_HTLC_ROUTEFAIL, NULL); CMD_SEND_HTLC_FAIL, NULL);
} }
static void json_failhtlc(struct command *cmd, static void json_failhtlc(struct command *cmd,

74
lightning.pb-c.c

@ -609,47 +609,47 @@ void update_timedout_htlc__free_unpacked
assert(message->base.descriptor == &update_timedout_htlc__descriptor); assert(message->base.descriptor == &update_timedout_htlc__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void update_routefail_htlc__init void update_fail_htlc__init
(UpdateRoutefailHtlc *message) (UpdateFailHtlc *message)
{ {
static UpdateRoutefailHtlc init_value = UPDATE_ROUTEFAIL_HTLC__INIT; static UpdateFailHtlc init_value = UPDATE_FAIL_HTLC__INIT;
*message = init_value; *message = init_value;
} }
size_t update_routefail_htlc__get_packed_size size_t update_fail_htlc__get_packed_size
(const UpdateRoutefailHtlc *message) (const UpdateFailHtlc *message)
{ {
assert(message->base.descriptor == &update_routefail_htlc__descriptor); assert(message->base.descriptor == &update_fail_htlc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
} }
size_t update_routefail_htlc__pack size_t update_fail_htlc__pack
(const UpdateRoutefailHtlc *message, (const UpdateFailHtlc *message,
uint8_t *out) uint8_t *out)
{ {
assert(message->base.descriptor == &update_routefail_htlc__descriptor); assert(message->base.descriptor == &update_fail_htlc__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
} }
size_t update_routefail_htlc__pack_to_buffer size_t update_fail_htlc__pack_to_buffer
(const UpdateRoutefailHtlc *message, (const UpdateFailHtlc *message,
ProtobufCBuffer *buffer) ProtobufCBuffer *buffer)
{ {
assert(message->base.descriptor == &update_routefail_htlc__descriptor); assert(message->base.descriptor == &update_fail_htlc__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
} }
UpdateRoutefailHtlc * UpdateFailHtlc *
update_routefail_htlc__unpack update_fail_htlc__unpack
(ProtobufCAllocator *allocator, (ProtobufCAllocator *allocator,
size_t len, size_t len,
const uint8_t *data) const uint8_t *data)
{ {
return (UpdateRoutefailHtlc *) return (UpdateFailHtlc *)
protobuf_c_message_unpack (&update_routefail_htlc__descriptor, protobuf_c_message_unpack (&update_fail_htlc__descriptor,
allocator, len, data); allocator, len, data);
} }
void update_routefail_htlc__free_unpacked void update_fail_htlc__free_unpacked
(UpdateRoutefailHtlc *message, (UpdateFailHtlc *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator)
{ {
assert(message->base.descriptor == &update_routefail_htlc__descriptor); assert(message->base.descriptor == &update_fail_htlc__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void update_accept__init void update_accept__init
@ -1923,7 +1923,7 @@ const ProtobufCMessageDescriptor update_timedout_htlc__descriptor =
(ProtobufCMessageInit) update_timedout_htlc__init, (ProtobufCMessageInit) update_timedout_htlc__init,
NULL,NULL,NULL /* reserved[123] */ NULL,NULL,NULL /* reserved[123] */
}; };
static const ProtobufCFieldDescriptor update_routefail_htlc__field_descriptors[2] = static const ProtobufCFieldDescriptor update_fail_htlc__field_descriptors[2] =
{ {
{ {
"revocation_hash", "revocation_hash",
@ -1931,7 +1931,7 @@ static const ProtobufCFieldDescriptor update_routefail_htlc__field_descriptors[2
PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_MESSAGE, PROTOBUF_C_TYPE_MESSAGE,
0, /* quantifier_offset */ 0, /* quantifier_offset */
offsetof(UpdateRoutefailHtlc, revocation_hash), offsetof(UpdateFailHtlc, revocation_hash),
&sha256_hash__descriptor, &sha256_hash__descriptor,
NULL, NULL,
0, /* flags */ 0, /* flags */
@ -1943,35 +1943,35 @@ static const ProtobufCFieldDescriptor update_routefail_htlc__field_descriptors[2
PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_MESSAGE, PROTOBUF_C_TYPE_MESSAGE,
0, /* quantifier_offset */ 0, /* quantifier_offset */
offsetof(UpdateRoutefailHtlc, r_hash), offsetof(UpdateFailHtlc, r_hash),
&sha256_hash__descriptor, &sha256_hash__descriptor,
NULL, NULL,
0, /* flags */ 0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0,NULL,NULL /* reserved1,reserved2, etc */
}, },
}; };
static const unsigned update_routefail_htlc__field_indices_by_name[] = { static const unsigned update_fail_htlc__field_indices_by_name[] = {
1, /* field[1] = r_hash */ 1, /* field[1] = r_hash */
0, /* field[0] = revocation_hash */ 0, /* field[0] = revocation_hash */
}; };
static const ProtobufCIntRange update_routefail_htlc__number_ranges[1 + 1] = static const ProtobufCIntRange update_fail_htlc__number_ranges[1 + 1] =
{ {
{ 1, 0 }, { 1, 0 },
{ 0, 2 } { 0, 2 }
}; };
const ProtobufCMessageDescriptor update_routefail_htlc__descriptor = const ProtobufCMessageDescriptor update_fail_htlc__descriptor =
{ {
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"update_routefail_htlc", "update_fail_htlc",
"UpdateRoutefailHtlc", "UpdateFailHtlc",
"UpdateRoutefailHtlc", "UpdateFailHtlc",
"", "",
sizeof(UpdateRoutefailHtlc), sizeof(UpdateFailHtlc),
2, 2,
update_routefail_htlc__field_descriptors, update_fail_htlc__field_descriptors,
update_routefail_htlc__field_indices_by_name, update_fail_htlc__field_indices_by_name,
1, update_routefail_htlc__number_ranges, 1, update_fail_htlc__number_ranges,
(ProtobufCMessageInit) update_routefail_htlc__init, (ProtobufCMessageInit) update_fail_htlc__init,
NULL,NULL,NULL /* reserved[123] */ NULL,NULL,NULL /* reserved[123] */
}; };
static const ProtobufCFieldDescriptor update_accept__field_descriptors[2] = static const ProtobufCFieldDescriptor update_accept__field_descriptors[2] =
@ -2346,13 +2346,13 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[17] =
0,NULL,NULL /* reserved1,reserved2, etc */ 0,NULL,NULL /* reserved1,reserved2, etc */
}, },
{ {
"update_routefail_htlc", "update_fail_htlc",
9, 9,
PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_MESSAGE, PROTOBUF_C_TYPE_MESSAGE,
offsetof(Pkt, pkt_case), offsetof(Pkt, pkt_case),
offsetof(Pkt, update_routefail_htlc), offsetof(Pkt, update_fail_htlc),
&update_routefail_htlc__descriptor, &update_fail_htlc__descriptor,
NULL, NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0,NULL,NULL /* reserved1,reserved2, etc */
@ -2480,8 +2480,8 @@ static const unsigned pkt__field_indices_by_name[] = {
0, /* field[0] = update_add_htlc */ 0, /* field[0] = update_add_htlc */
3, /* field[3] = update_complete */ 3, /* field[3] = update_complete */
4, /* field[4] = update_decline_htlc */ 4, /* field[4] = update_decline_htlc */
7, /* field[7] = update_fail_htlc */
5, /* field[5] = update_fulfill_htlc */ 5, /* field[5] = update_fulfill_htlc */
7, /* field[7] = update_routefail_htlc */
2, /* field[2] = update_signature */ 2, /* field[2] = update_signature */
6, /* field[6] = update_timedout_htlc */ 6, /* field[6] = update_timedout_htlc */
}; };

46
lightning.pb-c.h

@ -29,7 +29,7 @@ typedef struct _UpdateAddHtlc UpdateAddHtlc;
typedef struct _UpdateDeclineHtlc UpdateDeclineHtlc; typedef struct _UpdateDeclineHtlc UpdateDeclineHtlc;
typedef struct _UpdateFulfillHtlc UpdateFulfillHtlc; typedef struct _UpdateFulfillHtlc UpdateFulfillHtlc;
typedef struct _UpdateTimedoutHtlc UpdateTimedoutHtlc; typedef struct _UpdateTimedoutHtlc UpdateTimedoutHtlc;
typedef struct _UpdateRoutefailHtlc UpdateRoutefailHtlc; typedef struct _UpdateFailHtlc UpdateFailHtlc;
typedef struct _UpdateAccept UpdateAccept; typedef struct _UpdateAccept UpdateAccept;
typedef struct _UpdateSignature UpdateSignature; typedef struct _UpdateSignature UpdateSignature;
typedef struct _UpdateComplete UpdateComplete; typedef struct _UpdateComplete UpdateComplete;
@ -360,9 +360,9 @@ struct _UpdateTimedoutHtlc
/* /*
* Remove your HTLC: routing has failed upstream * Remove your HTLC: routing has failed upstream or we didn't like it.
*/ */
struct _UpdateRoutefailHtlc struct _UpdateFailHtlc
{ {
ProtobufCMessage base; ProtobufCMessage base;
/* /*
@ -374,8 +374,8 @@ struct _UpdateRoutefailHtlc
*/ */
Sha256Hash *r_hash; Sha256Hash *r_hash;
}; };
#define UPDATE_ROUTEFAIL_HTLC__INIT \ #define UPDATE_FAIL_HTLC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&update_routefail_htlc__descriptor) \ { PROTOBUF_C_MESSAGE_INIT (&update_fail_htlc__descriptor) \
, NULL, NULL } , NULL, NULL }
@ -512,7 +512,7 @@ typedef enum {
PKT__PKT_UPDATE_DECLINE_HTLC = 6, PKT__PKT_UPDATE_DECLINE_HTLC = 6,
PKT__PKT_UPDATE_FULFILL_HTLC = 7, PKT__PKT_UPDATE_FULFILL_HTLC = 7,
PKT__PKT_UPDATE_TIMEDOUT_HTLC = 8, PKT__PKT_UPDATE_TIMEDOUT_HTLC = 8,
PKT__PKT_UPDATE_ROUTEFAIL_HTLC = 9, PKT__PKT_UPDATE_FAIL_HTLC = 9,
PKT__PKT_CLOSE = 30, PKT__PKT_CLOSE = 30,
PKT__PKT_CLOSE_COMPLETE = 31, PKT__PKT_CLOSE_COMPLETE = 31,
PKT__PKT_CLOSE_ACK = 32, PKT__PKT_CLOSE_ACK = 32,
@ -548,7 +548,7 @@ struct _Pkt
UpdateDeclineHtlc *update_decline_htlc; UpdateDeclineHtlc *update_decline_htlc;
UpdateFulfillHtlc *update_fulfill_htlc; UpdateFulfillHtlc *update_fulfill_htlc;
UpdateTimedoutHtlc *update_timedout_htlc; UpdateTimedoutHtlc *update_timedout_htlc;
UpdateRoutefailHtlc *update_routefail_htlc; UpdateFailHtlc *update_fail_htlc;
/* /*
* Closing * Closing
*/ */
@ -832,24 +832,24 @@ UpdateTimedoutHtlc *
void update_timedout_htlc__free_unpacked void update_timedout_htlc__free_unpacked
(UpdateTimedoutHtlc *message, (UpdateTimedoutHtlc *message,
ProtobufCAllocator *allocator); ProtobufCAllocator *allocator);
/* UpdateRoutefailHtlc methods */ /* UpdateFailHtlc methods */
void update_routefail_htlc__init void update_fail_htlc__init
(UpdateRoutefailHtlc *message); (UpdateFailHtlc *message);
size_t update_routefail_htlc__get_packed_size size_t update_fail_htlc__get_packed_size
(const UpdateRoutefailHtlc *message); (const UpdateFailHtlc *message);
size_t update_routefail_htlc__pack size_t update_fail_htlc__pack
(const UpdateRoutefailHtlc *message, (const UpdateFailHtlc *message,
uint8_t *out); uint8_t *out);
size_t update_routefail_htlc__pack_to_buffer size_t update_fail_htlc__pack_to_buffer
(const UpdateRoutefailHtlc *message, (const UpdateFailHtlc *message,
ProtobufCBuffer *buffer); ProtobufCBuffer *buffer);
UpdateRoutefailHtlc * UpdateFailHtlc *
update_routefail_htlc__unpack update_fail_htlc__unpack
(ProtobufCAllocator *allocator, (ProtobufCAllocator *allocator,
size_t len, size_t len,
const uint8_t *data); const uint8_t *data);
void update_routefail_htlc__free_unpacked void update_fail_htlc__free_unpacked
(UpdateRoutefailHtlc *message, (UpdateFailHtlc *message,
ProtobufCAllocator *allocator); ProtobufCAllocator *allocator);
/* UpdateAccept methods */ /* UpdateAccept methods */
void update_accept__init void update_accept__init
@ -1047,8 +1047,8 @@ typedef void (*UpdateFulfillHtlc_Closure)
typedef void (*UpdateTimedoutHtlc_Closure) typedef void (*UpdateTimedoutHtlc_Closure)
(const UpdateTimedoutHtlc *message, (const UpdateTimedoutHtlc *message,
void *closure_data); void *closure_data);
typedef void (*UpdateRoutefailHtlc_Closure) typedef void (*UpdateFailHtlc_Closure)
(const UpdateRoutefailHtlc *message, (const UpdateFailHtlc *message,
void *closure_data); void *closure_data);
typedef void (*UpdateAccept_Closure) typedef void (*UpdateAccept_Closure)
(const UpdateAccept *message, (const UpdateAccept *message,
@ -1095,7 +1095,7 @@ extern const ProtobufCMessageDescriptor update_add_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_decline_htlc__descriptor; extern const ProtobufCMessageDescriptor update_decline_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_fulfill_htlc__descriptor; extern const ProtobufCMessageDescriptor update_fulfill_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_timedout_htlc__descriptor; extern const ProtobufCMessageDescriptor update_timedout_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_routefail_htlc__descriptor; extern const ProtobufCMessageDescriptor update_fail_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_accept__descriptor; extern const ProtobufCMessageDescriptor update_accept__descriptor;
extern const ProtobufCMessageDescriptor update_signature__descriptor; extern const ProtobufCMessageDescriptor update_signature__descriptor;
extern const ProtobufCMessageDescriptor update_complete__descriptor; extern const ProtobufCMessageDescriptor update_complete__descriptor;

6
lightning.proto

@ -147,8 +147,8 @@ message update_timedout_htlc {
required sha256_hash r_hash = 2; required sha256_hash r_hash = 2;
} }
// Remove your HTLC: routing has failed upstream // Remove your HTLC: routing has failed upstream or we didn't like it.
message update_routefail_htlc { message update_fail_htlc {
// Hash for which I will supply preimage to revoke this commitment tx. // Hash for which I will supply preimage to revoke this commitment tx.
required sha256_hash revocation_hash = 1; required sha256_hash revocation_hash = 1;
// Hash for HTLC R value. // Hash for HTLC R value.
@ -220,7 +220,7 @@ message pkt {
update_decline_htlc update_decline_htlc = 6; update_decline_htlc update_decline_htlc = 6;
update_fulfill_htlc update_fulfill_htlc = 7; update_fulfill_htlc update_fulfill_htlc = 7;
update_timedout_htlc update_timedout_htlc = 8; update_timedout_htlc update_timedout_htlc = 8;
update_routefail_htlc update_routefail_htlc = 9; update_fail_htlc update_fail_htlc = 9;
// Closing // Closing
close_channel close = 30; close_channel close = 30;
close_channel_complete close_complete = 31; close_channel_complete close_complete = 31;

18
state.c

@ -427,10 +427,10 @@ enum command_status state(const tal_t *ctx,
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
return next_state(peer, cstatus, return next_state(peer, cstatus,
prio(peer->state, STATE_WAIT_FOR_UPDATE_ACCEPT)); prio(peer->state, STATE_WAIT_FOR_UPDATE_ACCEPT));
} else if (input_is(input, CMD_SEND_HTLC_ROUTEFAIL)) { } else if (input_is(input, CMD_SEND_HTLC_FAIL)) {
/* We are to send an HTLC routefail. */ /* We are to send an HTLC fail. */
queue_pkt(out, queue_pkt(out,
pkt_htlc_routefail(ctx, peer, pkt_htlc_fail(ctx, peer,
idata->htlc_prog)); idata->htlc_prog));
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
return next_state(peer, cstatus, return next_state(peer, cstatus,
@ -446,9 +446,9 @@ enum command_status state(const tal_t *ctx,
} else if (input_is(input, PKT_UPDATE_TIMEDOUT_HTLC)) { } else if (input_is(input, PKT_UPDATE_TIMEDOUT_HTLC)) {
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_timedout; goto accept_htlc_timedout;
} else if (input_is(input, PKT_UPDATE_ROUTEFAIL_HTLC)) { } else if (input_is(input, PKT_UPDATE_FAIL_HTLC)) {
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_routefail; goto accept_htlc_fail;
} else if (input_is(input, BITCOIN_ANCHOR_THEIRSPEND)) { } else if (input_is(input, BITCOIN_ANCHOR_THEIRSPEND)) {
goto them_unilateral; goto them_unilateral;
} else if (input_is(input, BITCOIN_ANCHOR_OTHERSPEND)) { } else if (input_is(input, BITCOIN_ANCHOR_OTHERSPEND)) {
@ -507,7 +507,7 @@ enum command_status state(const tal_t *ctx,
/* Stay busy, since we're processing theirs. */ /* Stay busy, since we're processing theirs. */
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_timedout; goto accept_htlc_timedout;
} else if (input_is(input, PKT_UPDATE_ROUTEFAIL_HTLC)) { } else if (input_is(input, PKT_UPDATE_FAIL_HTLC)) {
/* If we're high priority, ignore their packet */ /* If we're high priority, ignore their packet */
if (high_priority(peer->state)) if (high_priority(peer->state))
return cstatus; return cstatus;
@ -517,7 +517,7 @@ enum command_status state(const tal_t *ctx,
complete_cmd(peer, &cstatus, CMD_REQUEUE); complete_cmd(peer, &cstatus, CMD_REQUEUE);
/* Stay busy, since we're processing theirs. */ /* Stay busy, since we're processing theirs. */
change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY); change_peer_cond(peer, PEER_CMD_OK, PEER_BUSY);
goto accept_htlc_routefail; goto accept_htlc_fail;
} else if (input_is(input, PKT_UPDATE_ACCEPT)) { } else if (input_is(input, PKT_UPDATE_ACCEPT)) {
err = accept_pkt_update_accept(ctx, peer, idata->pkt); err = accept_pkt_update_accept(ctx, peer, idata->pkt);
if (err) { if (err) {
@ -1052,8 +1052,8 @@ accept_htlc_update:
return next_state(peer, cstatus, return next_state(peer, cstatus,
prio(peer->state, STATE_WAIT_FOR_UPDATE_SIG)); prio(peer->state, STATE_WAIT_FOR_UPDATE_SIG));
accept_htlc_routefail: accept_htlc_fail:
err = accept_pkt_htlc_routefail(ctx, peer, idata->pkt); err = accept_pkt_htlc_fail(ctx, peer, idata->pkt);
if (err) if (err)
goto err_start_unilateral_close; goto err_start_unilateral_close;
queue_pkt(out, pkt_update_accept(ctx, peer)); queue_pkt(out, pkt_update_accept(ctx, peer));

12
state.h

@ -53,7 +53,7 @@ static inline bool input_is(enum state_input a, enum state_input b)
return input_is(a, CMD_SEND_HTLC_UPDATE) return input_is(a, CMD_SEND_HTLC_UPDATE)
| input_is(a, CMD_SEND_HTLC_FULFILL) | input_is(a, CMD_SEND_HTLC_FULFILL)
| input_is(a, CMD_SEND_HTLC_TIMEDOUT) | input_is(a, CMD_SEND_HTLC_TIMEDOUT)
| input_is(a, CMD_SEND_HTLC_ROUTEFAIL); | input_is(a, CMD_SEND_HTLC_FAIL);
} }
/* For test_state_coverate to make the states. */ /* For test_state_coverate to make the states. */
@ -80,7 +80,7 @@ void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
* - peer_htlc_added: a new HTLC was added successfully. * - peer_htlc_added: a new HTLC was added successfully.
* - peer_htlc_fulfilled: an existing HTLC was fulfilled successfully. * - peer_htlc_fulfilled: an existing HTLC was fulfilled successfully.
* - peer_htlc_timedout: an existing HTLC was timed out successfully. * - peer_htlc_timedout: an existing HTLC was timed out successfully.
* - peer_htlc_routefail: an existing HTLC failed to route. * - peer_htlc_fail: an existing HTLC failed to route.
* - peer_htlc_aborted: eg. comms error * - peer_htlc_aborted: eg. comms error
*/ */
@ -88,7 +88,7 @@ void peer_unexpected_pkt(struct peer *peer, const Pkt *pkt);
void peer_htlc_declined(struct peer *peer, const Pkt *pkt); void peer_htlc_declined(struct peer *peer, const Pkt *pkt);
/* Called when their update overrides our update cmd. */ /* Called when their update overrides our update cmd. */
void peer_htlc_ours_deferred(struct peer *peer); void peer_htlc_ours_deferred(struct peer *peer);
/* Successfully added/fulfilled/timedout/routefail an HTLC. */ /* Successfully added/fulfilled/timedout/fail an HTLC. */
void peer_htlc_done(struct peer *peer); void peer_htlc_done(struct peer *peer);
/* Someone aborted an existing HTLC. */ /* Someone aborted an existing HTLC. */
void peer_htlc_aborted(struct peer *peer); void peer_htlc_aborted(struct peer *peer);
@ -109,7 +109,7 @@ Pkt *pkt_htlc_fulfill(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog); const struct htlc_progress *htlc_prog);
Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog); const struct htlc_progress *htlc_prog);
Pkt *pkt_htlc_routefail(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_fail(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog); const struct htlc_progress *htlc_prog);
Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer); Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer);
Pkt *pkt_update_signature(const tal_t *ctx, const struct peer *peer); Pkt *pkt_update_signature(const tal_t *ctx, const struct peer *peer);
@ -139,8 +139,8 @@ Pkt *accept_pkt_htlc_update(const tal_t *ctx,
struct peer *peer, const Pkt *pkt, struct peer *peer, const Pkt *pkt,
Pkt **decline); Pkt **decline);
Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, Pkt *accept_pkt_htlc_fail(const tal_t *ctx,
struct peer *peer, const Pkt *pkt); struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_htlc_timedout(const tal_t *ctx, Pkt *accept_pkt_htlc_timedout(const tal_t *ctx,
struct peer *peer, const Pkt *pkt); struct peer *peer, const Pkt *pkt);

4
state_types.h

@ -193,7 +193,7 @@ enum state_input {
/* Updating the commit transaction: my HTLC timed out! */ /* Updating the commit transaction: my HTLC timed out! */
PKT_UPDATE_TIMEDOUT_HTLC = PKT__PKT_UPDATE_TIMEDOUT_HTLC, PKT_UPDATE_TIMEDOUT_HTLC = PKT__PKT_UPDATE_TIMEDOUT_HTLC,
/* Updating the commit transaction: your HTLC failed upstream */ /* Updating the commit transaction: your HTLC failed upstream */
PKT_UPDATE_ROUTEFAIL_HTLC = PKT__PKT_UPDATE_ROUTEFAIL_HTLC, PKT_UPDATE_FAIL_HTLC = PKT__PKT_UPDATE_FAIL_HTLC,
/* Update replies: */ /* Update replies: */
PKT_UPDATE_ACCEPT = PKT__PKT_UPDATE_ACCEPT, PKT_UPDATE_ACCEPT = PKT__PKT_UPDATE_ACCEPT,
@ -277,7 +277,7 @@ enum state_input {
CMD_SEND_HTLC_UPDATE, CMD_SEND_HTLC_UPDATE,
CMD_SEND_HTLC_FULFILL, CMD_SEND_HTLC_FULFILL,
CMD_SEND_HTLC_TIMEDOUT, CMD_SEND_HTLC_TIMEDOUT,
CMD_SEND_HTLC_ROUTEFAIL, CMD_SEND_HTLC_FAIL,
CMD_CLOSE, CMD_CLOSE,
INPUT_MAX INPUT_MAX

20
test/test_state_coverage.c

@ -37,7 +37,7 @@ enum failure {
FAIL_ACCEPT_OPEN_COMMIT_SIG, FAIL_ACCEPT_OPEN_COMMIT_SIG,
FAIL_ACCEPT_OPEN_COMPLETE, FAIL_ACCEPT_OPEN_COMPLETE,
FAIL_ACCEPT_HTLC_UPDATE, FAIL_ACCEPT_HTLC_UPDATE,
FAIL_ACCEPT_HTLC_ROUTEFAIL, FAIL_ACCEPT_HTLC_FAIL,
FAIL_ACCEPT_HTLC_TIMEDOUT, FAIL_ACCEPT_HTLC_TIMEDOUT,
FAIL_ACCEPT_HTLC_FULFILL, FAIL_ACCEPT_HTLC_FULFILL,
FAIL_ACCEPT_UPDATE_ACCEPT, FAIL_ACCEPT_UPDATE_ACCEPT,
@ -418,7 +418,7 @@ static const union input dup_idata(const tal_t *ctx,
i.pkt = (Pkt *)tal_strdup(ctx, (const char *)idata->pkt); i.pkt = (Pkt *)tal_strdup(ctx, (const char *)idata->pkt);
else if (input == CMD_SEND_HTLC_UPDATE else if (input == CMD_SEND_HTLC_UPDATE
|| input == CMD_SEND_HTLC_FULFILL || input == CMD_SEND_HTLC_FULFILL
|| input == CMD_SEND_HTLC_ROUTEFAIL || input == CMD_SEND_HTLC_FAIL
|| input == CMD_SEND_HTLC_TIMEDOUT) { || input == CMD_SEND_HTLC_TIMEDOUT) {
i.htlc_prog = tal_dup(ctx, struct htlc_progress, i.htlc_prog = tal_dup(ctx, struct htlc_progress,
idata->htlc_prog); idata->htlc_prog);
@ -636,10 +636,10 @@ Pkt *pkt_htlc_timedout(const tal_t *ctx, const struct peer *peer,
return htlc_pkt(ctx, "PKT_UPDATE_TIMEDOUT_HTLC", htlc_prog->htlc.id); return htlc_pkt(ctx, "PKT_UPDATE_TIMEDOUT_HTLC", htlc_prog->htlc.id);
} }
Pkt *pkt_htlc_routefail(const tal_t *ctx, const struct peer *peer, Pkt *pkt_htlc_fail(const tal_t *ctx, const struct peer *peer,
const struct htlc_progress *htlc_prog) const struct htlc_progress *htlc_prog)
{ {
return htlc_pkt(ctx, "PKT_UPDATE_ROUTEFAIL_HTLC", htlc_prog->htlc.id); return htlc_pkt(ctx, "PKT_UPDATE_FAIL_HTLC", htlc_prog->htlc.id);
} }
Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer) Pkt *pkt_update_accept(const tal_t *ctx, const struct peer *peer)
@ -744,13 +744,13 @@ Pkt *accept_pkt_htlc_update(const tal_t *ctx,
return NULL; return NULL;
} }
Pkt *accept_pkt_htlc_routefail(const tal_t *ctx, Pkt *accept_pkt_htlc_fail(const tal_t *ctx,
struct peer *peer, const Pkt *pkt) struct peer *peer, const Pkt *pkt)
{ {
unsigned int id = htlc_id_from_pkt(pkt); unsigned int id = htlc_id_from_pkt(pkt);
const struct htlc *h = find_htlc(peer, id); const struct htlc *h = find_htlc(peer, id);
if (fail(peer, FAIL_ACCEPT_HTLC_ROUTEFAIL)) if (fail(peer, FAIL_ACCEPT_HTLC_FAIL))
return pkt_err(ctx, "Error inject"); return pkt_err(ctx, "Error inject");
/* The shouldn't fail unless it's to them */ /* The shouldn't fail unless it's to them */
@ -1489,7 +1489,7 @@ void peer_htlc_ours_deferred(struct peer *peer)
clear_current_htlc(peer); clear_current_htlc(peer);
} }
/* Successfully added/fulfilled/timedout/routefail an HTLC. */ /* Successfully added/fulfilled/timedout/fail an HTLC. */
void peer_htlc_done(struct peer *peer) void peer_htlc_done(struct peer *peer)
{ {
if (peer->current_htlc.htlc.id == -1) if (peer->current_htlc.htlc.id == -1)
@ -1724,7 +1724,7 @@ static bool normal_path(enum state_input i, enum state src, enum state dst)
|| i == BITCOIN_ANCHOR_OTHERSPEND || i == BITCOIN_ANCHOR_OTHERSPEND
|| i == BITCOIN_STEAL_DONE || i == BITCOIN_STEAL_DONE
|| i == PKT_UPDATE_DECLINE_HTLC || i == PKT_UPDATE_DECLINE_HTLC
|| i == PKT_UPDATE_ROUTEFAIL_HTLC || i == PKT_UPDATE_FAIL_HTLC
|| i == PKT_UPDATE_TIMEDOUT_HTLC || i == PKT_UPDATE_TIMEDOUT_HTLC
|| i == INPUT_CLOSE_COMPLETE_TIMEOUT) || i == INPUT_CLOSE_COMPLETE_TIMEOUT)
return false; return false;
@ -2128,7 +2128,7 @@ static void run_peer(const struct peer *peer,
copy.current_htlc.htlc.id = -1; copy.current_htlc.htlc.id = -1;
} }
/* We can complete or routefail an HTLC they offered */ /* We can complete or fail an HTLC they offered */
for (i = 0; i < peer->num_htlcs_to_us; i++) { for (i = 0; i < peer->num_htlcs_to_us; i++) {
idata->htlc_prog = tal(idata, struct htlc_progress); idata->htlc_prog = tal(idata, struct htlc_progress);
idata->htlc_prog->htlc = peer->htlcs_to_us[i]; idata->htlc_prog->htlc = peer->htlcs_to_us[i];
@ -2147,7 +2147,7 @@ static void run_peer(const struct peer *peer,
idata, normalpath, errorpath, idata, normalpath, errorpath,
prev_trail, hist); prev_trail, hist);
} }
copy.core.current_command = CMD_SEND_HTLC_ROUTEFAIL; copy.core.current_command = CMD_SEND_HTLC_FAIL;
try_input(&copy, copy.core.current_command, try_input(&copy, copy.core.current_command,
idata, normalpath, errorpath, idata, normalpath, errorpath,
prev_trail, hist); prev_trail, hist);

Loading…
Cancel
Save