Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verified beacons manifest part to superblock validator #1711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/neuralnet/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ class SuperblockValidator
}
}

convergence.AddPart("BeaconList", GetBeaconPartData(latest_manifest));
AddBeaconPartsData(convergence, latest_manifest);

++m_current_combination;

Expand Down Expand Up @@ -993,14 +993,15 @@ class SuperblockValidator
}

//!
//! \brief Fetch the beacon list part data from the specified manifest.
//! \brief Insert the beacon list and verified beacons part data from
//! the specified manifest into the provided convergence candidate.
//!
//! \param manifest_hash Identifies the manifest to fetch the part from.
//! \param convergence Convergence to add the beacon parts to.
//! \param manifest_hash Identifies the manifest to fetch the parts from.
//!
//! \return Serialized binary data of the beacon list part to add to a
//! convergence.
//!
static CSerializeData GetBeaconPartData(const uint256& manifest_hash)
static void AddBeaconPartsData(
ConvergenceCandidate& convergence,
const uint256& manifest_hash)
{
LOCK(CScraperManifest::cs_mapManifest);

Expand All @@ -1009,19 +1010,46 @@ class SuperblockValidator
// If the manifest for the beacon list disappeared, we cannot
// proceed, but the most recent manifest should always exist:
if (iter == CScraperManifest::mapManifest.end()) {
LogPrintf("ValidateSuperblock(): beacon list manifest disappeared.");
return CSerializeData();
LogPrintf("ValidateSuperblock(): beacon manifest disappeared.");
return;
}

const CScraperManifest& manifest = *iter->second;

// 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 (iter->second->vParts.empty()) {
if (manifest.vParts.empty()) {
LogPrintf("ValidateSuperblock(): beacon list part missing.");
return CSerializeData();
return;
}

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

// Find the offset of the verified beacons project part. Typically
// this exists at vParts offset 1 when a scraper verified at least
// one pending beacon. If it doesn't exist, omit the part from the
// reconstructed convergence:
const auto verified_beacons_entry_iter = std::find_if(
manifest.projects.begin(),
manifest.projects.end(),
[](const CScraperManifest::dentry& entry) {
return entry.project == "VerifiedBeacons";
});

if (verified_beacons_entry_iter == manifest.projects.end()) {
LogPrintf("ValidateSuperblock(): verified beacon project missing.");
return;
}

const size_t part_offset = verified_beacons_entry_iter->part1;

if (part_offset == 0 || part_offset >= manifest.vParts.size()) {
LogPrintf("ValidateSuperblock(): out-of-range verified beacon part.");
return;
}

return iter->second->vParts[0]->data;
convergence.AddPart("VerifiedBeacons", manifest.vParts[part_offset]->data);
}
}; // ProjectCombiner

Expand Down
29 changes: 29 additions & 0 deletions src/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5704,6 +5704,35 @@ scraperSBvalidationtype ValidateSuperblock(const NN::Superblock& NewFormatSuperb
// The vParts[0] is always the BeaconList.
StructDummyConvergedManifest.ConvergedManifestPartsMap.insert(std::make_pair("BeaconList", manifest.vParts[0]->data));

// Find the offset of the verified beacons project part. Typically
// this exists at vParts offset 1 when a scraper verified at least
// one pending beacon. If it doesn't exist, omit the part from the
// reconstructed convergence:
const auto verified_beacons_entry_iter = std::find_if(
manifest.projects.begin(),
manifest.projects.end(),
[](const CScraperManifest::dentry& entry) {
return entry.project == "VerifiedBeacons";
});

if (verified_beacons_entry_iter != manifest.projects.end())
{
const size_t part_offset = verified_beacons_entry_iter->part1;

if (part_offset == 0 || part_offset >= manifest.vParts.size())
{
_log(logattribute::ERR, "ValidateSuperblock", "out-of-range verified beacon part.");
}
else
{
StructDummyConvergedManifest.ConvergedManifestPartsMap.insert(std::make_pair("VerifiedBeacons", manifest.vParts[part_offset]->data));
}
}
else
{
_log(logattribute::ERR, "ValidateSuperblock", "verified beacon project missing.");
}

StructDummyConvergedManifest.ConsensusBlock = ConvergenceInfo.nConvergedConsensusBlock;

// The ConvergedManifest content hash is in the order of the map key and on the data.
Expand Down