def test_history_reverse2(self, node_param): if node_param == "non_appbase": stm = self.bts else: stm = self.appbase account = Account("dpaygobot", dpay_instance=stm) h_list = [] max_index = account.virtual_op_count() for h in account.history_reverse(start=max_index, stop=max_index - 4, use_block_num=False, batch_size=2, raw_output=False): h_list.append(h) self.assertEqual(len(h_list), 5) for i in range(1, 5): self.assertEqual(h_list[i]["index"] - h_list[i - 1]["index"], -1) h_list = [] for h in account.history_reverse(start=max_index, stop=max_index - 4, use_block_num=False, batch_size=6, raw_output=False): h_list.append(h) self.assertEqual(len(h_list), 5) for i in range(1, 5): self.assertEqual(h_list[i]["index"] - h_list[i - 1]["index"], -1) h_list = [] for h in account.history_reverse(start=max_index, stop=max_index - 4, use_block_num=False, batch_size=6, raw_output=True): h_list.append(h) self.assertEqual(len(h_list), 5) for i in range(1, 5): self.assertEqual(h_list[i][0] - h_list[i - 1][0], -1) h_list = [] for h in account.history_reverse(start=max_index, stop=max_index - 4, use_block_num=False, batch_size=2, raw_output=True): h_list.append(h) self.assertEqual(len(h_list), 5) for i in range(1, 5): self.assertEqual(h_list[i][0] - h_list[i - 1][0], -1)
def profiling(name_list): stm = DPay() set_shared_dpay_instance(stm) del stm print("start") for name in name_list: print("account: %s" % (name)) acc = Account(name) max_index = acc.virtual_op_count() print(max_index) stopTime = datetime(2018, 4, 22, 0, 0, 0) hist_elem = None for h in acc.history_reverse(stop=stopTime): hist_elem = h print(hist_elem) print("blockchain") blockchain_object = Blockchain() current_num = blockchain_object.get_current_block_num() startBlockNumber = current_num - 20 endBlockNumber = current_num block_elem = None for o in blockchain_object.stream(start=startBlockNumber, stop=endBlockNumber): print("block %d" % (o["block_num"])) block_elem = o print(block_elem)
def test_history_block_num(self, node_param): if node_param == "non_appbase": stm = self.bts zero_element = 0 else: stm = self.appbase zero_element = 0 # bug in dpay account = Account("fullnodeupdate", dpay_instance=stm) h_all_raw = [] for h in account.history_reverse(raw_output=True): h_all_raw.append(h) h_list = [] for h in account.history(start=h_all_raw[-1][1]["block"], stop=h_all_raw[-11 + zero_element][1]["block"], use_block_num=True, batch_size=10, raw_output=True): h_list.append(h) self.assertEqual(h_list[0][0], zero_element) self.assertEqual(h_list[-1][0], 10) self.assertEqual(h_list[0][1]['block'], h_all_raw[-1][1]['block']) self.assertEqual(h_list[-1][1]['block'], h_all_raw[-11 + zero_element][1]['block']) h_list = [] for h in account.history_reverse(start=h_all_raw[-11 + zero_element][1]["block"], stop=h_all_raw[-1][1]["block"], use_block_num=True, batch_size=10, raw_output=True): h_list.append(h) self.assertEqual(h_list[0][0], 10) self.assertEqual(h_list[-1][0], zero_element) self.assertEqual(h_list[0][1]['block'], h_all_raw[-11 + zero_element][1]['block']) self.assertEqual(h_list[-1][1]['block'], h_all_raw[-1][1]['block']) h_list = [] for h in account.get_account_history(10, 10, use_block_num=True, start=h_all_raw[-2 + zero_element][1]["block"], stop=h_all_raw[-10 + zero_element][1]["block"], order=1, raw_output=True): h_list.append(h) self.assertEqual(h_list[0][0], 1) self.assertEqual(h_list[-1][0], 9) self.assertEqual(h_list[0][1]['block'], h_all_raw[-2 + zero_element][1]['block']) self.assertEqual(h_list[-1][1]['block'], h_all_raw[-10 + zero_element][1]['block']) h_list = [] for h in account.get_account_history(10, 10, use_block_num=True, start=h_all_raw[-10 + zero_element][1]["block"], stop=h_all_raw[-2 + zero_element][1]["block"], order=-1, raw_output=True): h_list.append(h) self.assertEqual(h_list[0][0], 9) self.assertEqual(h_list[-1][0], 1) self.assertEqual(h_list[0][1]['block'], h_all_raw[-10 + zero_element][1]['block']) self.assertEqual(h_list[-1][1]['block'], h_all_raw[-2 + zero_element][1]['block'])
dpaygo_acc.get_conversion_requests())) print("dpay_acc.get_conversion_requests() {}".format( dpay_acc.get_conversion_requests())) # export # history dpaygo_hist = [] for h in dpaygo_acc.history(only_ops=["transfer"]): dpaygo_hist.append(h) if len(dpaygo_hist) >= 10: break dpay_hist = [] for h in dpay_acc.history(filter_by="transfer", start=0): dpay_hist.append(h) if len(dpay_hist) >= 10: break print("dpaygo_acc.history() {}".format(dpaygo_hist)) print("dpay_acc.history() {}".format(dpay_hist)) # history_reverse dpaygo_hist = [] for h in dpaygo_acc.history_reverse(only_ops=["transfer"]): dpaygo_hist.append(h) if len(dpaygo_hist) >= 10: break dpay_hist = [] for h in dpay_acc.history_reverse(filter_by="transfer"): dpay_hist.append(h) if len(dpay_hist) >= 10: break print("dpaygo_acc.history_reverse() {}".format(dpaygo_hist)) print("dpay_acc.history_reverse() {}".format(dpay_hist))
if "block" in entry: block_time = parse_time(entry["block"]["timestamp"]) else: block_time = parse_time(entry["timestamp"]) if block_time > stopTime: total_duration = formatTimedelta(datetime.now() - startTime) last_block_id = block_no avtran = total_transaction / (last_block_id - 19273700) 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 except Exception as e: print("Error: " + str(e)) continue
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30): block_count = 0 history_count = 0 access_time = 0 follow_time = 0 blockchain_version = u'0.0.0' successful = True error_msg = None start_total = timer() max_batch_size = None threading = False thread_num = 16 authorpermvoter = u"@jared/dpay-pressure-4-need-for-speed|nomoreheroes" [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter) authorperm = construct_authorperm(author, permlink) last_block_id = 19273700 try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) blockchain = Blockchain(dpay_instance=stm) blockchain_version = stm.get_blockchain_version() last_block = Block(last_block_id, dpay_instance=stm) stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60) total_transaction = 0 start = timer() for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num): block_no = entry.identifier block_count += 1 if "block" in entry: trxs = entry["block"]["transactions"] else: trxs = entry["transactions"] for tx in trxs: for op in tx["operations"]: total_transaction += 1 if "block" in entry: block_time = parse_time(entry["block"]["timestamp"]) else: block_time = parse_time(entry["timestamp"]) if block_time > stopTime: last_block_id = block_no break if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' block_count = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) block_count = -1 try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", dpay_instance=stm) blockchain_version = stm.get_blockchain_version() start = timer() for acc_op in account.history_reverse(batch_size=100): history_count += 1 if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' history_count = -1 successful = False except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' history_count = -1 successful = False # quit = True except Exception as e: error_msg = str(e) history_count = -1 successful = False try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", dpay_instance=stm) blockchain_version = stm.get_blockchain_version() start = timer() Vote(authorpermvoter, dpay_instance=stm) stop = timer() vote_time = stop - start start = timer() Comment(authorperm, dpay_instance=stm) stop = timer() comment_time = stop - start start = timer() Account(author, dpay_instance=stm) stop = timer() account_time = stop - start start = timer() account.get_followers() stop = timer() follow_time = stop - start access_time = (vote_time + comment_time + account_time + follow_time) / 4.0 except NumRetriesReached: error_msg = 'NumRetriesReached' access_time = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) access_time = -1 return { 'successful': successful, 'node': node, 'error': error_msg, 'total_duration': timer() - start_total, 'block_count': block_count, 'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time, 'version': blockchain_version }