channeld: add hsm_capabilities and add hsm_is_capable to common
Changelog-Added: Added hsm_capabilities and hsm_is_capable to channeld.
This commit is contained in:
committed by
Rusty Russell
parent
b0054aad46
commit
d463b8d900
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
@@ -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 \
|
||||
|
||||
13
common/hsm_capable.c
Normal file
13
common/hsm_capable.c
Normal file
@@ -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(const u32 *capabilities, u32 msgtype)
|
||||
{
|
||||
for (size_t i = 0; i < tal_count(capabilities); i++) {
|
||||
if (capabilities[i] == msgtype)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
11
common/hsm_capable.h
Normal file
11
common/hsm_capable.h
Normal file
@@ -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(const u32 *capabilities, u32 msgtype);
|
||||
#endif /* LIGHTNING_COMMON_HSM_CAPABLE_H */
|
||||
@@ -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 \
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
@@ -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)
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user