mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
blockstorage: Adjust fastprune limit if block exceeds blockfile size
If the added block exceeds the blockfile size in test-only -fastprune mode, the node would get stuck in an infinite loop and run out of memory. Avoid this by raising the blockfile size to the size of the added block in this situation. Co-authored-by: TheCharlatan <seb.kung@gmail.com>
This commit is contained in:
parent
d908877c47
commit
271c23e87f
1 changed files with 12 additions and 1 deletions
|
@ -619,7 +619,18 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
|
|||
|
||||
bool finalize_undo = false;
|
||||
if (!fKnown) {
|
||||
while (m_blockfile_info[nFile].nSize + nAddSize >= (gArgs.GetBoolArg("-fastprune", false) ? 0x10000 /* 64kb */ : MAX_BLOCKFILE_SIZE)) {
|
||||
unsigned int max_blockfile_size{MAX_BLOCKFILE_SIZE};
|
||||
// Use smaller blockfiles in test-only -fastprune mode - but avoid
|
||||
// the possibility of having a block not fit into the block file.
|
||||
if (gArgs.GetBoolArg("-fastprune", false)) {
|
||||
max_blockfile_size = 0x10000; // 64kiB
|
||||
if (nAddSize >= max_blockfile_size) {
|
||||
// dynamically adjust the blockfile size to be larger than the added size
|
||||
max_blockfile_size = nAddSize + 1;
|
||||
}
|
||||
}
|
||||
assert(nAddSize < max_blockfile_size);
|
||||
while (m_blockfile_info[nFile].nSize + nAddSize >= max_blockfile_size) {
|
||||
// when the undo file is keeping up with the block file, we want to flush it explicitly
|
||||
// when it is lagging behind (more blocks arrive than are being connected), we let the
|
||||
// undo block write case handle it
|
||||
|
|
Loading…
Add table
Reference in a new issue