Skip to content

Commit

Permalink
channeld: add hsm_capabilities and add hsm_is_capable to common
Browse files Browse the repository at this point in the history
Changelog-Added: Added hsm_capabilities and hsm_is_capable to channeld.
  • Loading branch information
ksedgwic committed Jan 18, 2024
1 parent 1be7ec7 commit 4610473
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ COMMON_SRC_NOGEN := \
common/gossmap.c \
common/hash_u5.c \
common/hmac.c \
common/hsm_capable.c \
common/hsm_encryption.c \
common/htlc_state.c \
common/htlc_trim.c \
Expand Down
13 changes: 13 additions & 0 deletions common/hsm_capable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "config.h"
#include <common/hsm_capable.h>

/* Is this capability supported by the HSM? (So far, always a message
* number) */
bool hsm_is_capable(u32 *capabilities, u32 msgtype)
{
for (size_t i = 0; i < tal_count(capabilities); i++) {
if (capabilities[i] == msgtype)
return true;
}
return false;
}
11 changes: 11 additions & 0 deletions common/hsm_capable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef LIGHTNING_COMMON_HSM_CAPABLE_H
#define LIGHTNING_COMMON_HSM_CAPABLE_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>

/* Is this capability supported by the HSM? (So far, always a message
* number) */
bool hsm_is_capable(u32 *capabilities, u32 msgtype);
#endif /* LIGHTNING_COMMON_HSM_CAPABLE_H */
1 change: 1 addition & 0 deletions lightningd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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 \
Expand Down
3 changes: 3 additions & 0 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,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,
Expand Down
7 changes: 2 additions & 5 deletions lightningd/hsm_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ccan/fdpass/fdpass.h>
#include <common/ecdh.h>
#include <common/errcode.h>
#include <common/hsm_capable.h>
#include <common/hsm_encryption.h>
#include <common/hsm_version.h>
#include <common/invoice_path_id.h>
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions wallet/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 4610473

Please sign in to comment.