File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1455,6 +1455,8 @@ async def get_history_for_scripthash(self, sh: str) -> List[dict]:
14551455 height = assert_dict_contains_field (tx_item , field_name = 'height' )
14561456 assert_dict_contains_field (tx_item , field_name = 'tx_hash' )
14571457 assert_integer (height )
1458+ if height < - 1 :
1459+ raise RequestCorrupted (f'{ height !r} is not a valid block height' )
14581460 assert_hash256_str (tx_item ['tx_hash' ])
14591461 if height in (- 1 , 0 ):
14601462 assert_dict_contains_field (tx_item , field_name = 'fee' )
@@ -1465,6 +1467,11 @@ async def get_history_for_scripthash(self, sh: str) -> List[dict]:
14651467 if height < prev_height :
14661468 raise RequestCorrupted (f'heights of confirmed txs must be in increasing order' )
14671469 prev_height = height
1470+ if self .active_protocol_tuple >= (1 , 6 ):
1471+ # enforce order of mempool txs
1472+ mempool_txs = [tx_item for tx_item in res if tx_item ['height' ] <= 0 ]
1473+ if mempool_txs != sorted (mempool_txs , key = lambda x : (- x ['height' ], bytes .fromhex (x ['tx_hash' ]))):
1474+ raise RequestCorrupted (f'mempool txs not in canonical order' )
14681475 hashes = set (map (lambda item : item ['tx_hash' ], res ))
14691476 if len (hashes ) != len (res ):
14701477 # Either server is sending garbage... or maybe if server is race-prone
You can’t perform that action at this time.
0 commit comments