Skip to content

Commit 4390cf3

Browse files
JeremyRandSomberNight
authored andcommitted
Array headers: Refactor AuxPoW
1 parent e3dcef1 commit 4390cf3

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/electrumx/server/session.py

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

19781978
# Covered by a checkpoint; truncate AuxPoW data
1979-
result['header'] = self.truncate_auxpow(result['header'], height)
1979+
result['header'] = result['header'][:self.coin.TRUNCATED_HEADER_SIZE]
19801980
return result
19811981

19821982
async def block_headers(self, start_height, count, cp_height=0):
1983-
result = await super().block_headers(start_height, count, cp_height)
1984-
19851983
# Older protocol versions don't truncate AuxPoW
19861984
if self.protocol_tuple < (1, 4, 1):
1987-
return result
1985+
return await super().block_headers(start_height, count, cp_height)
19881986

19891987
# Not covered by a checkpoint; return full AuxPoW data
19901988
if cp_height == 0:
1991-
return result
1989+
return await super().block_headers(start_height, count, cp_height)
1990+
1991+
result = await super().block_headers_array(start_height, count, cp_height)
19921992

19931993
# Covered by a checkpoint; truncate AuxPoW data
1994+
result['headers'] = self.truncate_auxpow_headers(result['headers'])
1995+
1996+
# Return headers in array form
19941997
if self.protocol_tuple >= (1, 6):
1995-
result['headers'] = self.truncate_auxpow_headers(result['headers'])
1996-
return
1998+
return result
19971999

1998-
result['hex'] = self.truncate_auxpow(result['hex'], start_height)
2000+
# Return headers in concatenated form
2001+
result['hex'] = ''.join(result['headers'])
2002+
del result['headers']
19992003
return result
20002004

20012005
def truncate_auxpow_headers(self, headers):
@@ -2004,19 +2008,6 @@ def truncate_auxpow_headers(self, headers):
20042008
result.append(header[:self.coin.TRUNCATED_HEADER_SIZE])
20052009
return result
20062010

2007-
def truncate_auxpow(self, headers_full_hex, start_height):
2008-
height = start_height
2009-
headers_full = util.hex_to_bytes(headers_full_hex)
2010-
cursor = 0
2011-
headers = bytearray()
2012-
2013-
while cursor < len(headers_full):
2014-
headers += headers_full[cursor:cursor+self.coin.TRUNCATED_HEADER_SIZE]
2015-
cursor += self.db.dynamic_header_len(height)
2016-
height += 1
2017-
2018-
return headers.hex()
2019-
20202011

20212012
class NameIndexElectrumX(ElectrumX):
20222013
def set_request_handlers(self, ptuple):

0 commit comments

Comments
 (0)