Exemplo 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)
 def setup(self):
     self.prefix = u"HIVE"
     self.default_prefix = u"STM"
     self.wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
     self.ref_block_num = 34294
     self.ref_block_prefix = 3707022213
     self.expiration = "2016-04-06T08:29:27"
     self.hv = Hive(offline=True)
Exemplo n.º 3
0
def profiling(node, name_list, shared_instance=True, clear_acc_cache=False, clear_all_cache=True):
    print("shared_instance %d clear_acc_cache %d clear_all_cache %d" %
          (shared_instance, clear_acc_cache, clear_all_cache))
    if not shared_instance:
        hv = Hive(node=node)
        print(str(hv))
    else:
        hv = None
    acc_dict = {}
    for name in name_list:
        acc = Account(name, hive_instance=hv)
        acc_dict[name] = acc
        if clear_acc_cache:
            acc.clear_cache()
        acc_dict = {}
    if clear_all_cache:
        clear_cache()
    if not shared_instance:
        del hv.rpc
Exemplo n.º 4
0
if __name__ == "__main__":
    how_many_minutes = 10
    how_many_virtual_op = 10000
    max_batch_size = None
    threading = False
    thread_num = 16
    nodelist = NodeList()
    nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True)
    t = PrettyTable([
        "node", "10 blockchain minutes", "10000 virtual account op", "version"
    ])
    t.align = "l"
    for node in nodes:
        print("Current node:", node)
        try:
            hv = Hive(node=node, num_retries=3)
            blockchain = Blockchain(hive_instance=hv)
            account = Account("gtg", hive_instance=hv)
            virtual_op_count = account.virtual_op_count()
            blockchain_version = hv.get_blockchain_version()

            last_block_id = 19273700
            last_block = Block(last_block_id, hive_instance=hv)
            startTime = datetime.now()

            stopTime = last_block.time() + timedelta(seconds=how_many_minutes *
                                                     60)
            ltime = time.time()
            cnt = 0
            total_transaction = 0
Exemplo n.º 5
0
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import int, str
import sys
from datetime import timedelta
import time
import io
from bhive.hive import Hive
import logging
from prettytable import PrettyTable
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    hv = Hive(node="https://api.hive.blog")
    # hv = Hive(node="https://testnet.hiveitdev.com")
    # hv = Hive(node="wss://appbasetest.timcliff.com")
    # hv = Hive(node="https://api.hiveitstage.com")
    # hv = Hive(node="https://api.hiveitdev.com")
    all_calls = hv.rpc.get_methods(api="jsonrpc")
    t = PrettyTable(["method", "args", "ret"])
    t.align = "l"
    t_condenser = PrettyTable(["method", "args", "ret"])
    t_condenser.align = "l"
    for call in all_calls:
        if "condenser" not in call:
            ret = hv.rpc.get_signature({'method': call}, api="jsonrpc")
            t.add_row([call, ret['args'], ret['ret']])
        else:
            ret = hv.rpc.get_signature({'method': call}, api="jsonrpc")
Exemplo n.º 6
0
    return opcount, total_duration


if __name__ == "__main__":
    node_setup = 1
    threading = True
    thread_num = 8
    timeout = 10
    nodes = NodeList()
    nodes.update_nodes(weights={"block": 1})
    node_list_wss = nodes.get_nodes(https=False)[:5]
    node_list_https = nodes.get_nodes(wss=False)[:5]

    vote_result = []
    duration = []
    hv_wss = Hive(node=node_list_wss, timeout=timeout)
    hv_https = Hive(node=node_list_https, timeout=timeout)
    print("Without threading wss")
    opcount_wot_wss, total_duration_wot_wss = stream_votes(hv_wss, False, 8)
    print("Without threading https")
    opcount_wot_https, total_duration_wot_https = stream_votes(
        hv_https, False, 8)
    if threading:
        print("\n Threading with %d threads is activated now." % thread_num)

    hv = Hive(node=node_list_wss, timeout=timeout)
    opcount_wss, total_duration_wss = stream_votes(hv, threading, thread_num)
    opcount_https, total_duration_https = stream_votes(hv, threading,
                                                       thread_num)
    print("Finished!")
Exemplo n.º 7
0
import logging

from bhive.blockchain import Blockchain
from bhive.block import Block
from bhive.hive import Hive
from bhive.utils import parse_time, formatTimedelta
from bhive.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    node_setup = 1
    how_many_hours = 1
    nodes = NodeList()
    if node_setup == 0:
        hv = Hive(node=nodes.get_nodes(normal=True, wss=True), num_retries=10)
        max_batch_size = None
        threading = False
        thread_num = 8
    elif node_setup == 1:
        hv = Hive(node=nodes.get_nodes(normal=True, wss=True), num_retries=10)
        max_batch_size = None
        threading = True
        thread_num = 16
    elif node_setup == 2:
        hv = Hive(node=nodes.get_nodes(appbase=False, https=False),
                  num_retries=10)
        max_batch_size = None
        threading = True
        thread_num = 16
    blockchain = Blockchain(hive_instance=hv)
    bhive_test.setup()
    hive_times = []
    bhive_times = []
    loops = 50
    for i in range(0, loops):
        print(i)
        opHive = hiveOperations.Transfer(**{
            "from": "foo",
            "to": "baar",
            "amount": "111.110 HIVE",
            "memo": "Fooo"
        })
        opBhive = operations.Transfer(**{
            "from": "foo",
            "to": "baar",
            "amount": Amount("111.110 HIVE", hive_instance=Hive(offline=True)),
            "memo": "Fooo"
        })

        t_s, t_v = hive_test.doit(ops=opHive)
        hive_times.append([t_s, t_v])

        t_s, t_v = bhive_test.doit(ops=opBhive)
        bhive_times.append([t_s, t_v])

    hive_dt = [0, 0]
    bhive_dt = [0, 0]
    for i in range(0, loops):
        hive_dt[0] += hive_times[i][0]
        hive_dt[1] += hive_times[i][1]
        bhive_dt[0] += bhive_times[i][0]
Exemplo n.º 9
0
            quit_thread = True
            print("benchmark aborted.")
    else:
        for node in nodes:
            print("Current node:", node)
            result = benchmark_node(node, how_many_minutes, how_many_seconds)
            results.append(result)
    for result in results:
        t2.add_row([result["node"], result["version"]])
    print(t2)
    print("\n")

    sortedList = sorted(results, key=lambda self: self["history_count"], reverse=True)
    for result in sortedList:
        if result["successful"]:
            t.add_row([
                result["node"],
                result["block_count"],
                result["history_count"],
                ("%.2f" % (result["access_time"]))
            ])
            working_nodes.append(result["node"])
    print(t)
    print("\n")
    print("Total benchmark time: %.2f s\n" % (timer() - benchmark_time))
    if set_default_nodes:
        hv = Hive(offline=True)
        hv.set_default_nodes(working_nodes)
    else:
        print("bhivepy set nodes " + str(working_nodes))
Exemplo n.º 10
0
from bhivebase import operations
from bhive.transactionbuilder import TransactionBuilder
from bhivegraphenebase.account import PasswordKey, PrivateKey, PublicKey
from bhive.hive import Hive
from bhive.utils import parse_time, formatTimedelta
from bhiveapi.exceptions import NumRetriesReached
from bhive.nodelist import NodeList
from bhivebase.transactions import getBlockParams
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# example wif
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"

if __name__ == "__main__":
    hv_online = Hive()
    ref_block_num, ref_block_prefix = getBlockParams(hv_online)
    print("ref_block_num %d - ref_block_prefix %d" %
          (ref_block_num, ref_block_prefix))

    hv = Hive(offline=True)

    op = operations.Transfer({
        'from': 'bhive.app',
        'to': 'thecrazygm',
        'amount': "0.001 HBD",
        'memo': ""
    })
    tb = TransactionBuilder(hive_instance=hv)

    tb.appendOps([op])
Exemplo n.º 11
0
            "account": "guest123",
            "social_action_comment_update": {
                "permlink": 'just-a-test-post',
                "title": "just a test post",
                "body": "test post body",
            }
        })

    op3 = operations.Vote(
        **{
            'voter': 'guest123',
            'author': 'wlsuser',
            'permlink': 'another-test-post',
            'weight': 10000,
        })

    privateWif = "5K..."
    tx = TransactionBuilder(use_condenser_api=True, hive_instance=wls)
    tx.appendOps(op1)
    tx.appendWif(privateWif)
    tx.sign()
    tx.broadcast()


if __name__ == "__main__":
    # `blocking=True` forces use of broadcast_transaction_synchronous
    wls = Hive(node=["https://pubrpc.whaleshares.io"], blocking=True)
    print(wls.get_blockchain_version())
    print(wls.get_config())
    test_post(wls)
Exemplo n.º 12
0
        hv = None
    acc_dict = {}
    for name in name_list:
        acc = Account(name, hive_instance=hv)
        acc_dict[name] = acc
        if clear_acc_cache:
            acc.clear_cache()
        acc_dict = {}
    if clear_all_cache:
        clear_cache()
    if not shared_instance:
        del hv.rpc


if __name__ == "__main__":
    hv = Hive()
    print("Shared instance: " + str(hv))
    set_shared_hive_instance(hv)
    b = Blockchain()
    account_list = []
    for a in b.get_all_accounts(limit=500):
        account_list.append(a)
    shared_instance = False
    clear_acc_cache = False
    clear_all_cache = False
    node = "https://api.hive.blog"
    n = 3
    for i in range(1, n + 1):
        print("%d of %d" % (i, n))
        profiling(node, account_list, shared_instance=shared_instance, clear_acc_cache=clear_acc_cache, clear_all_cache=clear_all_cache)
    bsteem_times = []
    loops = 50
    for i in range(0, loops):
        print(i)
        opHive = hiveOperations.Transfer(**{
            "from": "foo",
            "to": "baar",
            "amount": "111.110 HIVE",
            "memo": "Fooo"
        })
        opBhive = operations.Transfer(
            **{
                "from": "foo",
                "to": "baar",
                "amount": Amount("111.110 HIVE",
                                 hive_instance=Hive(offline=True)),
                "memo": "Fooo"
            })

        t_s, t_v = steem_test.doit(ops=opHive)
        steem_times.append([t_s, t_v])

        t_s, t_v = bsteem_test.doit(ops=opBhive)
        bsteem_times.append([t_s, t_v])

    steem_dt = [0, 0]
    bsteem_dt = [0, 0]
    for i in range(0, loops):
        steem_dt[0] += steem_times[i][0]
        steem_dt[1] += steem_times[i][1]
        bsteem_dt[0] += bsteem_times[i][0]
Exemplo n.º 14
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}
Exemplo n.º 15
0
    return opcount, total_duration


if __name__ == "__main__":
    node_setup = 1
    threading = True
    thread_num = 8
    timeout = 10
    nodes = NodeList()
    nodes.update_nodes(weights={"block": 1})
    node_list = nodes.get_nodes()[:5]

    vote_result = []
    duration = []

    hv = Hive(node=node_list, timeout=timeout)
    b = Blockchain(hive_instance=hv)
    block = b.get_current_block()
    block.set_cache_auto_clean(False)
    opcount, total_duration = stream_votes(hv, threading, thread_num)
    print("Finished!")
    block.set_cache_auto_clean(True)
    cache_len = len(list(block._cache))
    start_time = time.time()
    block.clear_cache_from_expired_items()
    clear_duration = time.time() - start_time
    time.sleep(5)
    cache_len_after = len(list(block._cache))
    start_time = time.time()
    print(str(block._cache))
    clear_duration2 = time.time() - start_time
Exemplo n.º 16
0
if __name__ == "__main__":
    hv = Hive(
        node=["https://testnet.hiveitdev.com"],
        custom_chains={
            "TESTNETHF20": {
                'chain_assets': [{
                    "asset": "@@000000013",
                    "symbol": "HBD",
                    "precision": 3,
                    "id": 0
                }, {
                    "asset": "@@000000021",
                    "symbol": "HIVE",
                    "precision": 3,
                    "id": 1
                }, {
                    "asset": "@@000000037",
                    "symbol": "VESTS",
                    "precision": 6,
                    "id": 2
                }],
                'chain_id':
                '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32',
                'min_version':
                '0.20.0',
                'prefix':
                'TST'
            }
        })
    print(hv.get_blockchain_version())
    print(hv.get_config()["HIVE_CHAIN_ID"])
Exemplo n.º 17
0
from bhivegraphenebase.account import PasswordKey, PrivateKey, PublicKey
from bhive.hive import Hive
from bhive.utils import parse_time, formatTimedelta
from bhiveapi.exceptions import NumRetriesReached
from bhive.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

password = "******"
username = "******"
useWallet = False
walletpassword = "******"

if __name__ == "__main__":
    testnet_node = "https://testnet.hive.vc"
    hv = Hive(node=testnet_node)
    prefix = hv.prefix
    # curl --data "username=username&password=secretPassword" https://testnet.hive.vc/create
    if useWallet:
        hv.wallet.wipe(True)
        hv.wallet.create(walletpassword)
        hv.wallet.unlock(walletpassword)
    active_key = PasswordKey(username, password, role="active", prefix=prefix)
    owner_key = PasswordKey(username, password, role="owner", prefix=prefix)
    posting_key = PasswordKey(username,
                              password,
                              role="posting",
                              prefix=prefix)
    memo_key = PasswordKey(username, password, role="memo", prefix=prefix)
    active_pubkey = active_key.get_public_key()
    owner_pubkey = owner_key.get_public_key()