Ejemplo n.º 1
0
def profiling(name_list):
    hv = Hive()
    set_shared_hive_instance(hv)
    del hv
    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)
Ejemplo n.º 2
0
    def test_history_reverse2(self):
        hv = self.bts
        account = Account("bhive.app", hive_instance=hv)
        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)
Ejemplo n.º 3
0
                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
        bhive_acc.get_conversion_requests()))
    print("hive_acc.get_conversion_requests() {}".format(
        hive_acc.get_conversion_requests()))
    # export
    # history
    bhive_hist = []
    for h in bhive_acc.history(only_ops=["transfer"]):
        bhive_hist.append(h)
        if len(bhive_hist) >= 10:
            break
    hive_hist = []
    for h in hive_acc.history(filter_by="transfer", start=0):
        hive_hist.append(h)
        if len(hive_hist) >= 10:
            break
    print("bhive_acc.history()  {}".format(bhive_hist))
    print("hive_acc.history() {}".format(hive_hist))
    # history_reverse
    bhive_hist = []
    for h in bhive_acc.history_reverse(only_ops=["transfer"]):
        bhive_hist.append(h)
        if len(bhive_hist) >= 10:
            break
    hive_hist = []
    for h in hive_acc.history_reverse(filter_by="transfer"):
        hive_hist.append(h)
        if len(hive_hist) >= 10:
            break
    print("bhive_acc.history_reverse()  {}".format(bhive_hist))
    print("hive_acc.history_reverse() {}".format(hive_hist))
Ejemplo n.º 5
0
        bsteem_acc.get_conversion_requests()))
    print("steem_acc.get_conversion_requests() {}".format(
        steem_acc.get_conversion_requests()))
    # export
    # history
    bsteem_hist = []
    for h in bsteem_acc.history(only_ops=["transfer"]):
        bsteem_hist.append(h)
        if len(bsteem_hist) >= 10:
            break
    steem_hist = []
    for h in steem_acc.history(filter_by="transfer", start=0):
        steem_hist.append(h)
        if len(steem_hist) >= 10:
            break
    print("bsteem_acc.history()  {}".format(bsteem_hist))
    print("steem_acc.history() {}".format(steem_hist))
    # history_reverse
    bsteem_hist = []
    for h in bsteem_acc.history_reverse(only_ops=["transfer"]):
        bsteem_hist.append(h)
        if len(bsteem_hist) >= 10:
            break
    steem_hist = []
    for h in steem_acc.history_reverse(filter_by="transfer"):
        steem_hist.append(h)
        if len(steem_hist) >= 10:
            break
    print("bsteem_acc.history_reverse()  {}".format(bsteem_hist))
    print("steem_acc.history_reverse() {}".format(steem_hist))
Ejemplo n.º 6
0
 def test_history_block_num(self):
     hv = self.bts
     zero_element = 0
     account = Account("fullnodeupdate", hive_instance=hv)
     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'])
Ejemplo n.º 7
0
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"@gtg/hive-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(hive_instance=hv)
        blockchain_version = hv.get_blockchain_version()

        last_block = Block(last_block_id, hive_instance=hv)

        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:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", hive_instance=hv)
        blockchain_version = hv.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:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", hive_instance=hv)
        blockchain_version = hv.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, hive_instance=hv)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, hive_instance=hv)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, hive_instance=hv)
        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}