From 2c7256ac69828e1d46722aeea687a995e4ce1450 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 23 Aug 2016 13:29:40 +0930 Subject: [PATCH] protocol: add feechange packet. Signed-off-by: Rusty Russell --- lightning.pb-c.c | 134 ++++++++++++++++++++++++++++++++++++++++------- lightning.pb-c.h | 43 ++++++++++++++- lightning.proto | 10 +++- 3 files changed, 163 insertions(+), 24 deletions(-) diff --git a/lightning.pb-c.c b/lightning.pb-c.c index a30658e87..f297409c1 100644 --- a/lightning.pb-c.c +++ b/lightning.pb-c.c @@ -824,6 +824,49 @@ void update_fail_htlc__free_unpacked assert(message->base.descriptor == &update_fail_htlc__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } +void update_fee__init + (UpdateFee *message) +{ + static UpdateFee init_value = UPDATE_FEE__INIT; + *message = init_value; +} +size_t update_fee__get_packed_size + (const UpdateFee *message) +{ + assert(message->base.descriptor == &update_fee__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t update_fee__pack + (const UpdateFee *message, + uint8_t *out) +{ + assert(message->base.descriptor == &update_fee__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t update_fee__pack_to_buffer + (const UpdateFee *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &update_fee__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +UpdateFee * + update_fee__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (UpdateFee *) + protobuf_c_message_unpack (&update_fee__descriptor, + allocator, len, data); +} +void update_fee__free_unpacked + (UpdateFee *message, + ProtobufCAllocator *allocator) +{ + assert(message->base.descriptor == &update_fee__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} void update_commit__init (UpdateCommit *message) { @@ -2265,6 +2308,44 @@ const ProtobufCMessageDescriptor update_fail_htlc__descriptor = (ProtobufCMessageInit) update_fail_htlc__init, NULL,NULL,NULL /* reserved[123] */ }; +static const ProtobufCFieldDescriptor update_fee__field_descriptors[1] = +{ + { + "fee_rate", + 1, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(UpdateFee, fee_rate), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned update_fee__field_indices_by_name[] = { + 0, /* field[0] = fee_rate */ +}; +static const ProtobufCIntRange update_fee__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 1 } +}; +const ProtobufCMessageDescriptor update_fee__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "update_fee", + "UpdateFee", + "UpdateFee", + "", + sizeof(UpdateFee), + 1, + update_fee__field_descriptors, + update_fee__field_indices_by_name, + 1, update_fee__number_ranges, + (ProtobufCMessageInit) update_fee__init, + NULL,NULL,NULL /* reserved[123] */ +}; static const ProtobufCFieldDescriptor update_commit__field_descriptors[1] = { { @@ -2481,7 +2562,7 @@ const ProtobufCMessageDescriptor error__descriptor = (ProtobufCMessageInit) error__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor pkt__field_descriptors[14] = +static const ProtobufCFieldDescriptor pkt__field_descriptors[15] = { { "update_add_htlc", @@ -2520,11 +2601,23 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[14] = 0,NULL,NULL /* reserved1,reserved2, etc */ }, { - "update_commit", + "update_fee", 5, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE, offsetof(Pkt, pkt_case), + offsetof(Pkt, update_fee), + &update_fee__descriptor, + NULL, + 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "update_commit", + 6, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Pkt, pkt_case), offsetof(Pkt, update_commit), &update_commit__descriptor, NULL, @@ -2533,7 +2626,7 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[14] = }, { "update_revocation", - 6, + 7, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE, offsetof(Pkt, pkt_case), @@ -2653,29 +2746,30 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[14] = }, }; static const unsigned pkt__field_indices_by_name[] = { - 12, /* field[12] = auth */ - 9, /* field[9] = close_shutdown */ - 10, /* field[10] = close_signature */ - 11, /* field[11] = error */ - 5, /* field[5] = open */ - 6, /* field[6] = open_anchor */ - 7, /* field[7] = open_commit_sig */ - 8, /* field[8] = open_complete */ - 13, /* field[13] = reconnect */ + 13, /* field[13] = auth */ + 10, /* field[10] = close_shutdown */ + 11, /* field[11] = close_signature */ + 12, /* field[12] = error */ + 6, /* field[6] = open */ + 7, /* field[7] = open_anchor */ + 8, /* field[8] = open_commit_sig */ + 9, /* field[9] = open_complete */ + 14, /* field[14] = reconnect */ 0, /* field[0] = update_add_htlc */ - 3, /* field[3] = update_commit */ + 4, /* field[4] = update_commit */ 2, /* field[2] = update_fail_htlc */ + 3, /* field[3] = update_fee */ 1, /* field[1] = update_fulfill_htlc */ - 4, /* field[4] = update_revocation */ + 5, /* field[5] = update_revocation */ }; static const ProtobufCIntRange pkt__number_ranges[5 + 1] = { { 2, 0 }, - { 20, 5 }, - { 30, 9 }, - { 40, 11 }, - { 50, 12 }, - { 0, 14 } + { 20, 6 }, + { 30, 10 }, + { 40, 12 }, + { 50, 13 }, + { 0, 15 } }; const ProtobufCMessageDescriptor pkt__descriptor = { @@ -2685,7 +2779,7 @@ const ProtobufCMessageDescriptor pkt__descriptor = "Pkt", "", sizeof(Pkt), - 14, + 15, pkt__field_descriptors, pkt__field_indices_by_name, 5, pkt__number_ranges, diff --git a/lightning.pb-c.h b/lightning.pb-c.h index 06732c67a..893830a9c 100644 --- a/lightning.pb-c.h +++ b/lightning.pb-c.h @@ -34,6 +34,7 @@ typedef struct _UpdateAddHtlc UpdateAddHtlc; typedef struct _UpdateFulfillHtlc UpdateFulfillHtlc; typedef struct _FailReason FailReason; typedef struct _UpdateFailHtlc UpdateFailHtlc; +typedef struct _UpdateFee UpdateFee; typedef struct _UpdateCommit UpdateCommit; typedef struct _UpdateRevocation UpdateRevocation; typedef struct _CloseShutdown CloseShutdown; @@ -432,6 +433,19 @@ struct _UpdateFailHtlc , 0, NULL } +/* + * Fee rate change proposal + */ +struct _UpdateFee +{ + ProtobufCMessage base; + uint32_t fee_rate; +}; +#define UPDATE_FEE__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&update_fee__descriptor) \ + , 0 } + + /* * Commit all the staged changes. */ @@ -525,8 +539,9 @@ typedef enum { PKT__PKT_UPDATE_ADD_HTLC = 2, PKT__PKT_UPDATE_FULFILL_HTLC = 3, PKT__PKT_UPDATE_FAIL_HTLC = 4, - PKT__PKT_UPDATE_COMMIT = 5, - PKT__PKT_UPDATE_REVOCATION = 6, + PKT__PKT_UPDATE_FEE = 5, + PKT__PKT_UPDATE_COMMIT = 6, + PKT__PKT_UPDATE_REVOCATION = 7, PKT__PKT_CLOSE_SHUTDOWN = 30, PKT__PKT_CLOSE_SIGNATURE = 31, PKT__PKT_ERROR = 40, @@ -558,6 +573,7 @@ struct _Pkt UpdateAddHtlc *update_add_htlc; UpdateFulfillHtlc *update_fulfill_htlc; UpdateFailHtlc *update_fail_htlc; + UpdateFee *update_fee; UpdateCommit *update_commit; UpdateRevocation *update_revocation; /* @@ -937,6 +953,25 @@ UpdateFailHtlc * void update_fail_htlc__free_unpacked (UpdateFailHtlc *message, ProtobufCAllocator *allocator); +/* UpdateFee methods */ +void update_fee__init + (UpdateFee *message); +size_t update_fee__get_packed_size + (const UpdateFee *message); +size_t update_fee__pack + (const UpdateFee *message, + uint8_t *out); +size_t update_fee__pack_to_buffer + (const UpdateFee *message, + ProtobufCBuffer *buffer); +UpdateFee * + update_fee__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void update_fee__free_unpacked + (UpdateFee *message, + ProtobufCAllocator *allocator); /* UpdateCommit methods */ void update_commit__init (UpdateCommit *message); @@ -1110,6 +1145,9 @@ typedef void (*FailReason_Closure) typedef void (*UpdateFailHtlc_Closure) (const UpdateFailHtlc *message, void *closure_data); +typedef void (*UpdateFee_Closure) + (const UpdateFee *message, + void *closure_data); typedef void (*UpdateCommit_Closure) (const UpdateCommit *message, void *closure_data); @@ -1154,6 +1192,7 @@ extern const ProtobufCMessageDescriptor update_add_htlc__descriptor; extern const ProtobufCMessageDescriptor update_fulfill_htlc__descriptor; extern const ProtobufCMessageDescriptor fail_reason__descriptor; extern const ProtobufCMessageDescriptor update_fail_htlc__descriptor; +extern const ProtobufCMessageDescriptor update_fee__descriptor; extern const ProtobufCMessageDescriptor update_commit__descriptor; extern const ProtobufCMessageDescriptor update_revocation__descriptor; extern const ProtobufCMessageDescriptor close_shutdown__descriptor; diff --git a/lightning.proto b/lightning.proto index 4e8d2909c..69c768800 100644 --- a/lightning.proto +++ b/lightning.proto @@ -178,6 +178,11 @@ message update_fail_htlc { required fail_reason reason = 2; } +// Fee rate change proposal +message update_fee { + required uint32 fee_rate = 1; +} + // Commit all the staged changes. message update_commit { // Signature for your new commitment tx (if any outputs are HTLCs or to you) @@ -226,8 +231,9 @@ message pkt { update_add_htlc update_add_htlc = 2; update_fulfill_htlc update_fulfill_htlc = 3; update_fail_htlc update_fail_htlc = 4; - update_commit update_commit = 5; - update_revocation update_revocation = 6; + update_fee update_fee = 5; + update_commit update_commit = 6; + update_revocation update_revocation = 7; // Closing close_shutdown close_shutdown = 30;