MCPcopy Create free account
hub / github.com/LUX-Core/lux / headers_for

Method headers_for

qa/rpc-tests/test_framework/blockstore.py:55–78  ·  view source on GitHub ↗
(self, locator, hash_stop, current_tip=None)

Source from the content-addressed store, hash-verified

53 # the headers -- perhaps we could keep a separate data structure
54 # to avoid this overhead.
55 def headers_for(self, locator, hash_stop, current_tip=None):
56 if current_tip is None:
57 current_tip = self.currentBlock
58 current_block_header = self.get_header(current_tip)
59 if current_block_header is None:
60 return None
61
62 response = msg_headers()
63 headersList = [ current_block_header ]
64 maxheaders = 2000
65 while (headersList[0].sha256 not in locator.vHave):
66 prevBlockHash = headersList[0].hashPrevBlock
67 prevBlockHeader = self.get_header(prevBlockHash)
68 if prevBlockHeader is not None:
69 headersList.insert(0, prevBlockHeader)
70 else:
71 break
72 headersList = headersList[:maxheaders] # truncate if we have too many
73 hashList = [x.sha256 for x in headersList]
74 index = len(headersList)
75 if (hash_stop in hashList):
76 index = hashList.index(hash_stop)+1
77 response.headers = headersList[:index]
78 return response
79
80 def add_block(self, block):
81 block.calc_sha256()

Callers 1

on_getheadersMethod · 0.45

Calls 4

get_headerMethod · 0.95
msg_headersClass · 0.70
insertMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected