wallet: Erase wtxOrderd wtx pointer on removeprunedfunds#13437
Conversation
|
Oh, nice find! How was this issue found? |
See also (related?) issue #9729 I can reproduce on 0.15 and master, haven't checked 0.16. |
| { | ||
| uint256 hash = wtxIn.GetHash(); | ||
| CWalletTx& wtx = mapWallet.emplace(hash, wtxIn).first->second; | ||
| const auto& ins = mapWallet.emplace(hash, wtxIn); |
There was a problem hiding this comment.
May be a good place to use std::tie for more self-documenting code.
http://en.cppreference.com/w/cpp/utility/tuple/tie
|
@MarcoFalke: can you elaborate a bit more and/or add some source code documentations. A class self-referencing multimap in |
|
If someone finds a more elegant solution to erase from both ( |
promag
left a comment
There was a problem hiding this comment.
Concept ACK. Agree on @jonasschnelli, feels weird but not entirely bad. Alternative suggestion below.
| DBErrors nZapSelectTxRet = WalletBatch(*database,"cr+").ZapSelectTx(vHashIn, vHashOut); | ||
| for (uint256 hash : vHashOut) | ||
| mapWallet.erase(hash); | ||
| for (uint256 hash : vHashOut) { |
There was a problem hiding this comment.
nit, could change to const uint256&.
| char fFromMe; | ||
| std::string strFromAccount; | ||
| int64_t nOrderPos; //!< position in ordered transaction list | ||
| std::multimap<int64_t, std::pair<CWalletTx*, CAccountingEntry*>>::const_iterator m_it_wtxOrdered; |
There was a problem hiding this comment.
Remove, nOrderPos should be enough for fast lookup in wtxOrdered.
There was a problem hiding this comment.
@promag IIRC, nOrderPos is updated while the cache keeps the old value...
If I do this, I'd have to open a new pull request, since this is a different fix.
There was a problem hiding this comment.
Either way storing a map/multimap iterator is safe (while the entry exists) and this is the most performant solution AFAIK.
| mapWallet.erase(hash); | ||
| for (uint256 hash : vHashOut) { | ||
| const auto& it = mapWallet.find(hash); | ||
| wtxOrdered.erase(it->second.m_it_wtxOrdered); |
There was a problem hiding this comment.
Something like:
for (const auto& it_wtxOrdered = wtxOrdered.lower_bound(it->second.nOrderPos; ...) {
if (&it_wtxOrdered->second.first == &it->second) {
}
}|
Should backport? |
Note to 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. |
|
utACK faa18ca
I kind of like this solution of storing the iterator to be able to remove it later. |
faa18ca wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123
|
tested ACK faa18ca |
Github-Pull: bitcoin#13437 Rebased-From: faa18ca
|
Should be backported in #13644. |
Github-Pull: bitcoin#13437 Rebased-From: faa18ca
Summary: faa18ca wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123 Backport of Core PR13437 bitcoin/bitcoin#13437 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4540
…nedfunds faa18ca wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123
Summary: faa18ca046e9043b2cf68cb1bd17cc8c60fe26d9 wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123 Backport of Core PR13437 bitcoin/bitcoin#13437 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4540
Summary: faa18ca046e9043b2cf68cb1bd17cc8c60fe26d9 wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123 Backport of Core PR13437 bitcoin/bitcoin#13437 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4540
Summary: faa18ca046e9043b2cf68cb1bd17cc8c60fe26d9 wallet: Erase wtxOrderd wtx pointer on removeprunedfunds (MarcoFalke) Pull request description: This prevents segfaults, when reading from the freed memory. Tree-SHA512: 04f8190dea7901cf1cc298d5db98c83b02858f27114c5ef4da738accd176d6647d6b81f3dc39f3d5912b1a981cf0599370fd391c4154ffbde97afc1fac389123 Backport of Core PR13437 bitcoin/bitcoin#13437 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4540
This prevents segfaults, when reading from the freed memory.