MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run

Method run

contrib/linearize/linearize-data.py:234–299  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

232 self.writeBlock(extent.inhdr, extent.blkhdr, rawblock)
233
234 def run(self):
235 while self.blkCountOut < len(self.blkindex):
236 if not self.inF:
237 fname = self.inFileName(self.inFn)
238 print("Input file " + fname)
239 try:
240 self.inF = open(fname, "rb")
241 except IOError:
242 print("Premature end of block data")
243 return
244
245 inhdr = self.inF.read(8)
246 if (not inhdr or (inhdr[0] == "\0")):
247 self.inF.close()
248 self.inF = None
249 self.inFn = self.inFn + 1
250 continue
251
252 inMagic = inhdr[:4]
253 if (inMagic != self.settings['netmagic']):
254 print("Invalid magic: " + hexlify(inMagic).decode('utf-8'))
255 return
256 inLenLE = inhdr[4:]
257 su = struct.unpack("<I", inLenLE)
258 blk_hdr = b''
259 blk_hdr += self.inF.read(140)
260 nSol = deser_compact_size(self.inF)
261 blk_hdr += ser_compact_size(nSol)
262 blk_hdr += self.inF.read(nSol)
263 inLen = su[0] - len(blk_hdr) # length without header
264 inExtent = BlockExtent(self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen)
265
266 blk_height = struct.unpack('<I', blk_hdr[68:68+4])[0]
267 self.hash_str = calc_hash_str(blk_hdr, blk_height >= 491407)
268 if not self.hash_str in blkmap:
269 # Because blocks can be written to files out-of-order as of 0.10, the script
270 # may encounter blocks it doesn't know about. Treat as debug output.
271 if settings['debug_output'] == 'true':
272 print("Skipping unknown block " + self.hash_str)
273 self.inF.seek(inLen, os.SEEK_CUR)
274 continue
275
276 blkHeight = self.blkmap[self.hash_str]
277 self.blkCountIn += 1
278
279 if self.blkCountOut == blkHeight:
280 # If in-order block, just copy
281 rawblock = self.inF.read(inLen)
282 self.writeBlock(inhdr, blk_hdr, rawblock)
283
284 # See if we can catch up to prior out-of-order blocks
285 while self.blkCountOut in self.blockExtents:
286 self.copyOneBlock()
287
288 else: # If out-of-order, skip over block data for now
289 self.blockExtents[blkHeight] = inExtent
290 if self.outOfOrderSize < self.settings['out_of_order_cache_sz']:
291 # If there is space in the cache, read the data

Callers 1

linearize-data.pyFile · 0.45

Calls 9

inFileNameMethod · 0.95
writeBlockMethod · 0.95
copyOneBlockMethod · 0.95
calc_hash_strFunction · 0.85
deser_compact_sizeFunction · 0.70
ser_compact_sizeFunction · 0.70
readMethod · 0.45
closeMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected