Skip to content

Instantly share code, notes, and snippets.

@shazz

shazz/build.sh Secret

Last active August 8, 2021 14:20
Show Gist options
  • Select an option

  • Save shazz/cd7b4ad3b2fa24c9bf0a4010f48ce316 to your computer and use it in GitHub Desktop.

Select an option

Save shazz/cd7b4ad3b2fa24c9bf0a4010f48ce316 to your computer and use it in GitHub Desktop.
# --------------------------------------------------------------------------------------------------------
# Iroha Builder
# --------------------------------------------------------------------------------------------------------
# using iroha-builder
mkdir build
sudo docker run -it --name builder -v${PWD}/release:/opt/iroha hyperledger/iroha-builder:edge
# --------------------------------------------------------------------------------------------------------
# in the container
git clone --branch support/1.2.x https://github.com/hyperledger/iroha --depth=1
./iroha/vcpkg/build_iroha_deps.sh
./vcpkg-build/vcpkg integrate install
cd iroha
cmake -B build -DCMAKE_TOOLCHAIN_FILE=/opt/iroha/vcpkg-build/scripts/buildsystems/vcpkg.cmake -GNinja -DTESTING=OFF -DPACKAGE_DEB=ON -DUSE_BURROW=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -- -j4
cd build
cpack
cp *iroha_shepherd.deb ../docker/release/iroha_shepherd.deb
cp *irohad.deb ../docker/release/iroha.deb
# --------------------------------------------------------------------------------------------------------
# from host in another terminal
# --------------------------------------------------------------------------------------------------------
cd build
sudo docker build -t myiroha docker/release/
@shazz

shazz commented Jul 12, 2021

Copy link
Copy Markdown
Author

test_perf.py

# virtualenv .venv
# source .venv/bin/activate
# pip install iroha
# python test_perf.py

import time
from iroha import IrohaCrypto
from iroha import Iroha, IrohaGrpc

# -------------------------------------------------------------------------------
host_port = "50051"
host_ip = "<<your_iroha_ip>>"
private_key = "<<admin@test private key>>"
account = "admin@test"
precision = 6
asset_name = "perfcoin"
loop_size = 10
loop_start = 0
# -------------------------------------------------------------------------------

iroha = Iroha(account)
net = IrohaGrpc('{}:{}'.format(host_ip, host_port))

start_time = time.perf_counter()
for i in range(loop_start, loop_start+loop_size):
    domain = f"domain{i}"
    print(f"-- Create {domain} domain")

    commands = [
        iroha.command('CreateDomain', domain_id=domain, default_role='user'),
        iroha.command('CreateAsset', asset_name=asset_name, domain_id=domain, precision=precision)
    ]
    tx = IrohaCrypto.sign_transaction(iroha.transaction(commands), private_key)

    net.send_tx(tx)
    for i, status in enumerate(net.tx_status_stream(tx)):
        print(f"{i}: {status}")

        if 'STATEFUL_VALIDATION_FAILED' in status[0]:
            raise RuntimeError(f"Stateful validation failed on tx: {tx} due to reason {status[2]}")

        elif 'STATELESS_VALIDATION_FAILED' in status[0]:
            raise RuntimeError(f"Stateless validation failed on tx: {tx} due to reason {status[2]}")

        elif status[0] in ['REJECTED']:
            raise RuntimeError(f"Transaction {tx} rejected with status {status[2]} by the peer during stateful validation step in previous consensus rounds")

total_time = time.perf_counter() - start_time
print(f"domains created in {total_time:.4f} secs (avg: {total_time/loop_size:.4f} secs per domain)")

genesis.block:

{
   "block_v1":{
     "payload":{
        "transactions":[
           {
              "payload":{
                 "reducedPayload":{
                    "commands":[
                       {
                          "addPeer":{
                             "peer":{
                                "address":"127.0.0.1:10001",
                                "peerKey":"bddd58404d1315e0eb27902c5d7c8eb0602c16238f005773df406bc191308929"
                             }
                          }
                       },
                       {
                          "createRole":{
                             "roleName":"admin",
                             "permissions":[
                                "can_add_peer",
                                "can_add_signatory",
                                "can_create_account",
                                "can_create_domain",
                                "can_get_all_acc_ast",
                                "can_get_all_acc_ast_txs",
                                "can_get_all_acc_detail",
                                "can_get_all_acc_txs",
                                "can_get_all_accounts",
                                "can_get_all_signatories",
                                "can_get_all_txs",
                                "can_get_blocks",
                                "can_get_roles",
                                "can_read_assets",
                                "can_remove_signatory",
                                "can_set_quorum"
                             ]
                          }
                       },
                       {
                          "createRole":{
                             "roleName":"user",
                             "permissions":[
                                "can_add_signatory",
                                "can_get_my_acc_ast",
                                "can_get_my_acc_ast_txs",
                                "can_get_my_acc_detail",
                                "can_get_my_acc_txs",
                                "can_get_my_account",
                                "can_get_my_signatories",
                                "can_get_my_txs",
                                "can_grant_can_add_my_signatory",
                                "can_grant_can_remove_my_signatory",
                                "can_grant_can_set_my_account_detail",
                                "can_grant_can_set_my_quorum",
                                "can_grant_can_transfer_my_assets",
                                "can_receive",
                                "can_remove_signatory",
                                "can_set_quorum",
                                "can_transfer"
                             ]
                          }
                       },
                       {
                          "createRole":{
                             "roleName":"money_creator",
                             "permissions":[
                                "can_add_asset_qty",
                                "can_create_asset",
                                "can_receive",
                                "can_transfer"
                             ]
                          }
                       },
                       {
                          "createDomain":{
                             "domainId":"test",
                             "defaultRole":"user"
                          }
                       },
                       {
                          "createAsset":{
                             "assetName":"coin",
                             "domainId":"test",
                             "precision":2
                          }
                       },
                       {
                          "createAccount":{
                             "accountName":"admin",
                             "domainId":"test",
                             "publicKey":"313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910"
                          }
                       },
                       {
                          "createAccount":{
                             "accountName":"test",
                             "domainId":"test",
                             "publicKey":"716fe505f69f18511a1b083915aa9ff73ef36e6688199f3959750db38b8f4bfc"
                          }
                       },
                       {
                          "appendRole":{
                             "accountId":"admin@test",
                             "roleName":"admin"
                          }
                       },
                       {
                          "appendRole":{
                             "accountId":"admin@test",
                             "roleName":"money_creator"
                          }
                       }
                    ],
                    "quorum":1
                 }
              }
           }
        ],
        "txNumber":1,
        "height":"1",
        "prevBlockHash":"0000000000000000000000000000000000000000000000000000000000000000"
     }
   }
}

config.docker:

{
  "block_store_path" : "/tmp/block_store/",
  "torii_port" : 50051,
  "internal_port" : 10001,
  "pg_opt" : "host=some-postgres0 port=5432 user=postgres password=mysecretpassword",
  "max_proposal_size" : 10,
  "proposal_delay" : 2000,
  "vote_delay" : 1000,
  "mst_enable" : false,
  "mst_expiration_time" : 1440,
  "max_rounds_delay": 3000,
  "stale_stream_max_rounds": 2
}

Default node0.pub/priv used:

node0.pub

bddd58404d1315e0eb27902c5d7c8eb0602c16238f005773df406bc191308929

node0.priv

cc5013e43918bd0e5c4d800416c88bed77892ff077929162bb03ead40a745e88

Docker script:

echo "-> deleting postgres db container"
sudo docker rm -f some-postgres0

echo "-> deleting iroha container"
sudo docker rm -f iroha0

echo "-> resetting blockstore"
sudo docker volume rm blockstore0
sudo docker volume create blockstore0

sudo docker network create iroha-network

echo "-> creating postgres0 db container"
sudo docker run --rm --name some-postgres0 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 --network=iroha-network -d postgres:9.5 -c 'max_prepared_transactions=100'

sleep 10
echo "-> creating iroha node 0 container"
sudo docker run --rm --name iroha0 -d -p 50051:50051 -p 50081:50081 -v $(pwd)/config:/opt/iroha_data -v blockstore0:/tmp/block_store --network=iroha-network -e KEY='node0' iroha-release:latest

echo "-> Checking logs"
sudo docker logs -f iroha0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment