mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
[validation] Improve script check error reporting
Github-Pull: #31097
Rebased-From: f859ff8a4e
This commit is contained in:
parent
1248d0da22
commit
2d69e4c454
@ -2181,6 +2181,8 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
|
|||||||
if (pvChecks) {
|
if (pvChecks) {
|
||||||
pvChecks->emplace_back(std::move(check));
|
pvChecks->emplace_back(std::move(check));
|
||||||
} else if (!check()) {
|
} else if (!check()) {
|
||||||
|
ScriptError error{check.GetScriptError()};
|
||||||
|
|
||||||
if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
|
if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
|
||||||
// Check whether the failure was caused by a
|
// Check whether the failure was caused by a
|
||||||
// non-mandatory script verification check, such as
|
// non-mandatory script verification check, such as
|
||||||
@ -2194,6 +2196,14 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
|
|||||||
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
|
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
|
||||||
if (check2())
|
if (check2())
|
||||||
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
|
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
|
||||||
|
|
||||||
|
// If the second check failed, it failed due to a mandatory script verification
|
||||||
|
// flag, but the first check might have failed on a non-mandatory script
|
||||||
|
// verification flag.
|
||||||
|
//
|
||||||
|
// Avoid reporting a mandatory script check failure with a non-mandatory error
|
||||||
|
// string by reporting the error from the second check.
|
||||||
|
error = check2.GetScriptError();
|
||||||
}
|
}
|
||||||
// MANDATORY flag failures correspond to
|
// MANDATORY flag failures correspond to
|
||||||
// TxValidationResult::TX_CONSENSUS. Because CONSENSUS
|
// TxValidationResult::TX_CONSENSUS. Because CONSENSUS
|
||||||
@ -2204,7 +2214,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
|
|||||||
// support, to avoid splitting the network (but this
|
// support, to avoid splitting the network (but this
|
||||||
// depends on the details of how net_processing handles
|
// depends on the details of how net_processing handles
|
||||||
// such errors).
|
// such errors).
|
||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(check.GetScriptError())));
|
return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(error)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user