Skip to content
Snippets Groups Projects
Commit a6669107 authored by Holger's avatar Holger
Browse files

Add blocknumber check to wait_for_and_get_block

parent c54180ea
No related branches found
No related tags found
No related merge requests found
...@@ -162,6 +162,8 @@ Changelog ...@@ -162,6 +162,8 @@ Changelog
* Unit tests using testnet fixed * Unit tests using testnet fixed
* beem.snapshot improved * beem.snapshot improved
* Example account_sp_over_time added * 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 0.19.46
------- -------
......
...@@ -405,6 +405,7 @@ class Blockchain(object): ...@@ -405,6 +405,7 @@ class Blockchain(object):
num_retries_call=self.steem.rpc.num_retries_call, num_retries_call=self.steem.rpc.num_retries_call,
timeout=self.steem.rpc.timeout)) timeout=self.steem.rpc.timeout))
# We are going to loop indefinitely # We are going to loop indefinitely
latest_block = 0
while True: while True:
# Get chain properies to identify the # Get chain properies to identify the
...@@ -547,7 +548,7 @@ class Blockchain(object): ...@@ -547,7 +548,7 @@ class Blockchain(object):
# Blocks from start until head block # Blocks from start until head block
for blocknum in range(start, head_block + 1): for blocknum in range(start, head_block + 1):
# Get full block # 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 yield block
# Set new start # Set new start
start = head_block + 1 start = head_block + 1
...@@ -560,7 +561,7 @@ class Blockchain(object): ...@@ -560,7 +561,7 @@ class Blockchain(object):
# Sleep for one block # Sleep for one block
time.sleep(self.block_interval) 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) """ 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. then we wait, but a maxmimum of blocks_waiting_for * max_block_wait_repetition time before failure.
...@@ -569,6 +570,7 @@ class Blockchain(object): ...@@ -569,6 +570,7 @@ class Blockchain(object):
how many blocks we are willing to wait, positive int (default: None) 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_ops: Returns blocks with operations only, when set to True (default: False)
:param bool only_virtual_ops: Includes only virtual operations (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: if not blocks_waiting_for:
...@@ -584,10 +586,12 @@ class Blockchain(object): ...@@ -584,10 +586,12 @@ class Blockchain(object):
raise BlockWaitTimeExceeded("Already waited %d s" % (blocks_waiting_for * self.max_block_wait_repetition * self.block_interval)) raise BlockWaitTimeExceeded("Already waited %d s" % (blocks_waiting_for * self.max_block_wait_repetition * self.block_interval))
# block has to be returned properly # block has to be returned properly
repetition = 0 repetition = 0
cnt = 0
block = None 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: try:
block = Block(block_number, only_ops=only_ops, only_virtual_ops=only_virtual_ops, steem_instance=self.steem) block = Block(block_number, only_ops=only_ops, only_virtual_ops=only_virtual_ops, steem_instance=self.steem)
cnt += 1
except BlockDoesNotExistsException: except BlockDoesNotExistsException:
block = None block = None
if repetition > blocks_waiting_for * self.max_block_wait_repetition: if repetition > blocks_waiting_for * self.max_block_wait_repetition:
......
...@@ -47,7 +47,7 @@ if __name__ == "__main__": ...@@ -47,7 +47,7 @@ if __name__ == "__main__":
stm_https = Steem(node=node_list_https, timeout=timeout) stm_https = Steem(node=node_list_https, timeout=timeout)
print("Without threading wss") print("Without threading wss")
opcount_wot_wss, total_duration_wot_wss = stream_votes(stm_wss, False, 8) 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) opcount_wot_https, total_duration_wot_https = stream_votes(stm_https, False, 8)
if threading: if threading:
print("\n Threading with %d threads is activated now." % thread_num) print("\n Threading with %d threads is activated now." % thread_num)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment