Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
I have merged the Bitcoin PoW/PoT code into the BTC 26x baseline. After 8 hours of running I generally see the error:
Exception: St11logic_error Not all cached coins were erased bitcoin in Runaway exception
The code was posted here: https://github.com/bitcoin/bitcoin/pull/29455/
Not sure why the title was deleted...
BitcoinPoW (BTCW) is a modified version of Bitcoin. It uses proof of transactions as a way to perform work. This means that each wallet on the BTCW network generally has between 20,000 and 100,000 utxos and the txids of those utxos are used in the hashing.
The exception points to the Pool code here: https://github.com/bitcoin/bitcoin/blob/26.x/src/support/allocators/pool.h
I have not debugged in detail the issue, but seems that there is a possible bug in the pool.h code that hasn't surfaced because of low utxo counts in BTC wallets.
It should also be noted that:
using CCoinsMap = std::unordered_map<COutPoint, CCoinsCacheEntry, SaltedOutpointHasher, std::equal_to<COutPoint>, PoolAllocator<std::pair<const COutPoint, CCoinsCacheEntry>, sizeof(std::pair<const COutPoint, CCoinsCacheEntry>) + sizeof(void*) * 4>>;
Is new as of 26.x. Previous version of BTCW was using 21.x baseline and never encountered this issue. 25.x and earlier baselines never used the PoolAllocator for the CCoinsMap.
Turns out that if I comment out all the custom Pool Alloc/Dealloc code and only use new/delete as shown below, the problem goes away. This points to the below possibllities.
A) multi threading issues within these methods. - new/delete is thread safe, but the custom code is not. B) byte alignment issues, using 4 different variations of paths: -Allocate/Deallocate -Allocate/delete -new/Deallocate -new/delete -> this is safe and the issue is not present.
Have there been test cases to cover the 4 paths above?
/// NOTE: This code fixes the issue. void* Allocate(std::size_t bytes, std::size_t alignment) { // Can't use the pool => use operator new() return ::operator new (bytes, std::align_val_t{alignment}); }
void Deallocate(void* p, std::size_t bytes, std::size_t alignment) noexcept
{
// Can't use the pool => forward deallocation to ::operator delete().
::operator delete (p, std::align_val_t{alignment});
}
Expected behaviour
Exception should not be thrown.
Steps to reproduce
Modify the 26.x baseline with BTCW code here: https://github.com/bitcoin/bitcoin/pull/29455/
and mine on the BTCW network with 50,000 utxos.
Relevant log output
Exception: Stlllogic_error Not all cached coins were erased bitcoin in Runaway exception
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
https://github.com/bitcoin/bitcoin/commit/74df372750ceb4ccdfe310e18f14cdd3abac4a51
Operating system and version
Ubuntu 20 and 22
Machine specifications
No response