tinterface.get_history: enforce sorted order of heights - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 26d73cba0ee6ad8e07ba2262dc716a8658863899 DIR parent 99845942e5cef1b8e77efb32ca17a107940217c1 HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 23 Feb 2021 02:13:16 +0100 interface.get_history: enforce sorted order of heights related: #7058 Diffstat: M electrum/interface.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- DIR diff --git a/electrum/interface.py b/electrum/interface.py t@@ -938,14 +938,21 @@ class Interface(Logger): res = await self.session.send_request('blockchain.scripthash.get_history', [sh]) # check response assert_list_or_tuple(res) + prev_height = 1 for tx_item in res: - assert_dict_contains_field(tx_item, field_name='height') + height = assert_dict_contains_field(tx_item, field_name='height') assert_dict_contains_field(tx_item, field_name='tx_hash') - assert_integer(tx_item['height']) + assert_integer(height) assert_hash256_str(tx_item['tx_hash']) - if tx_item['height'] in (-1, 0): + if height in (-1, 0): assert_dict_contains_field(tx_item, field_name='fee') assert_non_negative_integer(tx_item['fee']) + prev_height = - float("inf") # this ensures confirmed txs can't follow mempool txs + else: + # check monotonicity of heights + if height < prev_height: + raise RequestCorrupted(f'heights of confirmed txs must be in increasing order') + prev_height = height return res async def listunspent_for_scripthash(self, sh: str) -> List[dict]: