Skip to content

Commit

Permalink
fix: started adding a yachli example and taskfile (#1132)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Kuzmin <[email protected]>
Signed-off-by: Jeromy Cannon <[email protected]>
Co-authored-by: Alex Kuzmin <[email protected]>
  • Loading branch information
jeromy-cannon and alex-kuzmin-hg authored Jan 13, 2025
1 parent 2b48f4e commit 8753723
Show file tree
Hide file tree
Showing 34 changed files with 979 additions and 411 deletions.
99 changes: 67 additions & 32 deletions Taskfile.helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ vars:
solo_logs_dir: "{{ .solo_user_dir }}/logs"
solo_keys_dir: "{{ .solo_cache_dir }}/keys"
solo_bin_dir: "{{ .solo_user_dir }}/bin"
temp_prefix:
sh: (echo "/tmp/solo-${USER}-$(date +%Y%m%d%H%M%S)")
run_build_file:
sh: (echo "/tmp/${USER}-run-build-$(date +%Y%m%d%H%M%S)")
sh: (echo "/tmp/solo-${USER}-run-build-$(date +%Y%m%d%H%M%S)")
var_check_file:
sh: (echo "/tmp/${USER}-var-check-$(date +%Y%m%d%H%M%S)")
sh: (echo "/tmp/solo-${USER}-var-check-$(date +%Y%m%d%H%M%S)")
minio_flag_file:
sh: (echo "/tmp/${USER}-minio-flag-$(date +%Y%m%d%H%M%S)")
sh: (echo "/tmp/solo-${USER}-minio-flag-$(date +%Y%m%d%H%M%S)")
solo_install_file:
sh: (echo "/tmp/${USER}-solo-install-$(date +%Y%m%d%H%M%S)")
sh: (echo "/tmp/solo-${USER}-solo-install-$(date +%Y%m%d%H%M%S)")

env:
SOLO_CLUSTER_SETUP_NAMESPACE: solo-setup
Expand Down Expand Up @@ -75,6 +77,11 @@ tasks:
- echo "LOCAL_BUILD_FLAG=${LOCAL_BUILD_FLAG}"
- echo "DEBUG_NODE_ALIAS=${DEBUG_NODE_ALIAS}"
- echo "SOLO_CHARTS_DIR_FLAG=${SOLO_CHARTS_DIR_FLAG}"
- echo "LOAD_BALANCER_FLAG=${LOAD_BALANCER_FLAG}"
- echo "ENABLE_EXPLORER_TLS_FLAG=${ENABLE_EXPLORER_TLS_FLAG}"
- echo "CLUSTER_TLS_FLAGS=${CLUSTER_TLS_FLAGS}"
- echo "NETWORK_DEPLOY_EXTRA_FLAGS=${NETWORK_DEPLOY_EXTRA_FLAGS}"
- echo "MIRROR_NODE_DEPLOY_EXTRA_FLAGS=${MIRROR_NODE_DEPLOY_EXTRA_FLAGS}"
- touch {{ .var_check_file }}

readme:
Expand All @@ -98,14 +105,15 @@ tasks:
- test -f {{ .solo_install_file }}
cmds:
- |
if [[ "$(ls -1 package.json)" == "" ]]; then
if [[ "$(ls -1 package.json > /dev/null 2>&1)" == "" ]]; then
cd ..
fi
pwd
- npm install
- touch {{ .solo_install_file }}

install:kubectl:darwin:
silent: true
internal: true
platforms:
- darwin
Expand All @@ -116,6 +124,7 @@ tasks:
- brew install kubernetes-cli

install:kubectl:linux:
silent: true
internal: true
platforms:
- linux
Expand All @@ -142,9 +151,10 @@ tasks:
#- test "$(yq -r '.flags."node-ids"' < {{ .solo_user_dir }}/solo.yaml)" == "{{ .node_identifiers }}"
- test "$(jq -r '.flags."node-ids"' < {{ .solo_user_dir }}/solo.config)" == "{{ .node_identifiers }}"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- init
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- init --dev

solo:keys:
silent: true
internal: true
status:
- |
Expand All @@ -157,9 +167,10 @@ tasks:
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node keys --gossip-keys --tls-keys --node-aliases-unparsed {{.node_identifiers}} -q
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node keys --gossip-keys --tls-keys --node-aliases-unparsed {{.node_identifiers}} -q --dev

solo:network:deploy:
silent: true
internal: true
deps:
- task: "init"
Expand All @@ -174,21 +185,31 @@ tasks:
if [[ "${SOLO_CHART_VERSION}" != "" ]]; then
export SOLO_CHART_FLAG='--solo-chart-version ${SOLO_CHART_VERSION}'
fi
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- network deploy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${CONSENSUS_NODE_FLAG} ${SOLO_CHART_FLAG} ${VALUES_FLAG} ${SETTINGS_FLAG} ${LOG4J2_FLAG} ${APPLICATION_PROPERTIES_FLAG} ${GENESIS_THROTTLES_FLAG} ${DEBUG_NODE_FLAG} ${SOLO_CHARTS_DIR_FLAG} -q
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- network deploy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${CONSENSUS_NODE_FLAG} ${SOLO_CHART_FLAG} ${VALUES_FLAG} ${SETTINGS_FLAG} ${LOG4J2_FLAG} ${APPLICATION_PROPERTIES_FLAG} ${GENESIS_THROTTLES_FLAG} ${DEBUG_NODE_FLAG} ${SOLO_CHARTS_DIR_FLAG} ${LOAD_BALANCER_FLAG} ${NETWORK_DEPLOY_EXTRA_FLAGS} -q --dev
- task: "solo:node:setup"

solo:node:setup:
silent: true
internal: true
deps:
- task: "init"
cmds:
- |
if [[ "${CONSENSUS_NODE_VERSION}" != "" ]]; then
export CONSENSUS_NODE_FLAG='--release-tag ${CONSENSUS_NODE_VERSION}'
fi
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node setup --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${CONSENSUS_NODE_FLAG} ${LOCAL_BUILD_FLAG} -q
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node setup --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${CONSENSUS_NODE_FLAG} ${LOCAL_BUILD_FLAG} -q --dev
solo:network:destroy:
silent: true
internal: true
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- network destroy --namespace "${SOLO_NAMESPACE}" --delete-pvcs --delete-secrets --force -q
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- network destroy --namespace "${SOLO_NAMESPACE}" --delete-pvcs --delete-secrets --force -q --dev

solo:node:start:
silent: true
internal: true
deps:
- task: "init"
Expand All @@ -197,42 +218,46 @@ tasks:
if [[ "${DEBUG_NODE_ALIAS}" != "" ]]; then
export DEBUG_NODE_FLAG="--debug-node-alias {{ .DEBUG_NODE_ALIAS }}"
fi
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node start --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${DEBUG_NODE_FLAG} -q {{ .CLI_ARGS }}
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node start --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} ${DEBUG_NODE_FLAG} -q {{ .CLI_ARGS }} --dev
- |
if [[ "{{ .use_port_forwards }}" == "true" ]];then
echo "Enable port forwarding for Hedera Node"
kubectl port-forward -n "${SOLO_NAMESPACE}" svc/haproxy-node1-svc 50211:50211 &
echo "Enable port forwarding for Hedera Network Node"
echo "Port forwarding for Hedera Network Node: grpc:50211"
nohup kubectl port-forward -n "${SOLO_NAMESPACE}" pod/network-node1-0 50211:50211 < /dev/null > {{.temp_prefix}}-50211-nohup.out 2>&1 &
sleep 4
fi
solo:node:stop:
silent: true
internal: true
ignore_error: true
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node stop --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} -q {{ .CLI_ARGS }}
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node stop --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} -q {{ .CLI_ARGS }} --dev

solo:relay:
silent: true
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- relay deploy -n "${SOLO_NAMESPACE}" -i node1 -q
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- relay deploy -n "${SOLO_NAMESPACE}" -i node1 ${RELAY_NODE_DEPLOY_EXTRA_FLAGS} -q --dev
- |
if [[ "{{ .use_port_forwards }}" == "true" ]];then
echo "Enable port forwarding for Hedera JSON RPC Relay"
kubectl port-forward -n "${SOLO_NAMESPACE}" svc/relay-node1-hedera-json-rpc-relay 7546:7546 &
nohup kubectl port-forward -n "${SOLO_NAMESPACE}" svc/relay-node1-hedera-json-rpc-relay 7546:7546 &
sleep 4
fi
solo:destroy-relay:
silent: true
status:
- |
{{.solo_bin_dir}}/helm list -n "${SOLO_NAMESPACE}" | grep -vqz relay-node1
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- relay destroy -n "${SOLO_NAMESPACE}" -i node1 -q
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- relay destroy -n "${SOLO_NAMESPACE}" -i node1 -q --dev

solo:cache:remove:
silent: true
Expand Down Expand Up @@ -261,21 +286,24 @@ tasks:
- echo "Removing solo config..."
- rm -rf {{ .solo_user_dir }}/solo.yaml

solo:freeze:restart:
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node prepare-upgrade --namespace "${SOLO_NAMESPACE}" -q --dev
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node freeze-upgrade --namespace "${SOLO_NAMESPACE}" -q --dev
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node stop --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} -q --dev
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node start --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} -q --dev

cluster:create:
silent: true
status:
- kind get clusters | grep -q "${SOLO_CLUSTER_NAME}"
cmds:
- kind create cluster -n "${SOLO_CLUSTER_NAME}" --image "${KIND_IMAGE}"
- sleep 10 # wait for control plane to come up
- kubectl config set-context kind-${SOLO_CLUSTER_NAME}

cluster:setup:
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- cluster setup --cluster-setup-namespace "${SOLO_CLUSTER_SETUP_NAMESPACE}" ${SOLO_CHARTS_DIR_FLAG} -q

cluster:destroy:
silent: true
cmds:
- kind delete cluster --name "${SOLO_CLUSTER_NAME}"

Expand Down Expand Up @@ -319,7 +347,7 @@ tasks:
cmds:
- |
export MINIO_FLAG=$(cat {{ .minio_flag_file }})
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- cluster setup --cluster-setup-namespace "${SOLO_CLUSTER_SETUP_NAMESPACE}" ${MINIO_FLAG} -q
SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- cluster setup --cluster-setup-namespace "${SOLO_CLUSTER_SETUP_NAMESPACE}" ${MINIO_FLAG} ${SOLO_CHARTS_DIR_FLAG} ${CLUSTER_TLS_FLAGS} -q --dev
solo:node:addresses:
internal: true
Expand All @@ -330,6 +358,11 @@ tasks:
export IP_LIST_TEMPLATE_FILE={{ .TASKFILE_DIR }}/list-external-ips.gotemplate
kubectl get svc -n "${SOLO_NAMESPACE}" -l "solo.hedera.com/type=network-node-svc" --output=go-template-file=${IP_LIST_TEMPLATE_FILE}
solo:node:logs:
silent: true
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- node logs --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} -q --dev

start:
desc: solo node start
deps:
Expand Down Expand Up @@ -383,28 +416,33 @@ tasks:
- task: "solo:relay"

solo:mirror-node:
silent: true
desc: solo mirror-node deploy with port forward on explorer
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- mirror-node deploy --namespace "${SOLO_NAMESPACE}" -q
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- mirror-node deploy --namespace "${SOLO_NAMESPACE}" -s ${SOLO_CLUSTER_SETUP_NAMESPACE} ${SOLO_CHARTS_DIR_FLAG} ${ENABLE_EXPLORER_TLS_FLAG} ${TLS_CLUSTER_ISSUER_TYPE_FLAG} ${MIRROR_NODE_DEPLOY_EXTRA_FLAGS} --pinger -q --dev
- |
if [[ "{{ .use_port_forwards }}" == "true" ]];then
echo "Enable port forwarding for Hedera Explorer & Mirror Node Network"
kubectl port-forward -n "${SOLO_NAMESPACE}" svc/hedera-explorer 8080:80 &
kubectl port-forward svc/mirror-grpc -n "${SOLO_NAMESPACE}" 5600:5600 &
echo "Port forwarding for Hedera Explorer: http://localhost:6789"
nohup kubectl port-forward -n "${SOLO_NAMESPACE}" svc/hedera-explorer 6789:80 < /dev/null > {{.temp_prefix}}-6789-nohup.out 2>&1 &
echo "Port forwarding for Mirror Node Network: grpc:5600, rest:5551"
nohup kubectl port-forward svc/mirror-grpc -n "${SOLO_NAMESPACE}" 5600:5600 < /dev/null > {{.temp_prefix}}-5600-nohup.out 2>&1 &
nohup kubectl port-forward svc/mirror-rest -n "${SOLO_NAMESPACE}" 5551:80 < /dev/null > {{.temp_prefix}}-5551-nohup.out 2>&1 &
sleep 4
fi
solo:destroy-mirror-node:
silent: true
desc: solo mirror-node destroy
status:
- |
{{.solo_bin_dir}}/helm list -n "${SOLO_NAMESPACE}" | grep -vqz "${MIRROR_RELEASE_NAME}"
deps:
- task: "init"
cmds:
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- mirror-node destroy --namespace "${SOLO_NAMESPACE}" --force -q || true
- SOLO_HOME_DIR=${SOLO_HOME_DIR} npm run solo -- mirror-node destroy --namespace "${SOLO_NAMESPACE}" --force -q --dev || true

clean:
desc: destroy, then remove cache directory, logs directory, config, and port forwards
Expand All @@ -423,7 +461,4 @@ tasks:
silent: true
cmds:
- echo "Cleaning up temporary files..."
- rm -f /tmp/${USER}-run-build-* || true
- rm -f /tmp/${USER}-var-check-* || true
- rm -f /tmp/${USER}-minio-flag-* || true
- rm -f /tmp/${USER}-solo-install-* || true
- rm -f /tmp/solo-${USER}-* || true
6 changes: 5 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ env:
# LOCAL_BUILD_FLAG: "--local-build-path {{.HEDERA_SERVICES_ROOT}}/hedera-node/data"
# DEBUG_NODE_ALIAS: "node2"
# SOLO_CHARTS_DIR_FLAG: "-d /Users/user/source/solo-charts/charts"
# LOAD_BALANCER_FLAG: "--load-balancer"
# ENABLE_EXPLORER_TLS_FLAG: "--enable-hedera-explorer-tls"
# TLS_CLUSTER_ISSUER_TYPE_FLAG: "--tls-cluster-issuer-type acme-staging"
# NETWORK_DEPLOY_EXTRA_FLAGS: "--haproxy-ips node1="
vars:
use_port_forwards: "true"

Expand All @@ -35,7 +39,7 @@ tasks:
cmds:
- task: "cluster:create"
- task: "solo:init"
- task: "cluster:setup"
- task: "solo:cluster:setup"
- task: "solo:keys"
- task: "solo:network:deploy"

Expand Down
3 changes: 3 additions & 0 deletions examples/address-book/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output/
syserr.log
/localhost/sysfiles/
50 changes: 50 additions & 0 deletions examples/address-book/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Yahcli Address Book Example

This is an example of how to use Yahcli to pull the ledger and mirror node address book. And to update the ledger address book. It updates File 101 (the ledger address book file) and File 102 (the ledger node details file).

NOTE: Mirror Node refers to File 102 as its address book.

## Usage

To get the address book from the ledger, this requires a port forward to be setup on port 50211 to consensus node with node ID = 0.
```bash
# try and detect if the port forward is already setup
netstat -na | grep 50211
ps -ef | grep 50211 | grep -v grep

# setup a port forward if you need to
kubectl port-forward -n "${SOLO_NAMESPACE}" pod/network-node1-0 50211:50211
```

To get the address book from the ledger, run the following command:
```bash
cd <solo-root>/examples/address-book
task get:ledger:addressbook
```
It will output the address book in JSON format to:
* `examples/address-book/localhost/sysfiles/addressBook.json`
* `examples/address-book/localhost/sysfiles/nodeDetails.json`

You can update the address book files with your favorite text editor.

Once the files are ready, you can upload them to the ledger by running the following command:
```bash
cd <solo-root>/examples/address-book
task update:ledger:addressbook
```

To get the address book from the mirror node, run the following command:
```bash
cd <solo-root>/examples/address-book
task get:mirror:addressbook
```
NOTE: Mirror Node may not pick up the changes automatically, it might require running some transactions through, example:
```bash
cd <solo-root>
npm run solo -- account create
npm run solo -- account create
npm run solo -- account create
npm run solo -- account create
npm run solo -- account create
npm run solo -- account update -n solo-e2e --account-id 0.0.1004 --hbar-amount 78910
```
34 changes: 34 additions & 0 deletions examples/address-book/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: 3
tasks:
get:ledger:addressbook:
silent: true
desc: retrieve the address book (file 101; examples/address-book/localhost/sysfiles/addressBook.json) and node details (file 102; examples/address-book/localhost/sysfiles/nodeDetails.json) from the ledger
cmds:
- java -jar yahcli.jar --verbose=WARN -n localhost -p 2 sysfiles download 102
- java -jar yahcli.jar --verbose=WARN -n localhost -p 2 sysfiles download 101
- echo "cat file 102 = localhost/sysfiles/nodeDetails.json"
- echo "---------------------------------------"
- cat localhost/sysfiles/nodeDetails.json
- echo "---------------------------------------"
- echo "cat file 101 = localhost/sysfiles/addressBook.json"
- echo "---------------------------------------"
- cat localhost/sysfiles/addressBook.json

update:ledger:addressbook:
silent: true
desc: update the address book (file 101; examples/address-book/localhost/sysfiles/addressBook.json) and node details (file 102; examples/address-book/localhost/sysfiles/nodeDetails.json) on the ledger
cmds:
- java -jar yahcli.jar --verbose=WARN -n localhost -p 2 sysfiles upload 102
- java -jar yahcli.jar --verbose=WARN -n localhost -p 2 sysfiles upload 101

get:mirror:addressbook:
silent: true
desc: retrieve the address book from the mirror node (file 102)
cmds:
- |
jq --version > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
curl -s http://localhost:5551/api/v1/network/nodes | jq
else
curl -s http://localhost:5551/api/v1/network/nodes
fi
6 changes: 6 additions & 0 deletions examples/address-book/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defaultNetwork: localhost
networks:
localhost:
allowedReceiverAccountIds: []
nodes:
- { id: 0, account: 3, ipv4Addr: 127.0.0.1 }
1 change: 1 addition & 0 deletions examples/address-book/localhost/keys/account2.pass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swirlds
7 changes: 7 additions & 0 deletions examples/address-book/localhost/keys/account2.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIHDMH8GCSqGSIb3DQEFDTByMFEGCSqGSIb3DQEFDDBEBDAqNosoP7Vz+faodhk1
2N4Lykgs3AjiaZws0sajodGNLax8pG0FIFarGWtJyRPSKvgCAicQMAwGCCqGSIb3
DQIKBQAwHQYJYIZIAWUDBAEqBBC6ckCkLqfdzlIynrvwtracBECvr1K4KI1PWJ5z
YY7WKfjy57ffuuQ2GlNZUrp6yylRlRPGqZ015XT2Cbph6sZNE4xwn0NMxGp7Wf2f
j0A8/Il/
-----END ENCRYPTED PRIVATE KEY-----
1 change: 1 addition & 0 deletions examples/address-book/localhost/keys/account55.pass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myOHiYnunypq
Loading

0 comments on commit 8753723

Please sign in to comment.