Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
/* Hex-encoded SHA256 block hash length (32 bytes = 64 hex chars) */
#define BLOCK_HASH_HEX_LEN 64

/* Bitcoin Core version 23.0.0 introduced getblockfrompeer RPC */
#define BITCOIND_VERSION_GETBLOCKFROMPEER 230000

struct bitcoind {
/* eg. "bitcoin-cli" */
char *cli;
Expand Down Expand Up @@ -402,42 +399,39 @@ static struct command_result *getrawblockbyheight(struct command *cmd,
block_hash, bitcoind->retry_timeout), NULL);
}

/* Try fetching from peers if bitcoind >= 23.0.0 */
if (bitcoind->version >= BITCOIND_VERSION_GETBLOCKFROMPEER) {
if (!peers)
peers = get_fullnode_peers(cmd, cmd);

if (tal_count(peers) > 0) {
int peer = peers[tal_count(peers) - 1];
tal_resize(&peers, tal_count(peers) - 1);

res = run_bitcoin_cli(cmd, cmd->plugin,
"getblockfrompeer",
block_hash,
tal_fmt(tmpctx, "%i", peer),
NULL);

if (res->exitstatus != 0) {
/* We still continue with the execution if we cannot fetch the
* block from peer */
plugin_log(cmd->plugin, LOG_DBG,
"failed to fetch block %s from peer %i, skip.",
block_hash, peer);
} else {
plugin_log(cmd->plugin, LOG_DBG,
"try to fetch block %s from peer %i.",
block_hash, peer);
}
}
if (!peers)
peers = get_fullnode_peers(cmd, cmd);

if (tal_count(peers) > 0) {
int peer = peers[tal_count(peers) - 1];
tal_resize(&peers, tal_count(peers) - 1);

res = run_bitcoin_cli(cmd, cmd->plugin,
"getblockfrompeer",
block_hash,
tal_fmt(tmpctx, "%i", peer),
NULL);

if (tal_count(peers) == 0) {
if (res->exitstatus != 0) {
/* We still continue with the execution if we cannot fetch the
* block from peer */
plugin_log(cmd->plugin, LOG_DBG,
"asked all known peers about block %s, retry",
block_hash);
peers = tal_free(peers);
"failed to fetch block %s from peer %i, skip.",
block_hash, peer);
} else {
plugin_log(cmd->plugin, LOG_DBG,
"try to fetch block %s from peer %i.",
block_hash, peer);
}
}

if (tal_count(peers) == 0) {
plugin_log(cmd->plugin, LOG_DBG,
"asked all known peers about block %s, retry",
block_hash);
peers = tal_free(peers);
}

sleep(1);
}
}
Expand Down Expand Up @@ -743,7 +737,7 @@ static void parse_getnetworkinfo_result(struct plugin *p, const char *buf)
{
const jsmntok_t *result;
bool tx_relay;
u32 min_version = 220000;
u32 min_version = 230000;
const char *err;

result = json_parse_simple(NULL, buf, strlen(buf));
Expand Down
19 changes: 2 additions & 17 deletions plugins/spender/openchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,9 @@ static bool update_parent_psbt(const tal_t *ctx,
goto fail;
}

/* We want to preserve the memory bits associated with
* the inputs/outputs we just copied over when we free
* the copy, so remove ones the *added* from the copy.
* We go from the back since this will modify the indexes */
for (size_t i = tal_count(changes->added_ins) - 1;
i > -1;
i--) {
psbt_rm_input(new_node_copy,
changes->added_ins[i].idx);
}
for (size_t i = tal_count(changes->added_outs) - 1;
i > -1;
i--) {
psbt_rm_output(new_node_copy,
changes->added_outs[i].idx);
}

tal_free(changes);
/* All those new_node_copy children are owned by clone
* already, so shallow copying them above was fine. */
tal_free(new_node_copy);

tal_free(*parent_psbt);
Expand Down
Loading