Browse Source

protocol: add decline response for HTLC.

We don't have to accept an HTLC they offer; we might not be able to
route it, or it might offer insufficient payment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
807ac38308
  1. 229
      lightning.pb-c.c
  2. 95
      lightning.pb-c.h
  3. 19
      lightning.proto

229
lightning.pb-c.c

@ -179,6 +179,49 @@ void bitcoin_pubkey__free_unpacked
assert(message->base.descriptor == &bitcoin_pubkey__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void funding__init
(Funding *message)
{
static Funding init_value = FUNDING__INIT;
*message = init_value;
}
size_t funding__get_packed_size
(const Funding *message)
{
assert(message->base.descriptor == &funding__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t funding__pack
(const Funding *message,
uint8_t *out)
{
assert(message->base.descriptor == &funding__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t funding__pack_to_buffer
(const Funding *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &funding__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
Funding *
funding__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (Funding *)
protobuf_c_message_unpack (&funding__descriptor,
allocator, len, data);
}
void funding__free_unpacked
(Funding *message,
ProtobufCAllocator *allocator)
{
assert(message->base.descriptor == &funding__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void open_channel__init
(OpenChannel *message)
{
@ -437,6 +480,49 @@ void update_add_htlc__free_unpacked
assert(message->base.descriptor == &update_add_htlc__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void update_decline_htlc__init
(UpdateDeclineHtlc *message)
{
static UpdateDeclineHtlc init_value = UPDATE_DECLINE_HTLC__INIT;
*message = init_value;
}
size_t update_decline_htlc__get_packed_size
(const UpdateDeclineHtlc *message)
{
assert(message->base.descriptor == &update_decline_htlc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t update_decline_htlc__pack
(const UpdateDeclineHtlc *message,
uint8_t *out)
{
assert(message->base.descriptor == &update_decline_htlc__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t update_decline_htlc__pack_to_buffer
(const UpdateDeclineHtlc *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &update_decline_htlc__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
UpdateDeclineHtlc *
update_decline_htlc__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (UpdateDeclineHtlc *)
protobuf_c_message_unpack (&update_decline_htlc__descriptor,
allocator, len, data);
}
void update_decline_htlc__free_unpacked
(UpdateDeclineHtlc *message,
ProtobufCAllocator *allocator)
{
assert(message->base.descriptor == &update_decline_htlc__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void update_complete_htlc__init
(UpdateCompleteHtlc *message)
{
@ -1162,6 +1248,59 @@ const ProtobufCMessageDescriptor bitcoin_pubkey__descriptor =
(ProtobufCMessageInit) bitcoin_pubkey__init,
NULL,NULL,NULL /* reserved[123] */
};
static const int64_t funding__fixed__default_value = 0ll;
static const int32_t funding__per_micro_satoshi__default_value = 0;
static const ProtobufCFieldDescriptor funding__field_descriptors[2] =
{
{
"fixed",
1,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_INT64,
offsetof(Funding, has_fixed),
offsetof(Funding, fixed),
NULL,
&funding__fixed__default_value,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"per_micro_satoshi",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_INT32,
offsetof(Funding, has_per_micro_satoshi),
offsetof(Funding, per_micro_satoshi),
NULL,
&funding__per_micro_satoshi__default_value,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned funding__field_indices_by_name[] = {
0, /* field[0] = fixed */
1, /* field[1] = per_micro_satoshi */
};
static const ProtobufCIntRange funding__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 2 }
};
const ProtobufCMessageDescriptor funding__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"funding",
"Funding",
"Funding",
"",
sizeof(Funding),
2,
funding__field_descriptors,
funding__field_indices_by_name,
1, funding__number_ranges,
(ProtobufCMessageInit) funding__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCEnumValue open_channel__anchor_offer__enum_values_by_number[2] =
{
{ "WILL_CREATE_ANCHOR", "OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR", 1 },
@ -1589,6 +1728,57 @@ const ProtobufCMessageDescriptor update_add_htlc__descriptor =
(ProtobufCMessageInit) update_add_htlc__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor update_decline_htlc__field_descriptors[2] =
{
{
"insufficient_funds",
1,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(UpdateDeclineHtlc, reason_case),
offsetof(UpdateDeclineHtlc, insufficient_funds),
&funding__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"cannot_route",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_BOOL,
offsetof(UpdateDeclineHtlc, reason_case),
offsetof(UpdateDeclineHtlc, cannot_route),
NULL,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned update_decline_htlc__field_indices_by_name[] = {
1, /* field[1] = cannot_route */
0, /* field[0] = insufficient_funds */
};
static const ProtobufCIntRange update_decline_htlc__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 2 }
};
const ProtobufCMessageDescriptor update_decline_htlc__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"update_decline_htlc",
"UpdateDeclineHtlc",
"UpdateDeclineHtlc",
"",
sizeof(UpdateDeclineHtlc),
2,
update_decline_htlc__field_descriptors,
update_decline_htlc__field_indices_by_name,
1, update_decline_htlc__number_ranges,
(ProtobufCMessageInit) update_decline_htlc__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor update_complete_htlc__field_descriptors[2] =
{
{
@ -1999,7 +2189,7 @@ const ProtobufCMessageDescriptor error__descriptor =
(ProtobufCMessageInit) error__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor pkt__field_descriptors[15] =
static const ProtobufCFieldDescriptor pkt__field_descriptors[16] =
{
{
"update",
@ -2097,6 +2287,18 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[15] =
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"update_decline_htlc",
9,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(Pkt, pkt_case),
offsetof(Pkt, update_decline_htlc),
&update_decline_htlc__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"open",
201,
@ -2183,18 +2385,19 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[15] =
},
};
static const unsigned pkt__field_indices_by_name[] = {
12, /* field[12] = close */
13, /* field[13] = close_complete */
14, /* field[14] = error */
8, /* field[8] = open */
9, /* field[9] = open_anchor */
10, /* field[10] = open_commit_sig */
11, /* field[11] = open_complete */
13, /* field[13] = close */
14, /* field[14] = close_complete */
15, /* field[15] = error */
9, /* field[9] = open */
10, /* field[10] = open_anchor */
11, /* field[11] = open_commit_sig */
12, /* field[12] = open_complete */
0, /* field[0] = update */
2, /* field[2] = update_accept */
1, /* field[1] = update_add_htlc */
4, /* field[4] = update_complete */
5, /* field[5] = update_complete_htlc */
8, /* field[8] = update_decline_htlc */
6, /* field[6] = update_remove_htlc */
7, /* field[7] = update_remove_htlc_delay */
3, /* field[3] = update_signature */
@ -2202,10 +2405,10 @@ static const unsigned pkt__field_indices_by_name[] = {
static const ProtobufCIntRange pkt__number_ranges[4 + 1] =
{
{ 1, 0 },
{ 201, 8 },
{ 401, 12 },
{ 1000, 14 },
{ 0, 15 }
{ 201, 9 },
{ 401, 13 },
{ 1000, 15 },
{ 0, 16 }
};
const ProtobufCMessageDescriptor pkt__descriptor =
{
@ -2215,7 +2418,7 @@ const ProtobufCMessageDescriptor pkt__descriptor =
"Pkt",
"",
sizeof(Pkt),
15,
16,
pkt__field_descriptors,
pkt__field_indices_by_name,
4, pkt__number_ranges,

95
lightning.pb-c.h

@ -19,12 +19,14 @@ typedef struct _Sha256Hash Sha256Hash;
typedef struct _Signature Signature;
typedef struct _Locktime Locktime;
typedef struct _BitcoinPubkey BitcoinPubkey;
typedef struct _Funding Funding;
typedef struct _OpenChannel OpenChannel;
typedef struct _OpenAnchor OpenAnchor;
typedef struct _OpenCommitSig OpenCommitSig;
typedef struct _OpenComplete OpenComplete;
typedef struct _Update Update;
typedef struct _UpdateAddHtlc UpdateAddHtlc;
typedef struct _UpdateDeclineHtlc UpdateDeclineHtlc;
typedef struct _UpdateCompleteHtlc UpdateCompleteHtlc;
typedef struct _UpdateRemoveHtlc UpdateRemoveHtlc;
typedef struct _UpdateRemoveHtlcDelay UpdateRemoveHtlcDelay;
@ -122,6 +124,28 @@ struct _BitcoinPubkey
, {0,NULL} }
/*
* How much a node charges (or pays!) for sending.
*/
struct _Funding
{
ProtobufCMessage base;
/*
* Base amount (in satoshi).
*/
protobuf_c_boolean has_fixed;
int64_t fixed;
/*
* This is charge per millionth of a satoshi.
*/
protobuf_c_boolean has_per_micro_satoshi;
int32_t per_micro_satoshi;
};
#define FUNDING__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&funding__descriptor) \
, 0,0ll, 0,0 }
/*
* Set channel params.
*/
@ -271,6 +295,29 @@ struct _UpdateAddHtlc
, NULL, 0, NULL, NULL }
typedef enum {
UPDATE_DECLINE_HTLC__REASON__NOT_SET = 0,
UPDATE_DECLINE_HTLC__REASON_INSUFFICIENT_FUNDS = 1,
UPDATE_DECLINE_HTLC__REASON_CANNOT_ROUTE = 2,
} UpdateDeclineHtlc__ReasonCase;
/*
* We can't do this HTLC, sorry.
*/
struct _UpdateDeclineHtlc
{
ProtobufCMessage base;
UpdateDeclineHtlc__ReasonCase reason_case;
union {
Funding *insufficient_funds;
protobuf_c_boolean cannot_route;
};
};
#define UPDATE_DECLINE_HTLC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&update_decline_htlc__descriptor) \
, UPDATE_DECLINE_HTLC__REASON__NOT_SET, {} }
/*
* Complete an HTLC
*/
@ -449,6 +496,7 @@ typedef enum {
PKT__PKT_UPDATE_COMPLETE_HTLC = 6,
PKT__PKT_UPDATE_REMOVE_HTLC = 7,
PKT__PKT_UPDATE_REMOVE_HTLC_DELAY = 8,
PKT__PKT_UPDATE_DECLINE_HTLC = 9,
PKT__PKT_CLOSE = 401,
PKT__PKT_CLOSE_COMPLETE = 402,
PKT__PKT_ERROR = 1000,
@ -480,6 +528,7 @@ struct _Pkt
UpdateCompleteHtlc *update_complete_htlc;
UpdateRemoveHtlc *update_remove_htlc;
UpdateRemoveHtlcDelay *update_remove_htlc_delay;
UpdateDeclineHtlc *update_decline_htlc;
/*
* Closing
*/
@ -572,6 +621,25 @@ BitcoinPubkey *
void bitcoin_pubkey__free_unpacked
(BitcoinPubkey *message,
ProtobufCAllocator *allocator);
/* Funding methods */
void funding__init
(Funding *message);
size_t funding__get_packed_size
(const Funding *message);
size_t funding__pack
(const Funding *message,
uint8_t *out);
size_t funding__pack_to_buffer
(const Funding *message,
ProtobufCBuffer *buffer);
Funding *
funding__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void funding__free_unpacked
(Funding *message,
ProtobufCAllocator *allocator);
/* OpenChannel methods */
void open_channel__init
(OpenChannel *message);
@ -686,6 +754,25 @@ UpdateAddHtlc *
void update_add_htlc__free_unpacked
(UpdateAddHtlc *message,
ProtobufCAllocator *allocator);
/* UpdateDeclineHtlc methods */
void update_decline_htlc__init
(UpdateDeclineHtlc *message);
size_t update_decline_htlc__get_packed_size
(const UpdateDeclineHtlc *message);
size_t update_decline_htlc__pack
(const UpdateDeclineHtlc *message,
uint8_t *out);
size_t update_decline_htlc__pack_to_buffer
(const UpdateDeclineHtlc *message,
ProtobufCBuffer *buffer);
UpdateDeclineHtlc *
update_decline_htlc__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void update_decline_htlc__free_unpacked
(UpdateDeclineHtlc *message,
ProtobufCAllocator *allocator);
/* UpdateCompleteHtlc methods */
void update_complete_htlc__init
(UpdateCompleteHtlc *message);
@ -890,6 +977,9 @@ typedef void (*Locktime_Closure)
typedef void (*BitcoinPubkey_Closure)
(const BitcoinPubkey *message,
void *closure_data);
typedef void (*Funding_Closure)
(const Funding *message,
void *closure_data);
typedef void (*OpenChannel_Closure)
(const OpenChannel *message,
void *closure_data);
@ -908,6 +998,9 @@ typedef void (*Update_Closure)
typedef void (*UpdateAddHtlc_Closure)
(const UpdateAddHtlc *message,
void *closure_data);
typedef void (*UpdateDeclineHtlc_Closure)
(const UpdateDeclineHtlc *message,
void *closure_data);
typedef void (*UpdateCompleteHtlc_Closure)
(const UpdateCompleteHtlc *message,
void *closure_data);
@ -948,6 +1041,7 @@ extern const ProtobufCMessageDescriptor sha256_hash__descriptor;
extern const ProtobufCMessageDescriptor signature__descriptor;
extern const ProtobufCMessageDescriptor locktime__descriptor;
extern const ProtobufCMessageDescriptor bitcoin_pubkey__descriptor;
extern const ProtobufCMessageDescriptor funding__descriptor;
extern const ProtobufCMessageDescriptor open_channel__descriptor;
extern const ProtobufCEnumDescriptor open_channel__anchor_offer__descriptor;
extern const ProtobufCMessageDescriptor open_anchor__descriptor;
@ -955,6 +1049,7 @@ extern const ProtobufCMessageDescriptor open_commit_sig__descriptor;
extern const ProtobufCMessageDescriptor open_complete__descriptor;
extern const ProtobufCMessageDescriptor update__descriptor;
extern const ProtobufCMessageDescriptor update_add_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_decline_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_complete_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_remove_htlc__descriptor;
extern const ProtobufCMessageDescriptor update_remove_htlc_delay__descriptor;

19
lightning.proto

@ -31,7 +31,7 @@ message locktime {
uint32 seconds = 1;
uint32 blocks = 2;
}
};
}
// Pubkey for commitment transaction input.
message bitcoin_pubkey {
@ -39,6 +39,14 @@ message bitcoin_pubkey {
required bytes key = 1;
}
// How much a node charges (or pays!) for sending.
message funding {
// Base amount (in satoshi).
optional int64 fixed = 1 [ default = 0 ];
// This is charge per millionth of a satoshi.
optional int32 per_micro_satoshi = 2 [ default = 0 ];
}
//
// Packet Types
//
@ -115,6 +123,14 @@ message update_add_htlc {
// FIXME: Routing information.
}
// We can't do this HTLC, sorry.
message update_decline_htlc {
oneof reason {
funding insufficient_funds = 1;
bool cannot_route = 2;
};
}
// Complete an HTLC
message update_complete_htlc {
// Hash for which I will supply preimage to revoke this commitment tx.
@ -198,6 +214,7 @@ message pkt {
update_complete_htlc update_complete_htlc = 6;
update_remove_htlc update_remove_htlc = 7;
update_remove_htlc_delay update_remove_htlc_delay = 8;
update_decline_htlc update_decline_htlc = 9;
// Closing
close_channel close = 401;
close_channel_complete close_complete = 402;

Loading…
Cancel
Save