aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorRjected <kidscline01@gmail.com>2019-10-27 23:01:22 -0400
committerRjected <kidscline01@gmail.com>2019-10-27 23:08:10 -0400
commit317fb96de9c6257972f1213b4ef2c3fe87dde99f (patch)
tree55f9ecd32de40dcba829ada811ce53302edc976a /contrib
parentbe50469217bd775c4305938634c32e5932f47841 (diff)
Add search for first blk file with pruned node
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/linearize/linearize-data.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index 863b22f6b1..9ad7a03941 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -15,6 +15,7 @@ import sys
import hashlib
import datetime
import time
+import glob
from collections import namedtuple
from binascii import unhexlify
@@ -92,6 +93,30 @@ def mkblockmap(blkindex):
blkmap[hash] = height
return blkmap
+# This gets the first block file ID that exists from the input block
+# file directory.
+def getFirstBlockFileId(block_dir_path):
+ # First, this sets up a pattern to search for block files, for
+ # example 'blkNNNNN.dat'.
+ blkFilePattern = os.path.join(block_dir_path, "blk[0-9][0-9][0-9][0-9][0-9].dat")
+
+ # This search is done with glob
+ blkFnList = glob.glob(blkFilePattern)
+
+ if len(blkFnList) == 0:
+ print("blocks not pruned - starting at 0")
+ return 0
+ # We then get the lexicographic minimum, which should be the first
+ # block file name.
+ firstBlkFilePath = min(blkFnList)
+ firstBlkFn = os.path.basename(firstBlkFilePath)
+
+ # now, the string should be ['b','l','k','N','N','N','N','N','.','d','a','t']
+ # So get the ID by choosing: 3 4 5 6 7
+ # The ID is not necessarily 0 if this is a pruned node.
+ blkId = int(firstBlkFn[3:8])
+ return blkId
+
# Block header and extent on disk
BlockExtent = namedtuple('BlockExtent', ['fn', 'offset', 'inhdr', 'blkhdr', 'size'])
@@ -101,7 +126,9 @@ class BlockDataCopier:
self.blkindex = blkindex
self.blkmap = blkmap
- self.inFn = 0
+ # Get first occurring block file id - for pruned nodes this
+ # will not necessarily be 0
+ self.inFn = getFirstBlockFileId(self.settings['input'])
self.inF = None
self.outFn = 0
self.outsz = 0