Skip to content

Commit 89931a1

Browse files
committed
channeld: routine to feed in a shachain.
This will be used by channeld_fakenet to create replies from the peer. Signed-off-by: Rusty Russell <[email protected]>
1 parent d7f380d commit 89931a1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

channeld/channeld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5760,6 +5760,7 @@ static void req_in(struct peer *peer, const u8 *msg)
57605760
case WIRE_CHANNELD_SPLICE_STATE_ERROR:
57615761
case WIRE_CHANNELD_LOCAL_ANCHOR_INFO:
57625762
case WIRE_CHANNELD_REESTABLISHED:
5763+
case WIRE_CHANNELD_DEV_PEER_SHACHAIN:
57635764
break;
57645765
}
57655766
master_badmsg(-1, msg);

channeld/channeld_wire.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,7 @@ msgdata,channeld_upgraded,new_type,channel_type,
347347
# Tell peer about our latest and greatest blockheight.
348348
msgtype,channeld_blockheight,1012
349349
msgdata,channeld_blockheight,blockheight,u32,
350+
351+
# Tell channeld about peer's shachain seed.
352+
msgtype,channeld_dev_peer_shachain,1013
353+
msgdata,channeld_dev_peer_shachain,seed,sha256,

lightningd/channel_control.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
15161516
case WIRE_CHANNELD_DEV_MEMLEAK:
15171517
case WIRE_CHANNELD_DEV_QUIESCE:
15181518
case WIRE_CHANNELD_GOT_INFLIGHT:
1519+
case WIRE_CHANNELD_DEV_PEER_SHACHAIN:
15191520
/* Replies go to requests. */
15201521
case WIRE_CHANNELD_OFFER_HTLC_REPLY:
15211522
case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY:
@@ -2306,6 +2307,51 @@ static const struct json_command dev_feerate_command = {
23062307
};
23072308
AUTODATA(json_command, &dev_feerate_command);
23082309

2310+
static struct command_result *json_dev_peer_shachain(struct command *cmd,
2311+
const char *buffer,
2312+
const jsmntok_t *obj UNNEEDED,
2313+
const jsmntok_t *params)
2314+
{
2315+
struct sha256 *shachain_seed;
2316+
struct node_id *id;
2317+
struct peer *peer;
2318+
struct channel *channel;
2319+
const u8 *msg;
2320+
bool more_than_one;
2321+
2322+
if (!param_check(cmd, buffer, params,
2323+
p_req("id", param_node_id, &id),
2324+
p_req("seed", param_sha256, &shachain_seed),
2325+
NULL))
2326+
return command_param_failed();
2327+
2328+
peer = peer_by_id(cmd->ld, id);
2329+
if (!peer)
2330+
return command_fail(cmd, LIGHTNINGD, "Peer not connected");
2331+
2332+
channel = peer_any_channel(peer, channel_state_can_add_htlc, &more_than_one);
2333+
if (!channel || !channel->owner)
2334+
return command_fail(cmd, LIGHTNINGD, "Peer bad state");
2335+
/* This is a dev command: fix the api if you need this! */
2336+
if (more_than_one)
2337+
return command_fail(cmd, LIGHTNINGD, "More than one channel");
2338+
2339+
if (command_check_only(cmd))
2340+
return command_check_done(cmd);
2341+
2342+
msg = towire_channeld_dev_peer_shachain(NULL, shachain_seed);
2343+
subd_send_msg(channel->owner, take(msg));
2344+
2345+
return command_success(cmd, json_stream_success(cmd));
2346+
}
2347+
2348+
static const struct json_command dev_peer_shachain_command = {
2349+
"dev-peer-shachain",
2350+
json_dev_peer_shachain,
2351+
.dev_only = true,
2352+
};
2353+
AUTODATA(json_command, &dev_peer_shachain_command);
2354+
23092355
static void quiesce_reply(struct subd *channeld UNUSED,
23102356
const u8 *reply,
23112357
const int *fds UNUSED,

0 commit comments

Comments
 (0)