2
2
// Distributed under the MIT/X11 software license, see the accompanying
3
3
// file COPYING or https://opensource.org/licenses/mit-license.php.
4
4
5
- #pragma once
5
+ #ifndef BITCOIN_GRIDCOIN_SCRAPER_FWD_H
6
+ #define BITCOIN_GRIDCOIN_SCRAPER_FWD_H
6
7
7
8
#include < string>
8
9
#include < vector>
17
18
* Scraper ENUMS *
18
19
*********************/
19
20
21
+ /* * Defines the object type of the stats entry */
20
22
enum class statsobjecttype
21
23
{
22
24
NetworkWide,
@@ -25,6 +27,7 @@ enum class statsobjecttype
25
27
byCPIDbyProject
26
28
};
27
29
30
+ /* * Defines the event type in the scraper system */
28
31
enum class scrapereventtypes
29
32
{
30
33
OutOfSync,
@@ -36,6 +39,7 @@ enum class scrapereventtypes
36
39
Sleep
37
40
};
38
41
42
+ /* * Defines the validation type of the convergence achieved by the subscriber */
39
43
enum class scraperSBvalidationtype
40
44
{
41
45
Invalid,
@@ -46,86 +50,131 @@ enum class scraperSBvalidationtype
46
50
ProjectLevelConvergence
47
51
};
48
52
53
+ /* * Currently the scraperID is a string. */
49
54
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. */
51
56
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. */
54
58
typedef std::map<ScraperID, mCSManifest > mmCSManifestsBinnedByScraper;
55
59
60
+ /* * Make the smart shared pointer a little less awkward for CScraperManifest */
56
61
typedef std::shared_ptr<CScraperManifest> CScraperManifest_shared_ptr;
57
62
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
+ */
66
73
typedef std::map<std::string, CSplitBlob::CPart*> mConvergedManifestPart_ptrs ;
67
74
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. */
68
78
struct ConvergedManifest
69
79
{
70
- // Empty converged manifest constructor
80
+ /* * Empty converged manifest constructor */
71
81
ConvergedManifest ();
72
82
73
- // For constructing a dummy converged manifest from a single manifest
83
+ /* * For constructing a dummy converged manifest from a single manifest */
74
84
ConvergedManifest (CScraperManifest_shared_ptr& in);
75
85
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 */
77
87
bool operator ()(const CScraperManifest_shared_ptr& in);
78
88
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
+ */
82
93
uint256 nContentHash;
94
+ /* * The block on which the convergence was formed. */
83
95
uint256 ConsensusBlock;
96
+ /* * The time of the convergence. */
84
97
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
+ */
85
103
bool bByParts = false ;
86
104
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
+ */
87
112
CScraperManifest_shared_ptr CScraperConvergedManifest_ptr = nullptr ;
88
113
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
+ */
89
117
mConvergedManifestPart_ptrs ConvergedManifestPartPtrsMap;
90
118
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
+ */
92
122
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
+ */
97
128
uint256 nUnderlyingManifestContentHash;
98
129
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
+ */
101
133
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
+ */
102
137
std::vector<ScraperID> vExcludedScrapers;
138
+ /* * The scrapers not publishing (i.e. no manifests present with the retention period) when the convergence was formed. */
103
139
std::vector<ScraperID> vScrapersNotPublishing;
104
140
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
+ */
107
145
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
+ */
109
150
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
+ */
112
154
std::map<std::string, unsigned int > mScraperConvergenceCountbyProject ;
113
155
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
+ */
115
160
std::vector<std::string> vExcludedProjects;
116
161
162
+ /* * Populates the part pointers map in the convergence */
117
163
bool PopulateConvergedManifestPartPtrsMap ();
118
164
165
+ /* * Computes the converged content hash */
119
166
void ComputeConvergedContentHash ();
120
167
};
121
168
122
169
170
+ /* * Used for the key of the statistics map(s) in the scraper */
123
171
struct ScraperObjectStatsKey
124
172
{
125
173
statsobjecttype objecttype;
126
174
std::string objectID;
127
175
};
128
176
177
+ /* * Used for the value of the stats entries in the statistics map(s) in the scraper */
129
178
struct ScraperObjectStatsValue
130
179
{
131
180
double dTC;
@@ -135,12 +184,14 @@ struct ScraperObjectStatsValue
135
184
double dMag;
136
185
};
137
186
187
+ /* * Used for the stats entries in the statistics map(s) in the scraper */
138
188
struct ScraperObjectStats
139
189
{
140
190
ScraperObjectStatsKey statskey;
141
191
ScraperObjectStatsValue statsvalue;
142
192
};
143
193
194
+ /* * Comparison for the statistics map entry ordering */
144
195
struct ScraperObjectStatsKeyComp
145
196
{
146
197
bool operator () ( ScraperObjectStatsKey a, ScraperObjectStatsKey b ) const
@@ -149,17 +200,20 @@ struct ScraperObjectStatsKeyComp
149
200
}
150
201
};
151
202
203
+ /* * Definition of the scraper statistics map(s) */
152
204
typedef std::map<ScraperObjectStatsKey, ScraperObjectStats, ScraperObjectStatsKeyComp> ScraperStats;
153
205
154
- // This is modeled after AppCacheEntry/Section but named separately.
206
+ /* * modeled after AppCacheEntry/Section but named separately. */
155
207
struct ScraperBeaconEntry
156
208
{
157
209
std::string value; // !< Value of entry.
158
210
int64_t timestamp; // !< Timestamp of entry.
159
211
};
160
212
213
+ /* * Definition of the scraper beacon map */
161
214
typedef std::map<std::string, ScraperBeaconEntry> ScraperBeaconMap;
162
215
216
+ /* * Small structure to define the fields and (un)serialization for pending beacon entries */
163
217
struct ScraperPendingBeaconEntry
164
218
{
165
219
std::string cpid;
@@ -183,16 +237,22 @@ struct ScraperPendingBeaconEntry
183
237
}
184
238
};
185
239
186
- // --- Base58 encoded public key ---- cpid, timestamp
240
+ /* * - Base58 encoded public key - {cpid, timestamp, keyid}
241
+ * std::map<std::string, ScraperPendingBeaconEntry> ScraperPendingBeaconMap
242
+ */
187
243
typedef std::map<std::string, ScraperPendingBeaconEntry> ScraperPendingBeaconMap;
188
244
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
+ */
189
248
struct BeaconConsensus
190
249
{
191
250
uint256 nBlockHash;
192
251
ScraperBeaconMap mBeaconMap ;
193
252
ScraperPendingBeaconMap mPendingMap ;
194
253
};
195
254
255
+ /* * Small structure to define the fields for verified beacons and (un)serialization */
196
256
struct ScraperVerifiedBeacons
197
257
{
198
258
// Initialize the timestamp to the current adjusted time.
@@ -216,18 +276,28 @@ struct ScraperVerifiedBeacons
216
276
}
217
277
};
218
278
279
+ /* * A combination of scraper stats and verified beacons. For convenience in the interface between the scraper and the
280
+ * quorum/superblock code.
281
+ */
219
282
struct ScraperStatsAndVerifiedBeacons
220
283
{
221
284
ScraperStats mScraperStats ;
222
285
ScraperPendingBeaconMap mVerifiedMap ;
223
286
};
224
287
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
+ */
226
291
struct AppCacheEntryExt
227
292
{
228
293
std::string value; // Value of entry.
229
294
int64_t timestamp; // Timestamp of entry/deletion
230
295
bool deleted; // Deleted flag.
231
296
};
232
297
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
+ */
233
301
typedef std::unordered_map<std::string, AppCacheEntryExt> AppCacheSectionExt;
302
+
303
+ #endif // BITCOIN_GRIDCOIN_SCRAPER_FWD_H
0 commit comments