Skip to content

Commit 7b711d5

Browse files
committed
Added push_value to hsm_ready_channel. Added sanity checking to hsm_ready_channel stub.
1 parent 6c12e7f commit 7b711d5

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

contrib/remote_hsmd/hsmd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
11571157
{
11581158
bool is_outbound;
11591159
struct amount_sat channel_value;
1160+
struct amount_msat push_value;
11601161
struct bitcoin_txid funding_txid;
11611162
u16 funding_txout;
11621163
u16 local_to_self_delay;
@@ -1168,7 +1169,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
11681169
bool option_static_remotekey;
11691170

11701171
if (!fromwire_hsm_ready_channel(tmpctx, msg_in, &is_outbound,
1171-
&channel_value, &funding_txid,
1172+
&channel_value, &push_value, &funding_txid,
11721173
&funding_txout, &local_to_self_delay,
11731174
&local_shutdown_script,
11741175
&remote_basepoints,
@@ -1182,6 +1183,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
11821183
&c->id, c->dbid,
11831184
is_outbound,
11841185
&channel_value,
1186+
&push_value,
11851187
&funding_txid,
11861188
funding_txout,
11871189
local_to_self_delay,

contrib/remote_hsmd/proxy.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ proxy_stat proxy_handle_ready_channel(
519519
u64 dbid,
520520
bool is_outbound,
521521
struct amount_sat *channel_value,
522+
struct amount_msat *push_value,
522523
struct bitcoin_txid *funding_txid,
523524
u16 funding_txout,
524525
u16 local_to_self_delay,
@@ -532,6 +533,7 @@ proxy_stat proxy_handle_ready_channel(
532533
status_debug(
533534
"%s:%d %s self_id=%s peer_id=%s dbid=%" PRIu64 " "
534535
"is_outbound=%s channel_value=%" PRIu64 " "
536+
"push_value=%" PRIu64 " "
535537
"funding_txid=%s funding_txout=%d "
536538
"local_to_self_delay=%d local_shutdown_script=%s "
537539
"remote_basepoints=%s remote_funding_pubkey=%s "
@@ -543,6 +545,7 @@ proxy_stat proxy_handle_ready_channel(
543545
dbid,
544546
(is_outbound ? "true" : "false"),
545547
channel_value->satoshis,
548+
push_value->millisatoshis,
546549
dump_bitcoin_txid(funding_txid).c_str(),
547550
funding_txout,
548551
local_to_self_delay,
@@ -562,6 +565,7 @@ proxy_stat proxy_handle_ready_channel(
562565
marshal_channel_nonce(peer_id, dbid, req.mutable_channel_nonce());
563566
req.set_is_outbound(is_outbound);
564567
req.set_channel_value_sat(channel_value->satoshis);
568+
req.set_push_value_msat(push_value->millisatoshis);
565569
marshal_outpoint(funding_txid, funding_txout, req.mutable_funding_outpoint());
566570
req.set_local_to_self_delay(local_to_self_delay);
567571
marshal_script(local_shutdown_script, req.mutable_local_shutdown_script());

contrib/remote_hsmd/proxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ proxy_stat proxy_handle_ready_channel(
5353
u64 dbid,
5454
bool is_outbound,
5555
struct amount_sat *channel_value,
56+
struct amount_msat *push_value,
5657
struct bitcoin_txid *funding_txid,
5758
u16 funding_txout,
5859
u16 local_to_self_delay,

hsmd/hsm_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ msgdata,hsm_get_channel_basepoints_reply,funding_pubkey,pubkey,
5656
msgtype,hsm_ready_channel,24
5757
msgdata,hsm_ready_channel,is_outbound,bool,
5858
msgdata,hsm_ready_channel,channel_value,amount_sat,
59+
msgdata,hsm_ready_channel,push_value,amount_msat,
5960
msgdata,hsm_ready_channel,funding_txid,bitcoin_txid,
6061
msgdata,hsm_ready_channel,funding_txout,u16,
6162
msgdata,hsm_ready_channel,local_to_self_delay,u16,

hsmd/hsmd.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,13 +1471,23 @@ static struct io_plan *handle_new_channel(struct io_conn *conn,
14711471
take(towire_hsm_new_channel_reply(NULL)));
14721472
}
14731473

1474+
static bool mem_is_zero(const void *mem, size_t len)
1475+
{
1476+
size_t i;
1477+
for (i = 0; i < len; ++i)
1478+
if (((const unsigned char *)mem)[i])
1479+
return false;
1480+
return true;
1481+
}
1482+
14741483
/*~ This is used to provide all unchanging public channel parameters. */
14751484
static struct io_plan *handle_ready_channel(struct io_conn *conn,
14761485
struct client *c,
14771486
const u8 *msg_in)
14781487
{
14791488
bool is_outbound;
14801489
struct amount_sat channel_value;
1490+
struct amount_msat push_value;
14811491
struct bitcoin_txid funding_txid;
14821492
u16 funding_txout;
14831493
u16 local_to_self_delay;
@@ -1489,7 +1499,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
14891499
bool option_static_remotekey;
14901500

14911501
if (!fromwire_hsm_ready_channel(tmpctx, msg_in, &is_outbound,
1492-
&channel_value, &funding_txid,
1502+
&channel_value, &push_value, &funding_txid,
14931503
&funding_txout, &local_to_self_delay,
14941504
&local_shutdown_script,
14951505
&remote_basepoints,
@@ -1499,6 +1509,15 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
14991509
&option_static_remotekey))
15001510
return bad_req(conn, c, msg_in);
15011511

1512+
/* Fail fast if any values are obviously uninitialized. */
1513+
assert(channel_value.satoshis > 0);
1514+
assert(push_value.millisatoshis / 1000 <= channel_value.satoshis);
1515+
assert(!mem_is_zero(&funding_txid, sizeof(funding_txid)));
1516+
assert(local_to_self_delay > 0);
1517+
assert(!mem_is_zero(&remote_basepoints, sizeof(remote_basepoints)));
1518+
assert(!mem_is_zero(&remote_funding_pubkey, sizeof(remote_funding_pubkey)));
1519+
assert(remote_to_self_delay > 0);
1520+
15021521
return req_reply(conn, c,
15031522
take(towire_hsm_ready_channel_reply(NULL)));
15041523
}

openingd/openingd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ static bool funder_finalize_channel_setup(struct state *state,
674674
msg = towire_hsm_ready_channel(NULL,
675675
true, /* is_outbound */
676676
state->funding,
677+
state->push_msat,
677678
&state->funding_txid,
678679
state->funding_txout,
679680
state->localconf.to_self_delay,
@@ -1196,6 +1197,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
11961197
msg = towire_hsm_ready_channel(NULL,
11971198
false, /* is_outbound */
11981199
state->funding,
1200+
state->push_msat,
11991201
&state->funding_txid,
12001202
state->funding_txout,
12011203
state->localconf.to_self_delay,

0 commit comments

Comments
 (0)