Browse Source

bitcoind: remove the chainparams member

We now have a global constant, prefer to use it instead of having
two variables with the same utility.
travis-debug
darosior 5 years ago
committed by Christian Decker
parent
commit
f075b87137
  1. 7
      common/wallet_tx.c
  2. 18
      lightningd/bitcoind.c
  3. 3
      lightningd/bitcoind.h
  4. 1
      lightningd/chaintopology.c
  5. 3
      lightningd/channel.c
  6. 2
      lightningd/closing_control.c
  7. 2
      lightningd/hsm_control.c
  8. 6
      lightningd/invoice.c
  9. 5
      lightningd/json.c
  10. 21
      lightningd/lightningd.c
  11. 2
      lightningd/lightningd.h
  12. 6
      lightningd/onchain_control.c
  13. 13
      lightningd/opening_control.c
  14. 15
      lightningd/options.c
  15. 21
      lightningd/peer_control.c
  16. 5
      lightningd/peer_htlcs.c
  17. 5
      lightningd/plugin.c
  18. 3
      lightningd/test/run-invoice-select-inchan.c
  19. 3
      lightningd/test/run-jsonrpc.c
  20. 5
      wallet/test/run-wallet.c
  21. 13
      wallet/walletrpc.c

7
common/wallet_tx.c

@ -3,6 +3,7 @@
#include <common/json_command.h> #include <common/json_command.h>
#include <common/json_helpers.h> #include <common/json_helpers.h>
#include <common/jsonrpc_errors.h> #include <common/jsonrpc_errors.h>
#include <common/utils.h>
#include <common/wallet_tx.h> #include <common/wallet_tx.h>
#include <inttypes.h> #include <inttypes.h>
#include <wallet/wallet.h> #include <wallet/wallet.h>
@ -117,7 +118,7 @@ static struct command_result *check_amount(const struct wallet_tx *wtx,
"Cannot afford transaction"); "Cannot afford transaction");
} }
if (amount_sat_less(amount, get_chainparams(wtx->cmd->ld)->dust_limit)) { if (amount_sat_less(amount, chainparams->dust_limit)) {
return command_fail(wtx->cmd, FUND_OUTPUT_IS_DUST, return command_fail(wtx->cmd, FUND_OUTPUT_IS_DUST,
"Output %s would be dust", "Output %s would be dust",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
@ -177,7 +178,7 @@ struct command_result *wtx_select_utxos(struct wallet_tx *tx,
if (res) if (res)
return res; return res;
if (amount_sat_less(tx->change, get_chainparams(tx->cmd->ld)->dust_limit)) { if (amount_sat_less(tx->change, chainparams->dust_limit)) {
tx->change = AMOUNT_SAT(0); tx->change = AMOUNT_SAT(0);
tx->change_key_index = 0; tx->change_key_index = 0;
} else { } else {
@ -224,7 +225,7 @@ struct command_result *wtx_from_utxos(struct wallet_tx *tx,
&& !amount_sat_sub(&tx->change, total_amount, tx->amount)) && !amount_sat_sub(&tx->change, total_amount, tx->amount))
fatal("Overflow when computing change"); fatal("Overflow when computing change");
if (amount_sat_greater_eq(tx->change, get_chainparams(tx->cmd->ld)->dust_limit)) { if (amount_sat_greater_eq(tx->change, chainparams->dust_limit)) {
/* Add the change output's weight */ /* Add the change output's weight */
weight += (8 + 1 + out_len) * 4; weight += (8 + 1 + out_len) * 4;
} }

18
lightningd/bitcoind.c

@ -42,9 +42,9 @@ static const char **gather_args(const struct bitcoind *bitcoind,
const char **args = tal_arr(ctx, const char *, 1); const char **args = tal_arr(ctx, const char *, 1);
const char *arg; const char *arg;
args[0] = bitcoind->cli ? bitcoind->cli : bitcoind->chainparams->cli; args[0] = bitcoind->cli ? bitcoind->cli : chainparams->cli;
if (bitcoind->chainparams->cli_args) if (chainparams->cli_args)
add_arg(&args, bitcoind->chainparams->cli_args); add_arg(&args, chainparams->cli_args);
if (bitcoind->datadir) if (bitcoind->datadir)
add_arg(&args, tal_fmt(args, "-datadir=%s", bitcoind->datadir)); add_arg(&args, tal_fmt(args, "-datadir=%s", bitcoind->datadir));
@ -379,7 +379,7 @@ static bool process_estimatefee(struct bitcoin_cli *bcli)
* with the minimal fee even if the estimate didn't * with the minimal fee even if the estimate didn't
* work out. This is less disruptive than erring out * work out. This is less disruptive than erring out
* all the time. */ * all the time. */
if (get_chainparams(bcli->bitcoind->ld)->testnet) if (chainparams->testnet)
efee->satoshi_per_kw[efee->i] = FEERATE_FLOOR; efee->satoshi_per_kw[efee->i] = FEERATE_FLOOR;
else else
efee->satoshi_per_kw[efee->i] = 0; efee->satoshi_per_kw[efee->i] = 0;
@ -467,7 +467,7 @@ static bool process_rawblock(struct bitcoin_cli *bcli)
struct bitcoin_block *blk, struct bitcoin_block *blk,
void *arg) = bcli->cb; void *arg) = bcli->cb;
blk = bitcoin_block_from_hex(bcli, bcli->bitcoind->chainparams, blk = bitcoin_block_from_hex(bcli, chainparams,
bcli->output, bcli->output_bytes); bcli->output, bcli->output_bytes);
if (!blk) if (!blk)
fatal("%s: bad block '%.*s'?", fatal("%s: bad block '%.*s'?",
@ -986,7 +986,7 @@ static bool extract_numeric_version(struct bitcoin_cli *bcli,
static bool process_getclientversion(struct bitcoin_cli *bcli) static bool process_getclientversion(struct bitcoin_cli *bcli)
{ {
u64 version; u64 version;
u64 min_version = bcli->bitcoind->chainparams->cli_min_supported_version; u64 min_version = chainparams->cli_min_supported_version;
if (!extract_numeric_version(bcli, bcli->output, if (!extract_numeric_version(bcli, bcli->output,
bcli->output_bytes, bcli->output_bytes,
@ -1178,10 +1178,10 @@ static char* check_blockchain_from_bitcoincli(const tal_t *ctx,
(int)output_bytes, output); (int)output_bytes, output);
if(!json_tok_streq(output, valuetok, if(!json_tok_streq(output, valuetok,
bitcoind->chainparams->bip70_name)) chainparams->bip70_name))
return tal_fmt(ctx, "Error blockchain for bitcoin-cli?" return tal_fmt(ctx, "Error blockchain for bitcoin-cli?"
" Should be: %s", " Should be: %s",
bitcoind->chainparams->bip70_name); chainparams->bip70_name);
is_bitcoind_synced_yet(bitcoind, output, output_bytes, tokens, true); is_bitcoind_synced_yet(bitcoind, output, output_bytes, tokens, true);
return NULL; return NULL;
@ -1249,8 +1249,6 @@ struct bitcoind *new_bitcoind(const tal_t *ctx,
{ {
struct bitcoind *bitcoind = tal(ctx, struct bitcoind); struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
/* Use testnet by default, change later if we want another network */
bitcoind->chainparams = chainparams_for_network("testnet");
bitcoind->cli = NULL; bitcoind->cli = NULL;
bitcoind->datadir = NULL; bitcoind->datadir = NULL;
bitcoind->ld = ld; bitcoind->ld = ld;

3
lightningd/bitcoind.h

@ -46,9 +46,6 @@ struct bitcoind {
/* Pending requests (high and low prio). */ /* Pending requests (high and low prio). */
struct list_head pending[BITCOIND_NUM_PRIO]; struct list_head pending[BITCOIND_NUM_PRIO];
/* What network are we on? */
const struct chainparams *chainparams;
/* If non-zero, time we first hit a bitcoind error. */ /* If non-zero, time we first hit a bitcoind error. */
unsigned int error_count; unsigned int error_count;
struct timemono first_error_time; struct timemono first_error_time;

1
lightningd/chaintopology.c

@ -746,7 +746,6 @@ static void have_new_block(struct bitcoind *bitcoind UNUSED,
struct bitcoin_block *blk, struct bitcoin_block *blk,
struct chain_topology *topo) struct chain_topology *topo)
{ {
const struct chainparams *chainparams = get_chainparams(topo->ld);
/* Annotate all transactions with the chainparams */ /* Annotate all transactions with the chainparams */
for (size_t i=0; i<tal_count(blk->tx); i++) for (size_t i=0; i<tal_count(blk->tx); i++)
blk->tx[i]->chainparams = chainparams; blk->tx[i]->chainparams = chainparams;

3
lightningd/channel.c

@ -3,6 +3,7 @@
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <common/json_command.h> #include <common/json_command.h>
#include <common/jsonrpc_errors.h> #include <common/jsonrpc_errors.h>
#include <common/utils.h>
#include <common/wire_error.h> #include <common/wire_error.h>
#include <connectd/gen_connect_wire.h> #include <connectd/gen_connect_wire.h>
#include <errno.h> #include <errno.h>
@ -234,7 +235,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->msat_to_us_min = msat_to_us_min; channel->msat_to_us_min = msat_to_us_min;
channel->msat_to_us_max = msat_to_us_max; channel->msat_to_us_max = msat_to_us_max;
channel->last_tx = tal_steal(channel, last_tx); channel->last_tx = tal_steal(channel, last_tx);
channel->last_tx->chainparams = get_chainparams(peer->ld); channel->last_tx->chainparams = chainparams;
channel->last_tx_type = TX_UNKNOWN; channel->last_tx_type = TX_UNKNOWN;
channel->last_sig = *last_sig; channel->last_sig = *last_sig;
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs); channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);

2
lightningd/closing_control.c

@ -108,7 +108,7 @@ static void peer_received_closing_signature(struct channel *channel,
tal_hex(msg, msg)); tal_hex(msg, msg));
return; return;
} }
tx->chainparams = get_chainparams(channel->peer->ld); tx->chainparams = chainparams;
/* FIXME: Make sure signature is correct! */ /* FIXME: Make sure signature is correct! */
if (better_closing_fee(ld, channel, tx)) { if (better_closing_fee(ld, channel, tx)) {

2
lightningd/hsm_control.c

@ -105,7 +105,7 @@ void hsm_init(struct lightningd *ld)
ld->hsm_fd = fds[0]; ld->hsm_fd = fds[0];
if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx, if (!wire_sync_write(ld->hsm_fd, towire_hsm_init(tmpctx,
&ld->topology->bitcoind->chainparams->bip32_key_version, &chainparams->bip32_key_version,
chainparams, chainparams,
ld->config.keypass, ld->config.keypass,
IFDEV(ld->dev_force_privkey, NULL), IFDEV(ld->dev_force_privkey, NULL),

6
lightningd/invoice.c

@ -301,7 +301,7 @@ static struct command_result *parse_fallback(struct command *cmd,
fallback_parse fallback_parse
= json_to_address_scriptpubkey(cmd, = json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, fallback, buffer, fallback,
fallback_script); fallback_script);
if (fallback_parse == ADDRESS_PARSE_UNRECOGNIZED) { if (fallback_parse == ADDRESS_PARSE_UNRECOGNIZED) {
@ -310,7 +310,7 @@ static struct command_result *parse_fallback(struct command *cmd,
} else if (fallback_parse == ADDRESS_PARSE_WRONG_NETWORK) { } else if (fallback_parse == ADDRESS_PARSE_WRONG_NETWORK) {
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Fallback address does not match our network %s", "Fallback address does not match our network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
} }
return NULL; return NULL;
} }
@ -683,7 +683,6 @@ static struct command_result *json_invoice(struct command *cmd,
u64 *expiry; u64 *expiry;
struct sha256 rhash; struct sha256 rhash;
bool *exposeprivate; bool *exposeprivate;
const struct chainparams *chainparams;
#if DEVELOPER #if DEVELOPER
const jsmntok_t *routes; const jsmntok_t *routes;
#endif #endif
@ -720,7 +719,6 @@ static struct command_result *json_invoice(struct command *cmd,
strlen(desc_val)); strlen(desc_val));
} }
chainparams = get_chainparams(cmd->ld);
if (msatoshi_val if (msatoshi_val
&& amount_msat_greater(*msatoshi_val, chainparams->max_payment)) { && amount_msat_greater(*msatoshi_val, chainparams->max_payment)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,

5
lightningd/json.c

@ -15,6 +15,7 @@
#include <common/node_id.h> #include <common/node_id.h>
#include <common/param.h> #include <common/param.h>
#include <common/type_to_string.h> #include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wallet_tx.h> #include <common/wallet_tx.h>
#include <common/wireaddr.h> #include <common/wireaddr.h>
#include <gossipd/routing.h> #include <gossipd/routing.h>
@ -552,7 +553,7 @@ struct command_result *param_bitcoin_address(struct command *cmd,
{ {
/* Parse address. */ /* Parse address. */
switch (json_to_address_scriptpubkey(cmd, switch (json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, tok, buffer, tok,
scriptpubkey)) { scriptpubkey)) {
case ADDRESS_PARSE_UNRECOGNIZED: case ADDRESS_PARSE_UNRECOGNIZED:
@ -563,7 +564,7 @@ struct command_result *param_bitcoin_address(struct command *cmd,
case ADDRESS_PARSE_WRONG_NETWORK: case ADDRESS_PARSE_WRONG_NETWORK:
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Destination address is not on network %s", "Destination address is not on network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
case ADDRESS_PARSE_SUCCESS: case ADDRESS_PARSE_SUCCESS:
return NULL; return NULL;
} }

21
lightningd/lightningd.c

@ -475,17 +475,6 @@ static void shutdown_subdaemons(struct lightningd *ld)
db_commit_transaction(ld->wallet->db); db_commit_transaction(ld->wallet->db);
} }
/*~ Chainparams are the parameters for eg. testnet vs mainnet. This wrapper
* saves lots of struggles with our 80-column guideline! */
const struct chainparams *get_chainparams(const struct lightningd *ld)
{
/* "The lightningd is connected to the blockchain."
* "The blockchain is connected to the bitcoind API."
* "The bitcoind API is connected chain parameters."
* -- Worst childhood song ever. */
return ld->topology->bitcoind->chainparams;
}
/*~ Our wallet logic needs to know what outputs we might be interested in. We /*~ Our wallet logic needs to know what outputs we might be interested in. We
* use BIP32 (a.k.a. "HD wallet") to generate keys from a single seed, so we * use BIP32 (a.k.a. "HD wallet") to generate keys from a single seed, so we
* keep the maximum-ever-used key index in the db, and add them all to the * keep the maximum-ever-used key index in the db, and add them all to the
@ -665,6 +654,10 @@ int main(int argc, char *argv[])
* backtraces when we crash (if supported on this platform). */ * backtraces when we crash (if supported on this platform). */
daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit); daemon_setup(argv[0], log_backtrace_print, log_backtrace_exit);
/*~ We use a global (in common/utils.h) for the chainparams.
* We default to testnet for now. */
chainparams = chainparams_for_network("testnet");
/*~ There's always a battle between what a constructor like this /*~ There's always a battle between what a constructor like this
* should do, and what should be added later by the caller. In * should do, and what should be added later by the caller. In
* general, because we use valgrind heavily for testing, we prefer not * general, because we use valgrind heavily for testing, we prefer not
@ -673,10 +666,6 @@ int main(int argc, char *argv[])
* variables. */ * variables. */
ld = new_lightningd(NULL); ld = new_lightningd(NULL);
/*~ The global chainparams is needed to init subdaemons, and defaults
* to testnet. */
chainparams = chainparams_for_network("testnet");
/* Figure out where our daemons are first. */ /* Figure out where our daemons are first. */
ld->daemon_dir = find_daemon_dir(ld, argv[0]); ld->daemon_dir = find_daemon_dir(ld, argv[0]);
if (!ld->daemon_dir) if (!ld->daemon_dir)
@ -753,7 +742,7 @@ int main(int argc, char *argv[])
/*~ Our default names, eg. for the database file, are not dependent on /*~ Our default names, eg. for the database file, are not dependent on
* the network. Instead, the db knows what chain it belongs to, and we * the network. Instead, the db knows what chain it belongs to, and we
* simple barf here if it's wrong. */ * simple barf here if it's wrong. */
if (!wallet_network_check(ld->wallet, get_chainparams(ld))) if (!wallet_network_check(ld->wallet, chainparams))
errx(1, "Wallet network check failed."); errx(1, "Wallet network check failed.");
/*~ Initialize the transaction filter with our pubkeys. */ /*~ Initialize the transaction filter with our pubkeys. */

2
lightningd/lightningd.h

@ -251,8 +251,6 @@ struct lightningd {
* Use only on carefully tested code! */ * Use only on carefully tested code! */
extern bool tal_oom_ok; extern bool tal_oom_ok;
const struct chainparams *get_chainparams(const struct lightningd *ld);
/* Check we can run subdaemons, and check their versions */ /* Check we can run subdaemons, and check their versions */
void test_subdaemons(const struct lightningd *ld); void test_subdaemons(const struct lightningd *ld);

6
lightningd/onchain_control.c

@ -1,6 +1,7 @@
#include <bitcoin/feerate.h> #include <bitcoin/feerate.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/utils.h>
#include <errno.h> #include <errno.h>
#include <hsmd/gen_hsm_wire.h> #include <hsmd/gen_hsm_wire.h>
#include <inttypes.h> #include <inttypes.h>
@ -187,7 +188,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
channel_internal_error(channel, "Invalid onchain_broadcast_tx"); channel_internal_error(channel, "Invalid onchain_broadcast_tx");
return; return;
} }
tx->chainparams = get_chainparams(channel->peer->ld); tx->chainparams = chainparams;
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
wallet_transaction_add(w, tx, 0, 0); wallet_transaction_add(w, tx, 0, 0);
@ -457,7 +458,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
struct pubkey final_key; struct pubkey final_key;
int hsmfd; int hsmfd;
u32 feerate; u32 feerate;
const struct chainparams *chainparams;
channel_fail_permanent(channel, "Funding transaction spent"); channel_fail_permanent(channel, "Funding transaction spent");
@ -531,8 +531,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
feerate = feerate_floor(); feerate = feerate_floor();
} }
chainparams = get_chainparams(channel->peer->ld);
msg = towire_onchain_init(channel, msg = towire_onchain_init(channel,
&channel->their_shachain.chain, &channel->their_shachain.chain,
chainparams, chainparams,

13
lightningd/opening_control.c

@ -11,6 +11,7 @@
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/param.h> #include <common/param.h>
#include <common/per_peer_state.h> #include <common/per_peer_state.h>
#include <common/utils.h>
#include <common/wallet_tx.h> #include <common/wallet_tx.h>
#include <common/wire_error.h> #include <common/wire_error.h>
#include <connectd/gen_connect_wire.h> #include <connectd/gen_connect_wire.h>
@ -301,7 +302,7 @@ static void funding_started_success(struct funding_channel *fc,
response = json_stream_success(cmd); response = json_stream_success(cmd);
out = encode_scriptpubkey_to_addr(cmd, out = encode_scriptpubkey_to_addr(cmd,
get_chainparams(cmd->ld), chainparams,
scriptPubkey); scriptPubkey);
if (out) { if (out) {
json_add_string(response, "funding_address", out); json_add_string(response, "funding_address", out);
@ -395,7 +396,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
tal_hex(fc->cmd, resp))); tal_hex(fc->cmd, resp)));
goto cleanup; goto cleanup;
} }
remote_commit->chainparams = get_chainparams(openingd->ld); remote_commit->chainparams = chainparams;
per_peer_state_set_fds_arr(pps, fds); per_peer_state_set_fds_arr(pps, fds);
log_debug(ld->log, log_debug(ld->log,
@ -488,7 +489,7 @@ static void opening_fundee_finished(struct subd *openingd,
goto failed; goto failed;
} }
remote_commit->chainparams = get_chainparams(openingd->ld); remote_commit->chainparams = chainparams;
per_peer_state_set_fds_arr(pps, fds); per_peer_state_set_fds_arr(pps, fds);
/* openingd should never accept them funding channel in this case. */ /* openingd should never accept them funding channel in this case. */
@ -660,7 +661,7 @@ static void channel_config(struct lightningd *ld,
ld->config.min_capacity_sat)) ld->config.min_capacity_sat))
fatal("amount_msat overflow for config.min_capacity_sat"); fatal("amount_msat overflow for config.min_capacity_sat");
/* Substract 2 * dust_limit, so fundchannel with min value is possible */ /* Substract 2 * dust_limit, so fundchannel with min value is possible */
if (!amount_sat_to_msat(&dust_limit, get_chainparams(ld)->dust_limit)) if (!amount_sat_to_msat(&dust_limit, chainparams->dust_limit))
fatal("amount_msat overflow for dustlimit"); fatal("amount_msat overflow for dustlimit");
if (!amount_msat_sub(min_effective_htlc_capacity, if (!amount_msat_sub(min_effective_htlc_capacity,
*min_effective_htlc_capacity, *min_effective_htlc_capacity,
@ -678,7 +679,7 @@ static void channel_config(struct lightningd *ld,
* - set `dust_limit_satoshis` to a sufficient value to allow * - set `dust_limit_satoshis` to a sufficient value to allow
* commitment transactions to propagate through the Bitcoin network. * commitment transactions to propagate through the Bitcoin network.
*/ */
ours->dust_limit = get_chainparams(ld)->dust_limit; ours->dust_limit = chainparams->dust_limit;
ours->max_htlc_value_in_flight = AMOUNT_MSAT(UINT64_MAX); ours->max_htlc_value_in_flight = AMOUNT_MSAT(UINT64_MAX);
/* Don't care */ /* Don't care */
@ -1080,7 +1081,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd,
u8 *msg = NULL; u8 *msg = NULL;
struct amount_sat max_funding_satoshi, *amount; struct amount_sat max_funding_satoshi, *amount;
max_funding_satoshi = get_chainparams(cmd->ld)->max_funding; max_funding_satoshi = chainparams->max_funding;
fc->cmd = cmd; fc->cmd = cmd;
fc->cancels = tal_arr(fc, struct command *, 0); fc->cancels = tal_arr(fc, struct command *, 0);
fc->uc = NULL; fc->uc = NULL;

15
lightningd/options.c

@ -1,4 +1,3 @@
#include <bitcoin/chainparams.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/json_escape/json_escape.h> #include <ccan/json_escape/json_escape.h>
@ -18,6 +17,7 @@
#include <common/jsonrpc_errors.h> #include <common/jsonrpc_errors.h>
#include <common/memleak.h> #include <common/memleak.h>
#include <common/param.h> #include <common/param.h>
#include <common/utils.h>
#include <common/version.h> #include <common/version.h>
#include <common/wireaddr.h> #include <common/wireaddr.h>
#include <errno.h> #include <errno.h>
@ -256,9 +256,7 @@ static char *opt_set_network(const char *arg, struct lightningd *ld)
/* Set the global chainparams instance */ /* Set the global chainparams instance */
chainparams = chainparams_for_network(arg); chainparams = chainparams_for_network(arg);
if (!chainparams)
ld->topology->bitcoind->chainparams = chainparams;
if (!ld->topology->bitcoind->chainparams)
return tal_fmt(NULL, "Unknown network name '%s'", arg); return tal_fmt(NULL, "Unknown network name '%s'", arg);
return NULL; return NULL;
} }
@ -281,7 +279,7 @@ static char *opt_set_mainnet(struct lightningd *ld)
static void opt_show_network(char buf[OPT_SHOW_LEN], static void opt_show_network(char buf[OPT_SHOW_LEN],
const struct lightningd *ld) const struct lightningd *ld)
{ {
snprintf(buf, OPT_SHOW_LEN, "%s", get_chainparams(ld)->network_name); snprintf(buf, OPT_SHOW_LEN, "%s", chainparams->network_name);
} }
static char *opt_set_rgb(const char *arg, struct lightningd *ld) static char *opt_set_rgb(const char *arg, struct lightningd *ld)
@ -692,14 +690,14 @@ static void check_config(struct lightningd *ld)
static void setup_default_config(struct lightningd *ld) static void setup_default_config(struct lightningd *ld)
{ {
if (get_chainparams(ld)->testnet) if (chainparams->testnet)
ld->config = testnet_config; ld->config = testnet_config;
else else
ld->config = mainnet_config; ld->config = mainnet_config;
/* Set default PID file name to be per-network */ /* Set default PID file name to be per-network */
tal_free(ld->pidfile); tal_free(ld->pidfile);
ld->pidfile = tal_fmt(ld, "lightningd-%s.pid", get_chainparams(ld)->network_name); ld->pidfile = tal_fmt(ld, "lightningd-%s.pid", chainparams->network_name);
} }
@ -830,8 +828,7 @@ static char *opt_lightningd_usage(struct lightningd *ld)
* to display before it exits */ * to display before it exits */
setup_default_config(ld); setup_default_config(ld);
char *extra = tal_fmt(NULL, "\nA bitcoin lightning daemon (default " char *extra = tal_fmt(NULL, "\nA bitcoin lightning daemon (default "
"values shown for network: %s).", "values shown for network: %s).", chainparams->network_name);
get_chainparams(ld)->network_name);
opt_usage_and_exit(extra); opt_usage_and_exit(extra);
tal_free(extra); tal_free(extra);
return NULL; return NULL;

21
lightningd/peer_control.c

@ -27,6 +27,7 @@
#include <common/per_peer_state.h> #include <common/per_peer_state.h>
#include <common/status.h> #include <common/status.h>
#include <common/timeout.h> #include <common/timeout.h>
#include <common/utils.h>
#include <common/version.h> #include <common/version.h>
#include <common/wire_error.h> #include <common/wire_error.h>
#include <connectd/gen_connect_wire.h> #include <connectd/gen_connect_wire.h>
@ -623,7 +624,7 @@ static void json_add_channel(struct lightningd *ld,
if (channel->shutdown_scriptpubkey[LOCAL]) { if (channel->shutdown_scriptpubkey[LOCAL]) {
char *addr = encode_scriptpubkey_to_addr(tmpctx, char *addr = encode_scriptpubkey_to_addr(tmpctx,
get_chainparams(ld), chainparams,
channel->shutdown_scriptpubkey[LOCAL]); channel->shutdown_scriptpubkey[LOCAL]);
if (addr) if (addr)
json_add_string(response, "close_to_addr", addr); json_add_string(response, "close_to_addr", addr);
@ -729,8 +730,8 @@ static void json_add_channel(struct lightningd *ld,
spendable = AMOUNT_MSAT(0); spendable = AMOUNT_MSAT(0);
/* We can't offer an HTLC over the max payment threshold either. */ /* We can't offer an HTLC over the max payment threshold either. */
if (amount_msat_greater(spendable, get_chainparams(ld)->max_payment)) if (amount_msat_greater(spendable, chainparams->max_payment))
spendable = get_chainparams(ld)->max_payment; spendable = chainparams->max_payment;
json_add_amount_msat_compat(response, spendable, json_add_amount_msat_compat(response, spendable,
"spendable_msatoshi", "spendable_msat"); "spendable_msatoshi", "spendable_msat");
@ -1271,7 +1272,7 @@ static struct command_result *param_tok_dest_or_timeout(
if (!json_to_number(buffer, tok, &timeout)) { if (!json_to_number(buffer, tok, &timeout)) {
enum address_parse_result res; enum address_parse_result res;
res = json_to_address_scriptpubkey(cmd, res = json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, tok, buffer, tok,
&script); &script);
if (res == ADDRESS_PARSE_UNRECOGNIZED) if (res == ADDRESS_PARSE_UNRECOGNIZED)
@ -1280,7 +1281,7 @@ static struct command_result *param_tok_dest_or_timeout(
else if (res == ADDRESS_PARSE_WRONG_NETWORK) else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s", "Destination address is not on network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
} }
return NULL; return NULL;
} }
@ -1355,7 +1356,7 @@ static struct command_result *json_close(struct command *cmd,
if (secondtok) { if (secondtok) {
enum address_parse_result res; enum address_parse_result res;
res = json_to_address_scriptpubkey(cmd, res = json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, secondtok, buffer, secondtok,
&close_to_script); &close_to_script);
if (res == ADDRESS_PARSE_UNRECOGNIZED) if (res == ADDRESS_PARSE_UNRECOGNIZED)
@ -1364,7 +1365,7 @@ static struct command_result *json_close(struct command *cmd,
else if (res == ADDRESS_PARSE_WRONG_NETWORK) else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s", "Destination address is not on network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
} }
} }
} else if (secondtok) { } else if (secondtok) {
@ -1378,7 +1379,7 @@ static struct command_result *json_close(struct command *cmd,
enum address_parse_result res; enum address_parse_result res;
res = json_to_address_scriptpubkey(cmd, res = json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, secondtok, buffer, secondtok,
&close_to_script); &close_to_script);
if (res == ADDRESS_PARSE_UNRECOGNIZED) if (res == ADDRESS_PARSE_UNRECOGNIZED)
@ -1387,7 +1388,7 @@ static struct command_result *json_close(struct command *cmd,
else if (res == ADDRESS_PARSE_WRONG_NETWORK) else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s", "Destination address is not on network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
} }
} else } else
old_style = false; old_style = false;
@ -1722,7 +1723,7 @@ static struct command_result *json_getinfo(struct command *cmd,
} }
json_add_string(response, "version", version()); json_add_string(response, "version", version());
json_add_num(response, "blockheight", get_block_height(cmd->ld->topology)); json_add_num(response, "blockheight", get_block_height(cmd->ld->topology));
json_add_string(response, "network", get_chainparams(cmd->ld)->network_name); json_add_string(response, "network", chainparams->network_name);
json_add_amount_msat_compat(response, json_add_amount_msat_compat(response,
wallet_total_forward_fees(cmd->ld->wallet), wallet_total_forward_fees(cmd->ld->wallet),
"msatoshi_fees_collected", "msatoshi_fees_collected",

5
lightningd/peer_htlcs.c

@ -12,6 +12,7 @@
#include <common/param.h> #include <common/param.h>
#include <common/sphinx.h> #include <common/sphinx.h>
#include <common/timeout.h> #include <common/timeout.h>
#include <common/utils.h>
#include <gossipd/gen_gossip_wire.h> #include <gossipd/gen_gossip_wire.h>
#include <lightningd/chaintopology.h> #include <lightningd/chaintopology.h>
#include <lightningd/htlc_end.h> #include <lightningd/htlc_end.h>
@ -527,7 +528,7 @@ static void forward_htlc(struct htlc_in *hin,
} }
if (amount_msat_greater(amt_to_forward, if (amount_msat_greater(amt_to_forward,
get_chainparams(ld)->max_payment)) { chainparams->max_payment)) {
/* ENOWUMBO! */ /* ENOWUMBO! */
failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING; failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING;
goto fail; goto fail;
@ -1549,7 +1550,7 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
tal_hex(channel, msg)); tal_hex(channel, msg));
return; return;
} }
tx->chainparams = get_chainparams(ld); tx->chainparams = chainparams;
log_debug(channel->log, log_debug(channel->log,
"got commitsig %"PRIu64 "got commitsig %"PRIu64

5
lightningd/plugin.c

@ -3,6 +3,7 @@
#include <ccan/opt/opt.h> #include <ccan/opt/opt.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <ccan/utf8/utf8.h> #include <ccan/utf8/utf8.h>
#include <common/utils.h>
#include <common/version.h> #include <common/version.h>
#include <lightningd/json.h> #include <lightningd/json.h>
#include <lightningd/notification.h> #include <lightningd/notification.h>
@ -1050,9 +1051,7 @@ plugin_populate_init_request(struct plugin *plugin, struct jsonrpc_request *req)
json_add_string(req->stream, "lightning-dir", ld->config_dir); json_add_string(req->stream, "lightning-dir", ld->config_dir);
json_add_string(req->stream, "rpc-file", ld->rpc_filename); json_add_string(req->stream, "rpc-file", ld->rpc_filename);
json_add_bool(req->stream, "startup", plugin->plugins->startup); json_add_bool(req->stream, "startup", plugin->plugins->startup);
json_add_string( json_add_string(req->stream, "network", chainparams->network_name);
req->stream, "network",
plugin->plugins->ld->topology->bitcoind->chainparams->network_name);
json_object_end(req->stream); json_object_end(req->stream);
} }

3
lightningd/test/run-invoice-select-inchan.c

@ -120,9 +120,6 @@ void fulfill_htlc(struct htlc_in *hin UNNEEDED, const struct preimage *preimage
/* Generated stub for get_block_height */ /* Generated stub for get_block_height */
u32 get_block_height(const struct chain_topology *topo UNNEEDED) u32 get_block_height(const struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "get_block_height called!\n"); abort(); } { fprintf(stderr, "get_block_height called!\n"); abort(); }
/* Generated stub for get_chainparams */
const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "get_chainparams called!\n"); abort(); }
/* Generated stub for get_log_level */ /* Generated stub for get_log_level */
enum log_level get_log_level(struct log_book *lr UNNEEDED) enum log_level get_log_level(struct log_book *lr UNNEEDED)
{ fprintf(stderr, "get_log_level called!\n"); abort(); } { fprintf(stderr, "get_log_level called!\n"); abort(); }

3
lightningd/test/run-jsonrpc.c

@ -30,9 +30,6 @@ const char *feerate_name(enum feerate feerate UNNEEDED)
/* Generated stub for fmt_wireaddr_without_port */ /* Generated stub for fmt_wireaddr_without_port */
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
/* Generated stub for get_chainparams */
const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "get_chainparams called!\n"); abort(); }
/* Generated stub for json_to_pubkey */ /* Generated stub for json_to_pubkey */
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct pubkey *pubkey UNNEEDED)

5
wallet/test/run-wallet.c

@ -29,11 +29,6 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool ca
bool deprecated_apis = true; bool deprecated_apis = true;
const struct chainparams *get_chainparams(const struct lightningd *ld)
{
return chainparams_for_network("bitcoin");
}
/* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */ /* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED) size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)

13
wallet/walletrpc.c

@ -11,6 +11,7 @@
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/param.h> #include <common/param.h>
#include <common/status.h> #include <common/status.h>
#include <common/utils.h>
#include <common/utxo.h> #include <common/utxo.h>
#include <common/wallet_tx.h> #include <common/wallet_tx.h>
#include <common/withdraw_tx.h> #include <common/withdraw_tx.h>
@ -320,7 +321,7 @@ static struct command_result *json_prepare_tx(struct command *cmd,
"{destination: amount}"); "{destination: amount}");
res = json_to_address_scriptpubkey(cmd, res = json_to_address_scriptpubkey(cmd,
get_chainparams(cmd->ld), chainparams,
buffer, &t[1], buffer, &t[1],
&destination); &destination);
if (res == ADDRESS_PARSE_UNRECOGNIZED) if (res == ADDRESS_PARSE_UNRECOGNIZED)
@ -329,7 +330,7 @@ static struct command_result *json_prepare_tx(struct command *cmd,
else if (res == ADDRESS_PARSE_WRONG_NETWORK) else if (res == ADDRESS_PARSE_WRONG_NETWORK)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Destination address is not on network %s", "Destination address is not on network %s",
get_chainparams(cmd->ld)->network_name); chainparams->network_name);
amount = tal(tmpctx, struct amount_sat); amount = tal(tmpctx, struct amount_sat);
if (!json_to_sat_or_all(buffer, &t[2], amount)) if (!json_to_sat_or_all(buffer, &t[2], amount))
@ -392,7 +393,7 @@ create_tx:
return command_fail(cmd, LIGHTNINGD, "Keys generation failure"); return command_fail(cmd, LIGHTNINGD, "Keys generation failure");
} else } else
changekey = NULL; changekey = NULL;
(*utx)->tx = withdraw_tx(*utx, get_chainparams(cmd->ld), (*utx)->tx = withdraw_tx(*utx, chainparams,
(*utx)->wtx->utxos, (*utx)->outputs, (*utx)->wtx->utxos, (*utx)->outputs,
changekey, (*utx)->wtx->change, changekey, (*utx)->wtx->change,
cmd->ld->wallet->bip32_base, cmd->ld->wallet->bip32_base,
@ -586,10 +587,10 @@ encode_pubkey_to_addr(const tal_t *ctx,
sha256(&h, redeemscript, tal_count(redeemscript)); sha256(&h, redeemscript, tal_count(redeemscript));
ripemd160(&h160, h.u.u8, sizeof(h)); ripemd160(&h160, h.u.u8, sizeof(h));
out = p2sh_to_base58(ctx, out = p2sh_to_base58(ctx,
get_chainparams(ld), chainparams,
&h160); &h160);
} else { } else {
hrp = get_chainparams(ld)->bip173_name; hrp = chainparams->bip173_name;
/* out buffer is 73 + strlen(human readable part), /* out buffer is 73 + strlen(human readable part),
* see common/bech32.h*/ * see common/bech32.h*/
@ -814,7 +815,7 @@ static struct command_result *json_listfunds(struct command *cmd,
json_add_string(response, "address", out); json_add_string(response, "address", out);
} else if (utxos[i]->scriptPubkey != NULL) { } else if (utxos[i]->scriptPubkey != NULL) {
out = encode_scriptpubkey_to_addr( out = encode_scriptpubkey_to_addr(
cmd, get_chainparams(cmd->ld), cmd, chainparams,
utxos[i]->scriptPubkey); utxos[i]->scriptPubkey);
if (out) if (out)
json_add_string(response, "address", out); json_add_string(response, "address", out);

Loading…
Cancel
Save