Skip to content

Commit

Permalink
Add m_requires_ext_adapter to project entry and associated machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jan 28, 2025
1 parent 4f3d6cd commit f55c405
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CMainParams : public CChainParams {
consensus.BlockV13Height = std::numeric_limits<int>::max();
consensus.PollV3Height = 2671700;
consensus.ProjectV2Height = 2671700;
consensus.ProjectV4Height = std::numeric_limits<int>::max();
consensus.SuperblockV3Height = std::numeric_limits<int>::max();
// Immediately post zero payment interval fees 40% for mainnet
consensus.InitialMRCFeeFractionPostZeroInterval = Fraction(2, 5);
Expand Down Expand Up @@ -189,6 +190,7 @@ class CTestNetParams : public CChainParams {
consensus.BlockV13Height = std::numeric_limits<int>::max();
consensus.PollV3Height = 1944820;
consensus.ProjectV2Height = 1944820;
consensus.ProjectV4Height = std::numeric_limits<int>::max();
consensus.SuperblockV3Height = std::numeric_limits<int>::max();
// Immediately post zero payment interval fees 40% for testnet, the same as mainnet
consensus.InitialMRCFeeFractionPostZeroInterval = Fraction(2, 5);
Expand Down
7 changes: 7 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ inline bool IsSuperblockV3Enabled(int nHeight)
return nHeight >= gArgs.GetArg("-superblockv3height", Params().GetConsensus().SuperblockV3Height);
}

inline bool IsProjectV4Enabled(int nHeight)
{
// The argument driven override temporarily here to facilitate testing.

return nHeight >= gArgs.GetArg("-projectv4height", Params().GetConsensus().ProjectV4Height);
}

inline int GetSuperblockAgeSpacing(int nHeight)
{
return (fTestNet ? 86400 : (nHeight > 364500) ? 86400 : 43200);
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct Params {
int PollV3Height;
/** Block height at which project v2 contracts are allowed */
int ProjectV2Height;
/** Block height at which project v4 contracts are allowed */
int ProjectV4Height;
/**
* @brief Block height at which superblock v3 contracts are allowed/required
*/
Expand Down
36 changes: 25 additions & 11 deletions src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,32 @@ ProjectEntry::ProjectEntry(uint32_t version)
, m_hash()
, m_previous_hash()
, m_gdpr_controls(false)
, m_requires_ext_adapter(false)
, m_public_key(CPubKey {})
, m_status(ProjectEntryStatus::UNKNOWN)
{
}

ProjectEntry::ProjectEntry(uint32_t version, std::string name, std::string url)
: ProjectEntry(version, name, url, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
: ProjectEntry(version, name, url, false, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
}

ProjectEntry::ProjectEntry(uint32_t version, std::string name, std::string url, bool gdpr_controls)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, int64_t {0})
: ProjectEntry(version, name, url, gdpr_controls, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
}

ProjectEntry::ProjectEntry(uint32_t version, std::string name, std::string url,
bool gdpr_controls, Status status, int64_t timestamp)
bool gdpr_controls, bool requires_ext_adapter, Status status, int64_t timestamp)
: m_version(version)
, m_name(name)
, m_url(url)
, m_timestamp(timestamp)
, m_hash()
, m_previous_hash()
, m_gdpr_controls(gdpr_controls)
, m_requires_ext_adapter(requires_ext_adapter)
, m_public_key(CPubKey {})
, m_status(status)
{
Expand Down Expand Up @@ -181,6 +183,17 @@ std::optional<bool> ProjectEntry::HasGDPRControls() const
return has_gdpr_controls;
}

std::optional<bool> ProjectEntry::RequiresExtAdapter() const
{
std::optional<bool> requires_ext_adapter;

if (m_version >= 4) {
requires_ext_adapter = m_requires_ext_adapter;
}

return requires_ext_adapter;
}

// -----------------------------------------------------------------------------
// Class: Project
// -----------------------------------------------------------------------------
Expand All @@ -193,27 +206,28 @@ Project::Project(uint32_t version)
}

Project::Project(std::string name, std::string url)
: ProjectEntry(1, name, url, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
: ProjectEntry(1, name, url, false, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
}

Project::Project(uint32_t version, std::string name, std::string url)
: ProjectEntry(version, name, url, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
: ProjectEntry(version, name, url, false, false,ProjectEntryStatus::UNKNOWN, int64_t {0})
{
}

Project::Project(std::string name, std::string url, int64_t timestamp, uint32_t version)
: ProjectEntry(version, name, url, false, ProjectEntryStatus::UNKNOWN, timestamp)
: ProjectEntry(version, name, url, false, false, ProjectEntryStatus::UNKNOWN, timestamp)
{
}

Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, int64_t {0})
: ProjectEntry(version, name, url, gdpr_controls, false, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
}

Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, ProjectEntryStatus status)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, int64_t {0})
Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls,
bool requires_ext_adapter, ProjectEntryStatus status)
: ProjectEntry(version, name, url, gdpr_controls, requires_ext_adapter, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
// The only two values that make sense for status using this constructor overload are MAN_GREYLISTED and
// AUTO_GREYLIST_OVERRIDE. The other are handled by the contract action context and the other overloads.
Expand All @@ -238,12 +252,12 @@ Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_
}

Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, int64_t timestamp)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, timestamp)
: ProjectEntry(version, name, url, gdpr_controls, false, ProjectEntryStatus::UNKNOWN, timestamp)
{
}

Project::Project(std::string name, std::string url, int64_t timestamp, uint32_t version, bool gdpr_controls)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, timestamp)
: ProjectEntry(version, name, url, gdpr_controls, false, ProjectEntryStatus::UNKNOWN, timestamp)
{
}

Expand Down
19 changes: 16 additions & 3 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ProjectEntry
//! ensure that the serialization/deserialization routines also handle all
//! of the previous versions.
//!
static constexpr uint32_t CURRENT_VERSION = 3;
static constexpr uint32_t CURRENT_VERSION = 4;

//!
//! \brief Version number of the serialized project format.
Expand All @@ -78,6 +78,7 @@ class ProjectEntry
uint256 m_hash; //!< The txid of the transaction that contains the project entry.
uint256 m_previous_hash; //!< The m_hash of the previous project entry with the same key.
bool m_gdpr_controls; //!< Boolean to indicate whether project has GDPR stats export controls.
bool m_requires_ext_adapter; //!< Boolean to indicate whether project requires external adapter.
CPubKey m_public_key; //!< Project public key.
Status m_status; //!< The status of the project entry. (Note serialization converts to/from int.)

Expand Down Expand Up @@ -113,10 +114,12 @@ class ProjectEntry
//! \param name. The key of the project entry.
//! \param url. The value of the project entry.
//! \param gdpr_controls. The gdpr control flag of the project entry
//! \param requires_ext_adapter. The flag that indicates whether the project requires an external adapter for stats.
//! \param status. the status of the project entry.
//! \param timestamp. The timestamp of the project entry that comes from the containing transaction
//!
ProjectEntry(uint32_t version, std::string name, std::string url, bool gdpr_controls, Status status, int64_t timestamp);
ProjectEntry(uint32_t version, std::string name, std::string url, bool gdpr_controls,
bool requires_ext_adapter, Status status, int64_t timestamp);

//!
//! \brief Determine whether a project entry contains each of the required elements.
Expand Down Expand Up @@ -184,6 +187,11 @@ class ProjectEntry
//!
std::optional<bool> HasGDPRControls() const;

//!
//! \brief Returns true if project requires an externel adapter for statistics collection.
//!
std::optional<bool> RequiresExtAdapter() const;

//!
//! \brief Comparison operator overload used in the unit test harness.
//!
Expand Down Expand Up @@ -300,7 +308,8 @@ class Project : public IContractPayload, public ProjectEntry
//! \param gdpr_controls Boolean to indicate gdpr stats export controls enforced
//! \param status ProjectEntryStatus to force project status.
//!
Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, ProjectEntryStatus status);
Project(uint32_t version, std::string name, std::string url, bool gdpr_controls,
bool requires_ext_adapter, ProjectEntryStatus status);

//!
//! \brief Initialize a \c Project using data from the contract.
Expand Down Expand Up @@ -416,6 +425,10 @@ class Project : public IContractPayload, public ProjectEntry
READWRITE(m_previous_hash);
READWRITE(m_status);
}

if (m_version >= 4) {
READWRITE(m_requires_ext_adapter);
}
}
}; // Project (entry payload)

Expand Down
5 changes: 3 additions & 2 deletions src/gridcoin/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ unsigned int SCRAPER_MISBEHAVING_NODE_BANSCORE GUARDED_BY(cs_ScraperGlobals) = 0
bool REQUIRE_TEAM_WHITELIST_MEMBERSHIP GUARDED_BY(cs_ScraperGlobals) = false;
/** Default team whitelist. Remember this will be overridden by appcache entries. */
std::string TEAM_WHITELIST GUARDED_BY(cs_ScraperGlobals) = "Gridcoin";
/** This is a short term place to hold projects that require an external adapter for the scrapers.*/
/** This is a short term place to hold projects that require an external adapter for the scrapers. This will be retired after
the block v13/superblock v3/project v4 mandatory */
std::string EXTERNAL_ADAPTER_PROJECTS GUARDED_BY(cs_ScraperGlobals) = std::string{};
/** This is the period after the deauthorizing of a scraper in seconds before the nodes will start
* to assign banscore to nodes sending unauthorized manifests.
Expand Down Expand Up @@ -6228,7 +6229,7 @@ UniValue convergencereport(const UniValue& params, bool fHelp)
for (const auto& entry : ConvergedScraperStatsCache.Convergence.vGreylistedProjects) {
ProjectEntry::Status status = GRC::EnumByte<GRC::ProjectEntryStatus>(entry.second);

ProjectEntry dummy_project(3, entry.first, "foo", false, status, 0);
ProjectEntry dummy_project(3, entry.first, "foo", false, false, status, 0);

UniValue greylisted_project_entry(UniValue::VOBJ);

Expand Down
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ void SetupServerArgs()
// Temporary hidden option for block v13 height override to facilitate testing.
hidden_args.emplace_back("-blockv13height");

// Temporary hidden option for project v4 height override to facilitate testing.
hidden_args.emplace_back("-projectv4height");

// Temporary hidden option for superblock v3 height override to facilitate testing.
hidden_args.emplace_back("-superblockv3height");

Expand Down
4 changes: 3 additions & 1 deletion src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ std::vector<ProjectRow> ResearcherModel::buildProjectTable(bool extended) const
row.m_name = QString::fromStdString(project.DisplayName()).toLower();
row.m_magnitude = 0.0;

if (std::find(external_adapter_projects.begin(),
// the external adapter code below only appears here because if the project is in BOINC it does not need
// an external adapter.
if (!project.RequiresExtAdapter() && std::find(external_adapter_projects.begin(),
external_adapter_projects.end(),
project.m_name) == external_adapter_projects.end()) {
row.m_error = tr("Not attached");
Expand Down
Loading

0 comments on commit f55c405

Please sign in to comment.