Skip to content

Commit 14e7ffc

Browse files
committed
Use standard BIP 22 rejection reasons where applicable
1 parent dfd0d38 commit 14e7ffc

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/main.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -605,29 +605,29 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
605605
// Basic checks that don't depend on any context
606606
if (tx.vin.empty())
607607
return state.DoS(10, error("CheckTransaction() : vin empty"),
608-
REJECT_INVALID, "vin empty");
608+
REJECT_INVALID, "bad-txns-vin-empty");
609609
if (tx.vout.empty())
610610
return state.DoS(10, error("CheckTransaction() : vout empty"),
611-
REJECT_INVALID, "vout empty");
611+
REJECT_INVALID, "bad-txns-vout-empty");
612612
// Size limits
613613
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
614614
return state.DoS(100, error("CheckTransaction() : size limits failed"),
615-
REJECT_INVALID, "oversize");
615+
REJECT_INVALID, "bad-txns-oversize");
616616

617617
// Check for negative or overflow output values
618618
int64_t nValueOut = 0;
619619
BOOST_FOREACH(const CTxOut& txout, tx.vout)
620620
{
621621
if (txout.nValue < 0)
622622
return state.DoS(100, error("CheckTransaction() : txout.nValue negative"),
623-
REJECT_INVALID, "vout negative");
623+
REJECT_INVALID, "bad-txns-vout-negative");
624624
if (txout.nValue > MAX_MONEY)
625625
return state.DoS(100, error("CheckTransaction() : txout.nValue too high"),
626-
REJECT_INVALID, "vout too large");
626+
REJECT_INVALID, "bad-txns-vout-toolarge");
627627
nValueOut += txout.nValue;
628628
if (!MoneyRange(nValueOut))
629629
return state.DoS(100, error("CheckTransaction() : txout total out of range"),
630-
REJECT_INVALID, "txout total too large");
630+
REJECT_INVALID, "bad-txns-txouttotal-toolarge");
631631
}
632632

633633
// Check for duplicate inputs
@@ -636,22 +636,22 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
636636
{
637637
if (vInOutPoints.count(txin.prevout))
638638
return state.DoS(100, error("CheckTransaction() : duplicate inputs"),
639-
REJECT_INVALID, "duplicate inputs");
639+
REJECT_INVALID, "bad-txns-inputs-duplicate");
640640
vInOutPoints.insert(txin.prevout);
641641
}
642642

643643
if (tx.IsCoinBase())
644644
{
645645
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
646646
return state.DoS(100, error("CheckTransaction() : coinbase script size"),
647-
REJECT_INVALID, "coinbase script too large");
647+
REJECT_INVALID, "bad-cb-length");
648648
}
649649
else
650650
{
651651
BOOST_FOREACH(const CTxIn& txin, tx.vin)
652652
if (txin.prevout.IsNull())
653653
return state.DoS(10, error("CheckTransaction() : prevout is null"),
654-
REJECT_INVALID, "prevout null");
654+
REJECT_INVALID, "bad-txns-prevout-null");
655655
}
656656

657657
return true;
@@ -759,7 +759,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
759759
// are the actual inputs available?
760760
if (!view.HaveInputs(tx))
761761
return state.Invalid(error("AcceptToMemoryPool : inputs already spent"),
762-
REJECT_DUPLICATE, "inputs spent");
762+
REJECT_DUPLICATE, "bad-txns-inputs-spent");
763763

764764
// Bring the best block into scope
765765
view.GetBestBlock();
@@ -1404,30 +1404,30 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach
14041404
if (nSpendHeight - coins.nHeight < COINBASE_MATURITY)
14051405
return state.Invalid(
14061406
error("CheckInputs() : tried to spend coinbase at depth %d", nSpendHeight - coins.nHeight),
1407-
REJECT_INVALID, "premature spend of coinbase");
1407+
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
14081408
}
14091409

14101410
// Check for negative or overflow input values
14111411
nValueIn += coins.vout[prevout.n].nValue;
14121412
if (!MoneyRange(coins.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
14131413
return state.DoS(100, error("CheckInputs() : txin values out of range"),
1414-
REJECT_INVALID, "input values out of range");
1414+
REJECT_INVALID, "bad-txns-inputvalues-outofrange");
14151415

14161416
}
14171417

14181418
if (nValueIn < tx.GetValueOut())
14191419
return state.DoS(100, error("CheckInputs() : %s value in < value out", tx.GetHash().ToString()),
1420-
REJECT_INVALID, "in < out");
1420+
REJECT_INVALID, "bad-txns-in-belowout");
14211421

14221422
// Tally transaction fees
14231423
int64_t nTxFee = nValueIn - tx.GetValueOut();
14241424
if (nTxFee < 0)
14251425
return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", tx.GetHash().ToString()),
1426-
REJECT_INVALID, "fee < 0");
1426+
REJECT_INVALID, "bad-txns-fee-negative");
14271427
nFees += nTxFee;
14281428
if (!MoneyRange(nFees))
14291429
return state.DoS(100, error("CheckInputs() : nFees out of range"),
1430-
REJECT_INVALID, "fee out of range");
1430+
REJECT_INVALID, "bad-txns-fee-outofrange");
14311431

14321432
// The first loop above does all the inexpensive checks.
14331433
// Only if ALL inputs pass do we perform expensive ECDSA signature checks.
@@ -1624,7 +1624,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
16241624
uint256 hash = block.GetTxHash(i);
16251625
if (view.HaveCoins(hash) && !view.GetCoins(hash).IsPruned())
16261626
return state.DoS(100, error("ConnectBlock() : tried to overwrite transaction"),
1627-
REJECT_INVALID, "BIP30");
1627+
REJECT_INVALID, "bad-txns-BIP30");
16281628
}
16291629
}
16301630

@@ -1654,13 +1654,13 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
16541654
nSigOps += GetLegacySigOpCount(tx);
16551655
if (nSigOps > MAX_BLOCK_SIGOPS)
16561656
return state.DoS(100, error("ConnectBlock() : too many sigops"),
1657-
REJECT_INVALID, "too many sigops");
1657+
REJECT_INVALID, "bad-blk-sigops");
16581658

16591659
if (!tx.IsCoinBase())
16601660
{
16611661
if (!view.HaveInputs(tx))
16621662
return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
1663-
REJECT_INVALID, "inputs missing/spent");
1663+
REJECT_INVALID, "bad-txns-inputs-missingorspent");
16641664

16651665
if (fStrictPayToScriptHash)
16661666
{
@@ -1670,7 +1670,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
16701670
nSigOps += GetP2SHSigOpCount(tx, view);
16711671
if (nSigOps > MAX_BLOCK_SIGOPS)
16721672
return state.DoS(100, error("ConnectBlock() : too many sigops"),
1673-
REJECT_INVALID, "too many sigops");
1673+
REJECT_INVALID, "bad-blk-sigops");
16741674
}
16751675

16761676
nFees += view.GetValueIn(tx)-tx.GetValueOut();
@@ -1697,7 +1697,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
16971697
return state.DoS(100,
16981698
error("ConnectBlock() : coinbase pays too much (actual=%"PRId64" vs limit=%"PRId64")",
16991699
block.vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)),
1700-
REJECT_INVALID, "coinbase too large");
1700+
REJECT_INVALID, "bad-cb-amount");
17011701

17021702
if (!control.Wait())
17031703
return state.DoS(100, false);
@@ -2075,26 +2075,26 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
20752075
// Size limits
20762076
if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
20772077
return state.DoS(100, error("CheckBlock() : size limits failed"),
2078-
REJECT_INVALID, "block size too large");
2078+
REJECT_INVALID, "bad-blk-length");
20792079

20802080
// Check proof of work matches claimed amount
20812081
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits))
20822082
return state.DoS(50, error("CheckBlock() : proof of work failed"),
2083-
REJECT_INVALID, "invalid pow");
2083+
REJECT_INVALID, "high-hash");
20842084

20852085
// Check timestamp
20862086
if (block.GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60)
20872087
return state.Invalid(error("CheckBlock() : block timestamp too far in the future"),
2088-
REJECT_INVALID, "time in future");
2088+
REJECT_INVALID, "time-too-new");
20892089

20902090
// First transaction must be coinbase, the rest must not be
20912091
if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
20922092
return state.DoS(100, error("CheckBlock() : first tx is not coinbase"),
2093-
REJECT_INVALID, "no coinbase");
2093+
REJECT_INVALID, "bad-cb-missing");
20942094
for (unsigned int i = 1; i < block.vtx.size(); i++)
20952095
if (block.vtx[i].IsCoinBase())
20962096
return state.DoS(100, error("CheckBlock() : more than one coinbase"),
2097-
REJECT_INVALID, "duplicate coinbase");
2097+
REJECT_INVALID, "bad-cb-multiple");
20982098

20992099
// Check transactions
21002100
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -2114,7 +2114,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
21142114
}
21152115
if (uniqueTx.size() != block.vtx.size())
21162116
return state.DoS(100, error("CheckBlock() : duplicate transaction"),
2117-
REJECT_INVALID, "duplicate transaction", true);
2117+
REJECT_INVALID, "bad-txns-duplicate", true);
21182118

21192119
unsigned int nSigOps = 0;
21202120
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -2123,12 +2123,12 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
21232123
}
21242124
if (nSigOps > MAX_BLOCK_SIGOPS)
21252125
return state.DoS(100, error("CheckBlock() : out-of-bounds SigOpCount"),
2126-
REJECT_INVALID, "sig op count", true);
2126+
REJECT_INVALID, "bad-blk-sigops", true);
21272127

21282128
// Check merkle root
21292129
if (fCheckMerkleRoot && block.hashMerkleRoot != block.vMerkleTree.back())
21302130
return state.DoS(100, error("CheckBlock() : hashMerkleRoot mismatch"),
2131-
REJECT_INVALID, "bad merkle root", true);
2131+
REJECT_INVALID, "bad-txnmrklroot", true);
21322132

21332133
return true;
21342134
}
@@ -2153,18 +2153,18 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
21532153
// Check proof of work
21542154
if (block.nBits != GetNextWorkRequired(pindexPrev, &block))
21552155
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"),
2156-
REJECT_INVALID, "bad pow");
2156+
REJECT_INVALID, "bad-diffbits");
21572157

21582158
// Check timestamp against prev
21592159
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())
21602160
return state.Invalid(error("AcceptBlock() : block's timestamp is too early"),
2161-
REJECT_INVALID, "timestamp too early");
2161+
REJECT_INVALID, "time-too-old");
21622162

21632163
// Check that all transactions are finalized
21642164
BOOST_FOREACH(const CTransaction& tx, block.vtx)
21652165
if (!IsFinalTx(tx, nHeight, block.GetBlockTime()))
21662166
return state.DoS(10, error("AcceptBlock() : contains a non-final transaction"),
2167-
REJECT_INVALID, "non-final tx");
2167+
REJECT_INVALID, "bad-txns-nonfinal");
21682168

21692169
// Check that the block chain matches the known block chain up to a checkpoint
21702170
if (!Checkpoints::CheckBlock(nHeight, hash))
@@ -2178,7 +2178,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
21782178
(TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100)))
21792179
{
21802180
return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
2181-
REJECT_OBSOLETE, "version 1 blocks obsolete");
2181+
REJECT_OBSOLETE, "bad-version");
21822182
}
21832183
}
21842184
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
@@ -2192,7 +2192,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
21922192
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
21932193
!std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin()))
21942194
return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"),
2195-
REJECT_INVALID, "height incorrect in coinbase");
2195+
REJECT_INVALID, "bad-cb-height");
21962196
}
21972197
}
21982198
}
@@ -2285,7 +2285,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
22852285
if (deltaTime < 0)
22862286
{
22872287
return state.DoS(100, error("ProcessBlock() : block with timestamp before last checkpoint"),
2288-
REJECT_CHECKPOINT, "timestamp before checkpoint");
2288+
REJECT_CHECKPOINT, "time-too-old");
22892289
}
22902290
CBigNum bnNewBlock;
22912291
bnNewBlock.SetCompact(pblock->nBits);
@@ -2294,7 +2294,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
22942294
if (bnNewBlock > bnRequired)
22952295
{
22962296
return state.DoS(100, error("ProcessBlock() : block with too little proof-of-work"),
2297-
REJECT_INVALID, "invalid pow");
2297+
REJECT_INVALID, "bad-diffbits");
22982298
}
22992299
}
23002300

0 commit comments

Comments
 (0)