Skip to content

Commit

Permalink
Merge pull request #2779 from jamescowens/fix_scraper_convergedstats_…
Browse files Browse the repository at this point in the history
…file_lock

scraper: Protect access to ConvergedStats.csv.gz with a lock
  • Loading branch information
jamescowens authored Oct 24, 2024
2 parents 92bf8af + 1f388c3 commit 7b3748b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/gridcoin/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ CCriticalSection cs_ScraperGlobals;
* file side.
*/
CCriticalSection cs_StructScraperFileManifest;
/**
* @brief Protects access to the ConvergedStats.csv.gz compressed statistics map output file.
*/
CCriticalSection cs_ConvergedStats;
/**
* @brief Protects the global converged scraper stats cache, which is populated by periodic runs of the scraper and/or
* subscriber loop, and is used to validate superblocks.
Expand Down Expand Up @@ -3452,6 +3456,8 @@ bool StoreScraperFileManifest(const fs::path& file)

bool StoreStats(const fs::path& file, const ScraperStats& mScraperStats)
{
LOCK(cs_ConvergedStats);

if (fs::exists(file))
fs::remove(file);

Expand Down Expand Up @@ -6069,13 +6075,13 @@ UniValue testnewsb(const UniValue& params, bool fHelp)
{
LOCK(cs_ConvergedScraperStatsCache);

if (!ConvergedScraperStatsCache.NewFormatSuperblock.WellFormed())
{
UniValue error(UniValue::VOBJ);
error.pushKV("Error:", "Wait until a convergence is formed.");
if (!ConvergedScraperStatsCache.NewFormatSuperblock.WellFormed())
{
UniValue error(UniValue::VOBJ);
error.pushKV("Error:", "Wait until a convergence is formed.");

return error;
}
return error;
}

_log(logattribute::INFO, "testnewsb",
"Size of the PastConvergences map = " + ToString(ConvergedScraperStatsCache.PastConvergences.size()));
Expand Down
1 change: 1 addition & 0 deletions src/gridcoin/scraper/scraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
extern CCriticalSection cs_Scraper;
extern CCriticalSection cs_ScraperGlobals;
extern CCriticalSection cs_StructScraperFileManifest;
extern CCriticalSection cs_ConvergedStats;
extern CCriticalSection cs_ConvergedScraperStatsCache;
extern CCriticalSection cs_TeamIDMap;
extern CCriticalSection cs_VerifiedBeacons;
Expand Down

0 comments on commit 7b3748b

Please sign in to comment.