Skip to content

Commit bbd3e06

Browse files
JeremyRandSomberNight
authored andcommitted
Array headers: Refactor AuxPoW
1 parent bfb7079 commit bbd3e06

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

src/electrumx/server/session.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,26 +1985,30 @@ async def block_header(self, height, cp_height=0):
19851985
return result
19861986

19871987
# Covered by a checkpoint; truncate AuxPoW data
1988-
result['header'] = self.truncate_auxpow(result['header'], height)
1988+
result['header'] = result['header'][:self.coin.TRUNCATED_HEADER_SIZE]
19891989
return result
19901990

19911991
async def block_headers(self, start_height, count, cp_height=0):
1992-
result = await super().block_headers(start_height, count, cp_height)
1993-
19941992
# Older protocol versions don't truncate AuxPoW
19951993
if self.protocol_tuple < (1, 4, 1):
1996-
return result
1994+
return await super().block_headers(start_height, count, cp_height)
19971995

19981996
# Not covered by a checkpoint; return full AuxPoW data
19991997
if cp_height == 0:
2000-
return result
1998+
return await super().block_headers(start_height, count, cp_height)
1999+
2000+
result = await super().block_headers_array(start_height, count, cp_height)
20012001

20022002
# Covered by a checkpoint; truncate AuxPoW data
2003+
result['headers'] = self.truncate_auxpow_headers(result['headers'])
2004+
2005+
# Return headers in array form
20032006
if self.protocol_tuple >= (1, 6):
2004-
result['headers'] = self.truncate_auxpow_headers(result['headers'])
2005-
return
2007+
return result
20062008

2007-
result['hex'] = self.truncate_auxpow(result['hex'], start_height)
2009+
# Return headers in concatenated form
2010+
result['hex'] = ''.join(result['headers'])
2011+
del result['headers']
20082012
return result
20092013

20102014
def truncate_auxpow_headers(self, headers):
@@ -2013,19 +2017,6 @@ def truncate_auxpow_headers(self, headers):
20132017
result.append(header[:self.coin.TRUNCATED_HEADER_SIZE])
20142018
return result
20152019

2016-
def truncate_auxpow(self, headers_full_hex, start_height):
2017-
height = start_height
2018-
headers_full = util.hex_to_bytes(headers_full_hex)
2019-
cursor = 0
2020-
headers = bytearray()
2021-
2022-
while cursor < len(headers_full):
2023-
headers += headers_full[cursor:cursor+self.coin.TRUNCATED_HEADER_SIZE]
2024-
cursor += self.db.dynamic_header_len(height)
2025-
height += 1
2026-
2027-
return headers.hex()
2028-
20292020

20302021
class NameIndexElectrumX(ElectrumX):
20312022
def set_request_handlers(self, ptuple):

0 commit comments

Comments
 (0)