Skip to content

Commit

Permalink
Update Node Sync test and run scripts
Browse files Browse the repository at this point in the history
Signed-off-by: alexander.shenshin <alexander.shenshin@dsr-corporation.com>
  • Loading branch information
AlexanderShenshin committed Jan 18, 2023
1 parent 9217324 commit a721b3e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 127 deletions.
34 changes: 16 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,22 @@ services:
#
# Synchronization test
#
# synctest:
# image: von-network-base
# command: ./scripts/start_synctest.sh
# environment:
# - IP=${IP}
# - IPS=${IPS}
# - DOCKERHOST=${DOCKERHOST}
# - LOG_LEVEL=${LOG_LEVEL}
# - RUST_LOG=${RUST_LOG}
# networks:
# - von
# ports:
# - ${WEB_SERVER_HOST_PORT:-9000}:8000
# volumes:
# - ./config:/home/indy/config
# - ./server:/home/indy/server
# - webserver-cli:/home/indy/.indy-cli
# - webserver-ledger:/home/indy/ledger
synctest:
image: von-network-base
command: ./scripts/start_synctest.sh
environment:
- IP=${IP}
- IPS=${IPS}
- DOCKERHOST=${DOCKERHOST}
- LOG_LEVEL=${LOG_LEVEL}
- RUST_LOG=${RUST_LOG}
networks:
- von
ports:
- ${WEB_SERVER_HOST_PORT:-9000}:8000
volumes:
- ./config:/home/indy/config
- ./server:/home/indy/server

#
# Nodes
Expand Down
17 changes: 11 additions & 6 deletions manage
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,16 @@ function getVolumeMount() {
fi
echo ${path}
}

function ensureGenesisTransactionsFile() {
if [ ! -f config/genesis.txn ]; then
echo "Genesis transaction file not found, creating..."
docker run --rm -e "DOCKERHOST=${DOCKERHOST}" -e "IP=${IP}" -e "IPS=${IPS}" \
-v /$(pwd)/config:/home/indy/config \
von-network-base scripts/init_genesis.sh
fi
}

# =================================================================================================================

pushd "${SCRIPT_HOME}" >/dev/null
Expand All @@ -832,12 +842,7 @@ case "${COMMAND}" in
start|up)
initEnv "$@"
export LEDGER_SEED=${LEDGER_SEED:-000000000000000000000000Trustee1}
if [ ! -f config/genesis.txn ]; then
echo "Genesis transaction file not found, creating..."
docker run --rm -e "DOCKERHOST=${DOCKERHOST}" -e "IP=${IP}" -e "IPS=${IPS}" \
-v /$(pwd)/config:/home/indy/config \
von-network-base scripts/init_genesis.sh
fi
ensureGenesisTransactionsFile
install_taa
${dockerCompose} \
up \
Expand Down
2 changes: 1 addition & 1 deletion scripts/start_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fi
mkdir -p .indy_client/pool/sandbox
cp /home/indy/ledger/sandbox/pool_transactions_genesis .indy_client/pool/sandbox/sandbox.txn

indy-cli "$@"
indy-cli "$@"
17 changes: 5 additions & 12 deletions scripts/start_synctest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

set -e

if [ ! -f "/home/indy/ledger/sandbox/pool_transactions_genesis" ] && [ -z "${GENESIS_URL}" ] && [ -z "${GENESIS_FILE}" ]; then
echo "Ledger does not exist - Creating genesis data..."
if [ ! -z "$IPS" ]; then
echo von_generate_transactions -s "$IPS"
von_generate_transactions -s "$IPS"
elif [ ! -z "$IP" ]; then
echo von_generate_transactions -i "$IP"
von_generate_transactions -i "$IP"
else
echo von_generate_transactions
von_generate_transactions
fi
if [ ! -f "/home/indy/config/genesis.txn" ] && [ -z "${GENESIS_FILE}" ]; then
bash ./scripts/init_genesis.sh
fi

pip3 install -U pip &&
pip install --no-cache-dir -r server/requirements.txt

python -m server.synctest
14 changes: 2 additions & 12 deletions scripts/start_webserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

set -e

if [ ! -f "/home/indy/ledger/sandbox/pool_transactions_genesis" ] && [ -z "${GENESIS_URL}" ] && [ -z "${GENESIS_FILE}" ]; then
echo "Ledger does not exist - Creating genesis data..."
if [ ! -z "$IPS" ]; then
echo von_generate_transactions -s "$IPS"
von_generate_transactions -s "$IPS"
elif [ ! -z "$IP" ]; then
echo von_generate_transactions -i "$IP"
von_generate_transactions -i "$IP"
else
echo von_generate_transactions
von_generate_transactions
fi
if [ ! -f "/home/indy/config/genesis.txn" ] && [ -z "${GENESIS_URL}" ] && [ -z "${GENESIS_FILE}" ]; then
bash ./scripts/init_genesis.sh
fi

# link node ledgers where webserver can find them
Expand Down
18 changes: 2 additions & 16 deletions server/anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import indy_vdr
from indy_vdr import ledger, open_pool, LedgerType, VdrError, VdrErrorCode

from .utils import env_bool, is_int, run_thread

LOGGER = logging.getLogger(__name__)

INDY_TXN_TYPES = {
Expand Down Expand Up @@ -51,10 +53,6 @@
"122": "AUTH_RULES",
}

def env_bool(param: str, defval=None) -> bool:
val = os.getenv(param, defval)
return bool(val and val != "0" and val.lower() != "false")

INDY_ROLE_TYPES = {"0": "TRUSTEE", "2": "STEWARD", "100": "TGB", "101": "ENDORSER"}

DEFAULT_PROTOCOL = 2
Expand Down Expand Up @@ -99,10 +97,6 @@ def format_validator_info(node_data):
return ret


async def run_thread(fn, *args):
return await asyncio.get_event_loop().run_in_executor(None, fn, *args)


def nacl_seed_to_did(seed):
seed = seed_as_bytes(seed)
vk = bytes(nacl.signing.SigningKey(seed).verify_key)
Expand All @@ -111,14 +105,6 @@ def nacl_seed_to_did(seed):
return did, verkey


def is_int(val):
if isinstance(val, int):
return True
if isinstance(val, str) and val.isdigit():
return True
return False


async def _fetch_url(the_url):
async with aiohttp.ClientSession() as session:
async with session.get(the_url) as resp:
Expand Down
77 changes: 15 additions & 62 deletions server/synctest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import asyncio
import json
import logging
import os
import sys

# from indy.error import ErrorCode, IndyError
# from indy import did, ledger, pool, wallet
import indy_vdr
from indy_vdr import ledger, open_pool

LOGGER = logging.getLogger(__name__)

GENESIS_FILE = (
os.getenv("GENESIS_FILE") or "/home/indy/ledger/sandbox/pool_transactions_genesis"
)
GENESIS_FILE = os.getenv("GENESIS_FILE") or "/home/indy/config/genesis.txn"

POOL = 0
DOMAIN = 1
Expand All @@ -21,71 +18,28 @@


async def sync():
LOGGER.info("Connecting to ledger pool")

pool_name = "nodepool"
pool_cfg = {}
indy_vdr.set_protocol_version(2)

await pool.set_protocol_version(2)
pool = await open_pool(transactions_path=GENESIS_FILE)

pool_names = {cfg["pool"] for cfg in await pool.list_pools()}
if pool_name not in pool_names:
await pool.create_pool_ledger_config(
pool_name, json.dumps({"genesis_txn": GENESIS_FILE})
)

pool_handle = await pool.open_pool_ledger(pool_name, json.dumps(pool_cfg))
LOGGER.info("Connected to ledger pool")

wallet_cfg = {"id": "trustee_wallet", "freshness_time": 0}
wallet_access = {"key": "key"}

try:
await wallet.create_wallet(
config=json.dumps(wallet_cfg), credentials=json.dumps(wallet_access)
)
except IndyError as e:
if e.error_code == ErrorCode.WalletAlreadyExistsError:
LOGGER.info("Wallet already exists")
else:
raise

wallet_handle = await wallet.open_wallet(
config=json.dumps(wallet_cfg), credentials=json.dumps(wallet_access)
)
LOGGER.info("Opened wallet")

try:
(my_did, my_verkey) = await did.create_and_store_my_did(
wallet_handle, json.dumps({"seed": LEDGER_SEED})
)
LOGGER.info("Created wallet DID")
except IndyError as e:
if e.error_code == ErrorCode.DidAlreadyExistsError:
LOGGER.info("DID already exists in wallet")
else:
raise

get_aml_req = await ledger.build_get_acceptance_mechanisms_request(
my_did, None, None
)
rv_json = await ledger.sign_and_submit_request(
pool_handle, wallet_handle, my_did, get_aml_req
)
print("AML", rv_json)
get_aml_req = ledger.build_get_acceptance_mechanisms_request()
rv = await pool.submit_request(get_aml_req)
print("AML", rv)

get_taa_req = await ledger.build_get_txn_author_agreement_request(my_did, None)
rv_json = await ledger.sign_and_submit_request(
pool_handle, wallet_handle, my_did, get_taa_req
)
print("TAA", rv_json)
get_taa_req = ledger.build_get_txn_author_agreement_request()
rv = await pool.submit_request(get_taa_req)
print("TAA", rv)

for ledger_name in ("DOMAIN",):
txn_idx = 1
while True:
req_json = await ledger.build_get_txn_request(my_did, ledger_name, txn_idx)
rv_json = await ledger.submit_request(pool_handle, req_json)
rv = json.loads(rv_json)
if not rv["result"]["data"]:
request = ledger.build_get_txn_request(None, ledger_name, txn_idx)
rv = await pool.submit_request(request)
if not rv["data"]:
break
print(ledger_name, txn_idx)
txn_idx += 1
Expand All @@ -95,7 +49,6 @@ async def sync():
if __name__ == "__main__":
level = os.getenv("LOG_LEVEL", "INFO").upper()
logging.basicConfig(stream=sys.stdout, level=level)
logging.getLogger("indy.libindy").setLevel(logging.WARNING)
try:
asyncio.get_event_loop().run_until_complete(sync())
except Exception:
Expand Down
15 changes: 15 additions & 0 deletions server/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import asyncio


def env_bool(param: str, defval=None) -> bool:
val = os.getenv(param, defval)
return bool(val and val != "0" and val.lower() != "false")


def is_int(val):
return isinstance(val, int) or (isinstance(val, str) and val.isdigit())


async def run_thread(fn, *args):
return await asyncio.get_event_loop().run_in_executor(None, fn, *args)

0 comments on commit a721b3e

Please sign in to comment.