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;