Skip to content
Snippets Groups Projects
Commit 582f3414 authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Improvements for blockchain parameter reading and nodes benchmark

steem
* Robustify reading of blockchain parameters
utils
* improve formatTimedelta output
Examples
* improve benchmark_nodes by added account history
parent 988ff029
No related branches found
No related tags found
No related merge requests found
......@@ -89,7 +89,8 @@ class Blockchain(object):
.. note:: The block number returned depends on the ``mode`` used
when instanciating from this class.
"""
return int(self.steem.get_dynamic_global_properties(False).get(self.mode))
props = self.steem.get_dynamic_global_properties(False)
return int(props.get(self.mode))
def get_current_block(self):
""" This call returns the current block
......
......@@ -220,13 +220,15 @@ class Steem(object):
return self.data['dynamic_global_properties']
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_dynamic_global_properties(api="database")
else:
return self.rpc.get_dynamic_global_properties()
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
ret = self.rpc.get_dynamic_global_properties(api="database")
except:
ret = None
count += 1
return ret
def get_reserve_ratio(self, use_stored_data=True):
""" This call returns the *dynamic global properties*
......@@ -239,16 +241,21 @@ class Steem(object):
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_reserve_ratio(api="witness")
else:
props = self.get_dynamic_global_properties()
return {'id': 0, 'average_block_size': props['average_block_size'],
'current_reserve_ratio': props['current_reserve_ratio'],
'max_virtual_bandwidth': props['max_virtual_bandwidth']}
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
if self.rpc.get_use_appbase():
return self.rpc.get_reserve_ratio(api="witness")
else:
props = self.get_dynamic_global_properties()
return {'id': 0, 'average_block_size': props['average_block_size'],
'current_reserve_ratio': props['current_reserve_ratio'],
'max_virtual_bandwidth': props['max_virtual_bandwidth']}
except:
ret = None
count += 1
return ret
def get_feed_history(self, use_stored_data=True):
""" Returns the feed_history
......@@ -258,15 +265,17 @@ class Steem(object):
if use_stored_data:
self.refresh_data()
return self.data['feed_history']
try:
if self.rpc is None:
return None
if self.rpc.get_use_appbase():
return self.rpc.get_feed_history(api="database")
else:
return self.rpc.get_feed_history()
except:
if self.rpc is None:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
ret = self.rpc.get_feed_history(api="database")
except:
ret = None
count += 1
return ret
def get_reward_funds(self, use_stored_data=True):
""" Get details for a reward fund.
......@@ -279,16 +288,21 @@ class Steem(object):
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
funds = self.rpc.get_reward_funds(api="database")['funds']
if len(funds) > 0:
funds = funds[0]
return funds
else:
return self.rpc.get_reward_fund("post")
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
if self.rpc.get_use_appbase():
funds = self.rpc.get_reward_funds(api="database")['funds']
if len(funds) > 0:
funds = funds[0]
ret = funds
else:
ret = self.rpc.get_reward_fund("post")
except:
ret = None
count += 1
return ret
def get_current_median_history(self, use_stored_data=True):
""" Returns the current median price
......@@ -303,13 +317,18 @@ class Steem(object):
return None
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_feed_history(api="database")['current_median_history']
else:
return self.rpc.get_current_median_history_price(api="database")
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
if self.rpc.get_use_appbase():
ret = self.rpc.get_feed_history(api="database")['current_median_history']
else:
ret = self.rpc.get_current_median_history_price(api="database")
except:
ret = None
count += 1
return ret
def get_hardfork_properties(self, use_stored_data=True):
""" Returns Hardfork and live_time of the hardfork
......@@ -321,13 +340,18 @@ class Steem(object):
return self.data['hardfork_properties']
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_hardfork_properties(api="database")
else:
return self.rpc.get_next_scheduled_hardfork(api="database")
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
if self.rpc.get_use_appbase():
ret = self.rpc.get_hardfork_properties(api="database")
else:
ret = self.rpc.get_next_scheduled_hardfork(api="database")
except:
ret = None
count += 1
return ret
def get_network(self, use_stored_data=True):
""" Identify the network
......@@ -484,13 +508,15 @@ class Steem(object):
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_witness_schedule(api="database")
else:
return self.rpc.get_witness_schedule()
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
ret = self.rpc.get_witness_schedule(api="database")
except:
ret = None
count += 1
return ret
def get_config(self, use_stored_data=True):
""" Returns internal chain configuration.
......@@ -500,13 +526,15 @@ class Steem(object):
return self.data['config']
if self.rpc is None:
return None
try:
if self.rpc.get_use_appbase():
return self.rpc.get_config(api="database")
else:
return self.rpc.get_config()
except:
return None
count = 0
ret = None
while ret is None and count < 2:
try:
ret = self.rpc.get_config(api="database")
except:
ret = None
count += 1
return ret
@property
def chain_params(self):
......
......@@ -54,7 +54,7 @@ def formatTimedelta(td):
hours = days * 24 + seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 60)
return "%d:%s.%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2))
return "%d:%s:%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2))
def parse_time(block_time):
......
......@@ -9,6 +9,7 @@ import io
import logging
from prettytable import PrettyTable
from beem.blockchain import Blockchain
from beem.account import Account
from beem.block import Block
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta
......@@ -25,16 +26,19 @@ nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.s
if __name__ == "__main__":
how_many_minutes = 10
how_many_virtual_op = 10000
max_batch_size = None
threading = False
thread_num = 16
t = PrettyTable(["node", "10 blockchain minutes", "version"])
t = PrettyTable(["node", "10 blockchain minutes", "10000 virtual account op", "version"])
t.align = "l"
for node in nodes:
print("Current node:", node)
try:
stm = Steem(node=node, num_retries=2)
stm = Steem(node=node, num_retries=3)
blockchain = Blockchain(steem_instance=stm)
account = Account("gtg", steem_instance=stm)
virtual_op_count = account.virtual_op_count()
blockchain_version = stm.get_blockchain_version()
last_block_id = 19273700
......@@ -68,14 +72,24 @@ if __name__ == "__main__":
total_duration = formatTimedelta(datetime.now() - startTime)
last_block_id = block_no
avtran = total_transaction / (last_block_id - 19273700)
print("* Processed %d blockchain minutes in %s" % (how_many_minutes, total_duration))
print("* blockchain version: %s" % (blockchain_version))
t.add_row([
node,
total_duration,
blockchain_version
])
break
start_time = time.time()
stopOP = virtual_op_count - how_many_virtual_op + 1
i = 0
for acc_op in account.history_reverse(stop=stopOP):
i += 1
total_duration_acc = formatTimedelta(datetime.now() - startTime)
print("* Processed %d blockchain minutes in %s" % (how_many_minutes, total_duration))
print("* Processed %d account ops in %s" % (i, total_duration_acc))
print("* blockchain version: %s" % (blockchain_version))
t.add_row([
node,
total_duration,
total_duration_acc,
blockchain_version
])
except NumRetriesReached:
print("NumRetriesReached")
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment