Skip to content

Commit fb65e18

Browse files
committed
Added push_value to hsm_ready_channel. Added sanity checking to hsm_ready_channel stub.
1 parent c345f0a commit fb65e18

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
@@ -1506,13 +1506,23 @@ static struct io_plan *handle_new_channel(struct io_conn *conn,
15061506
take(towire_hsm_new_channel_reply(NULL)));
15071507
}
15081508

1509+
static bool mem_is_zero(const void *mem, size_t len)
1510+
{
1511+
size_t i;
1512+
for (i = 0; i < len; ++i)
1513+
if (((const unsigned char *)mem)[i])
1514+
return false;
1515+
return true;
1516+
}
1517+
15091518
/*~ This is used to provide all unchanging public channel parameters. */
15101519
static struct io_plan *handle_ready_channel(struct io_conn *conn,
15111520
struct client *c,
15121521
const u8 *msg_in)
15131522
{
15141523
bool is_outbound;
15151524
struct amount_sat channel_value;
1525+
struct amount_msat push_value;
15161526
struct bitcoin_txid funding_txid;
15171527
u16 funding_txout;
15181528
u16 local_to_self_delay;
@@ -1524,7 +1534,7 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
15241534
bool option_static_remotekey;
15251535

15261536
if (!fromwire_hsm_ready_channel(tmpctx, msg_in, &is_outbound,
1527-
&channel_value, &funding_txid,
1537+
&channel_value, &push_value, &funding_txid,
15281538
&funding_txout, &local_to_self_delay,
15291539
&local_shutdown_script,
15301540
&remote_basepoints,
@@ -1534,6 +1544,15 @@ static struct io_plan *handle_ready_channel(struct io_conn *conn,
15341544
&option_static_remotekey))
15351545
return bad_req(conn, c, msg_in);
15361546

1547+
/* Fail fast if any values are obviously uninitialized. */
1548+
assert(channel_value.satoshis > 0);
1549+
assert(push_value.millisatoshis / 1000 <= channel_value.satoshis);
1550+
assert(!mem_is_zero(&funding_txid, sizeof(funding_txid)));
1551+
assert(local_to_self_delay > 0);
1552+
assert(!mem_is_zero(&remote_basepoints, sizeof(remote_basepoints)));
1553+
assert(!mem_is_zero(&remote_funding_pubkey, sizeof(remote_funding_pubkey)));
1554+
assert(remote_to_self_delay > 0);
1555+
15371556
return req_reply(conn, c,
15381557
take(towire_hsm_ready_channel_reply(NULL)));
15391558
}

openingd/openingd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ static bool funder_finalize_channel_setup(struct state *state,
673673
msg = towire_hsm_ready_channel(NULL,
674674
true, /* is_outbound */
675675
state->funding,
676+
state->push_msat,
676677
&state->funding_txid,
677678
state->funding_txout,
678679
state->localconf.to_self_delay,
@@ -1191,6 +1192,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
11911192
msg = towire_hsm_ready_channel(NULL,
11921193
false, /* is_outbound */
11931194
state->funding,
1195+
state->push_msat,
11941196
&state->funding_txid,
11951197
state->funding_txout,
11961198
state->localconf.to_self_delay,

0 commit comments

Comments
 (0)