Skip to content

Commit 7b99910

Browse files
TheBlueMattajtowns
authored andcommitted
Clean up banning levels
Compared with previous bans, the following changes are made: * Txn with empty vin/vout or null prevouts move from 10 DoS points to 100. * Loose transactions with a dependency loop now result in a ban instead of 10 DoS points. * Many pre-segwit soft-fork errors now result in a ban. Note: Transactions that violate soft-fork script flags since P2SH do not generally result in a ban. Also, banning behavior for invalid blocks is dependent on whether the node is validating with multiple script check threads, due to a long- standing bug. That inconsistency is still present after this commit. * Proof of work failure moves from 50 DoS points to a ban. * Blocks with timestamps under MTP now result in a ban, blocks too far in the future continue to *not* result in a ban. * Inclusion of non-final transactions in a block now results in a ban instead of 10 DoS points. Co-authored-by: Anthony Towns <[email protected]>
1 parent b8b4c80 commit 7b99910

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/consensus/tx_check.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
1111
{
1212
// Basic checks that don't depend on any context
1313
if (tx.vin.empty())
14-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
14+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vin-empty");
1515
if (tx.vout.empty())
16-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");
16+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-empty");
1717
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
1818
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
1919
return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
@@ -50,7 +50,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
5050
{
5151
for (const auto& txin : tx.vin)
5252
if (txin.prevout.IsNull())
53-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
53+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-prevout-null");
5454
}
5555

5656
return true;

src/consensus/tx_verify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c
172172

173173
// If prev is coinbase, check that it's matured
174174
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < COINBASE_MATURITY) {
175-
return state.Invalid(false,
176-
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
175+
return state.DoS(0, false,
176+
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase", false,
177177
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
178178
}
179179

src/validation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
760760
const uint256 &hashAncestor = ancestorIt->GetTx().GetHash();
761761
if (setConflicts.count(hashAncestor))
762762
{
763-
return state.DoS(10, false,
763+
return state.DoS(100, false,
764764
REJECT_INVALID, "bad-txns-spends-conflicting-tx", false,
765765
strprintf("%s spends conflicting transaction %s",
766766
hash.ToString(),
@@ -3047,7 +3047,7 @@ static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state,
30473047
{
30483048
// Check proof of work matches claimed amount
30493049
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
3050-
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");
3050+
return state.DoS(100, false, REJECT_INVALID, "high-hash", false, "proof of work failed");
30513051

30523052
return true;
30533053
}
@@ -3214,7 +3214,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
32143214

32153215
// Check timestamp against prev
32163216
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())
3217-
return state.Invalid(false, REJECT_INVALID, "time-too-old", "block's timestamp is too early");
3217+
return state.DoS(100, false, REJECT_INVALID, "time-too-old", false, "block's timestamp is too early");
32183218

32193219
// Check timestamp
32203220
if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME)
@@ -3225,7 +3225,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
32253225
if((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) ||
32263226
(block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) ||
32273227
(block.nVersion < 4 && nHeight >= consensusParams.BIP65Height))
3228-
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
3228+
return state.DoS(100, false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion), false,
32293229
strprintf("rejected nVersion=0x%08x block", block.nVersion));
32303230

32313231
return true;
@@ -3255,7 +3255,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
32553255
// Check that all transactions are finalized
32563256
for (const auto& tx : block.vtx) {
32573257
if (!IsFinalTx(*tx, nHeight, nLockTimeCutoff)) {
3258-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-nonfinal", false, "non-final transaction");
3258+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-nonfinal", false, "non-final transaction");
32593259
}
32603260
}
32613261

test/functional/data/invalid_txs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_tx(self, *args, **kwargs):
5858

5959
class OutputMissing(BadTxTemplate):
6060
reject_reason = "bad-txns-vout-empty"
61-
expect_disconnect = False
61+
expect_disconnect = True
6262

6363
def get_tx(self):
6464
tx = CTransaction()
@@ -69,7 +69,7 @@ def get_tx(self):
6969

7070
class InputMissing(BadTxTemplate):
7171
reject_reason = "bad-txns-vin-empty"
72-
expect_disconnect = False
72+
expect_disconnect = True
7373

7474
def get_tx(self):
7575
tx = CTransaction()

test/functional/feature_block.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def run_test(self):
630630
while b47.sha256 < target:
631631
b47.nNonce += 1
632632
b47.rehash()
633-
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash')
633+
self.send_blocks([b47], False, force_send=True, reject_reason='high-hash', reconnect=True)
634634

635635
self.log.info("Reject a block with a timestamp >2 hours in the future")
636636
self.move_tip(44)
@@ -681,7 +681,7 @@ def run_test(self):
681681
b54 = self.next_block(54, spend=out[15])
682682
b54.nTime = b35.nTime - 1
683683
b54.solve()
684-
self.send_blocks([b54], False, force_send=True, reject_reason='time-too-old')
684+
self.send_blocks([b54], False, force_send=True, reject_reason='time-too-old', reconnect=True)
685685

686686
# valid timestamp
687687
self.move_tip(53)
@@ -827,7 +827,7 @@ def run_test(self):
827827
assert tx.vin[0].nSequence < 0xffffffff
828828
tx.calc_sha256()
829829
b62 = self.update_block(62, [tx])
830-
self.send_blocks([b62], success=False, reject_reason='bad-txns-nonfinal')
830+
self.send_blocks([b62], success=False, reject_reason='bad-txns-nonfinal', reconnect=True)
831831

832832
# Test a non-final coinbase is also rejected
833833
#
@@ -841,7 +841,7 @@ def run_test(self):
841841
b63.vtx[0].vin[0].nSequence = 0xDEADBEEF
842842
b63.vtx[0].rehash()
843843
b63 = self.update_block(63, [])
844-
self.send_blocks([b63], success=False, reject_reason='bad-txns-nonfinal')
844+
self.send_blocks([b63], success=False, reject_reason='bad-txns-nonfinal', reconnect=True)
845845

846846
# This checks that a block with a bloated VARINT between the block_header and the array of tx such that
847847
# the block is > MAX_BLOCK_BASE_SIZE with the bloated varint, but <= MAX_BLOCK_BASE_SIZE without the bloated varint,
@@ -1255,7 +1255,7 @@ def run_test(self):
12551255

12561256
self.log.info("Reject a block with an invalid block header version")
12571257
b_v1 = self.next_block('b_v1', version=1)
1258-
self.send_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)')
1258+
self.send_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)', reconnect=True)
12591259

12601260
self.move_tip(chain1_tip + 2)
12611261
b_cb34 = self.next_block('b_cb34', version=4)

0 commit comments

Comments
 (0)