Skip to content

Commit 264daec

Browse files
JeremyRandSomberNight
authored andcommitted
Array headers: Refactor AuxPoW
1 parent 31f8427 commit 264daec

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

electrumx/server/session.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,43 +2147,34 @@ async def block_header(self, height, cp_height=0):
21472147
return result
21482148

21492149
# Covered by a checkpoint; truncate AuxPoW data
2150-
result['header'] = self.truncate_auxpow(result['header'], height)
2150+
result['header'] = result['header'][:self.coin.TRUNCATED_HEADER_SIZE]
21512151
return result
21522152

21532153
async def block_headers(self, start_height, count, cp_height=0):
2154-
result = await super().block_headers(start_height, count, cp_height)
2155-
21562154
# Older protocol versions don't truncate AuxPoW
21572155
if self.protocol_tuple < (1, 4, 1):
2158-
return result
2156+
return await super().block_headers(start_height, count, cp_height)
21592157

21602158
# Not covered by a checkpoint; return full AuxPoW data
21612159
if cp_height == 0:
2162-
return result
2160+
return await super().block_headers(start_height, count, cp_height)
2161+
2162+
result = await super().block_headers_array(start_height, count, cp_height)
21632163

21642164
# Covered by a checkpoint; truncate AuxPoW data
2165+
result['headers'] = self.truncate_auxpow_headers(result['headers'])
2166+
2167+
# Return headers in array form
21652168
if self.protocol_tuple >= (1, 5):
2166-
result['headers'] = self.truncate_auxpow_headers(result['headers'])
2167-
return
2169+
return result
21682170

2169-
result['hex'] = self.truncate_auxpow(result['hex'], start_height)
2171+
# Return headers in concatenated form
2172+
result['hex'] = ''.join(result['headers'])
2173+
del result['headers']
21702174
return result
21712175

21722176
def truncate_auxpow_headers(self, headers):
21732177
result = []
21742178
for header in headers:
21752179
result.append(header[:self.coin.TRUNCATED_HEADER_SIZE])
21762180
return result
2177-
2178-
def truncate_auxpow(self, headers_full_hex, start_height):
2179-
height = start_height
2180-
headers_full = util.hex_to_bytes(headers_full_hex)
2181-
cursor = 0
2182-
headers = bytearray()
2183-
2184-
while cursor < len(headers_full):
2185-
headers += headers_full[cursor:cursor+self.coin.TRUNCATED_HEADER_SIZE]
2186-
cursor += self.db.dynamic_header_len(height)
2187-
height += 1
2188-
2189-
return headers.hex()

0 commit comments

Comments
 (0)