Browse Source

daemon/chaintopology: move dev_no_broadcast from lightningd_state to here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
38cc6c2f21
  1. 18
      daemon/chaintopology.c
  2. 9
      daemon/chaintopology.h
  3. 16
      daemon/lightningd.c
  4. 3
      daemon/lightningd.h
  5. 3
      daemon/options.c
  6. 1
      lightningd/lightningd.c

18
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,7 +488,8 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo,
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)
{
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",
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;
}

9
daemon/chaintopology.h

@ -7,11 +7,13 @@
#include <ccan/short_types/short_types.h>
#include <ccan/structeq/structeq.h>
#include <ccan/time/time.h>
#include <daemon/jsmn/jsmn.h>
#include <daemon/watch.h>
#include <stddef.h>
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 */

16
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();

3
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;

3
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 = {

1
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;

Loading…
Cancel
Save