mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
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:
parent
61e576ef12
commit
38cc6c2f21
6 changed files with 33 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue