diff --git a/channeld/channeld.c b/channeld/channeld.c index 798056562..6f1811705 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -77,6 +77,9 @@ struct peer { /* Features we support. */ struct feature_set *our_features; + /* What (additional) messages the HSM accepts */ + u32 *hsm_capabilities; + /* Tolerable amounts for feerate (only relevant for fundee). */ u32 feerate_min, feerate_max; @@ -6085,6 +6088,7 @@ static void init_channel(struct peer *peer) if (!fromwire_channeld_init(peer, msg, &chainparams, &peer->our_features, + &peer->hsm_capabilities, &peer->channel_id, &funding, &funding_sats, diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index 53590a2e6..fcc76b5ff 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -15,6 +15,8 @@ msgtype,channeld_init,1000 msgdata,channeld_init,chainparams,chainparams, msgdata,channeld_init,our_features,feature_set, +msgdata,channeld_init,num_hsm_capabilities,u16, +msgdata,channeld_init,hsm_capabilities,u32,num_hsm_capabilities msgdata,channeld_init,channel_id,channel_id, msgdata,channeld_init,funding,bitcoin_outpoint, msgdata,channeld_init,funding_satoshi,amount_sat, diff --git a/common/Makefile b/common/Makefile index 159068750..83820bf16 100644 --- a/common/Makefile +++ b/common/Makefile @@ -43,6 +43,7 @@ COMMON_SRC_NOGEN := \ common/gossmods_listpeerchannels.c \ common/hash_u5.c \ common/hmac.c \ + common/hsm_capable.c \ common/hsm_encryption.c \ common/htlc_state.c \ common/htlc_trim.c \ diff --git a/common/hsm_capable.c b/common/hsm_capable.c new file mode 100644 index 000000000..a8187681c --- /dev/null +++ b/common/hsm_capable.c @@ -0,0 +1,13 @@ +#include "config.h" +#include + +/* Is this capability supported by the HSM? (So far, always a message + * number) */ +bool hsm_is_capable(const u32 *capabilities, u32 msgtype) +{ + for (size_t i = 0; i < tal_count(capabilities); i++) { + if (capabilities[i] == msgtype) + return true; + } + return false; +} diff --git a/common/hsm_capable.h b/common/hsm_capable.h new file mode 100644 index 000000000..82c9f00f1 --- /dev/null +++ b/common/hsm_capable.h @@ -0,0 +1,11 @@ +#ifndef LIGHTNING_COMMON_HSM_CAPABLE_H +#define LIGHTNING_COMMON_HSM_CAPABLE_H +#include "config.h" +#include +#include +#include + +/* Is this capability supported by the HSM? (So far, always a message + * number) */ +bool hsm_is_capable(const u32 *capabilities, u32 msgtype); +#endif /* LIGHTNING_COMMON_HSM_CAPABLE_H */ diff --git a/lightningd/Makefile b/lightningd/Makefile index e8af8beef..670b1a82e 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -104,6 +104,7 @@ LIGHTNINGD_COMMON_OBJS := \ common/status_wiregen.o \ common/hash_u5.o \ common/hmac.o \ + common/hsm_capable.o \ common/hsm_encryption.o \ common/htlc_state.o \ common/htlc_trim.o \ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index ae57e891a..161c8508a 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -1631,6 +1631,9 @@ bool peer_start_channeld(struct channel *channel, initmsg = towire_channeld_init(tmpctx, chainparams, ld->our_features, + /* Capabilities arg needs to be a tal array */ + tal_dup_arr(tmpctx, u32, ld->hsm_capabilities, + tal_count(ld->hsm_capabilities), 0), &channel->cid, &channel->funding, channel->funding_sats, diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c index 8d1b6c536..3765787c6 100644 --- a/lightningd/hsm_control.c +++ b/lightningd/hsm_control.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -78,11 +79,7 @@ static unsigned int hsm_msg(struct subd *hsmd, * number) */ bool hsm_capable(struct lightningd *ld, u32 msgtype) { - for (size_t i = 0; i < tal_count(ld->hsm_capabilities); i++) { - if (ld->hsm_capabilities[i] == msgtype) - return true; - } - return false; + return hsm_is_capable(ld->hsm_capabilities, msgtype); } struct ext_key *hsm_init(struct lightningd *ld) diff --git a/wallet/test/Makefile b/wallet/test/Makefile index 2f5952967..f5ab780e0 100644 --- a/wallet/test/Makefile +++ b/wallet/test/Makefile @@ -14,6 +14,7 @@ WALLET_TEST_COMMON_OBJS := \ common/derive_basepoints.o \ common/features.o \ common/htlc_state.o \ + common/hsm_capable.o \ common/htlc_wire.o \ common/fee_states.o \ common/type_to_string.o \