diff --git a/README.rst b/README.rst index a6c47a450a42191d7412213f55bed8ad9a7a611e..c3b5825a64ed02db9a107855b94ed95ba6b63e42 100644 --- a/README.rst +++ b/README.rst @@ -162,6 +162,8 @@ Changelog * Unit tests using testnet fixed * beem.snapshot improved * Example account_sp_over_time added +* Example account_curation_per_week_and_1k_sp added +* Add block_number check to wait_for_and_get_block 0.19.46 ------- diff --git a/beem/blockchain.py b/beem/blockchain.py index 1ce7b39138bc6f05ae5d4c724468bf6fd005de06..c903d0be81540f3612067b2d4ffc7e410b479ac3 100644 --- a/beem/blockchain.py +++ b/beem/blockchain.py @@ -405,6 +405,7 @@ class Blockchain(object): num_retries_call=self.steem.rpc.num_retries_call, timeout=self.steem.rpc.timeout)) # We are going to loop indefinitely + latest_block = 0 while True: # Get chain properies to identify the @@ -547,7 +548,7 @@ class Blockchain(object): # Blocks from start until head block for blocknum in range(start, head_block + 1): # Get full block - block = self.wait_for_and_get_block(blocknum, only_ops=only_ops, only_virtual_ops=only_virtual_ops) + block = self.wait_for_and_get_block(blocknum, only_ops=only_ops, only_virtual_ops=only_virtual_ops, block_number_check_cnt=5) yield block # Set new start start = head_block + 1 @@ -560,7 +561,7 @@ class Blockchain(object): # Sleep for one block time.sleep(self.block_interval) - def wait_for_and_get_block(self, block_number, blocks_waiting_for=None, only_ops=False, only_virtual_ops=False): + def wait_for_and_get_block(self, block_number, blocks_waiting_for=None, only_ops=False, only_virtual_ops=False, block_number_check_cnt=-1): """ Get the desired block from the chain, if the current head block is smaller (for both head and irreversible) then we wait, but a maxmimum of blocks_waiting_for * max_block_wait_repetition time before failure. @@ -569,6 +570,7 @@ class Blockchain(object): how many blocks we are willing to wait, positive int (default: None) :param bool only_ops: Returns blocks with operations only, when set to True (default: False) :param bool only_virtual_ops: Includes only virtual operations (default: False) + :param int block_number_check_cnt: limit the number of retries when greater than -1 """ if not blocks_waiting_for: @@ -584,10 +586,12 @@ class Blockchain(object): raise BlockWaitTimeExceeded("Already waited %d s" % (blocks_waiting_for * self.max_block_wait_repetition * self.block_interval)) # block has to be returned properly repetition = 0 + cnt = 0 block = None - while not block: + while (block is None or block.block_num is None or int(block.block_num) != block_number) and (block_number_check_cnt < 0 or cnt < block_number_check_cnt): try: block = Block(block_number, only_ops=only_ops, only_virtual_ops=only_virtual_ops, steem_instance=self.steem) + cnt += 1 except BlockDoesNotExistsException: block = None if repetition > blocks_waiting_for * self.max_block_wait_repetition: diff --git a/examples/stream_threading_performance.py b/examples/stream_threading_performance.py index 1977d42f0d383c2100c744aa204d47eb57082509..2508ae6d5ac8096e0800fbd8c5effa764a3f0648 100644 --- a/examples/stream_threading_performance.py +++ b/examples/stream_threading_performance.py @@ -47,7 +47,7 @@ if __name__ == "__main__": stm_https = Steem(node=node_list_https, timeout=timeout) print("Without threading wss") opcount_wot_wss, total_duration_wot_wss = stream_votes(stm_wss, False, 8) - print("Without threading wss") + print("Without threading https") opcount_wot_https, total_duration_wot_https = stream_votes(stm_https, False, 8) if threading: print("\n Threading with %d threads is activated now." % thread_num)