diff --git a/src/gridcoin/voting/registry.cpp b/src/gridcoin/voting/registry.cpp index 83c548d1b4..bac6812cc6 100644 --- a/src/gridcoin/voting/registry.cpp +++ b/src/gridcoin/voting/registry.cpp @@ -349,10 +349,19 @@ PollOption PollReference::TryReadFromDisk(CTxDB& txdb) const auto payload = contract.PullPayloadAs(); // The time for the poll is the time of the containing transaction. payload.m_poll.m_timestamp = tx.nTime; + m_timestamp = tx.nTime; // This is a critical initialization, because the magnitude weight factor is only stored // in memory and is not serialized. payload.m_poll.m_magnitude_weight_factor = payload.m_poll.ResolveMagnitudeWeightFactor(); + m_magnitude_weight_factor = payload.m_poll.m_magnitude_weight_factor; + + LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: reference.m_timestamp = %" PRId64 " , poll.m_timestamp = %" PRId64 " , " + "poll.m_magnitude_weight_factor = %s", + __func__, + m_timestamp, + payload.m_poll.m_timestamp, + payload.m_poll.m_magnitude_weight_factor.ToString()); return std::move(payload.m_poll); } @@ -482,6 +491,11 @@ std::optional PollReference::GetEndingHeight() const EXCLUSIVE_LOCKS_REQUIR return std::nullopt; } +Fraction PollReference::GetMagnitudeWeightFactor() const +{ + return m_magnitude_weight_factor; +} + std::optional PollReference::GetActiveVoteWeight(const PollResultOption& result) const { // Instrument this so we can log real time performance. @@ -653,13 +667,15 @@ std::optional PollReference::GetActiveVoteWeight(const PollResultOption // If voting logging category is active, log the first block and every superblock if (blocks == 1 || pindex->IsSuperblock()) { LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: tally_active_vote_weight: net_weight = %f, money_supply = %f, " - "pool_magnitude = %f, network_magnitude = %f, block height = %i, " - "blocks = %u, active_vote_weight_tally = %f, active_vote_weight = %f.", + "pool_magnitude = %f, network_magnitude = %f, magnitude weight factor = %s, " + "block height = %i, blocks = %u, active_vote_weight_tally = %f, " + "active_vote_weight = %f.", __func__, net_weight.getdouble() / (double) COIN, money_supply.getdouble() / (double) COIN, scaled_pool_magnitude.getdouble() / 100.0, scaled_network_magnitude.getdouble() / 100.0, + m_magnitude_weight_factor.ToString(), pindex->nHeight, blocks, active_vote_weight_tally.getdouble() / (double) COIN, @@ -670,13 +686,15 @@ std::optional PollReference::GetActiveVoteWeight(const PollResultOption // Log the last block and break if at pindex_end. if (pindex == pindex_end) { LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: tally_active_vote_weight: net_weight = %f, money_supply = %f, " - "pool_magnitude = %f, network_magnitude = %f, block height = %i, " - "blocks = %u, active_vote_weight_tally = %f, active_vote_weight = %f.", + "pool_magnitude = %f, network_magnitude = %f, magnitude weight factor = %s, " + "block height = %i, blocks = %u, active_vote_weight_tally = %f, " + "active_vote_weight = %f.", __func__, net_weight.getdouble() / (double) COIN, money_supply.getdouble() / (double) COIN, scaled_pool_magnitude.getdouble() / 100.0, scaled_network_magnitude.getdouble() / 100.0, + m_magnitude_weight_factor.ToString(), pindex->nHeight, blocks, active_vote_weight_tally.getdouble() / (double) COIN, diff --git a/src/gridcoin/voting/registry.h b/src/gridcoin/voting/registry.h index 5b2538d330..5102c742ff 100644 --- a/src/gridcoin/voting/registry.h +++ b/src/gridcoin/voting/registry.h @@ -153,6 +153,13 @@ class PollReference //! std::optional GetEndingHeight() const; + //! + //! \brief Get the magnitude weight factor at the poll start. + //! + //! \return Fraction representing magnitude weight factor. + //! + Fraction GetMagnitudeWeightFactor() const; + //! //! \brief Computes the Active Vote Weight for the poll, which is used to determine whether the poll is validated. //! \param result: The actual tabulated votes (poll result) @@ -176,15 +183,15 @@ class PollReference void UnlinkVote(const uint256 txid); private: - uint256 m_txid; //!< Hash of the poll transaction. - uint32_t m_payload_version; //!< Version of the poll (payload). - PollType m_type; //!< Type of the poll. - const std::string* m_ptitle; //!< Title of the poll for indexing/mapping purposes. - std::string m_title; //!< Original title of the poll for display purposes. - int64_t m_timestamp; //!< Timestamp of the poll transaction. - uint32_t m_duration_days; //!< Number of days the poll remains active. - std::vector m_votes; //!< Hashes of the linked vote transactions. - Fraction m_magnitude_weight_factor; //!< Magnitude weight factor for the poll (defined at poll start). + uint256 m_txid; //!< Hash of the poll transaction. + uint32_t m_payload_version; //!< Version of the poll (payload). + PollType m_type; //!< Type of the poll. + const std::string* m_ptitle; //!< Title of the poll for indexing/mapping purposes. + std::string m_title; //!< Original title of the poll for display purposes. + mutable int64_t m_timestamp; //!< Timestamp of the poll transaction. + uint32_t m_duration_days; //!< Number of days the poll remains active. + std::vector m_votes; //!< Hashes of the linked vote transactions. + mutable Fraction m_magnitude_weight_factor; //!< Magnitude weight factor for the poll (defined at poll start). }; // PollReference //! diff --git a/src/gridcoin/voting/result.cpp b/src/gridcoin/voting/result.cpp index 0b45856801..bd3bdb0a55 100644 --- a/src/gridcoin/voting/result.cpp +++ b/src/gridcoin/voting/result.cpp @@ -1198,6 +1198,11 @@ PollResultOption PollResult::BuildFor(const PollReference& poll_ref) counter.CountVotes(result, poll_ref.Votes()); + LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: poll_ref.Time() = %" PRId64 " poll.GetMagnitudeWeightFactor() = %s", + __func__, + poll_ref.Time(), + poll_ref.GetMagnitudeWeightFactor().ToString()); + if (auto active_vote_weight = poll_ref.GetActiveVoteWeight(result)) { result.m_active_vote_weight = active_vote_weight;