2020-05-16 03:29:05 +02:00
|
|
|
#include <bitcoin/block.h>
|
2017-04-01 12:25:59 +02:00
|
|
|
#include <wire/peer_wire.h>
|
|
|
|
|
2020-08-31 03:13:25 +02:00
|
|
|
static bool unknown_type(enum peer_wire t)
|
2017-04-01 12:25:59 +02:00
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case WIRE_INIT:
|
|
|
|
case WIRE_ERROR:
|
|
|
|
case WIRE_OPEN_CHANNEL:
|
|
|
|
case WIRE_ACCEPT_CHANNEL:
|
|
|
|
case WIRE_FUNDING_CREATED:
|
|
|
|
case WIRE_FUNDING_SIGNED:
|
|
|
|
case WIRE_FUNDING_LOCKED:
|
|
|
|
case WIRE_SHUTDOWN:
|
|
|
|
case WIRE_CLOSING_SIGNED:
|
|
|
|
case WIRE_UPDATE_ADD_HTLC:
|
|
|
|
case WIRE_UPDATE_FULFILL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
|
|
|
|
case WIRE_COMMITMENT_SIGNED:
|
|
|
|
case WIRE_REVOKE_AND_ACK:
|
|
|
|
case WIRE_UPDATE_FEE:
|
2017-06-20 07:40:03 +02:00
|
|
|
case WIRE_CHANNEL_REESTABLISH:
|
2017-04-01 12:25:59 +02:00
|
|
|
case WIRE_ANNOUNCEMENT_SIGNATURES:
|
|
|
|
case WIRE_CHANNEL_ANNOUNCEMENT:
|
|
|
|
case WIRE_NODE_ANNOUNCEMENT:
|
|
|
|
case WIRE_CHANNEL_UPDATE:
|
2017-04-12 18:10:10 +02:00
|
|
|
case WIRE_PING:
|
|
|
|
case WIRE_PONG:
|
2018-06-04 06:18:25 +02:00
|
|
|
case WIRE_QUERY_SHORT_CHANNEL_IDS:
|
|
|
|
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
|
|
|
|
case WIRE_QUERY_CHANNEL_RANGE:
|
|
|
|
case WIRE_REPLY_CHANNEL_RANGE:
|
|
|
|
case WIRE_GOSSIP_TIMESTAMP_FILTER:
|
2020-04-01 01:52:03 +02:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
case WIRE_ONION_MESSAGE:
|
2020-09-09 09:20:53 +02:00
|
|
|
case WIRE_TX_ADD_INPUT:
|
|
|
|
case WIRE_TX_REMOVE_INPUT:
|
|
|
|
case WIRE_TX_ADD_OUTPUT:
|
|
|
|
case WIRE_TX_REMOVE_OUTPUT:
|
|
|
|
case WIRE_TX_COMPLETE:
|
|
|
|
case WIRE_TX_SIGNATURES:
|
|
|
|
case WIRE_OPEN_CHANNEL2:
|
|
|
|
case WIRE_ACCEPT_CHANNEL2:
|
|
|
|
case WIRE_INIT_RBF:
|
|
|
|
case WIRE_BLACKLIST_PODLE:
|
2020-04-01 01:52:03 +02:00
|
|
|
#endif
|
2017-04-01 12:25:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-08 04:17:05 +01:00
|
|
|
bool is_msg_for_gossipd(const u8 *cursor)
|
2017-05-05 08:41:45 +02:00
|
|
|
{
|
2020-08-31 03:13:25 +02:00
|
|
|
switch ((enum peer_wire)fromwire_peektype(cursor)) {
|
2017-05-05 08:41:45 +02:00
|
|
|
case WIRE_CHANNEL_ANNOUNCEMENT:
|
|
|
|
case WIRE_NODE_ANNOUNCEMENT:
|
|
|
|
case WIRE_CHANNEL_UPDATE:
|
2018-06-04 06:18:25 +02:00
|
|
|
case WIRE_QUERY_SHORT_CHANNEL_IDS:
|
|
|
|
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
|
|
|
|
case WIRE_QUERY_CHANNEL_RANGE:
|
|
|
|
case WIRE_REPLY_CHANNEL_RANGE:
|
2018-07-24 02:26:43 +02:00
|
|
|
case WIRE_PING:
|
|
|
|
case WIRE_PONG:
|
2021-01-07 19:42:47 +01:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
case WIRE_ONION_MESSAGE:
|
|
|
|
#endif
|
2017-05-05 08:41:45 +02:00
|
|
|
return true;
|
|
|
|
case WIRE_INIT:
|
|
|
|
case WIRE_ERROR:
|
|
|
|
case WIRE_OPEN_CHANNEL:
|
|
|
|
case WIRE_ACCEPT_CHANNEL:
|
|
|
|
case WIRE_FUNDING_CREATED:
|
|
|
|
case WIRE_FUNDING_SIGNED:
|
|
|
|
case WIRE_FUNDING_LOCKED:
|
|
|
|
case WIRE_SHUTDOWN:
|
|
|
|
case WIRE_CLOSING_SIGNED:
|
|
|
|
case WIRE_UPDATE_ADD_HTLC:
|
|
|
|
case WIRE_UPDATE_FULFILL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
|
|
|
|
case WIRE_COMMITMENT_SIGNED:
|
|
|
|
case WIRE_REVOKE_AND_ACK:
|
|
|
|
case WIRE_UPDATE_FEE:
|
2018-03-08 04:17:05 +01:00
|
|
|
case WIRE_CHANNEL_REESTABLISH:
|
|
|
|
case WIRE_ANNOUNCEMENT_SIGNATURES:
|
2019-06-03 20:19:25 +02:00
|
|
|
case WIRE_GOSSIP_TIMESTAMP_FILTER:
|
2020-04-01 01:52:03 +02:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
2020-09-09 09:20:53 +02:00
|
|
|
case WIRE_TX_ADD_INPUT:
|
|
|
|
case WIRE_TX_REMOVE_INPUT:
|
|
|
|
case WIRE_TX_ADD_OUTPUT:
|
|
|
|
case WIRE_TX_REMOVE_OUTPUT:
|
|
|
|
case WIRE_TX_COMPLETE:
|
|
|
|
case WIRE_TX_SIGNATURES:
|
|
|
|
case WIRE_OPEN_CHANNEL2:
|
|
|
|
case WIRE_ACCEPT_CHANNEL2:
|
|
|
|
case WIRE_INIT_RBF:
|
|
|
|
case WIRE_BLACKLIST_PODLE:
|
2020-04-01 01:52:03 +02:00
|
|
|
#endif
|
2017-05-05 08:41:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-01 12:25:59 +02:00
|
|
|
/* Return true if it's an unknown ODD message. cursor is a tal ptr. */
|
2017-06-27 04:50:10 +02:00
|
|
|
bool is_unknown_msg_discardable(const u8 *cursor)
|
2017-04-01 12:25:59 +02:00
|
|
|
{
|
2020-08-31 03:13:25 +02:00
|
|
|
enum peer_wire t = fromwire_peektype(cursor);
|
2017-04-01 12:25:59 +02:00
|
|
|
return unknown_type(t) && (t & 1);
|
|
|
|
}
|
2018-01-10 05:47:22 +01:00
|
|
|
|
|
|
|
/* Extract channel_id from various packets, return true if possible. */
|
|
|
|
bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
|
|
|
|
{
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat ignored_sat;
|
|
|
|
struct amount_msat ignored_msat;
|
2018-01-10 05:47:22 +01:00
|
|
|
u64 ignored_u64;
|
|
|
|
u32 ignored_u32;
|
|
|
|
u16 ignored_u16;
|
|
|
|
u8 ignored_u8;
|
|
|
|
struct pubkey ignored_pubkey;
|
|
|
|
struct bitcoin_blkid ignored_chainhash;
|
2020-06-22 07:06:03 +02:00
|
|
|
struct secret ignored_secret;
|
|
|
|
struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx);
|
2018-01-10 05:47:22 +01:00
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
if (fromwire_channel_reestablish(in_pkt, channel_id,
|
2020-06-22 07:06:03 +02:00
|
|
|
&ignored_u64, &ignored_u64,
|
|
|
|
&ignored_secret, &ignored_pubkey))
|
2018-01-10 05:47:22 +01:00
|
|
|
return true;
|
2018-02-20 21:59:09 +01:00
|
|
|
if (fromwire_open_channel(in_pkt, &ignored_chainhash,
|
2019-02-21 04:45:55 +01:00
|
|
|
channel_id, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_u32,
|
2018-01-10 05:47:22 +01:00
|
|
|
&ignored_u16, &ignored_u16,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
2020-06-22 07:06:03 +02:00
|
|
|
&ignored_u8, tlvs))
|
2018-01-10 05:47:22 +01:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|