Skip to content

Commit 2c9d640

Browse files
committed
bcli: don't try asking non-full nodes for blocks.
Suggested-by: @NicolasDorier Closes: ElementsProject#8078 Signed-off-by: Rusty Russell <[email protected]> Changelog-Changed: Protocol: we no longer try asking for blocks from bitcoind's peers if they don't store blocks.
1 parent 8e41ee4 commit 2c9d640

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

plugins/bcli.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,20 @@ static struct command_result *process_getpeerinfo(struct bitcoin_cli *bcli)
626626
json_for_each_arr(i, t, toks)
627627
{
628628
int id;
629-
if (json_scan(tmpctx, bcli->output, t, "{id:%}",
630-
JSON_SCAN(json_to_int, &id)) == NULL) {
631-
// fixme: future optimization: a) filter for full nodes,
632-
// b) sort by last ping
633-
tal_arr_expand(&stash->peers, id);
629+
u8 *services;
630+
631+
if (json_scan(tmpctx, bcli->output, t, "{id:%,services:%}",
632+
JSON_SCAN(json_to_int, &id),
633+
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &services)) == NULL) {
634+
/* From bitcoin source:
635+
* // NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently
636+
* // set by all Bitcoin Core non pruned nodes, and is unset by SPV clients or other light clients.
637+
* NODE_NETWORK = (1 << 0)
638+
*/
639+
if (tal_count(services) > 0 && (services[tal_count(services)-1] & (1<<0))) {
640+
// fixme: future optimization: sort by last ping
641+
tal_arr_expand(&stash->peers, id);
642+
}
634643
}
635644
}
636645

0 commit comments

Comments
 (0)