12
12
#include " gridcoin/voting/payloads.h"
13
13
#include " gridcoin/voting/registry.h"
14
14
#include " gridcoin/voting/vote.h"
15
+ #include " gridcoin/voting/result.h"
15
16
#include " gridcoin/support/block_finder.h"
16
17
#include " node/blockstorage.h"
17
18
#include " txdb.h"
@@ -368,7 +369,7 @@ std::optional<int> PollReference::GetEndingHeight() const
368
369
return std::nullopt;
369
370
}
370
371
371
- std::optional<CAmount> PollReference::GetActiveVoteWeight () const
372
+ std::optional<CAmount> PollReference::GetActiveVoteWeight (const PollResultOption& result ) const
372
373
{
373
374
// Instrument this so we can log real time performance.
374
375
g_timer.InitTimer (__func__, LogInstance ().WillLogCategory (BCLog::LogFlags::VOTE));
@@ -394,6 +395,28 @@ std::optional<CAmount> PollReference::GetActiveVoteWeight() const
394
395
__func__, pindex_end->nHeight );
395
396
}
396
397
398
+ // determine the pools that did NOT vote in the poll (via the result passed in). Only pools that did not
399
+ // vote contribute to the magnitude correction for pools.
400
+ std::vector<MiningPool> pools_not_voting;
401
+ const std::vector<MiningPool>& mining_pools = g_mining_pools.GetMiningPools ();
402
+
403
+ LogPrint (BCLog::LogFlags::VOTE, " INFO: %s: %u out of %u pool cpids voted." ,
404
+ __func__,
405
+ result->m_pools_voted .size (),
406
+ mining_pools.size ());
407
+
408
+ for (const auto & pool : mining_pools) {
409
+ if (result && std::find (result->m_pools_voted .begin (), result->m_pools_voted .end (),
410
+ pool.m_cpid ) == result->m_pools_voted .end ()) {
411
+ LogPrint (BCLog::LogFlags::VOTE, " INFO: %s: pool with cpid %s did not vote and will be removed from magnitude "
412
+ " in the AVW calculation." ,
413
+ __func__,
414
+ pool.m_cpid .ToString ());
415
+
416
+ pools_not_voting.push_back (pool);
417
+ }
418
+ }
419
+
397
420
// Since this calculation by its very nature is going to be heavyweight, we are going to
398
421
// dispense with using the heavyweight averaging functions, and instead accumulate the necessary
399
422
// values directly in a for loop that traverses the index. This will do it all in a single index
@@ -439,7 +462,7 @@ std::optional<CAmount> PollReference::GetActiveVoteWeight() const
439
462
440
463
superblock_well_formed = superblock.WellFormed ();
441
464
442
- for (const auto & pool : g_mining_pools. GetMiningPools () ) {
465
+ for (const auto & pool : pools_not_voting ) {
443
466
scaled_pool_magnitude += superblock.m_cpids .MagnitudeOf (pool.m_cpid ).Scaled ();
444
467
}
445
468
@@ -489,7 +512,7 @@ std::optional<CAmount> PollReference::GetActiveVoteWeight() const
489
512
if (claim && claim->ContainsSuperblock ()) {
490
513
const GRC::Superblock& superblock = *claim->m_superblock ;
491
514
492
- for (const auto & pool : g_mining_pools. GetMiningPools () ) {
515
+ for (const auto & pool : pools_not_voting ) {
493
516
scaled_pool_magnitude += superblock.m_cpids .MagnitudeOf (pool.m_cpid ).Scaled ();
494
517
}
495
518
0 commit comments