Context:
I'm working on an application in which we'd like to know if the current node is sufficiently synced to be able to handle RPC requests. The method we would like to use is to see if our node has at least 2-4 peers and if a majority of the peers are reporting the same best height / best block hash.
Previous research:
- I know the
version
network call gets the height of the peer at that time, but it isn't updated. In addition, any furtherversion
requests result in an increase of the ban score of a node, so this cannot be used frequently. - Bitcoinj keeps track of the height of the best known peer by using the height given in the version message and then incrementing whenever the peer processes an
inv
message showing they have a new best-block height. This seems fast, but tricky/error prone. - This question is similar, but it asks about how to do this with RPC calls, and it doesn't seem to want to use the same method for determining whether the node is synced as the one I've proposed.
- This question helped provide a temporary solution (calling get work and seeing if it fails), but this method is not accurate enough.
Is there a way to just ask a peer what the height of its best block is without getting banned?
Could I just make multiple getheaders
requests and see if the peer returns any headers later than the header I have, or would the peer ban me for requesting the same headers again and again?
inv
right after they have a new best block every time? Even if you are the one who sent them the new block data? – morsecoder Jan 16 '15 at 00:45inv
, they shouldn't send you aninv
for the same data. Bitcoin Core also won't sendinv
s while they're in IBD. For all other cases, Bitcoin Core full nodes will send you aninv
for each new block they validate. Based on my reading of the 0.10.0 code a few weeks ago, there is no built-in delay (like for txinv
s) or network partitioning (like foraddr
s) when it comes to blockinv
s. Of course, nothing is guaranteed on a P2P network. – David A. Harding Jan 16 '15 at 01:22getpeerinfo
may be just what I need. False negatives (reporting that the node is not sufficiently caught up to handle requests when they actually are) are fine, it's false positives that would be the real kicker. I think the methods in the newgetpeerinfo
should meet those requirements. So, thanks! – morsecoder Jan 16 '15 at 02:29getblockchaininfo
would be more useful because it has the height of the highest of your peer connections (so you don't need to iterate over each connection). – David A. Harding Jan 16 '15 at 02:48