Skip to content

Commit

Permalink
Use big endian inversed height in CInstantSendDb
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Apr 5, 2019
1 parent 4b9f6cd commit 206e5a1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/llmq/quorums_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,26 @@ void CInstantSendDb::RemoveInstantSendLock(CDBBatch& batch, const uint256& hash,
}
}

static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockMinedKey(int nHeight, const uint256& islockHash)
{
return std::make_tuple(std::string("is_m"), htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
}

void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight)
{
db.Write(std::make_tuple(std::string("is_m"), std::numeric_limits<int>::max() - nHeight, hash), true);
db.Write(BuildInversedISLockMinedKey(nHeight, hash), true);
}

void CInstantSendDb::RemoveInstantSendLockMined(const uint256& hash, int nHeight)
{
db.Erase(std::make_tuple(std::string("is_m"), std::numeric_limits<int>::max() - nHeight, hash));
db.Erase(BuildInversedISLockMinedKey(nHeight, hash));
}

std::unordered_map<uint256, CInstantSendLockPtr> CInstantSendDb::RemoveConfirmedInstantSendLocks(int nUntilHeight)
{
auto it = std::unique_ptr<CDBIterator>(db.NewIterator());

auto firstKey = std::make_tuple(std::string("is_m"), std::numeric_limits<int>::max() - nUntilHeight, uint256());
auto firstKey = BuildInversedISLockMinedKey(nUntilHeight, uint256());

it->Seek(firstKey);

Expand All @@ -115,7 +120,7 @@ std::unordered_map<uint256, CInstantSendLockPtr> CInstantSendDb::RemoveConfirmed
if (!it->GetKey(curKey) || std::get<0>(curKey) != "is_m") {
break;
}
int nHeight = std::numeric_limits<int>::max() - std::get<1>(curKey);
uint32_t nHeight = std::numeric_limits<uint32_t>::max() - be32toh(std::get<1>(curKey));
if (nHeight > nUntilHeight) {
break;
}
Expand Down

0 comments on commit 206e5a1

Please sign in to comment.