From 4ddd8f1fe36fd71780b55c5533340cd6a3a9fb33 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Thu, 15 Apr 2021 23:13:30 +0200 Subject: [PATCH] [BUG] Use arith_uint256 for old modifier's block sorting --- src/legacy/stakemodifier.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/legacy/stakemodifier.cpp b/src/legacy/stakemodifier.cpp index 175c3966615fa..a718a571043f6 100644 --- a/src/legacy/stakemodifier.cpp +++ b/src/legacy/stakemodifier.cpp @@ -130,6 +130,16 @@ bool GetOldStakeModifier(CStakeInput* stake, uint64_t& nStakeModifier) return true; } +// sort blocks by timestamp, soliving tie with hash (taken as arith_uint) +static bool sortedByTimestamp(const std::pair& a, + const std::pair& b) +{ + if (a.first == b.first) { + return UintToArith256(a.second) < UintToArith256(b.second); + } + return a.first < b.first; +} + // Stake Modifier (hash modifier of proof-of-stake): // The purpose of stake modifier is to prevent a txout (coin) owner from // computing future proof-of-stake generated by this txout at the time @@ -183,7 +193,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod } std::reverse(vSortedByTimestamp.begin(), vSortedByTimestamp.end()); - std::sort(vSortedByTimestamp.begin(), vSortedByTimestamp.end()); + std::sort(vSortedByTimestamp.begin(), vSortedByTimestamp.end(), sortedByTimestamp); // Select 64 blocks from candidate blocks to generate stake modifier uint64_t nStakeModifierNew = 0;