Skip to content

Commit a49e1c8

Browse files
committed
Call validate_initial_commitment_signature in dualopend
1 parent f5fdf26 commit a49e1c8

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

openingd/common.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
#include <common/channel_config.h>
44
#include <common/features.h>
55
#include <common/initial_commit_tx.h>
6+
#include <common/status.h>
67
#include <common/type_to_string.h>
8+
#include <hsmd/hsmd_wiregen.h>
79
#include <openingd/common.h>
10+
#include <wire/wire_sync.h>
11+
12+
#define HSM_FD 6
813

914
/*~ This is the key function that checks that their configuration is reasonable:
1015
* it applied for both the case where they're trying to open a channel, and when
@@ -225,3 +230,32 @@ u8 *no_upfront_shutdown_script(const tal_t *ctx,
225230

226231
return NULL;
227232
}
233+
234+
void validate_initial_commitment_signature(struct bitcoin_tx *tx,
235+
struct bitcoin_signature *sig)
236+
{
237+
// Validate the counterparty's signature.
238+
struct existing_htlc **htlcs = tal_arr(NULL, struct existing_htlc *, 0);
239+
struct bitcoin_signature *htlc_sigs = tal_arr(NULL, struct bitcoin_signature, 0);
240+
u32 feerate = 0; // unused since there are no htlcs
241+
u64 commit_num = 0;
242+
const u8 * msg =
243+
towire_hsmd_validate_commitment_tx(NULL,
244+
tx,
245+
(const struct simple_htlc **) htlcs,
246+
commit_num,
247+
feerate,
248+
sig,
249+
htlc_sigs);
250+
tal_free(htlc_sigs);
251+
tal_free(htlcs);
252+
wire_sync_write(HSM_FD, take(msg));
253+
msg = wire_sync_read(tmpctx, HSM_FD);
254+
struct secret *old_secret;
255+
struct pubkey next_point;
256+
if (!fromwire_hsmd_validate_commitment_tx_reply(tmpctx, msg, &old_secret, &next_point))
257+
status_failed(STATUS_FAIL_HSM_IO,
258+
"Reading validate_commitment_tx reply: %s",
259+
tal_hex(tmpctx, msg));
260+
}
261+

openingd/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "config.h"
55

66
struct amount_sat;
7+
struct bitcoin_tx;
8+
struct bitcoin_signature;
79
struct channel_config;
810

911

@@ -21,4 +23,7 @@ bool check_config_bounds(const tal_t *ctx,
2123
u8 *no_upfront_shutdown_script(const tal_t *ctx,
2224
struct feature_set *our_features,
2325
const u8 *their_features);
26+
27+
void validate_initial_commitment_signature(struct bitcoin_tx *tx,
28+
struct bitcoin_signature *sig);
2429
#endif /* LIGHTNING_OPENINGD_COMMON_H */

openingd/dualopend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,8 @@ static u8 *accepter_commits(struct state *state,
18601860
return NULL;
18611861
}
18621862

1863+
validate_initial_commitment_signature(local_commit, &remote_sig);
1864+
18631865
/* BOLT #2:
18641866
*
18651867
* The recipient:
@@ -2585,6 +2587,8 @@ static u8 *opener_commits(struct state *state,
25852587
return NULL;
25862588
}
25872589

2590+
validate_initial_commitment_signature(local_commit, &remote_sig);
2591+
25882592
/* BOLT #2:
25892593
*
25902594
* The recipient:

openingd/openingd.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -509,34 +509,6 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
509509
state->channel_type);
510510
}
511511

512-
static void validate_initial_commitment_signature(struct bitcoin_tx *tx,
513-
struct bitcoin_signature *sig)
514-
{
515-
// Validate the counterparty's signature.
516-
struct existing_htlc **htlcs = tal_arr(NULL, struct existing_htlc *, 0);
517-
struct bitcoin_signature *htlc_sigs = tal_arr(NULL, struct bitcoin_signature, 0);
518-
u32 feerate = 0; // unused since there are no htlcs
519-
u64 commit_num = 0;
520-
const u8 * msg =
521-
towire_hsmd_validate_commitment_tx(NULL,
522-
tx,
523-
(const struct simple_htlc **) htlcs,
524-
commit_num,
525-
feerate,
526-
sig,
527-
htlc_sigs);
528-
tal_free(htlc_sigs);
529-
tal_free(htlcs);
530-
wire_sync_write(HSM_FD, take(msg));
531-
msg = wire_sync_read(tmpctx, HSM_FD);
532-
struct secret *old_secret;
533-
struct pubkey next_point;
534-
if (!fromwire_hsmd_validate_commitment_tx_reply(tmpctx, msg, &old_secret, &next_point))
535-
status_failed(STATUS_FAIL_HSM_IO,
536-
"Reading validate_commitment_tx reply: %s",
537-
tal_hex(tmpctx, msg));
538-
}
539-
540512
static bool funder_finalize_channel_setup(struct state *state,
541513
struct amount_msat local_msat,
542514
struct bitcoin_signature *sig,

0 commit comments

Comments
 (0)