daemon/chaintopology: move dev_no_broadcast from lightningd_state to here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-03-02 22:51:49 +10:30
parent 61e576ef12
commit 38cc6c2f21
6 changed files with 33 additions and 19 deletions

View file

@ -206,7 +206,7 @@ static void rebroadcast_txs(struct topology *topo, struct command *cmd)
struct txs_to_broadcast *txs; struct txs_to_broadcast *txs;
struct outgoing_tx *otx; struct outgoing_tx *otx;
if (cmd->dstate->dev_no_broadcast) if (topo->dev_no_broadcast)
return; return;
txs = tal(topo, struct txs_to_broadcast); txs = tal(topo, struct txs_to_broadcast);
@ -267,7 +267,7 @@ void broadcast_tx(struct topology *topo,
log_add_struct(topo->bitcoind->log, log_add_struct(topo->bitcoind->log,
" (tx %s)", struct sha256_double, &otx->txid); " (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); broadcast_done(topo->bitcoind, 0, "dev_no_broadcast", otx);
else else
bitcoind_sendrawtx(peer, topo->bitcoind, otx->hextx, bitcoind_sendrawtx(peer, topo->bitcoind, otx->hextx,
@ -488,7 +488,8 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo,
return tal_free(loc); return tal_free(loc);
} }
static void json_dev_broadcast(struct command *cmd, void json_dev_broadcast(struct command *cmd,
struct topology *topo,
const char *buffer, const jsmntok_t *params) const char *buffer, const jsmntok_t *params)
{ {
jsmntok_t *enabletok; jsmntok_t *enabletok;
@ -508,7 +509,7 @@ static void json_dev_broadcast(struct command *cmd,
log_debug(cmd->dstate->base_log, "dev-broadcast: broadcast %s", log_debug(cmd->dstate->base_log, "dev-broadcast: broadcast %s",
enable ? "enabled" : "disabled"); enable ? "enabled" : "disabled");
cmd->dstate->dev_no_broadcast = !enable; cmd->dstate->topology->dev_no_broadcast = !enable;
/* If enabling, flush and wait. */ /* If enabling, flush and wait. */
if (enable) if (enable)
@ -517,14 +518,6 @@ static void json_dev_broadcast(struct command *cmd,
command_success(cmd, null_response(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 /* On shutdown, peers get deleted last. That frees from our list, so
* do it now instead. */ * do it now instead. */
static void destroy_outgoing_txs(struct topology *topo) 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); list_head_init(&topo->outgoing_txs);
txwatch_hash_init(&topo->txwatches); txwatch_hash_init(&topo->txwatches);
txowatch_hash_init(&topo->txowatches); txowatch_hash_init(&topo->txowatches);
topo->dev_no_broadcast = false;
return topo; return topo;
} }

View file

@ -7,11 +7,13 @@
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/structeq/structeq.h> #include <ccan/structeq/structeq.h>
#include <ccan/time/time.h> #include <ccan/time/time.h>
#include <daemon/jsmn/jsmn.h>
#include <daemon/watch.h> #include <daemon/watch.h>
#include <stddef.h> #include <stddef.h>
struct bitcoin_tx; struct bitcoin_tx;
struct bitcoind; struct bitcoind;
struct command;
struct lightningd_state; struct lightningd_state;
struct peer; struct peer;
struct sha256_double; struct sha256_double;
@ -99,6 +101,9 @@ struct topology {
/* Transactions/txos we are watching. */ /* Transactions/txos we are watching. */
struct txwatch_hash txwatches; struct txwatch_hash txwatches;
struct txowatch_hash txowatches; struct txowatch_hash txowatches;
/* Suppress broadcast (for testing) */
bool dev_no_broadcast;
}; };
/* Information relevant to locating a TX in a blockchain. */ /* 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 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 */ #endif /* LIGHTNING_DAEMON_CRYPTOPKT_H */

View file

@ -44,7 +44,6 @@ static struct lightningd_state *lightningd_state(void)
list_head_init(&dstate->wallet); list_head_init(&dstate->wallet);
list_head_init(&dstate->addresses); list_head_init(&dstate->addresses);
dstate->dev_never_routefail = false; dstate->dev_never_routefail = false;
dstate->dev_no_broadcast = false;
dstate->rstate = new_routing_state(dstate, dstate->base_log); dstate->rstate = new_routing_state(dstate, dstate->base_log);
dstate->reexec = NULL; dstate->reexec = NULL;
dstate->external_ip = NULL; dstate->external_ip = NULL;
@ -53,6 +52,21 @@ static struct lightningd_state *lightningd_state(void)
return dstate; 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[]) int main(int argc, char *argv[])
{ {
struct lightningd_state *dstate = lightningd_state(); struct lightningd_state *dstate = lightningd_state();

View file

@ -125,9 +125,6 @@ struct lightningd_state {
/* For testing: don't fail if we can't route. */ /* For testing: don't fail if we can't route. */
bool dev_never_routefail; bool dev_never_routefail;
/* For testing: don't broadcast txs (but pretend it worked)(. */
bool dev_no_broadcast;
/* Re-exec hack for testing. */ /* Re-exec hack for testing. */
char **reexec; char **reexec;

View file

@ -1,4 +1,5 @@
#include "daemon/bitcoind.h" #include "daemon/bitcoind.h"
#include "daemon/chaintopology.h"
#include "daemon/configdir.h" #include "daemon/configdir.h"
#include "daemon/lightningd.h" #include "daemon/lightningd.h"
#include "daemon/log.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, opt_register_noarg("--dev-no-routefail", opt_set_bool,
&dstate->dev_never_routefail, opt_hidden); &dstate->dev_never_routefail, opt_hidden);
opt_register_noarg("--dev-no-broadcast", opt_set_bool, 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 = { static const struct config testnet_config = {

View file

@ -91,7 +91,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
list_head_init(&ld->dstate.wallet); list_head_init(&ld->dstate.wallet);
list_head_init(&ld->dstate.addresses); list_head_init(&ld->dstate.addresses);
ld->dstate.dev_never_routefail = false; ld->dstate.dev_never_routefail = false;
ld->dstate.dev_no_broadcast = false;
ld->dstate.reexec = NULL; ld->dstate.reexec = NULL;
ld->dstate.external_ip = NULL; ld->dstate.external_ip = NULL;
ld->dstate.announce = NULL; ld->dstate.announce = NULL;