Break the function into 2 loops so that:
- the fast test is executed first for all inputs.
IsMine(txout)is only executed after all inputs are checked.
This is relevant since after #12296 CWallet::IsAllFromMe is called from the UI.
This needs benchmarking/profliling results. As discussed on IRC, it's not clear how to evaluate changes like this right now.
1429 | + outs.push_back(&prev.tx->vout[txin.prevout.n]); 1430 | } 1431 | + 1432 | + assert(outs.size() == tx.vin.size()); 1433 | + 1434 | + // then check if every isminetype matches filter
Would suggest adding a comment that the code is intentionally written to use 2 passes for better performance. Otherwise it's unclear why the code would be organized this way.
Done. PR description also explains the idea behind the 2 loops.
utACK 8ee4bd5837d22304c194b38293fbc85b4899cba9
If necessary I can work out some benchmarking. Please let me know.
@ryanofsky also took the opportunity to push a commit replacing LOCK(cs_wallet) with AssertLockHeld(cs_wallet). I can push to a new PR if preferable.
Agree on this needing benchmarks.
<!--5d09a71f8925f3f132321140b44b946d-->The last travis run for this pull request was 164 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.
How about splitting the lock change out, and making use of EXCLUSIVE_LOCKS_REQUIRED?
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
1407 | - for (const CTxIn& txin : tx.vin) 1408 | - { 1409 | + std::vector<const CTxOut*> outs; 1410 | + outs.reserve(tx.vin.size()); 1411 | + 1412 | + // The folllwing is a 2 pass algorithm. Both passes can early return if an
Should be "following" :-)
The code changes look sane, light code review utACK https://github.com/bitcoin/bitcoin/pull/12297/commits/6037efd7c5087b1e53f426c0e48595dc073da9d3 modulo benchmarking as mentioned above
CWallet::IsAllFromMe is only called from feebumper::CreateTransaction. I guess this performance improvement is not worth it.