diff --git a/src/avalanche/validation.h b/src/avalanche/validation.h --- a/src/avalanche/validation.h +++ b/src/avalanche/validation.h @@ -22,11 +22,11 @@ ProofValidationResult m_result = ProofValidationResult::NONE; public: - bool Invalid(ProofValidationResult result, unsigned int chRejectCodeIn = 0, + bool Invalid(ProofValidationResult result, const std::string &reject_reason = "", const std::string &debug_message = "") { m_result = result; - ValidationState::Invalid(chRejectCodeIn, reject_reason, debug_message); + ValidationState::Invalid(reject_reason, debug_message); return false; } ProofValidationResult GetResult() const { return m_result; } diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp --- a/src/consensus/tx_check.cpp +++ b/src/consensus/tx_check.cpp @@ -14,18 +14,18 @@ TxValidationState &state) { // Basic checks that don't depend on any context if (tx.vin.empty()) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vin-empty"); } if (tx.vout.empty()) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-empty"); } // Size limit if (::GetSerializeSize(tx, PROTOCOL_VERSION) > MAX_TX_SIZE) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-oversize"); } @@ -34,18 +34,17 @@ for (const auto &txout : tx.vout) { if (txout.nValue < Amount::zero()) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-vout-negative"); + "bad-txns-vout-negative"); } if (txout.nValue > MAX_MONEY) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-vout-toolarge"); + "bad-txns-vout-toolarge"); } nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } } @@ -55,8 +54,8 @@ bool CheckCoinbase(const CTransaction &tx, TxValidationState &state) { if (!tx.IsCoinBase()) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, - "bad-cb-missing", "first tx is not coinbase"); + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-missing", + "first tx is not coinbase"); } if (!CheckTransactionCommon(tx, state)) { @@ -66,8 +65,7 @@ if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > MAX_COINBASE_SCRIPTSIG_SIZE) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, - "bad-cb-length"); + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cb-length"); } return true; @@ -75,7 +73,7 @@ bool CheckRegularTransaction(const CTransaction &tx, TxValidationState &state) { if (tx.IsCoinBase()) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-tx-coinbase"); } @@ -88,7 +86,7 @@ for (const auto &txin : tx.vin) { if (txin.prevout.IsNull()) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-prevout-null"); + "bad-txns-prevout-null"); } // Check for duplicate inputs (see CVE-2018-17144) @@ -99,7 +97,7 @@ // implementation of the underlying coins database. if (!vInOutPoints.insert(txin.prevout).second) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-inputs-duplicate"); + "bad-txns-inputs-duplicate"); } } diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -45,7 +45,7 @@ if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) { // While this is only one transaction, we use txns in the error to // ensure continuity with other clients. - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-nonfinal", "non-final transaction"); } @@ -53,7 +53,7 @@ // Size limit if (::GetSerializeSize(tx, PROTOCOL_VERSION) < MIN_TX_SIZE) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-undersize"); + "bad-txns-undersize"); } } @@ -161,7 +161,7 @@ // are the actual inputs available? if (!inputs.HaveInputs(tx)) { return state.Invalid(TxValidationResult::TX_MISSING_INPUTS, - REJECT_INVALID, "bad-txns-inputs-missingorspent", + "bad-txns-inputs-missingorspent", strprintf("%s: inputs missing/spent", __func__)); } @@ -175,7 +175,7 @@ if (coin.IsCoinBase() && nSpendHeight - coin.GetHeight() < COINBASE_MATURITY) { return state.Invalid( - TxValidationResult::TX_PREMATURE_SPEND, REJECT_INVALID, + TxValidationResult::TX_PREMATURE_SPEND, "bad-txns-premature-spend-of-coinbase", strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.GetHeight())); @@ -185,24 +185,22 @@ nValueIn += coin.GetTxOut().nValue; if (!MoneyRange(coin.GetTxOut().nValue) || !MoneyRange(nValueIn)) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "bad-txns-inputvalues-outofrange"); } } const Amount value_out = tx.GetValueOut(); if (nValueIn < value_out) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, - "bad-txns-in-belowout", - strprintf("value in (%s) < value out (%s)", - FormatMoney(nValueIn), - FormatMoney(value_out))); + return state.Invalid( + TxValidationResult::TX_CONSENSUS, "bad-txns-in-belowout", + strprintf("value in (%s) < value out (%s)", FormatMoney(nValueIn), + FormatMoney(value_out))); } // Tally transaction fees const Amount txfee_aux = nValueIn - value_out; if (!MoneyRange(txfee_aux)) { - return state.Invalid(TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-fee-outofrange"); } diff --git a/src/consensus/validation.h b/src/consensus/validation.h --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -9,20 +9,9 @@ #include #include -/** "reject" message codes */ -static const uint8_t REJECT_MALFORMED = 0x01; -static const uint8_t REJECT_INVALID = 0x10; -static const uint8_t REJECT_OBSOLETE = 0x11; -static const uint8_t REJECT_DUPLICATE = 0x12; -static const uint8_t REJECT_NONSTANDARD = 0x40; -static const uint8_t REJECT_INSUFFICIENTFEE = 0x42; -static const uint8_t REJECT_CHECKPOINT = 0x43; - /** * A "reason" why a transaction was invalid, suitable for determining whether * the provider of the transaction should be banned/ignored/disconnected/etc. - * These are much more granular than the rejection codes, which may be more - * useful for some other use-cases. */ enum class TxValidationResult { //! initial value. Tx has not yet been rejected @@ -102,14 +91,11 @@ MODE_ERROR, //!< run-time error } m_mode; std::string m_reject_reason; - unsigned int chRejectCode; std::string m_debug_message; protected: - void Invalid(unsigned int chRejectCodeIn = 0, - const std::string &reject_reason = "", + void Invalid(const std::string &reject_reason = "", const std::string &debug_message = "") { - chRejectCode = chRejectCodeIn; m_reject_reason = reject_reason; m_debug_message = debug_message; if (m_mode != MODE_ERROR) { @@ -121,7 +107,7 @@ // ValidationState is abstract. Have a pure virtual destructor. virtual ~ValidationState() = 0; - ValidationState() : m_mode(MODE_VALID), chRejectCode(0) {} + ValidationState() : m_mode(MODE_VALID) {} bool Error(const std::string &reject_reason) { if (m_mode == MODE_VALID) { m_reject_reason = reject_reason; @@ -132,7 +118,6 @@ bool IsValid() const { return m_mode == MODE_VALID; } bool IsInvalid() const { return m_mode == MODE_INVALID; } bool IsError() const { return m_mode == MODE_ERROR; } - unsigned int GetRejectCode() const { return chRejectCode; } std::string GetRejectReason() const { return m_reject_reason; } std::string GetDebugMessage() const { return m_debug_message; } }; @@ -144,11 +129,11 @@ TxValidationResult m_result = TxValidationResult::TX_RESULT_UNSET; public: - bool Invalid(TxValidationResult result, unsigned int chRejectCodeIn = 0, + bool Invalid(TxValidationResult result, const std::string &reject_reason = "", const std::string &debug_message = "") { m_result = result; - ValidationState::Invalid(chRejectCodeIn, reject_reason, debug_message); + ValidationState::Invalid(reject_reason, debug_message); return false; } TxValidationResult GetResult() const { return m_result; } @@ -159,11 +144,11 @@ BlockValidationResult m_result = BlockValidationResult::BLOCK_RESULT_UNSET; public: - bool Invalid(BlockValidationResult result, unsigned int chRejectCodeIn = 0, + bool Invalid(BlockValidationResult result, const std::string &reject_reason = "", const std::string &debug_message = "") { m_result = result; - ValidationState::Invalid(chRejectCodeIn, reject_reason, debug_message); + ValidationState::Invalid(reject_reason, debug_message); return false; } BlockValidationResult GetResult() const { return m_result; } diff --git a/src/test/blockcheck_tests.cpp b/src/test/blockcheck_tests.cpp --- a/src/test/blockcheck_tests.cpp +++ b/src/test/blockcheck_tests.cpp @@ -36,7 +36,6 @@ BlockValidationState state; RunCheckOnBlockImpl(config, block, state, false); - BOOST_CHECK_EQUAL(state.GetRejectCode(), REJECT_INVALID); BOOST_CHECK_EQUAL(state.GetRejectReason(), reason); } diff --git a/src/test/checkpoints_tests.cpp b/src/test/checkpoints_tests.cpp --- a/src/test/checkpoints_tests.cpp +++ b/src/test/checkpoints_tests.cpp @@ -174,7 +174,6 @@ BlockValidationState state; BOOST_CHECK(!ProcessNewBlockHeaders(config, {headerB}, state, &pindex)); BOOST_CHECK(state.IsInvalid()); - BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); BOOST_CHECK(state.GetRejectReason() == "bad-fork-prior-to-checkpoint"); BOOST_CHECK(pindex == nullptr); } @@ -191,7 +190,6 @@ BOOST_CHECK( !ProcessNewBlockHeaders(config, {headerAB}, state, &pindex)); BOOST_CHECK(state.IsInvalid()); - BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); BOOST_CHECK(state.GetRejectReason() == "checkpoint mismatch"); BOOST_CHECK(pindex == nullptr); } diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -801,7 +801,6 @@ params, minTx, state, magneticAnomalyActivationHeight - 1, 5678, 1234)); BOOST_CHECK(!ContextualCheckTransaction( params, minTx, state, magneticAnomalyActivationHeight, 5678, 1234)); - BOOST_CHECK_EQUAL(state.GetRejectCode(), REJECT_INVALID); BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-txns-undersize"); } diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -1106,17 +1106,6 @@ int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms); -/** - * Reject codes greater or equal to this can be returned by AcceptToMemPool or - * AcceptBlock for blocks/transactions, to signal internal conditions. They - * cannot and should not be sent over the P2P network. - */ -static const unsigned int REJECT_INTERNAL = 0x100; -/** Too high fee. Can not be triggered by P2P transactions */ -static const unsigned int REJECT_HIGHFEE = 0x100; -/** Block conflicts with a transaction already known */ -static const unsigned int REJECT_AGAINST_FINALIZED = 0x103; - /** Get block file info entry for one block file */ CBlockFileInfo *GetBlockFileInfo(size_t n); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -361,8 +361,7 @@ // Rather not work on nonstandard transactions (unless -testnet) std::string reason; if (fRequireStandard && !IsStandardTx(tx, reason)) { - return state.Invalid(TxValidationResult::TX_NOT_STANDARD, - REJECT_NONSTANDARD, reason); + return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason); } // Only accept nLockTime-using transactions that can be mined in the next @@ -374,13 +373,13 @@ // We copy the state from a dummy to ensure we don't increase the // ban score of peer for transaction that could be valid in the future. return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, - REJECT_NONSTANDARD, ctxState.GetRejectReason(), + ctxState.GetRejectReason(), ctxState.GetDebugMessage()); } // Is it already in the memory pool? if (pool.exists(txid)) { - return state.Invalid(TxValidationResult::TX_CONFLICT, REJECT_DUPLICATE, + return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-already-in-mempool"); } @@ -390,7 +389,7 @@ if (itConflicting != pool.mapNextTx.end()) { // Disable replacement feature for good return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, - REJECT_DUPLICATE, "txn-mempool-conflict"); + "txn-mempool-conflict"); } } @@ -420,7 +419,6 @@ // outputs. if (coins_cache.HaveCoinInCache(COutPoint(txid, out))) { return state.Invalid(TxValidationResult::TX_CONFLICT, - REJECT_DUPLICATE, "txn-already-known"); } } @@ -428,7 +426,6 @@ // Otherwise assume this might be an orphan tx for which we just // haven't seen parents yet. return state.Invalid(TxValidationResult::TX_MISSING_INPUTS, - REJECT_INVALID, "bad-txns-inputs-missingorspent"); } } @@ -436,7 +433,7 @@ // Are the actual inputs available? if (!view.HaveInputs(tx)) { return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, - REJECT_DUPLICATE, "bad-txns-inputs-spent"); + "bad-txns-inputs-spent"); } // Bring the best block into scope. @@ -454,7 +451,7 @@ if (!CheckSequenceLocks(pool, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp)) { return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, - REJECT_NONSTANDARD, "non-BIP68-final"); + "non-BIP68-final"); } Amount nFees = Amount::zero(); @@ -471,7 +468,6 @@ if (fRequireStandard && !AreInputsStandard(tx, view, nextBlockScriptVerifyFlags)) { return state.Invalid(TxValidationResult::TX_NOT_STANDARD, - REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs"); } @@ -498,13 +494,12 @@ // policy upgrade. if (!bypass_limits && nModifiedFees < minRelayTxFee.GetFee(nSize)) { return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, - REJECT_INSUFFICIENTFEE, "min relay fee not met"); } if (nAbsurdFee != Amount::zero() && nFees > nAbsurdFee) { return state.Invalid(TxValidationResult::TX_NOT_STANDARD, - REJECT_HIGHFEE, "absurdly-high-fee", + "absurdly-high-fee", strprintf("%d > %d", nFees, nAbsurdFee)); } @@ -532,7 +527,7 @@ if (!bypass_limits && mempoolRejectFee > Amount::zero() && nModifiedFees < mempoolRejectFee) { return state.Invalid( - TxValidationResult::TX_MEMPOOL_POLICY, REJECT_INSUFFICIENTFEE, + TxValidationResult::TX_MEMPOOL_POLICY, "mempool min fee not met", strprintf("%d < %d", nModifiedFees, mempoolRejectFee)); } @@ -555,8 +550,7 @@ entry, setAncestors, nLimitAncestors, nLimitAncestorSize, nLimitDescendants, nLimitDescendantSize, errString)) { return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, - REJECT_NONSTANDARD, "too-long-mempool-chain", - errString); + "too-long-mempool-chain", errString); } // Check again against the next block's script verification flags @@ -608,7 +602,7 @@ gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}); if (!pool.exists(txid)) { return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, - REJECT_INSUFFICIENTFEE, "mempool full"); + "mempool full"); } } } @@ -1023,7 +1017,7 @@ (pBlockLimitSigChecks && !pBlockLimitSigChecks->consume_and_check(nSigChecksOut))) { return state.Invalid(TxValidationResult::TX_CONSENSUS, - REJECT_INVALID, "too-many-sigchecks"); + "too-many-sigchecks"); } return true; } @@ -1069,7 +1063,7 @@ sigCacheStore, txdata); if (check2()) { return state.Invalid( - TxValidationResult::TX_NOT_STANDARD, REJECT_NONSTANDARD, + TxValidationResult::TX_NOT_STANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(scriptError))); } @@ -1085,7 +1079,7 @@ // support, to avoid splitting the network (but this depends on the // details of how net_processing handles such errors). return state.Invalid( - TxValidationResult::TX_CONSENSUS, REJECT_INVALID, + TxValidationResult::TX_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(scriptError))); } @@ -1618,7 +1612,7 @@ LogPrintf("ERROR: ConnectBlock(): tried to overwrite " "transaction\n"); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-txns-BIP30"); + "bad-txns-BIP30"); } } } @@ -1676,7 +1670,7 @@ // with checkpointing off. LogPrintf("ERROR: ConnectBlock(): tried to overwrite transaction\n"); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "tx-duplicate"); + "tx-duplicate"); } size_t txIndex = 0; @@ -1694,7 +1688,6 @@ // Any transaction validation failure in ConnectBlock is a block // consensus failure. state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - tx_state.GetRejectCode(), tx_state.GetRejectReason(), tx_state.GetDebugMessage()); @@ -1708,7 +1701,6 @@ LogPrintf("ERROR: %s: accumulated fee in the block out of range.\n", __func__); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-txns-accumulated-fee-outofrange"); } @@ -1729,7 +1721,7 @@ LogPrintf("ERROR: %s: contains a non-BIP68-final transaction\n", __func__); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-txns-nonfinal"); + "bad-txns-nonfinal"); } // Don't cache results if we're actually connecting blocks (still @@ -1757,7 +1749,7 @@ // Any transaction validation failure in ConnectBlock is a block // consensus failure state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - tx_state.GetRejectCode(), tx_state.GetRejectReason(), + tx_state.GetRejectReason(), tx_state.GetDebugMessage()); return error("ConnectBlock(): CheckInputs on %s failed with %s", tx.GetId().ToString(), FormatStateMessage(state)); @@ -1791,7 +1783,7 @@ "limit=%d)\n", block.vtx[0]->GetValueOut(), blockReward); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-cb-amount"); + "bad-cb-amount"); } const std::vector whitelist = @@ -1819,15 +1811,14 @@ // We did not find an output that match the miner fund requirements. return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-cb-minerfund"); + "bad-cb-minerfund"); } MinerFundSuccess: if (!control.Wait()) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "blk-bad-inputs", - "parallel script check failed"); + "blk-bad-inputs", "parallel script check failed"); } int64_t nTime4 = GetTimeMicros(); @@ -2234,7 +2225,7 @@ LogPrintf("ERROR: %s: Trying to finalize invalid block %s\n", __func__, pindex->GetBlockHash().ToString()); return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, - REJECT_INVALID, "finalize-invalid-block"); + "finalize-invalid-block"); } // Check that the request is consistent with current finalization. @@ -2244,7 +2235,6 @@ "already finalized block\n", __func__, pindex->GetBlockHash().ToString()); return state.Invalid(BlockValidationResult::BLOCK_FINALIZATION, - REJECT_AGAINST_FINALIZED, "bad-fork-prior-finalized"); } @@ -3514,8 +3504,7 @@ if (validationOptions.shouldValidatePoW() && !CheckProofOfWork(block.GetHash(), block.nBits, params)) { return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, - REJECT_INVALID, "high-hash", - "proof of work failed"); + "high-hash", "proof of work failed"); } return true; @@ -3541,8 +3530,7 @@ uint256 hashMerkleRoot2 = BlockMerkleRoot(block, &mutated); if (block.hashMerkleRoot != hashMerkleRoot2) { return state.Invalid(BlockValidationResult::BLOCK_MUTATED, - REJECT_INVALID, "bad-txnmrklroot", - "hashMerkleRoot mismatch"); + "bad-txnmrklroot", "hashMerkleRoot mismatch"); } // Check for merkle tree malleability (CVE-2012-2459): repeating @@ -3550,8 +3538,7 @@ // root of a block, while still invalidating it. if (mutated) { return state.Invalid(BlockValidationResult::BLOCK_MUTATED, - REJECT_INVALID, "bad-txns-duplicate", - "duplicate transaction"); + "bad-txns-duplicate", "duplicate transaction"); } } @@ -3562,8 +3549,7 @@ // First transaction must be coinbase. if (block.vtx.empty()) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-cb-missing", - "first tx is not coinbase"); + "bad-cb-missing", "first tx is not coinbase"); } // Size limits. @@ -3572,22 +3558,19 @@ // Bail early if there is no way this block is of reasonable size. if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-blk-length", - "size limits failed"); + "bad-blk-length", "size limits failed"); } auto currentBlockSize = ::GetSerializeSize(block, PROTOCOL_VERSION); if (currentBlockSize > nMaxBlockSize) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-blk-length", - "size limits failed"); + "bad-blk-length", "size limits failed"); } // And a valid coinbase. TxValidationState tx_state; if (!CheckCoinbase(*block.vtx[0], tx_state)) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - tx_state.GetRejectCode(), tx_state.GetRejectReason(), strprintf("Coinbase check failed (txid %s) %s", block.vtx[0]->GetId().ToString(), @@ -3601,7 +3584,7 @@ if (!CheckRegularTransaction(*tx, tx_state)) { return state.Invalid( BlockValidationResult::BLOCK_CONSENSUS, - tx_state.GetRejectCode(), tx_state.GetRejectReason(), + tx_state.GetRejectReason(), strprintf("Transaction check failed (txid %s) %s", tx->GetId().ToString(), tx_state.GetDebugMessage())); } @@ -3638,8 +3621,7 @@ if (block.nBits != GetNextWorkRequired(pindexPrev, &block, params)) { LogPrintf("bad bits after height: %d\n", pindexPrev->nHeight); return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, - REJECT_INVALID, "bad-diffbits", - "incorrect proof of work"); + "bad-diffbits", "incorrect proof of work"); } // Check against checkpoints @@ -3652,7 +3634,7 @@ LogPrintf("ERROR: %s: rejected by checkpoint lock-in at %d\n", __func__, nHeight); return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, - REJECT_CHECKPOINT, "checkpoint mismatch"); + "checkpoint mismatch"); } // Don't accept any forks from the main chain prior to last checkpoint. @@ -3664,7 +3646,6 @@ "(height %d)\n", __func__, nHeight); return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, - REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint"); } } @@ -3672,14 +3653,13 @@ // Check timestamp against prev if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) { return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, - REJECT_INVALID, "time-too-old", - "block's timestamp is too early"); + "time-too-old", "block's timestamp is too early"); } // Check timestamp if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) { return state.Invalid(BlockValidationResult::BLOCK_TIME_FUTURE, - REJECT_INVALID, "time-too-new", + "time-too-new", "block timestamp too far in the future"); } @@ -3691,7 +3671,7 @@ (block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) || (block.nVersion < 4 && nHeight >= consensusParams.BIP65Height)) { return state.Invalid( - BlockValidationResult::BLOCK_INVALID_HEADER, REJECT_OBSOLETE, + BlockValidationResult::BLOCK_INVALID_HEADER, strprintf("bad-version(0x%08x)", block.nVersion), strprintf("rejected nVersion=0x%08x block", block.nVersion)); } @@ -3781,14 +3761,13 @@ if (prevTx && (tx.GetId() <= prevTx->GetId())) { if (tx.GetId() == prevTx->GetId()) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "tx-duplicate", + "tx-duplicate", strprintf("Duplicated transaction %s", tx.GetId().ToString())); } return state.Invalid( - BlockValidationResult::BLOCK_CONSENSUS, REJECT_INVALID, - "tx-ordering", + BlockValidationResult::BLOCK_CONSENSUS, "tx-ordering", strprintf("Transaction order is invalid (%s < %s)", tx.GetId().ToString(), prevTx->GetId().ToString())); @@ -3803,7 +3782,7 @@ if (!ContextualCheckTransaction(params, tx, tx_state, nHeight, nLockTimeCutoff, nMedianTimePast)) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, tx_state.GetRejectReason(), + tx_state.GetRejectReason(), tx_state.GetDebugMessage()); } } @@ -3815,7 +3794,7 @@ !std::equal(expect.begin(), expect.end(), block.vtx[0]->vin[0].scriptSig.begin())) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, - REJECT_INVALID, "bad-cb-height", + "bad-cb-height", "block height mismatch in coinbase"); } } @@ -3851,8 +3830,7 @@ LogPrintf("ERROR: %s: block %s is marked invalid\n", __func__, hash.ToString()); return state.Invalid( - BlockValidationResult::BLOCK_CACHED_INVALID, 0, - "duplicate"); + BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate"); } return true; @@ -3868,7 +3846,7 @@ BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock); if (mi == m_block_index.end()) { LogPrintf("ERROR: %s: prev block not found\n", __func__); - return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, 0, + return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found"); } @@ -3877,7 +3855,7 @@ if (pindexPrev->nStatus.isInvalid()) { LogPrintf("ERROR: %s: prev block invalid\n", __func__); return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, - REJECT_INVALID, "bad-prevblk"); + "bad-prevblk"); } if (!ContextualCheckBlockHeader(chainparams, block, state, pindexPrev, @@ -3924,7 +3902,7 @@ LogPrintf("ERROR: %s: prev block invalid\n", __func__); return state.Invalid( BlockValidationResult::BLOCK_INVALID_PREV, - REJECT_INVALID, "bad-prevblk"); + "bad-prevblk"); } } }