diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index 8c28a18f5..1a4877e99 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -206,7 +206,7 @@ static void rebroadcast_txs(struct topology *topo, struct command *cmd) struct txs_to_broadcast *txs; struct outgoing_tx *otx; - if (cmd->dstate->dev_no_broadcast) + if (topo->dev_no_broadcast) return; txs = tal(topo, struct txs_to_broadcast); @@ -267,7 +267,7 @@ void broadcast_tx(struct topology *topo, log_add_struct(topo->bitcoind->log, " (tx %s)", struct sha256_double, &otx->txid); - if (peer->dstate->dev_no_broadcast) + if (topo->dev_no_broadcast) broadcast_done(topo->bitcoind, 0, "dev_no_broadcast", otx); else bitcoind_sendrawtx(peer, topo->bitcoind, otx->hextx, @@ -488,8 +488,9 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo, return tal_free(loc); } -static void json_dev_broadcast(struct command *cmd, - const char *buffer, const jsmntok_t *params) +void json_dev_broadcast(struct command *cmd, + struct topology *topo, + const char *buffer, const jsmntok_t *params) { jsmntok_t *enabletok; bool enable; @@ -508,7 +509,7 @@ static void json_dev_broadcast(struct command *cmd, log_debug(cmd->dstate->base_log, "dev-broadcast: broadcast %s", enable ? "enabled" : "disabled"); - cmd->dstate->dev_no_broadcast = !enable; + cmd->dstate->topology->dev_no_broadcast = !enable; /* If enabling, flush and wait. */ if (enable) @@ -517,14 +518,6 @@ static void json_dev_broadcast(struct command *cmd, command_success(cmd, null_response(cmd)); } -static const struct json_command dev_broadcast_command = { - "dev-broadcast", - json_dev_broadcast, - "Pretend we broadcast txs, but don't send to bitcoind", - "Returns an empty result on success (waits for flush if enabled)" -}; -AUTODATA(json_command, &dev_broadcast_command); - /* On shutdown, peers get deleted last. That frees from our list, so * do it now instead. */ static void destroy_outgoing_txs(struct topology *topo) @@ -543,6 +536,7 @@ struct topology *new_topology(const tal_t *ctx) list_head_init(&topo->outgoing_txs); txwatch_hash_init(&topo->txwatches); txowatch_hash_init(&topo->txowatches); + topo->dev_no_broadcast = false; return topo; } diff --git a/daemon/chaintopology.h b/daemon/chaintopology.h index b0d80e962..45d942e12 100644 --- a/daemon/chaintopology.h +++ b/daemon/chaintopology.h @@ -7,11 +7,13 @@ #include #include #include +#include #include #include struct bitcoin_tx; struct bitcoind; +struct command; struct lightningd_state; struct peer; struct sha256_double; @@ -99,6 +101,9 @@ struct topology { /* Transactions/txos we are watching. */ struct txwatch_hash txwatches; struct txowatch_hash txowatches; + + /* Suppress broadcast (for testing) */ + bool dev_no_broadcast; }; /* 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 void notify_new_block(struct topology *topo, unsigned int height); +void json_dev_broadcast(struct command *cmd, + struct topology *topo, + const char *buffer, const jsmntok_t *params); + #endif /* LIGHTNING_DAEMON_CRYPTOPKT_H */ diff --git a/daemon/lightningd.c b/daemon/lightningd.c index c92f134d5..1fcf8f67e 100644 --- a/daemon/lightningd.c +++ b/daemon/lightningd.c @@ -44,7 +44,6 @@ static struct lightningd_state *lightningd_state(void) list_head_init(&dstate->wallet); list_head_init(&dstate->addresses); dstate->dev_never_routefail = false; - dstate->dev_no_broadcast = false; dstate->rstate = new_routing_state(dstate, dstate->base_log); dstate->reexec = NULL; dstate->external_ip = NULL; @@ -53,6 +52,21 @@ static struct lightningd_state *lightningd_state(void) return dstate; } +static void json_lightningd_dev_broadcast(struct command *cmd, + const char *buffer, + const jsmntok_t *params) +{ + json_dev_broadcast(cmd, cmd->dstate->topology, buffer, params); +} + +static const struct json_command dev_broadcast_command = { + "dev-broadcast", + json_lightningd_dev_broadcast, + "Pretend we broadcast txs, but don't send to bitcoind", + "Returns an empty result on success (waits for flush if enabled)" +}; +AUTODATA(json_command, &dev_broadcast_command); + int main(int argc, char *argv[]) { struct lightningd_state *dstate = lightningd_state(); diff --git a/daemon/lightningd.h b/daemon/lightningd.h index 881478315..66394c83a 100644 --- a/daemon/lightningd.h +++ b/daemon/lightningd.h @@ -125,9 +125,6 @@ struct lightningd_state { /* For testing: don't fail if we can't route. */ bool dev_never_routefail; - /* For testing: don't broadcast txs (but pretend it worked)(. */ - bool dev_no_broadcast; - /* Re-exec hack for testing. */ char **reexec; diff --git a/daemon/options.c b/daemon/options.c index 3446db069..be59bb6c0 100644 --- a/daemon/options.c +++ b/daemon/options.c @@ -1,4 +1,5 @@ #include "daemon/bitcoind.h" +#include "daemon/chaintopology.h" #include "daemon/configdir.h" #include "daemon/lightningd.h" #include "daemon/log.h" @@ -211,7 +212,7 @@ static void dev_register_opts(struct lightningd_state *dstate) opt_register_noarg("--dev-no-routefail", opt_set_bool, &dstate->dev_never_routefail, opt_hidden); opt_register_noarg("--dev-no-broadcast", opt_set_bool, - &dstate->dev_no_broadcast, opt_hidden); + &dstate->topology->dev_no_broadcast, opt_hidden); } static const struct config testnet_config = { diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 7ab15dd82..e8e3190ee 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -91,7 +91,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx) list_head_init(&ld->dstate.wallet); list_head_init(&ld->dstate.addresses); ld->dstate.dev_never_routefail = false; - ld->dstate.dev_no_broadcast = false; ld->dstate.reexec = NULL; ld->dstate.external_ip = NULL; ld->dstate.announce = NULL;