Skip to content

Commit

Permalink
corrections 2 (to be squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 22, 2024
1 parent 18e4400 commit 00a8d6b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/gridcoin/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ ProtocolEntryOption ProtocolRegistry::TryActive(const std::string& key) const
return nullptr;
}

ProtocolEntryOption ProtocolRegistry::TryLastActiveBeforeTimestamp(const std::string& key, const int64_t& timestamp)
ProtocolEntryOption ProtocolRegistry::TryLastBeforeTimestamp(const std::string& key, const int64_t& timestamp)
{
LOCK(cs_lock);

Expand All @@ -304,9 +304,9 @@ ProtocolEntryOption ProtocolRegistry::TryLastActiveBeforeTimestamp(const std::st
return nullptr;
}

// If the latest (current) active protocol entry for the given key has a timestamp before or equal to the provided timestamp then
// If the latest (current) protocol entry for the given key has a timestamp before or equal to the provided timestamp then
// return the latest entry.
if (iter->second->m_timestamp <= timestamp && iter->second->m_status == ProtocolEntryStatus::ACTIVE) {
if (iter->second->m_timestamp <= timestamp) {
return iter->second;
}

Expand All @@ -322,8 +322,7 @@ ProtocolEntryOption ProtocolRegistry::TryLastActiveBeforeTimestamp(const std::st

while (hist_protocol_entry_iter != m_protocol_db.end()
&& !hist_protocol_entry_iter->second->m_previous_hash.IsNull()
&& (hist_protocol_entry_iter->second->m_timestamp > timestamp
|| hist_protocol_entry_iter->second->m_status != ProtocolEntryStatus::ACTIVE))
&& hist_protocol_entry_iter->second->m_timestamp > timestamp)
{
hist_protocol_entry_iter = m_protocol_db.find(hist_protocol_entry_iter->second->m_previous_hash);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gridcoin/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ class ProtocolRegistry : public IContractHandler
ProtocolEntryOption TryActive(const std::string& key) const;

//!
//! \brief Get the last ACTIVE protocol entry for the specified key string at or before the specified timestamp
//! \brief Get the last protocol entry for the specified key string at or before the specified timestamp
//!
//! \param key The key string of the protocol entry.
//! \param timestamp The desired timestamp to limit the find.
//!
//! \return An object that either contains a reference to some protocol entry if it exists
//! for the key at or before the provided timestamp or does not.
//!
ProtocolEntryOption TryLastActiveBeforeTimestamp(const std::string& key, const int64_t& timestamp);
ProtocolEntryOption TryLastBeforeTimestamp(const std::string& key, const int64_t& timestamp);

//!
//! \brief Get the first ACTIVE protocol entry for the specified key string at or after the specified timestamp
Expand Down
9 changes: 4 additions & 5 deletions src/gridcoin/staking/reward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ CAmount GRC::GetConstantBlockReward(const CBlockIndex* index)
CAmount MIN_CBR = 0;
CAmount MAX_CBR = 0;

ProtocolEntryOption reward_entry = GetProtocolRegistry().TryActive("blockreward1");
ProtocolEntryOption reward_entry = GetProtocolRegistry().TryLastBeforeTimestamp("blockreward1",
index->GetBlockTime());

// The constant block reward is set to a default, voted on value, but this can
// be overridden using an admin message. This allows us to change the reward
Expand All @@ -56,9 +57,7 @@ CAmount GRC::GetConstantBlockReward(const CBlockIndex* index)
MIN_CBR = Params().GetConsensus().ConstantBlockRewardFloor;
MAX_CBR = Params().GetConsensus().ConstantBlockRewardCeiling;

//CBlockIndex* pindex_lookback_pin = GRC::BlockFinder::FindByHeight(Params().GetConsensus().BlockV13Height);

if (reward_entry != nullptr) {
if (reward_entry != nullptr && reward_entry->m_status == ProtocolEntryStatus::ACTIVE) {
// There is no contract lookback limitation v13+.
if (!ParseInt64(reward_entry->m_value, &reward)) {
error("%s: Cannot parse constant block reward from protocol entry: %s",
Expand All @@ -73,7 +72,7 @@ CAmount GRC::GetConstantBlockReward(const CBlockIndex* index)
MIN_CBR = 0;
MAX_CBR = Params().GetConsensus().DefaultConstantBlockReward * 2;

if (reward_entry != nullptr) {
if (reward_entry != nullptr && reward_entry->m_status == ProtocolEntryStatus::ACTIVE) {
// The contract lookback window here for block version less than v13 is the same as the standard contract
// replay lookback.
if (index->nTime - reward_entry->m_timestamp <= Params().GetConsensus().StandardContractReplayLookback) {
Expand Down
6 changes: 4 additions & 2 deletions src/gridcoin/voting/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,11 @@ Fraction ResolveMagnitudeWeightFactorForPoll(const Poll& poll)
Fraction magnitude_weight_factor = Params().GetConsensus().DefaultMagnitudeWeightFactor;

// Find the current protocol entry value for Magnitude Weight Factor, if it exists.
ProtocolEntryOption protocol_entry = GetProtocolRegistry().TryLastActiveBeforeTimestamp("magnitudeweightfactor", poll.m_timestamp);
ProtocolEntryOption protocol_entry = GetProtocolRegistry().TryLastBeforeTimestamp("magnitudeweightfactor", poll.m_timestamp);

if (protocol_entry != nullptr) {
// If their is an entry prior or equal in timestemp to the start of the poll and it is active then set the magnitude weight
// factor to that value. If the last entry is not active (i.e. deleted), then leave at the default.
if (protocol_entry != nullptr && protocol_entry->m_status == ProtocolEntryStatus::ACTIVE) {
magnitude_weight_factor = Fraction().FromString(protocol_entry->m_value);
}

Expand Down

0 comments on commit 00a8d6b

Please sign in to comment.