Closed shohu closed 6 years ago
/**
* Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
* This does not modify the UTXO set.
*
* If pvChecks is not nullptr, script checks are pushed onto it instead of being performed inline. Any
* script checks which are not necessary (eg due to script execution cache hits) are, obviously,
* not pushed onto pvChecks/run.
*
* Setting cacheSigStore/cacheFullScriptStore to false will remove elements from the corresponding cache
* which are matched. This is useful for checking blocks where we will likely never need the cache
* entry again.
*
* Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
*/
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
{
:
:
for (unsigned int i = 0; i < tx.vin.size(); i++) {
const COutPoint &prevout = tx.vin[i].prevout;
const Coin& coin = inputs.AccessCoin(prevout);
assert(!coin.IsSpent());
// We very carefully only pass in things to CScriptCheck which
// are clearly committed to by tx' witness hash. This provides
// a sanity check that our caching is not introducing consensus
// failures through additional data in, eg, the coins being
// spent being checked as a part of CScriptCheck.
const CScript& scriptPubKey = coin.out.scriptPubKey;
const CAmount amount = coin.out.nValue;
// Verify signature
CScriptCheck check(scriptPubKey, amount, tx, i, flags, cacheSigStore, &txdata);
if (pvChecks) {
pvChecks->push_back(CScriptCheck());
check.swap(pvChecks->back());
} else if (!check()) {
if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) {
// Check whether the failure was caused by a
// non-mandatory script verification check, such as
// non-standard DER encodings or non-null dummy
// arguments; if so, don't trigger DoS protection to
// avoid splitting the network between upgraded and
// non-upgraded nodes.
CScriptCheck check2(scriptPubKey, amount, tx, i,
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
if (check2())
return state.Invalid(false, REJECT_NONSTANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
}
// Failures of other flags indicate a transaction that is
// invalid in new blocks, e.g. an invalid P2SH. We DoS ban
// such nodes as they are not following the protocol. That
// said during an upgrade careful thought should be taken
// as to the correct behavior - we may want to continue
// peering with non-upgraded nodes even after soft-fork
// super-majority signaling has occurred.
return state.DoS(100,false, REJECT_INVALID, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(check.GetScriptError())));
}
}
đź‘Ť
# test/functional/segwit.py
2018-03-22 05:44:56.455000 TestFramework (INFO): Initializing test directory /tmp/testd4pb60ap
2018-03-22 05:44:57.509000 TestFramework (INFO): Verify sigops are counted in GBT with pre-BIP141 rules before the fork
2018-03-22 05:44:58.891000 TestFramework (INFO): Verify default node can't accept any witness format txs before fork
2018-03-22 05:44:58.914000 TestFramework (INFO): Verify witness txs are skipped for mining before the fork
2018-03-22 05:44:59.097000 TestFramework (INFO): Verify unsigned bare witness txs in versionbits-setting blocks are valid before the fork
2018-03-22 05:44:59.135000 TestFramework (INFO): Verify unsigned p2sh witness txs without a redeem script are invalid
2018-03-22 05:44:59.139000 TestFramework (INFO): Verify unsigned p2sh witness txs with a redeem script in versionbits-settings blocks are valid before the fork
2018-03-22 05:44:59.169000 TestFramework (INFO): Verify previous witness txs skipped for mining can now be mined
2018-03-22 05:44:59.188000 TestFramework (INFO): Verify block and transaction serialization rpcs return differing serializations depending on rpc serialization flag
2018-03-22 05:44:59.243000 TestFramework (INFO): Verify witness txs without witness data are invalid after the fork
2018-03-22 05:44:59.292000 TestFramework (INFO): Verify default node can now use witness txs
2018-03-22 05:44:59.368000 TestFramework (INFO): Verify sigops are counted in GBT with BIP141 rules after the fork
2018-03-22 05:44:59.407000 TestFramework (INFO): Non-segwit miners are able to use GBT response after activation.
2018-03-22 05:44:59.493000 TestFramework (INFO): Verify behaviour of importaddress, addwitnessaddress and listunspent
2018-03-22 05:45:02.233000 TestFramework (INFO): Stopping nodes
2018-03-22 05:45:04.372000 TestFramework (INFO): Cleaning up
2018-03-22 05:45:04.377000 TestFramework (INFO): Tests successful