Skip to content

Commit 1c7d08b

Browse files
committed
validation: Stricter assumeutxo error handling in InvalidateCoinsDBOnDisk
Currently InvalidateCoinsDBOnDisk is calling AbortNode without an error to the caller if it fails. Change it to return just return util::Result, and update the caller to handle the error itself. This causes the secondary error to be shown below the main error instead of the other way around.
1 parent 9047337 commit 1c7d08b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/validation.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5411,7 +5411,7 @@ SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation(
54115411
"restart, the node will resume syncing from %d "
54125412
"without using any snapshot data. "
54135413
"Please report this incident to %s, including how you obtained the snapshot. "
5414-
"The invalid snapshot chainstate has been left on disk in case it is "
5414+
"The invalid snapshot chainstate will be left on disk in case it is "
54155415
"helpful in diagnosing the issue that caused this error."),
54165416
PACKAGE_NAME, snapshot_tip_height, snapshot_base_height, snapshot_base_height, PACKAGE_BUGREPORT
54175417
);
@@ -5424,7 +5424,10 @@ SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation(
54245424
assert(!this->IsUsable(m_snapshot_chainstate.get()));
54255425
assert(this->IsUsable(m_ibd_chainstate.get()));
54265426

5427-
m_snapshot_chainstate->InvalidateCoinsDBOnDisk();
5427+
auto rename_result = m_snapshot_chainstate->InvalidateCoinsDBOnDisk();
5428+
if (!rename_result) {
5429+
user_error = strprintf(Untranslated("%s\n%s"), user_error, util::ErrorString(rename_result));
5430+
}
54285431

54295432
shutdown_fnc(user_error);
54305433
};
@@ -5626,7 +5629,7 @@ bool IsBIP30Unspendable(const CBlockIndex& block_index)
56265629
(block_index.nHeight==91812 && block_index.GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"));
56275630
}
56285631

5629-
void Chainstate::InvalidateCoinsDBOnDisk()
5632+
util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
56305633
{
56315634
AssertLockHeld(::cs_main);
56325635
// Should never be called on a non-snapshot chainstate.
@@ -5655,13 +5658,14 @@ void Chainstate::InvalidateCoinsDBOnDisk()
56555658

56565659
LogPrintf("%s: error renaming file '%s' -> '%s': %s\n",
56575660
__func__, src_str, dest_str, e.what());
5658-
AbortNode(strprintf(
5661+
return util::Error{strprintf(_(
56595662
"Rename of '%s' -> '%s' failed. "
56605663
"You should resolve this by manually moving or deleting the invalid "
56615664
"snapshot directory %s, otherwise you will encounter the same error again "
5662-
"on the next startup.",
5663-
src_str, dest_str, src_str));
5665+
"on the next startup."),
5666+
src_str, dest_str, src_str)};
56645667
}
5668+
return {};
56655669
}
56665670

56675671
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const

src/validation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <util/check.h>
3232
#include <util/fs.h>
3333
#include <util/hasher.h>
34+
#include <util/result.h>
3435
#include <util/translation.h>
3536
#include <versionbits.h>
3637

@@ -810,7 +811,7 @@ class Chainstate
810811
* In case of an invalid snapshot, rename the coins leveldb directory so
811812
* that it can be examined for issue diagnosis.
812813
*/
813-
void InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
814+
[[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
814815

815816
friend ChainstateManager;
816817
};

0 commit comments

Comments
 (0)