Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Do not DoS ban peers for giving you valid headers #656

Closed
Closed
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
7 changes: 4 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3692,8 +3692,9 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
if (mi == mapBlockIndex.end())
return state.DoS(10, error("%s: prev block not found", __func__), 0, "prev-blk-not-found");
pindexPrev = (*mi).second;
if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
return state.DoS(g_signed_blocks ? 0 : 100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
}
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state));

Expand Down Expand Up @@ -3730,7 +3731,7 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
setDirtyBlockIndex.insert(invalid_walk);
invalid_walk = invalid_walk->pprev;
}
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
return state.DoS(g_signed_blocks ? 0 : 100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def run_test(self):
proof = parent.gettxoutproof([txid])
raw = parent.gettransaction(txid)["hex"]
sidechain.claimpegin(raw, proof) # stuck peg
sidechain.generate(1)
sidechain.generatetoaddress(10, sidechain.getnewaddress())
print("Waiting to ensure block is being rejected by sidechain2")
time.sleep(5)

Expand All @@ -427,6 +427,16 @@ def run_test(self):
self.start_node(1)
connect_nodes_bi(self.nodes, 0, 1)

# We need to make more blockheaders to cause the faulty node to know the peer has a now-valid header chain
# TODO make this more robust via better test, or somehow improve p2p behavior
attempts_to_prod_node = 10
while sidechain.getblockcount() != sidechain2.getblockcount():
print("Failing to sync, trying again: " +str(sidechain.getblockcount()) +" vs "+str(sidechain2.getblockcount()))
sidechain.generate(1)
time.sleep(5)
assert attempts_to_prod_node != 0
attempts_to_prod_node -= 1

# Don't make a block, race condition when pegin-invalid block
# is awaiting further validation, nodes reject subsequent blocks
# even ones they create
Expand Down