Skip to content

Commit fa7a170

Browse files
committed
Code and documentation cleanup
1 parent 5d8af06 commit fa7a170

File tree

6 files changed

+1244
-571
lines changed

6 files changed

+1244
-571
lines changed

src/gridcoin/scraper/fwd.h

+104-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Distributed under the MIT/X11 software license, see the accompanying
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

5-
#pragma once
5+
#ifndef BITCOIN_GRIDCOIN_SCRAPER_FWD_H
6+
#define BITCOIN_GRIDCOIN_SCRAPER_FWD_H
67

78
#include <string>
89
#include <vector>
@@ -17,6 +18,7 @@
1718
* Scraper ENUMS *
1819
*********************/
1920

21+
/** Defines the object type of the stats entry */
2022
enum class statsobjecttype
2123
{
2224
NetworkWide,
@@ -25,6 +27,7 @@ enum class statsobjecttype
2527
byCPIDbyProject
2628
};
2729

30+
/** Defines the event type in the scraper system */
2831
enum class scrapereventtypes
2932
{
3033
OutOfSync,
@@ -36,6 +39,7 @@ enum class scrapereventtypes
3639
Sleep
3740
};
3841

42+
/** Defines the validation type of the convergence achieved by the subscriber */
3943
enum class scraperSBvalidationtype
4044
{
4145
Invalid,
@@ -46,86 +50,131 @@ enum class scraperSBvalidationtype
4650
ProjectLevelConvergence
4751
};
4852

53+
/** Currently the scraperID is a string. */
4954
typedef std::string ScraperID;
50-
// The inner map is sorted in descending order of time. The pair is manifest hash, content hash.
55+
/** The inner map is sorted in descending order of time. The pair is manifest hash, content hash. */
5156
typedef std::multimap<int64_t, std::pair<uint256, uint256>, std::greater <int64_t>> mCSManifest;
52-
// This is sCManifestName, which is the string version of the originating scraper pubkey.
53-
// See the ScraperID typedef above.
57+
/** This is sCManifestName, which is the string version of the originating scraper pubkey. */
5458
typedef std::map<ScraperID, mCSManifest> mmCSManifestsBinnedByScraper;
5559

60+
/** Make the smart shared pointer a little less awkward for CScraperManifest */
5661
typedef std::shared_ptr<CScraperManifest> CScraperManifest_shared_ptr;
5762

58-
// Note the CParts pointed to by this map are safe to access, because the pointers are guaranteed valid
59-
// as long as the holding CScraperManifests (both in the CScaperManifest global map, and this cache)
60-
// still exist. So the safety of these pointers is coincident with the lifespan of CScraperManifests
61-
// that have reference to them. If you have questions about this, you should review the CSplitBlob abstract
62-
// class, which is the base class of the CScraperManifest class, and provides the mechanisms for part
63-
// control. Note that two LOCKS are used to protect the integrity of the underlying global maps,
64-
// CScraperManifest::cs_mapManifest and CSplitBlob::cs_mapParts.
65-
// -------------- Project -- Converged Part Pointer
63+
/** Note the CParts pointed to by this map are safe to access, because the pointers are guaranteed valid
64+
* as long as the holding CScraperManifests (both in the CScaperManifest global map, and this cache)
65+
* still exist. So the safety of these pointers is coincident with the lifespan of CScraperManifests
66+
* that have reference to them. If you have questions about this, you should review the CSplitBlob abstract
67+
* class, which is the base class of the CScraperManifest class, and provides the mechanisms for part
68+
* control. Note that two LOCKS are used to protect the integrity of the underlying global maps,
69+
* CScraperManifest::cs_mapManifest and CSplitBlob::cs_mapParts.
70+
* ---------- Project -- Converged Part Pointer
71+
* std::map<std::string, CSplitBlob::CPart*> mConvergedManifestPart_ptrs
72+
*/
6673
typedef std::map<std::string, CSplitBlob::CPart*> mConvergedManifestPart_ptrs;
6774

75+
/** Used for a "convergence", which is the result of the subscriber comparing published manifests from the scrapers in
76+
* accordance with the rules of convergence, where the rules have been met. The convergence is used as the basis of
77+
* constructing a superblock. */
6878
struct ConvergedManifest
6979
{
70-
// Empty converged manifest constructor
80+
/** Empty converged manifest constructor */
7181
ConvergedManifest();
7282

73-
// For constructing a dummy converged manifest from a single manifest
83+
/** For constructing a dummy converged manifest from a single manifest */
7484
ConvergedManifest(CScraperManifest_shared_ptr& in);
7585

76-
// Call operator to update an already initialized ConvergedManifest with a passed in CScraperManifest
86+
/** Call operator to update an already initialized ConvergedManifest with a passed in CScraperManifest */
7787
bool operator()(const CScraperManifest_shared_ptr& in);
7888

79-
// IMPORTANT... nContentHash is NOT the hash of part hashes in the order of vParts unlike CScraper::manifest.
80-
// It is the hash of the data in the ConvergedManifestPartsMap in the order of the key. It represents
81-
// the composite convergence by taking parts piecewise in the case of the fallback to bByParts (project) level.
89+
/** IMPORTANT... nContentHash is NOT the hash of part hashes in the order of vParts unlike CScraper::manifest.
90+
* It is the hash of the data in the ConvergedManifestPartsMap in the order of the key. It represents
91+
* the composite convergence by taking parts piecewise in the case of the fallback to bByParts (project) level.
92+
*/
8293
uint256 nContentHash;
94+
/** The block on which the convergence was formed. */
8395
uint256 ConsensusBlock;
96+
/** The time of the convergence. */
8497
int64_t timestamp = 0;
98+
/** Flag indicating whether the convergence was formed at the project level. If the rules of convergence cannot
99+
* be met at the whole manifest level (which could happen if a project were not available in some manifests, for
100+
* example), then in the fallback to put together a convergence from matching at the project (part) level, this flag
101+
* will be set if a convergence is formed that way.
102+
*/
85103
bool bByParts = false;
86104

105+
/** The shared pointer to the CScraperManifest that underlies the convergence. If the convergence was at the manifest
106+
* level, this will be the manifest selected as the representation of the equivalent manifests used to determine the
107+
* convergence. If the convergence is at the parts (project) level, then this will point to a synthesized (non-published)
108+
* manifest which only has the vParts vector filled out, and which content is the parts selected to form the byParts
109+
* (project) level convergence. Note that this synthesized manifest is LOCAL ONLY and will not be added to mapManifests
110+
* or published to other nodes. Convergences in general are the responsibility of the subscriber, not the publisher.
111+
*/
87112
CScraperManifest_shared_ptr CScraperConvergedManifest_ptr = nullptr;
88113

114+
/** A map to the pointers of the parts used to form the convergence. This will be essentially the same as the vParts
115+
* vector in the CScraperManifest pointed to by the CScraperConvergedManifest_ptr.
116+
*/
89117
mConvergedManifestPart_ptrs ConvergedManifestPartPtrsMap;
90118

91-
// Used when convergence is at the manifest level (normal)
119+
/** A map of the manifests by hash (key) that formed this convergence. This is used when convergence is at the manifest
120+
* level (normal).
121+
*/
92122
std::map<ScraperID, uint256> mIncludedScraperManifests;
93-
// The below is the manifest content hash for the underlying manifests that comprise the convergence. This
94-
// will only be populated if the convergence is at the manifest level (bByParts == false). In that case, each
95-
// manifest's content in the convergence must be the same. If the convergence is by project, this does not
96-
// make sense to populate. See the above comment.
123+
/** The below is the manifest content hash for the underlying manifests that comprise the convergence. This
124+
* will only be populated if the convergence is at the manifest level (bByParts == false). In that case, each
125+
* manifest's content in the convergence must be the same. If the convergence is by project, this does not
126+
* make sense to populate.
127+
*/
97128
uint256 nUnderlyingManifestContentHash;
98129

99-
// Used when convergence is at the manifest level (normal) and also at the part (project) level for
100-
// scrapers that are not part of any part (project) level convergence.
130+
/** The publishing scrapers included in the convergence. If the convergence is at the project level, a scraper in this
131+
* vector would have to be included in at least one project level match for the synthesized convergence.
132+
*/
101133
std::vector<ScraperID> vIncludedScrapers;
134+
/** The publishing scrapers excluded from the convergence. If the convergence is at the project level, a scraper in this
135+
* vector would not have been included in ANY project level match for the synthesized convergence.
136+
*/
102137
std::vector<ScraperID> vExcludedScrapers;
138+
/** The scrapers not publishing (i.e. no manifests present with the retention period) when the convergence was formed. */
103139
std::vector<ScraperID> vScrapersNotPublishing;
104140

105-
// Used when convergence is at the project (bByParts) level (fallback)
106-
// ----- Project --------- ScraperID
141+
/** Used when convergence is at the project (bByParts) level (fallback)
142+
* -------------- Project --- ScraperID
143+
* std::multimap<std::string, ScraperID> mIncludedScrapersbyProject
144+
*/
107145
std::multimap<std::string, ScraperID> mIncludedScrapersbyProject;
108-
// ----- ScraperID ------- Project
146+
/** Used when convergence is at the project (bByParts) level (fallback)
147+
* ------------- ScraperID --- Project
148+
* std::multimap<ScraperID, std::string> mIncludedProjectsbyScraper
149+
*/
109150
std::multimap<ScraperID, std::string> mIncludedProjectsbyScraper;
110-
// When bByParts (project) level convergence occurs, this records the count of scrapers in the
111-
// convergences by project.
151+
/** When bByParts (project) level convergence occurs, this records the count of scrapers in the
152+
* convergences by project.
153+
*/
112154
std::map<std::string, unsigned int> mScraperConvergenceCountbyProject;
113155

114-
// --------- project
156+
/** The projects excluded from the convergence. Since the convergence rules REQUIRE a fallback to project level
157+
* convergence if the trial convergence formed at the manifest level excludes a project, this vector should only have
158+
* an entry if bByParts is also true.
159+
*/
115160
std::vector<std::string> vExcludedProjects;
116161

162+
/** Populates the part pointers map in the convergence */
117163
bool PopulateConvergedManifestPartPtrsMap();
118164

165+
/** Computes the converged content hash */
119166
void ComputeConvergedContentHash();
120167
};
121168

122169

170+
/** Used for the key of the statistics map(s) in the scraper */
123171
struct ScraperObjectStatsKey
124172
{
125173
statsobjecttype objecttype;
126174
std::string objectID;
127175
};
128176

177+
/** Used for the value of the stats entries in the statistics map(s) in the scraper */
129178
struct ScraperObjectStatsValue
130179
{
131180
double dTC;
@@ -135,12 +184,14 @@ struct ScraperObjectStatsValue
135184
double dMag;
136185
};
137186

187+
/** Used for the stats entries in the statistics map(s) in the scraper */
138188
struct ScraperObjectStats
139189
{
140190
ScraperObjectStatsKey statskey;
141191
ScraperObjectStatsValue statsvalue;
142192
};
143193

194+
/** Comparison for the statistics map entry ordering */
144195
struct ScraperObjectStatsKeyComp
145196
{
146197
bool operator() ( ScraperObjectStatsKey a, ScraperObjectStatsKey b ) const
@@ -149,17 +200,20 @@ struct ScraperObjectStatsKeyComp
149200
}
150201
};
151202

203+
/** Definition of the scraper statistics map(s) */
152204
typedef std::map<ScraperObjectStatsKey, ScraperObjectStats, ScraperObjectStatsKeyComp> ScraperStats;
153205

154-
// This is modeled after AppCacheEntry/Section but named separately.
206+
/** modeled after AppCacheEntry/Section but named separately. */
155207
struct ScraperBeaconEntry
156208
{
157209
std::string value; //!< Value of entry.
158210
int64_t timestamp; //!< Timestamp of entry.
159211
};
160212

213+
/** Definition of the scraper beacon map */
161214
typedef std::map<std::string, ScraperBeaconEntry> ScraperBeaconMap;
162215

216+
/** Small structure to define the fields and (un)serialization for pending beacon entries */
163217
struct ScraperPendingBeaconEntry
164218
{
165219
std::string cpid;
@@ -183,16 +237,22 @@ struct ScraperPendingBeaconEntry
183237
}
184238
};
185239

186-
// --- Base58 encoded public key ---- cpid, timestamp
240+
/** - Base58 encoded public key - {cpid, timestamp, keyid}
241+
* std::map<std::string, ScraperPendingBeaconEntry> ScraperPendingBeaconMap
242+
*/
187243
typedef std::map<std::string, ScraperPendingBeaconEntry> ScraperPendingBeaconMap;
188244

245+
/** Used to hold the block hash, scraper beacon map and pending beacon map at the ladder consensus point. This will be used
246+
* as appropriate in the convergence formed.
247+
*/
189248
struct BeaconConsensus
190249
{
191250
uint256 nBlockHash;
192251
ScraperBeaconMap mBeaconMap;
193252
ScraperPendingBeaconMap mPendingMap;
194253
};
195254

255+
/** Small structure to define the fields for verified beacons and (un)serialization */
196256
struct ScraperVerifiedBeacons
197257
{
198258
// Initialize the timestamp to the current adjusted time.
@@ -216,18 +276,28 @@ struct ScraperVerifiedBeacons
216276
}
217277
};
218278

279+
/** A combination of scraper stats and verified beacons. For convenience in the interface between the scraper and the
280+
* quorum/superblock code.
281+
*/
219282
struct ScraperStatsAndVerifiedBeacons
220283
{
221284
ScraperStats mScraperStats;
222285
ScraperPendingBeaconMap mVerifiedMap;
223286
};
224287

225-
// Extended AppCache structures similar to those in AppCache.h, except a deleted flag is provided
288+
/** Extended AppCache structure similar to those in AppCache.h, except a deleted flag is provided. This will be
289+
* reimplemented in the future with a custom contract handler since the appcache is being retired.
290+
*/
226291
struct AppCacheEntryExt
227292
{
228293
std::string value; // Value of entry.
229294
int64_t timestamp; // Timestamp of entry/deletion
230295
bool deleted; // Deleted flag.
231296
};
232297

298+
/** Extended AppCache map typedef similar to those in AppCache.h, except a deleted flag is provided. This will be
299+
* reimplemented in the future with a custom contract handler since the appcache is being retired.
300+
*/
233301
typedef std::unordered_map<std::string, AppCacheEntryExt> AppCacheSectionExt;
302+
303+
#endif //BITCOIN_GRIDCOIN_SCRAPER_FWD_H

0 commit comments

Comments
 (0)