[refactor] Add useful-for-dos "reason" field to CValidationState

This is a first step towards cleaning up our DoS interface - make
validation return *why* something is invalid, and let net_processing
figure out what that implies in terms of banning/disconnection/etc.

Behavior change: peers will now be banned for providing blocks
with premature coinbase spends.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
                Suhas Daftuar <sdaftuar@gmail.com>
This commit is contained in:
Matt Corallo
2019-01-16 13:11:13 +10:00
committed by Suhas Daftuar
parent 6a7f8777a0
commit 34477ccd39
7 changed files with 173 additions and 78 deletions

View File

@@ -961,6 +961,7 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV
static bool TxRelayMayResultInDisconnect(const CValidationState& state)
{
assert(state.GetDoS() == state.GetDoSForReason());
return (state.GetDoS() > 0);
}
@@ -975,6 +976,7 @@ static bool TxRelayMayResultInDisconnect(const CValidationState& state)
* txs, the peer should not be punished. See BIP 152.
*/
static bool MaybePunishNode(NodeId nodeid, const CValidationState& state, bool via_compact_block, const std::string& message = "") {
assert(state.GetDoS() == state.GetDoSForReason());
int nDoS = state.GetDoS();
if (nDoS > 0 && !via_compact_block) {
LOCK(cs_main);