Merge #664: Do non-depth check for peg-in witness where possible

8838e7675 Do non-depth check for peg-in witness where possible (Gregory Sanders)

Pull request description:

  The non-depth check is very cheap, and could be made even cheaper in the future given the proper assumptions. Depth checks are only required for `CheckTxInputs`.

Tree-SHA512: 46b9214146c49a0a82147927b897e51af98852ecb86a7a6dd220b7daf4a4a443d262dc576f958642e70476f283733e1c7022f3c0c7214d57581a8cbf3a8f0f2c
This commit is contained in:
Steven Roose 2019-06-13 16:53:55 +01:00
commit c977f2b99d
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87
2 changed files with 7 additions and 7 deletions

View file

@ -162,7 +162,8 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
CTxOut prevout;
if (tx.vin[i].m_is_pegin) {
std::string err;
if (tx.witness.vtxinwit.size() <= i || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, true)) {
// Make sure witness exists and is properly formatted
if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, false)) {
continue;
}
prevout = GetPeginOutputFromWitness(tx.witness.vtxinwit[i].m_pegin_witness);

View file

@ -700,12 +700,11 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
// This only checks the UTXO set for already claimed pegins. For mempool conflicts,
// we rely on the GetConflictTx check done above.
if (txin.m_is_pegin) {
// Quick sanity check on witness first.
if (tx.witness.vtxinwit.size() <= i ||
tx.witness.vtxinwit[i].m_pegin_witness.stack.size() < 6 ||
uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]).IsNull() ||
tx.vin[i].prevout.hash.IsNull()) {
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness");
// Peg-in witness is required, check here without validating existence in parent chain
std::string err_msg = "no peg-in witness attached";
if (tx.witness.vtxinwit.size() != tx.vin.size() ||
!IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err_msg, false)) {
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness", err_msg);
}
std::pair<uint256, COutPoint> pegin = std::make_pair(uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]), tx.vin[i].prevout);