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

Method run

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

Source from the content-addressed store, hash-verified

198 self.writeBlock(extent.inhdr, extent.blkhdr, rawblock)
199
200 def run(self):
201 while self.blkCountOut < len(self.blkindex):
202 if not self.inF:
203 fname = self.inFileName(self.inFn)
204 print("Input file " + fname)
205 try:
206 self.inF = open(fname, "rb")
207 except IOError:
208 print("Premature end of block data")
209 return
210
211 inhdr = self.read_xored(self.inF, 8)
212 if (not inhdr or (inhdr[0] == "\0")):
213 self.inF.close()
214 self.inF = None
215 self.inFn = self.inFn + 1
216 continue
217
218 inMagic = inhdr[:4]
219 if (inMagic != self.settings['netmagic']):
220 # Seek backwards 7 bytes (skipping the first byte in the previous search)
221 # and continue searching from the new position if the magic bytes are not
222 # found.
223 self.inF.seek(-7, os.SEEK_CUR)
224 continue
225 inLenLE = inhdr[4:]
226 su = struct.unpack("<I", inLenLE)
227 inLen = su[0] - 80 # length without header
228 blk_hdr = self.read_xored(self.inF, 80)
229 inExtent = BlockExtent(self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen)
230
231 self.hash_str = calc_hash_str(blk_hdr)
232 if self.hash_str not in blkmap:
233 # Because blocks can be written to files out-of-order as of 0.10, the script
234 # may encounter blocks it doesn't know about. Treat as debug output.
235 if settings['debug_output'] == 'true':
236 print("Skipping unknown block " + self.hash_str)
237 self.inF.seek(inLen, os.SEEK_CUR)
238 continue
239
240 blkHeight = self.blkmap[self.hash_str]
241 self.blkCountIn += 1
242
243 if self.blkCountOut == blkHeight:
244 # If in-order block, just copy
245 rawblock = self.read_xored(self.inF, inLen)
246 self.writeBlock(inhdr, blk_hdr, rawblock)
247
248 # See if we can catch up to prior out-of-order blocks
249 while self.blkCountOut in self.blockExtents:
250 self.copyOneBlock()
251
252 else: # If out-of-order, skip over block data for now
253 self.blockExtents[blkHeight] = inExtent
254 if self.outOfOrderSize < self.settings['out_of_order_cache_sz']:
255 # If there is space in the cache, read the data
256 # Reading the data in file sequence instead of seeking and fetching it later is preferred,
257 # but we don't want to fill up memory

Callers 15

linearize-data.pyFile · 0.45
mainFunction · 0.45
run_verifyFunction · 0.45
download_with_wgetFunction · 0.45
verify_with_gpgFunction · 0.45
check_multisigFunction · 0.45
gen-manpages.pyFile · 0.45
getcoins.pyFile · 0.45
MemPoolAddTransactionsFunction · 0.45
ComplexMemPoolFunction · 0.45
MempoolCheckFunction · 0.45

Calls 8

inFileNameMethod · 0.95
read_xoredMethod · 0.95
writeBlockMethod · 0.95
copyOneBlockMethod · 0.95
calc_hash_strFunction · 0.85
tellMethod · 0.80
closeMethod · 0.45
seekMethod · 0.45

Tested by 1

run_verifyFunction · 0.36