Skip to content

Commit 38cc6c2

Browse files
committed
daemon/chaintopology: move dev_no_broadcast from lightningd_state to here.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 61e576e commit 38cc6c2

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

daemon/chaintopology.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void rebroadcast_txs(struct topology *topo, struct command *cmd)
206206
struct txs_to_broadcast *txs;
207207
struct outgoing_tx *otx;
208208

209-
if (cmd->dstate->dev_no_broadcast)
209+
if (topo->dev_no_broadcast)
210210
return;
211211

212212
txs = tal(topo, struct txs_to_broadcast);
@@ -267,7 +267,7 @@ void broadcast_tx(struct topology *topo,
267267
log_add_struct(topo->bitcoind->log,
268268
" (tx %s)", struct sha256_double, &otx->txid);
269269

270-
if (peer->dstate->dev_no_broadcast)
270+
if (topo->dev_no_broadcast)
271271
broadcast_done(topo->bitcoind, 0, "dev_no_broadcast", otx);
272272
else
273273
bitcoind_sendrawtx(peer, topo->bitcoind, otx->hextx,
@@ -488,8 +488,9 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo,
488488
return tal_free(loc);
489489
}
490490

491-
static void json_dev_broadcast(struct command *cmd,
492-
const char *buffer, const jsmntok_t *params)
491+
void json_dev_broadcast(struct command *cmd,
492+
struct topology *topo,
493+
const char *buffer, const jsmntok_t *params)
493494
{
494495
jsmntok_t *enabletok;
495496
bool enable;
@@ -508,7 +509,7 @@ static void json_dev_broadcast(struct command *cmd,
508509

509510
log_debug(cmd->dstate->base_log, "dev-broadcast: broadcast %s",
510511
enable ? "enabled" : "disabled");
511-
cmd->dstate->dev_no_broadcast = !enable;
512+
cmd->dstate->topology->dev_no_broadcast = !enable;
512513

513514
/* If enabling, flush and wait. */
514515
if (enable)
@@ -517,14 +518,6 @@ static void json_dev_broadcast(struct command *cmd,
517518
command_success(cmd, null_response(cmd));
518519
}
519520

520-
static const struct json_command dev_broadcast_command = {
521-
"dev-broadcast",
522-
json_dev_broadcast,
523-
"Pretend we broadcast txs, but don't send to bitcoind",
524-
"Returns an empty result on success (waits for flush if enabled)"
525-
};
526-
AUTODATA(json_command, &dev_broadcast_command);
527-
528521
/* On shutdown, peers get deleted last. That frees from our list, so
529522
* do it now instead. */
530523
static void destroy_outgoing_txs(struct topology *topo)
@@ -543,6 +536,7 @@ struct topology *new_topology(const tal_t *ctx)
543536
list_head_init(&topo->outgoing_txs);
544537
txwatch_hash_init(&topo->txwatches);
545538
txowatch_hash_init(&topo->txowatches);
539+
topo->dev_no_broadcast = false;
546540

547541
return topo;
548542
}

daemon/chaintopology.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
#include <ccan/short_types/short_types.h>
88
#include <ccan/structeq/structeq.h>
99
#include <ccan/time/time.h>
10+
#include <daemon/jsmn/jsmn.h>
1011
#include <daemon/watch.h>
1112
#include <stddef.h>
1213

1314
struct bitcoin_tx;
1415
struct bitcoind;
16+
struct command;
1517
struct lightningd_state;
1618
struct peer;
1719
struct sha256_double;
@@ -99,6 +101,9 @@ struct topology {
99101
/* Transactions/txos we are watching. */
100102
struct txwatch_hash txwatches;
101103
struct txowatch_hash txowatches;
104+
105+
/* Suppress broadcast (for testing) */
106+
bool dev_no_broadcast;
102107
};
103108

104109
/* Information relevant to locating a TX in a blockchain. */
@@ -146,4 +151,8 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo, const
146151

147152
void notify_new_block(struct topology *topo, unsigned int height);
148153

154+
void json_dev_broadcast(struct command *cmd,
155+
struct topology *topo,
156+
const char *buffer, const jsmntok_t *params);
157+
149158
#endif /* LIGHTNING_DAEMON_CRYPTOPKT_H */

daemon/lightningd.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ static struct lightningd_state *lightningd_state(void)
4444
list_head_init(&dstate->wallet);
4545
list_head_init(&dstate->addresses);
4646
dstate->dev_never_routefail = false;
47-
dstate->dev_no_broadcast = false;
4847
dstate->rstate = new_routing_state(dstate, dstate->base_log);
4948
dstate->reexec = NULL;
5049
dstate->external_ip = NULL;
@@ -53,6 +52,21 @@ static struct lightningd_state *lightningd_state(void)
5352
return dstate;
5453
}
5554

55+
static void json_lightningd_dev_broadcast(struct command *cmd,
56+
const char *buffer,
57+
const jsmntok_t *params)
58+
{
59+
json_dev_broadcast(cmd, cmd->dstate->topology, buffer, params);
60+
}
61+
62+
static const struct json_command dev_broadcast_command = {
63+
"dev-broadcast",
64+
json_lightningd_dev_broadcast,
65+
"Pretend we broadcast txs, but don't send to bitcoind",
66+
"Returns an empty result on success (waits for flush if enabled)"
67+
};
68+
AUTODATA(json_command, &dev_broadcast_command);
69+
5670
int main(int argc, char *argv[])
5771
{
5872
struct lightningd_state *dstate = lightningd_state();

daemon/lightningd.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ struct lightningd_state {
125125
/* For testing: don't fail if we can't route. */
126126
bool dev_never_routefail;
127127

128-
/* For testing: don't broadcast txs (but pretend it worked)(. */
129-
bool dev_no_broadcast;
130-
131128
/* Re-exec hack for testing. */
132129
char **reexec;
133130

daemon/options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "daemon/bitcoind.h"
2+
#include "daemon/chaintopology.h"
23
#include "daemon/configdir.h"
34
#include "daemon/lightningd.h"
45
#include "daemon/log.h"
@@ -211,7 +212,7 @@ static void dev_register_opts(struct lightningd_state *dstate)
211212
opt_register_noarg("--dev-no-routefail", opt_set_bool,
212213
&dstate->dev_never_routefail, opt_hidden);
213214
opt_register_noarg("--dev-no-broadcast", opt_set_bool,
214-
&dstate->dev_no_broadcast, opt_hidden);
215+
&dstate->topology->dev_no_broadcast, opt_hidden);
215216
}
216217

217218
static const struct config testnet_config = {

lightningd/lightningd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
9191
list_head_init(&ld->dstate.wallet);
9292
list_head_init(&ld->dstate.addresses);
9393
ld->dstate.dev_never_routefail = false;
94-
ld->dstate.dev_no_broadcast = false;
9594
ld->dstate.reexec = NULL;
9695
ld->dstate.external_ip = NULL;
9796
ld->dstate.announce = NULL;

0 commit comments

Comments
 (0)