-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Takeshi Yonezu <[email protected]>
- Loading branch information
Showing
39 changed files
with
907 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
IROHA_PRJ=hyperledger | ||
IROHA_IMG=iroha:1.2.1 | ||
COMPOSE_PROJECT_NAME=iroha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Building Hyperledger Iroha testnet | ||
|
||
## Abstract | ||
|
||
This tool allows you to launch test net on a single instance using Iroha's docker container. | ||
|
||
In addition, you can launch 4 instances of Iroha on your PC or cloud environment. | ||
|
||
In either case, you can run Iroha's API using a test script called setup-iroha-wallet. | ||
|
||
## How to run | ||
|
||
### Single Host Single instance | ||
|
||
Use docker-compose to launch it as follows: | ||
|
||
``` | ||
$ docker-compose up -d | ||
``` | ||
|
||
If it starts normally, the docker ps command will display: | ||
|
||
``` | ||
$ docker ps | ||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ||
4370a2679d7e hyperledger/iroha:1.2.1 "/opt/iroha/config/e…" About a minute ago Up About a minute 0.0.0.0:50051->50051/tcp, :::50051->50051/tcp iroha_node_1 | ||
f14813ae92b9 postgres:13.2-alpine "docker-entrypoint.s…" About a minute ago Up About a minute 5432/tcp iroha_postgres_1 | ||
``` | ||
|
||
You can view the Iroha execution log using the docker logs command. | ||
|
||
``` | ||
$ docker logs -f iroha_node_1 | ||
``` | ||
|
||
### Single Host 4 Instances | ||
|
||
You can also run four Iroha instances on a single PC or cloud for testing. In this case, do the following: | ||
|
||
``` | ||
$ cd example/node4 | ||
$ docker-compose up -d | ||
``` | ||
|
||
In this case, Iroha's distributed ledger and PostgreSQL DB used for [WSV](https://iroha.readthedocs.io/en/main/concepts_architecture/architecture.html#world-state-view) are created on the host and volume mounted on docker. Depending on the version of docker, you may get an error due to permission issues when writing blocks to the directory for the distributed ledger. | ||
|
||
In such a case, delete the directory created as iroha1 ~ iroha4 and the files under it, and then execute the setup.sh script. | ||
In this case, do the following: | ||
|
||
``` | ||
$ sudo rm -fr iroha? | ||
$ bash setup.sh | ||
``` | ||
In this state, try starting Iroha again with docker-compose. | ||
|
||
``` | ||
$ docker-compose up -d | ||
``` | ||
|
||
## View Iroha Log | ||
|
||
In the case of Single Host 4 instance, you can display the log of each Iroha on 4 terminal screens. | ||
|
||
In this case, first open the four terminal screens. In addition, open 5 screens in total, and execute the following script from the last terminal. | ||
|
||
``` | ||
$ cd example/node4 | ||
$ bash logs4.sh | ||
``` | ||
|
||
This script keeps displaying the Iroha logs obtained by docker logs -f on the screens of the four terminals starting with the one with the smallest terminal number. Of course, you can use the docker logs command individually. | ||
|
||
## Test script | ||
|
||
You can run the test script while Iroha is running. In this case, run the setup-iroha-wallet.sh script located in the example / iroha-wallet directory. | ||
|
||
``` | ||
$ cd example/iroha-wallet | ||
$ bash seetup-iroha-wallet.sh | ||
``` | ||
|
||
This script performs the following transactional operations: | ||
|
||
1. Create an alice account | ||
2. Create a bob account | ||
3. Create an asset called coolcoin | ||
4. Create an asset called hotcoin | ||
5. Add 1000 units of cool coin | ||
6,. Add 1000 units of hot coin | ||
7. Transfer 500 units of cool coin to alice | ||
8. Transfer 500 units of hot coin to alice | ||
9. Transfer 500 units of cool coin to bob | ||
10. Transfer 500 units of hotcoin to bob | ||
|
||
After performing all transaction operations, the status is queried each time. | ||
|
||
## How to stop | ||
|
||
If you want to stop it, run docker-compose down. Here, in the case of Single Host Single Instance, execute it in the iroha-testnet directory. For Single Host 4Instances, run in the example/node4 directory. | ||
|
||
Since we are using the ccache-data volume in the docker-compose.yml file, it's a good idea to add the "-v" option when running docker-compose down. | ||
|
||
``` | ||
$ docker-compose down -v | ||
``` | ||
|
||
## References | ||
|
||
Please refer to [Hyperledger Iroha documentation](https://iroha.readthedocs.io/en/main/index.html) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: '3' | ||
|
||
services: | ||
node: | ||
image: ${IROHA_PRJ}/${IROHA_IMG} | ||
ports: | ||
- "50051:50051" | ||
environment: | ||
- IROHA_HOME=/opt/iroha | ||
- IROHA_CONF=config.docker | ||
- IROHA_NODEKEY=node1 | ||
- CCACHE_DIR=/tmp/ccache | ||
volumes: | ||
- ${PWD}/example:/opt/iroha/config | ||
- ccache-data:/tmp/ccache | ||
working_dir: /opt/iroha/config | ||
entrypoint: /opt/iroha/config/entrypoint.sh | ||
depends_on: | ||
- postgres | ||
|
||
postgres: | ||
image: postgres:13.2-alpine | ||
environment: | ||
- POSTGRES_USER=iroha | ||
- POSTGRES_PASSWORD=HelloW0rld | ||
|
||
volumes: | ||
ccache-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"block_store_path" : "/tmp/block_store/", | ||
"torii_port" : 50051, | ||
"internal_port" : 10001, | ||
"pg_opt" : "host=iroha_postgres_1 port=5432 user=iroha password=HelloW0rld", | ||
"max_proposal_size" : 10, | ||
"proposal_delay" : 5000, | ||
"vote_delay" : 5000, | ||
"mst_enable" : false, | ||
"mst_expiration_time" : 1440, | ||
"max_rounds_delay": 3000, | ||
"stale_stream_max_rounds": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
cd ${IROHA_HOME}/config | ||
|
||
IROHA_CONF=${IROHA_CONF:-iroha.conf} | ||
IROHA_BLOCK=$(cat ${IROHA_CONF} | grep block_store_path | | ||
sed -e 's/^.*: "//' -e 's/".*$//') | ||
IROHA_GENESIS=${IROHA_GENESIS:-genesis.block} | ||
IROHA_NODEKEY=${IROHA_NODEKEY:-node1} | ||
|
||
if grep -q pg_opt ${IROHA_CONF}; then | ||
PG_HOST=$(cat ${IROHA_CONF} | grep pg_opt | sed -e 's/^.*host=//' -e 's/ .*//') | ||
PG_PORT=$(cat ${IROHA_CONF} | grep pg_opt | sed -e 's/^.*port=//' -e 's/ .*//') | ||
else | ||
PG_HOST=$(cat ${IROHA_CONF} | grep host | sed -e 's/^.*host" *: *"//' -e 's/".*//') | ||
PG_PORT=$(cat ${IROHA_CONF} | grep "[^_]port" | sed -e 's/^.*port" *: *//' -e 's/,.*//') | ||
fi | ||
|
||
if [ -x ${IROHA_HOME}/bin/wait-for-it.sh ]; then | ||
WAIT_FOR_IT="${IROHA_HOME}/bin/wait-for-it.sh" | ||
else | ||
WAIT_FOR_IT="/wait-for-it.sh" | ||
fi | ||
|
||
${WAIT_FOR_IT} -h ${PG_HOST} -p ${PG_PORT} -t 60 -- true | ||
|
||
# Raspberry Pi, Wait until PostgreSQL is stabilized | ||
if [ "$(uname -m)" = "armv7l" ]; then | ||
# Raspberry Pi 4B does'nt need sleep | ||
if ! grep ^Model /proc/cpuinfo | grep -q "Raspberry Pi 4"; then | ||
sleep 30 | ||
fi | ||
fi | ||
|
||
if [ ! -f ${IROHA_BLOCK}0000000000000001 ]; then | ||
echo "$ irohad --config ${IROHA_CONF} --genesis_block ${IROHA_GENESIS} --keypair_name ${IROHA_NODEKEY} --drop_state" | ||
|
||
irohad --config ${IROHA_CONF} \ | ||
--genesis_block ${IROHA_GENESIS} \ | ||
--keypair_name ${IROHA_NODEKEY} \ | ||
--drop_state | ||
elif [ ! -f ${IROHA_BLOCK}0000000000000002 ]; then | ||
echo "$ irohad --config ${IROHA_CONF} --genesis_block ${IROHA_GENESIS} --keypair_name ${IROHA_NODEKEY}" | ||
|
||
irohad --config ${IROHA_CONF} \ | ||
--genesis_block ${IROHA_GENESIS} \ | ||
--keypair_name ${IROHA_NODEKEY} | ||
else | ||
echo "$ irohad --config ${IROHA_CONF} --keypair_name ${IROHA_NODEKEY}" | ||
|
||
irohad --config ${IROHA_CONF} \ | ||
--keypair_name ${IROHA_NODEKEY} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"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" | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tools/docker/iroha-testnet/example/iroha-wallet/[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9c430dfe8c54b0a447e25f75121119ac3b649c1253bce8420f245e4c104dccd1 |
1 change: 1 addition & 0 deletions
1
tools/docker/iroha-testnet/example/iroha-wallet/[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bcc4ab167ae7db371672170ed31e382f7c612fbfe918f99c276cd9dc199446a4 |
1 change: 1 addition & 0 deletions
1
tools/docker/iroha-testnet/example/iroha-wallet/[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a997d9631aa6f2a60b2776d72a2e12228db972e03b7aa987fee8997354a3b236 |
1 change: 1 addition & 0 deletions
1
tools/docker/iroha-testnet/example/iroha-wallet/[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
583a55172a77c9881699306c6f69defac6cb939aa45afb87b7d35bcf06cdd786 |
Oops, something went wrong.