Skip to content

Commit d926fd0

Browse files
committed
Ability to ignore AreInputsStandard rejection reasons
1 parent b716189 commit d926fd0

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/policy/policy.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
194194
*
195195
* Note that only the non-witness portion of the transaction is checked here.
196196
*/
197-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason)
197+
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason, const ignore_rejects_type& ignore_rejects)
198198
{
199199
if (tx.IsCoinBase()) {
200200
return true; // Coinbases don't use vin normally
@@ -206,32 +206,37 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs,
206206
std::vector<std::vector<unsigned char> > vSolutions;
207207
TxoutType whichType = Solver(prev.scriptPubKey, vSolutions);
208208
if (whichType == TxoutType::NONSTANDARD) {
209-
out_reason = reason_prefix + "script-unknown";
210-
return false;
209+
MaybeReject("script-unknown");
211210
} else if (whichType == TxoutType::WITNESS_UNKNOWN) {
212211
// WITNESS_UNKNOWN failures are typically also caught with a policy
213212
// flag in the script interpreter, but it can be helpful to catch
214213
// this type of NONSTANDARD transaction earlier in transaction
215214
// validation.
216-
out_reason = reason_prefix + "witness-unknown";
217-
return false;
215+
MaybeReject("witness-unknown");
218216
} else if (whichType == TxoutType::SCRIPTHASH) {
217+
if (!tx.vin[i].scriptSig.IsPushOnly()) {
218+
// The only way we got this far, is if the user ignored scriptsig-not-pushonly.
219+
// However, this case is invalid, and will be caught later on.
220+
// But for now, we don't want to run the [possibly expensive] script here.
221+
continue;
222+
}
219223
std::vector<std::vector<unsigned char> > stack;
220224
// convert the scriptSig into a stack, so we can inspect the redeemScript
221225
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
222226
{
227+
// This case is also invalid or a bug
223228
out_reason = reason_prefix + "scriptsig-failure";
224229
return false;
225230
}
226231
if (stack.empty())
227232
{
233+
// Also invalid
228234
out_reason = reason_prefix + "scriptcheck-missing";
229235
return false;
230236
}
231237
CScript subscript(stack.back().begin(), stack.back().end());
232238
if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
233-
out_reason = reason_prefix + "scriptcheck-sigops";
234-
return false;
239+
MaybeReject("scriptcheck-sigops");
235240
}
236241
}
237242
}

src/policy/policy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
147147
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
148148
* @return True if all inputs (scriptSigs) use only standard transaction forms
149149
*/
150-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason);
150+
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
151151

152152
inline bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs) {
153153
std::string reason;

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
919919
return false; // state filled in by CheckTxInputs
920920
}
921921

922-
if (m_pool.m_opts.require_standard && !AreInputsStandard(tx, m_view, "bad-txns-input-", reason)) {
922+
if (m_pool.m_opts.require_standard && !AreInputsStandard(tx, m_view, "bad-txns-input-", reason, ignore_rejects)) {
923923
return state.Invalid(TxValidationResult::TX_INPUTS_NOT_STANDARD, reason);
924924
}
925925

0 commit comments

Comments
 (0)