Skip to content

Commit

Permalink
WIP 3 - Scraper thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Aug 28, 2021
1 parent 93de2a9 commit d06dcfe
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 144 deletions.
27 changes: 17 additions & 10 deletions src/gridcoin/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,17 +1039,22 @@ class SuperblockValidator

const CScraperManifest_shared_ptr manifest = iter->second;

LOCK(manifest->cs_manifest);

// If the manifest for the beacon list is now empty, we cannot
// proceed, but ProjectResolver should always select manifests
// with a beacon list part:
if (manifest->vParts.empty()) {
LogPrintf("ValidateSuperblock(): beacon list part missing.");
return;
}

convergence.AddPart("BeaconList", manifest->vParts[0]);
// Note using fine-grained locking here to avoid lock-order issues and
// also to deal with Clang potential false positive below.
{
LOCK(manifest->cs_manifest);

if (manifest->vParts.empty()) {
LogPrintf("ValidateSuperblock(): beacon list part missing.");
return;
}

convergence.AddPart("BeaconList", manifest->vParts[0]);
}

// Find the offset of the verified beacons project part. Typically
// this exists at vParts offset 1 when a scraper verified at least
Expand All @@ -1058,10 +1063,14 @@ class SuperblockValidator
const auto verified_beacons_entry_iter = std::find_if(
manifest->projects.begin(),
manifest->projects.end(),
[](const CScraperManifest::dentry& entry) {
[manifest](const CScraperManifest::dentry& entry) {
// Clang was giving a false positive on thread safety without this.
LOCK(manifest->cs_manifest);
return entry.project == "VerifiedBeacons";
});

LOCK2(CSplitBlob::cs_mapParts, manifest->cs_manifest);

if (verified_beacons_entry_iter == manifest->projects.end()) {
LogPrintf("ValidateSuperblock(): verified beacon project missing.");
return;
Expand All @@ -1074,8 +1083,6 @@ class SuperblockValidator
return;
}

LOCK(CSplitBlob::cs_mapParts);

convergence.AddPart("VerifiedBeacons", manifest->vParts[part_offset]);
}
}; // ProjectCombiner
Expand Down
Loading

0 comments on commit d06dcfe

Please sign in to comment.