9
9
#include " util.h"
10
10
#include " streams.h"
11
11
12
+ #include " scraper_net.h"
13
+
12
14
/* ********************
13
15
* Scraper ENUMS *
14
16
*********************/
@@ -56,12 +58,164 @@ typedef std::multimap<int64_t, std::pair<uint256, uint256>, std::greater <int64_
56
58
typedef std::map<ScraperID, mCSManifest > mmCSManifestsBinnedByScraper;
57
59
58
60
// -------------- Project ---- Converged Part
59
- typedef std::map<std::string, CSerializeData> mConvergedManifestParts ;
60
- // Note that this IS a copy not a pointer. Since manifests and parts can be deleted because of aging rules,
61
- // it is dangerous to save memory and point to the actual part objects themselves.
61
+ // typedef std::map<std::string, CSerializeData> mConvergedManifestParts;
62
+
63
+ // -------------- Project -- Converged Part Pointer
64
+ typedef std::map<std::string, CSplitBlob::CPart*> mConvergedManifestPart_ptrs ;
62
65
63
66
struct ConvergedManifest
64
67
{
68
+ ConvergedManifest ()
69
+ {
70
+ nContentHash = {};
71
+ ConsensusBlock = {};
72
+ timestamp = 0 ;
73
+ bByParts = false ;
74
+
75
+ CScraperConvergedManifest_ptr = nullptr ;
76
+
77
+ ConvergedManifestPartPtrsMap = {};
78
+
79
+ mIncludedScraperManifests = {};
80
+
81
+ nUnderlyingManifestContentHash = {};
82
+
83
+ vIncludedScrapers = {};
84
+ vExcludedScrapers = {};
85
+ vScrapersNotPublishing = {};
86
+
87
+ mIncludedScrapersbyProject = {};
88
+ mIncludedProjectsbyScraper = {};
89
+
90
+ mScraperConvergenceCountbyProject = {};
91
+
92
+ vExcludedProjects = {};
93
+ }
94
+
95
+ ConvergedManifest (const ConvergedManifest& in)
96
+ {
97
+ // We can use the content hash from the specified converged manifest. We do not need to recompute it.
98
+ nContentHash = in.nContentHash ;
99
+
100
+ ConsensusBlock = in.ConsensusBlock ;
101
+ timestamp = in.timestamp ;
102
+ bByParts = in.bByParts ;
103
+
104
+ CScraperConvergedManifest_ptr = in.CScraperConvergedManifest_ptr ;
105
+
106
+ PopulateConvergedManifestPartPtrsMap ();
107
+
108
+ mIncludedScraperManifests = in.mIncludedScraperManifests ;
109
+
110
+ nUnderlyingManifestContentHash = in.nUnderlyingManifestContentHash ;
111
+
112
+ vIncludedScrapers = in.vIncludedScrapers ;
113
+ vExcludedScrapers = in.vExcludedScrapers ;
114
+ vScrapersNotPublishing = in.vScrapersNotPublishing ;
115
+
116
+ mIncludedScrapersbyProject = in.mIncludedScrapersbyProject ;
117
+ mIncludedProjectsbyScraper = in.mIncludedProjectsbyScraper ;
118
+
119
+ mScraperConvergenceCountbyProject = in.mScraperConvergenceCountbyProject ;
120
+
121
+ vExcludedProjects = in.vExcludedProjects ;
122
+ }
123
+
124
+ // For constructing a dummy converged manifest from a single manifest
125
+ ConvergedManifest (CScraperManifest& in)
126
+ {
127
+ ConsensusBlock = in.ConsensusBlock ;
128
+ timestamp = GetAdjustedTime ();
129
+ bByParts = false ;
130
+
131
+ CScraperConvergedManifest_ptr = std::make_shared<CScraperManifest>(in);
132
+
133
+ PopulateConvergedManifestPartPtrsMap ();
134
+
135
+ ComputeConvergedContentHash ();
136
+
137
+ nUnderlyingManifestContentHash = in.nContentHash ;
138
+ }
139
+
140
+
141
+ void operator ()(ConvergedManifest& in)
142
+ {
143
+ // We can use the content hash from the specified converged manifest. We do not need to recompute it.
144
+ nContentHash = in.nContentHash ;
145
+
146
+ ConsensusBlock = in.ConsensusBlock ;
147
+ timestamp = in.timestamp ;
148
+ bByParts = in.bByParts ;
149
+
150
+ CScraperConvergedManifest_ptr = in.CScraperConvergedManifest_ptr ;
151
+
152
+ PopulateConvergedManifestPartPtrsMap ();
153
+
154
+ // ConvergedManifestPartsMap = in.ConvergedManifestPartsMap;
155
+
156
+ mIncludedScraperManifests = in.mIncludedScraperManifests ;
157
+
158
+ nUnderlyingManifestContentHash = in.nUnderlyingManifestContentHash ;
159
+
160
+ vIncludedScrapers = in.vIncludedScrapers ;
161
+ vExcludedScrapers = in.vExcludedScrapers ;
162
+ vScrapersNotPublishing = in.vScrapersNotPublishing ;
163
+
164
+ mIncludedScrapersbyProject = in.mIncludedScrapersbyProject ;
165
+ mIncludedProjectsbyScraper = in.mIncludedProjectsbyScraper ;
166
+
167
+ mScraperConvergenceCountbyProject = in.mScraperConvergenceCountbyProject ;
168
+
169
+ vExcludedProjects = in.vExcludedProjects ;
170
+ }
171
+
172
+ bool operator ()(const CScraperManifest& in)
173
+ {
174
+ ConsensusBlock = in.ConsensusBlock ;
175
+ timestamp = GetAdjustedTime ();
176
+ bByParts = false ;
177
+
178
+ CScraperConvergedManifest_ptr = std::make_shared<CScraperManifest>(in);
179
+
180
+ bool bConvergedContentHashMatches = PopulateConvergedManifestPartPtrsMap ();
181
+
182
+ ComputeConvergedContentHash ();
183
+
184
+ nUnderlyingManifestContentHash = in.nContentHash ;
185
+
186
+ return bConvergedContentHashMatches;
187
+ }
188
+
189
+ void Reset ()
190
+ {
191
+ nContentHash = {};
192
+ ConsensusBlock = {};
193
+ timestamp = 0 ;
194
+ bByParts = false ;
195
+
196
+ CScraperConvergedManifest_ptr = nullptr ;
197
+
198
+ // ConvergedManifestPartsMap = {};
199
+
200
+ ConvergedManifestPartPtrsMap = {};
201
+
202
+ mIncludedScraperManifests = {};
203
+
204
+ nUnderlyingManifestContentHash = {};
205
+
206
+ vIncludedScrapers = {};
207
+ vExcludedScrapers = {};
208
+ vScrapersNotPublishing = {};
209
+
210
+ mIncludedScrapersbyProject = {};
211
+ mIncludedProjectsbyScraper = {};
212
+
213
+ mScraperConvergenceCountbyProject = {};
214
+
215
+ vExcludedProjects = {};
216
+ }
217
+
218
+
65
219
// IMPORTANT... nContentHash is NOT the hash of part hashes in the order of vParts unlike CScraper::manifest.
66
220
// It is the hash of the data in the ConvergedManifestPartsMap in the order of the key. It represents
67
221
// the composite convergence by taking parts piecewise in the case of the fallback to bByParts (project) level.
@@ -70,7 +224,11 @@ struct ConvergedManifest
70
224
int64_t timestamp;
71
225
bool bByParts;
72
226
73
- mConvergedManifestParts ConvergedManifestPartsMap;
227
+ std::shared_ptr<CScraperManifest> CScraperConvergedManifest_ptr;
228
+
229
+ // mConvergedManifestParts ConvergedManifestPartsMap;
230
+
231
+ mConvergedManifestPart_ptrs ConvergedManifestPartPtrsMap;
74
232
75
233
// Used when convergence is at the manifest level (normal)
76
234
std::map<ScraperID, uint256> mIncludedScraperManifests ;
@@ -97,6 +255,62 @@ struct ConvergedManifest
97
255
98
256
// --------- project
99
257
std::vector<std::string> vExcludedProjects;
258
+
259
+ bool PopulateConvergedManifestPartPtrsMap ()
260
+ {
261
+ if (CScraperConvergedManifest_ptr == nullptr ) return false ;
262
+
263
+ int iPartNum = 0 ;
264
+ CDataStream ss (SER_NETWORK,1 );
265
+ WriteCompactSize (ss, CScraperConvergedManifest_ptr->vParts .size ());
266
+ uint256 nContentHashCheck;
267
+
268
+ for (const auto & iter : CScraperConvergedManifest_ptr->vParts )
269
+ {
270
+ std::string sProject ;
271
+
272
+ if (iPartNum == 0 )
273
+ sProject = " BeaconList" ;
274
+ else
275
+ sProject = CScraperConvergedManifest_ptr->projects [iPartNum-1 ].project ;
276
+
277
+ // Copy the pointer to the CPart into the map. This is ok, because the parts will be held
278
+ // until the CScraperManifest in this object is destroyed and all of the manifest refs to the part
279
+ // are gone.
280
+ ConvergedManifestPartPtrsMap.insert (std::make_pair (sProject , iter));
281
+
282
+ // Serialize the hash to doublecheck the content hash.
283
+ ss << iter->hash ;
284
+
285
+ iPartNum++;
286
+ }
287
+
288
+ ss << CScraperConvergedManifest_ptr->ConsensusBlock ;
289
+
290
+ nContentHashCheck = Hash (ss.begin (), ss.end ());
291
+
292
+ if (nContentHashCheck != CScraperConvergedManifest_ptr->nContentHash )
293
+ {
294
+ LogPrintf (" ERROR: PopulateConvergedManifestPartPtrsMap(): Selected Manifest content hash check failed! "
295
+ " nContentHashCheck = %s and nContentHash = %s." ,
296
+ nContentHashCheck.GetHex (), CScraperConvergedManifest_ptr->nContentHash .GetHex ());
297
+ return false ;
298
+ }
299
+
300
+ return true ;
301
+ }
302
+
303
+ void ComputeConvergedContentHash ()
304
+ {
305
+ CDataStream ss (SER_NETWORK,1 );
306
+
307
+ for (const auto & iter : ConvergedManifestPartPtrsMap)
308
+ {
309
+ ss << iter.second ->data ;
310
+ }
311
+
312
+ nContentHash = Hash (ss.begin (), ss.end ());
313
+ }
100
314
};
101
315
102
316
0 commit comments