@@ -1357,6 +1357,8 @@ async def block_headers(self, start_height, count, cp_height=0):
13571357 start_height and count must be non-negative integers. At most
13581358 MAX_CHUNK_SIZE headers will be returned.
13591359 '''
1360+ if self .protocol_tuple >= (1 , 6 ):
1361+ return await self .block_headers_array (start_height , count , cp_height )
13601362 start_height = non_negative_integer (start_height )
13611363 count = non_negative_integer (count )
13621364 cp_height = non_negative_integer (cp_height )
@@ -1373,6 +1375,38 @@ async def block_headers(self, start_height, count, cp_height=0):
13731375 self .bump_cost (cost )
13741376 return result
13751377
1378+ async def block_headers_array (self , start_height , count , cp_height = 0 ):
1379+ '''Return block headers in an array for the main chain;
1380+ starting at start_height.
1381+ start_height and count must be non-negative integers. At most
1382+ MAX_CHUNK_SIZE headers will be returned.
1383+ '''
1384+ start_height = non_negative_integer (start_height )
1385+ count = non_negative_integer (count )
1386+ cp_height = non_negative_integer (cp_height )
1387+ cost = count / 50
1388+
1389+ max_size = self .MAX_CHUNK_SIZE
1390+ count = min (count , max_size )
1391+ headers , count = await self .db .read_headers (start_height , count )
1392+ result = {'count' : count , 'max' : max_size , 'headers' : []}
1393+ if count and cp_height :
1394+ cost += 1.0
1395+ last_height = start_height + count - 1
1396+ result .update (await self ._merkle_proof (cp_height , last_height ))
1397+
1398+ cursor = 0
1399+ height = 0
1400+ while cursor < len (headers ):
1401+ next_cursor = self .db .header_offset (height + 1 )
1402+ header = headers [cursor :next_cursor ]
1403+ result ['headers' ].append (header .hex ())
1404+ cursor = next_cursor
1405+ height += 1
1406+
1407+ self .bump_cost (cost )
1408+ return result
1409+
13761410 def is_tor (self ):
13771411 '''Try to detect if the connection is to a tor hidden service we are
13781412 running.'''
@@ -1975,9 +2009,19 @@ async def block_headers(self, start_height, count, cp_height=0):
19752009 return result
19762010
19772011 # Covered by a checkpoint; truncate AuxPoW data
2012+ if self .protocol_tuple >= (1 , 6 ):
2013+ result ['headers' ] = self .truncate_auxpow_headers (result ['headers' ])
2014+ return
2015+
19782016 result ['hex' ] = self .truncate_auxpow (result ['hex' ], start_height )
19792017 return result
19802018
2019+ def truncate_auxpow_headers (self , headers ):
2020+ result = []
2021+ for header in headers :
2022+ result .append (header [:self .coin .TRUNCATED_HEADER_SIZE ])
2023+ return result
2024+
19812025 def truncate_auxpow (self , headers_full_hex , start_height ):
19822026 height = start_height
19832027 headers_full = util .hex_to_bytes (headers_full_hex )
0 commit comments