Skip to content

Commit

Permalink
[BUG] Use arith_uint256 for old modifier's block sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 5, 2021
1 parent b1c0afb commit 4ddd8f1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/legacy/stakemodifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t, uint256>& a,
const std::pair<uint64_t, uint256>& 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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4ddd8f1

Please sign in to comment.