@@ -214,16 +214,41 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee(const CBlockIndex* pIndex)
214
214
return best;
215
215
}
216
216
217
- std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayeesAtChainTip (int nCount) const
218
- {
219
- return GetProjectedMNPayees (::ChainActive ()[nHeight], nCount);
220
- }
221
-
222
- std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees (const CBlockIndex* const pindex, int nCount) const
217
+ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees (int nCount) const
223
218
{
224
219
if (nCount < 0 ) {
225
220
return {};
226
221
}
222
+
223
+ bool isMNRewardReallocation{false };
224
+ if (auto pindex = ::ChainActive ()[nHeight]; pindex == nullptr ) {
225
+ // Something went wrong, probably a race condition in tip and mnlist updates,
226
+ // try ecovering...
227
+ pindex = ::ChainActive ().Tip ();
228
+ const auto mn_rr_state = llmq::utils::GetMNRewardReallocationState (pindex);
229
+ isMNRewardReallocation = (mn_rr_state == ThresholdState::ACTIVE);
230
+ if (!isMNRewardReallocation) {
231
+ const auto w_size = static_cast <int >(Params ().GetConsensus ().vDeployments [Consensus::DEPLOYMENT_MN_RR].nWindowSize );
232
+ // Check if mn_rr is going to be active at nHeight
233
+ if (mn_rr_state == ThresholdState::LOCKED_IN) {
234
+ int activation_height = llmq::utils::GetMNRewardReallocationSince (pindex) + w_size;
235
+ if (nHeight >= activation_height) {
236
+ isMNRewardReallocation = true ;
237
+ }
238
+ } else {
239
+ if (nHeight - pindex->nHeight > w_size) {
240
+ // Should never happen, can't do anything
241
+ return {};
242
+ }
243
+ // No way we reach mn_rr activation if it's not locked in yet
244
+ // and height diff is less than or equal w_size, so isMNRewardReallocation == false
245
+ // but it's safe to continue nevertheless.
246
+ }
247
+ }
248
+ } else {
249
+ isMNRewardReallocation = llmq::utils::IsMNRewardReallocationActive (pindex);
250
+ }
251
+
227
252
nCount = std::min (nCount, int (GetValidWeightedMNsCount ()));
228
253
229
254
std::vector<CDeterministicMNCPtr> result;
0 commit comments