Skip to content

Commit 03ea129

Browse files
committed
fix: apply review suggestions
1 parent c5e0f90 commit 03ea129

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/evo/deterministicmns.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,8 @@ bool CDeterministicMNManager::IsMigrationRequired() const
13421342
{
13431343
// Check if there are any legacy format diffs in the database
13441344
// by looking for DB_LIST_DIFF_LEGACY entries
1345-
LOCK(::cs_main);
1345+
1346+
AssertLockHeld(::cs_main);
13461347

13471348
std::unique_ptr<CDBIterator> pcursor{m_evoDb.GetRawDB().NewIterator()};
13481349
auto start{std::make_tuple(DB_LIST_DIFF_LEGACY, uint256())};
@@ -1368,8 +1369,9 @@ bool CDeterministicMNManager::MigrateLegacyDiffs()
13681369
// CRITICAL: This migration converts ALL stored CDeterministicMNListDiff entries
13691370
// from legacy database key (DB_LIST_DIFF_LEGACY) to new key (DB_LIST_DIFF) format
13701371

1372+
AssertLockHeld(::cs_main);
1373+
13711374
LogPrintf("CDeterministicMNManager::%s -- Starting migration to nVersion-first format\n", __func__);
1372-
LOCK(::cs_main);
13731375

13741376
std::vector<uint256> keys_to_erase;
13751377

src/evo/deterministicmns.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ class CDeterministicMNListDiff
563563

564564
for (size_t to_read = ReadCompactSize(s); to_read > 0; --to_read) {
565565
uint64_t internalId = ReadVarInt<Stream, VarIntMode::DEFAULT, uint64_t>(s);
566-
566+
// CDeterministicMNState can have newer fields but doesn't need migration logic here as
567+
// CDeterministicMNStateDiff is always serialised using a bitmask and new fields have a new bit guide value,
568+
// so we are good to continue. We do need migration logic to change field order though.
567569
if (isLegacyFormat) {
568570
// Use legacy deserializer for old format
569571
CDeterministicMNStateDiffLegacy legacyDiff(deserialize, s);
@@ -654,8 +656,8 @@ class CDeterministicMNManager
654656
void DoMaintenance() EXCLUSIVE_LOCKS_REQUIRED(!cs);
655657

656658
// Migration support for nVersion-first CDeterministicMNStateDiff format
657-
[[nodiscard]] bool IsMigrationRequired() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
658-
[[nodiscard]] bool MigrateLegacyDiffs() EXCLUSIVE_LOCKS_REQUIRED(!cs);
659+
[[nodiscard]] bool IsMigrationRequired() const EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
660+
[[nodiscard]] bool MigrateLegacyDiffs() EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
659661

660662
private:
661663
void CleanupCache(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);

src/evo/dmnstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ class CDeterministicMNStateDiff
246246
{
247247
READWRITE(VARINT(obj.fields));
248248

249-
if ((obj.fields & Field_pubKeyOperator) || (obj.fields & Field_netInfo)) {
249+
if (((obj.fields & Field_pubKeyOperator) || (obj.fields & Field_netInfo)) && !(obj.fields & Field_nVersion)) {
250250
// pubKeyOperator and netInfo need nVersion
251-
assert(obj.fields & Field_nVersion);
251+
throw std::ios_base::failure("Invalid data, nVersion unset when pubKeyOperator or netInfo set");
252252
}
253253

254254
boost::hana::for_each(members, [&](auto&& member) {

0 commit comments

Comments
 (0)