Seeder: Verify that nodes are on the correct chain
Summary:
Since there have been 2 splits of the BCH chain that haven't modified
their network magic, the seeder considers a lot of nodes as good that
are actually on the wrong chain.
To fix this, the seeder will check the headers of all nodes synced
higher than the last checkpoint's height. To do this, a P2P getheaders
with the last checkpoint's hash as locator is sent, the first returned
header's previous block hash is compared to checkpoint's hash and the
node is banned if they do not match.
This is a backport of bchn#1040
Note that the nodes are considered "good" until proven otherwise, so the seeder will still mistakenly consider BCH nodes to be good for a limited duration (until the HEADERS message is received), or even permanently if the HEADERS message is not yet received when the connection is closed.
However, this is still a net improvement compared to the previous behavior, as most BCH nodes are now banned and not written to the database. The behavior can be improved further in a separate diff (see https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node/-/merge_requests/1820/diffs?commit_id=4c8604800ba9ea67c61dd8c7c426d260004d853e)
Test Plan:
- ninja check-bitcoin-seeder
- Uncomment the wrong chain print in src/seeder/bitcoin.cpp
- ninja
- Run a mainnet seeder: src/seeder/bitcoin-seeder -dumpinterval=60
- Observe node versions being banned, should not include eCash nodes.
- Observe which nodes are ending up as good in dnsseed.dump: awk '{ if ($2 == 1) { print } }' dnsseed.dump
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D16465