diff --git a/lib/sui/README.md b/lib/sui/README.md index 8be1ed57..fe137b47 100644 --- a/lib/sui/README.md +++ b/lib/sui/README.md @@ -90,7 +90,7 @@ The EC2 instance will deploy, initialize the node and start the first sync. In C 4. Once the initial synchronization is done, you should be able to access the RPC API of that node from within the same VPC. The RPC port is not exposed to the Internet. Check if the JSON-RPC port is open and working — run the following command from a terminal: ```bash -INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.node-instance-id? | select(. != null)') +INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.nodeinstanceid? | select(. != null)') NODE_INTERNAL_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text --region us-east-1) echo "NODE_INTERNAL_IP=$NODE_INTERNAL_IP" ``` diff --git a/lib/sui/lib/assets/sync-checker/syncchecker-sui.sh b/lib/sui/lib/assets/sync-checker/syncchecker-sui.sh new file mode 100644 index 00000000..9c5b69c4 --- /dev/null +++ b/lib/sui/lib/assets/sync-checker/syncchecker-sui.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set +e + +source /etc/environment + +CURRENT_CHECKPOINT_SEQ_NUMBER=$(curl --location --request POST localhost:9000 --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getLatestCheckpointSequenceNumber", "params": [], "id":1}' | jq -r .result) +CURRENT_CHECKPOINT_TIMESTAMP_MS=$(curl --location --request POST localhost:9000 --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getCheckpoint", "params": ['\"$CURRENT_CHECKPOINT_SEQ_NUMBER\"'], "id":1}' | jq -r .result.timestampMs) + +EPOCH_SECONDS=$(date +%s) + +# Convert seconds to milliseconds +EPOCH_MS=$((EPOCH_SECONDS * 1000)) + +CURRENT_CHECKPOINT_MS_BEHIND=$(($EPOCH_MS - $CURRENT_CHECKPOINT_TIMESTAMP_MS)) + +CURRENT_CHECKPOINT_MIN_BEHIND=$(($CURRENT_CHECKPOINT_MS_BEHIND / 60000)) + +# Sending data to CloudWatch +TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") +INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id) +REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq .region -r) +TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S%:z") + +aws cloudwatch put-metric-data --metric-name sui_current_checkpoint_no --namespace CWAgent --value $CURRENT_CHECKPOINT_SEQ_NUMBER --timestamp $TIMESTAMP --dimensions InstanceId=$INSTANCE_ID --region $REGION +aws cloudwatch put-metric-data --metric-name sui_minutes_behind --namespace CWAgent --value $CURRENT_CHECKPOINT_MIN_BEHIND --timestamp $TIMESTAMP --dimensions InstanceId=$INSTANCE_ID --region $REGION diff --git a/lib/sui/lib/assets/user-data/node.sh b/lib/sui/lib/assets/user-data/node.sh index 3bd0727a..bb6c8ef9 100644 --- a/lib/sui/lib/assets/user-data/node.sh +++ b/lib/sui/lib/assets/user-data/node.sh @@ -140,8 +140,6 @@ echo "Starting CloudWatch Agent" -a fetch-config -c file:/opt/aws/amazon-cloudwatch-agent/etc/custom-amazon-cloudwatch-agent.json -m ec2 -s systemctl status amazon-cloudwatch-agent - - # Download Sui artifacts cd $HOME @@ -314,6 +312,38 @@ echo "[LOG] Sui Version: $(sui -V)" echo "Sui Version: $(sui -V)" +cd /opt +sudo mv /opt/sync-checker/syncchecker-sui.sh /opt/syncchecker.sh +sudo chmod +x /opt/syncchecker.sh + + +echo "Setting up sync-checker service" +cat >/etc/systemd/system/sync-checker.service </etc/systemd/system/sync-checker.timer <= 14.15.0" - }, - "peerDependencies": { - "constructs": "^10.0.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/@balena/dockerignore": { - "version": "1.0.2", - "inBundle": true, - "license": "Apache-2.0" - }, - "node_modules/aws-cdk-lib/node_modules/ajv": { - "version": "8.16.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/aws-cdk-lib/node_modules/ansi-regex": { - "version": "5.0.1", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/aws-cdk-lib/node_modules/ansi-styles": { - "version": "4.3.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/aws-cdk-lib/node_modules/astral-regex": { - "version": "2.0.0", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/aws-cdk-lib/node_modules/balanced-match": { - "version": "1.0.2", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/brace-expansion": { - "version": "1.1.11", - "inBundle": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/aws-cdk-lib/node_modules/case": { - "version": "1.6.3", - "inBundle": true, - "license": "(MIT OR GPL-3.0-or-later)", - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/color-convert": { - "version": "2.0.1", - "inBundle": true, - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/color-name": { - "version": "1.1.4", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/concat-map": { - "version": "0.0.1", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/emoji-regex": { - "version": "8.0.0", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/fast-deep-equal": { - "version": "3.1.3", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/fs-extra": { - "version": "11.2.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, - "node_modules/aws-cdk-lib/node_modules/graceful-fs": { - "version": "4.2.11", - "inBundle": true, - "license": "ISC" - }, - "node_modules/aws-cdk-lib/node_modules/ignore": { - "version": "5.3.1", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">= 4" - } - }, - "node_modules/aws-cdk-lib/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/aws-cdk-lib/node_modules/json-schema-traverse": { - "version": "1.0.0", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/jsonfile": { - "version": "6.1.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/aws-cdk-lib/node_modules/jsonschema": { - "version": "1.4.1", - "inBundle": true, - "license": "MIT", - "engines": { - "node": "*" - } - }, - "node_modules/aws-cdk-lib/node_modules/lodash.truncate": { - "version": "4.4.2", - "inBundle": true, - "license": "MIT" - }, - "node_modules/aws-cdk-lib/node_modules/mime-db": { - "version": "1.52.0", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/aws-cdk-lib/node_modules/mime-types": { - "version": "2.1.35", - "inBundle": true, - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/aws-cdk-lib/node_modules/minimatch": { - "version": "3.1.2", - "inBundle": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/aws-cdk-lib/node_modules/punycode": { - "version": "2.3.1", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, - "node_modules/aws-cdk-lib/node_modules/require-from-string": { - "version": "2.0.2", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/semver": { - "version": "7.6.2", - "inBundle": true, - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/aws-cdk-lib/node_modules/slice-ansi": { - "version": "4.0.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.0.0", - "astral-regex": "^2.0.0", - "is-fullwidth-code-point": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/slice-ansi?sponsor=1" - } - }, - "node_modules/aws-cdk-lib/node_modules/string-width": { - "version": "4.2.3", - "inBundle": true, - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/aws-cdk-lib/node_modules/strip-ansi": { - "version": "6.0.1", - "inBundle": true, - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/aws-cdk-lib/node_modules/table": { - "version": "6.8.2", - "inBundle": true, - "license": "BSD-3-Clause", - "dependencies": { - "ajv": "^8.0.1", - "lodash.truncate": "^4.4.2", - "slice-ansi": "^4.0.0", - "string-width": "^4.2.3", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/universalify": { - "version": "2.0.1", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">= 10.0.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/uri-js": { - "version": "4.4.1", - "inBundle": true, - "license": "BSD-2-Clause", - "dependencies": { - "punycode": "^2.1.0" - } - }, - "node_modules/aws-cdk-lib/node_modules/yaml": { - "version": "1.10.2", - "inBundle": true, - "license": "ISC", - "engines": { - "node": ">= 6" - } - }, - "node_modules/cdk-nag": { - "version": "2.28.157", - "resolved": "https://registry.npmjs.org/cdk-nag/-/cdk-nag-2.28.157.tgz", - "integrity": "sha512-5nwOEq5bXMl1Hfe4ig1JNtECVM2jt6ISO8kZq5eq6YflLp2YLrhkAoDWSdyEDDo0l30uDLGSl9sxxkdR39l5gQ==", - "peerDependencies": { - "aws-cdk-lib": "^2.116.0", - "constructs": "^10.0.5" - } - }, - "node_modules/constructs": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/constructs/-/constructs-10.3.0.tgz", - "integrity": "sha512-vbK8i3rIb/xwZxSpTjz3SagHn1qq9BChLEfy5Hf6fB3/2eFbrwt2n9kHwQcS0CPTRBesreeAcsJfMq2229FnbQ==", - "peer": true, - "engines": { - "node": ">= 16.14.0" - } - }, - "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - } - } -} diff --git a/lib/sui/sample-configs/.env-sample-full b/lib/sui/sample-configs/.env-sample-full index c436cc87..0dd14146 100644 --- a/lib/sui/sample-configs/.env-sample-full +++ b/lib/sui/sample-configs/.env-sample-full @@ -1,12 +1,12 @@ ############################################################# -# Example configuration for Sui Node Runner app on AWS # +# Example configuration for Sui Node Runner app on AWS # ############################################################# ## Set the AWS account is and region for your environment ## AWS_ACCOUNT_ID="" AWS_REGION="us-east-1" # your region of choice ## Common configuration parameters # -SUI_NETWORK_ID="testnet" # All options: "mainnet", "testnet" , "devnet" +SUI_NETWORK_ID="mainnet" # All options: "mainnet", "testnet" , "devnet" SUI_INSTANCE_TYPE="m6i.4xlarge" # Data volume configuration diff --git a/lib/sui/test/.env-test b/lib/sui/test/.env-test index 5ca8cf77..f4ca8665 100644 --- a/lib/sui/test/.env-test +++ b/lib/sui/test/.env-test @@ -1,19 +1,17 @@ ############################################################# -# Example configuration for Starknet nodes runner app on AWS # +# Example configuration for Sui Node Runner app on AWS # ############################################################# ## Set the AWS account is and region for your environment ## AWS_ACCOUNT_ID="xxxxxxxxxxx" -AWS_REGION="us-east-1" # Regions supported by Amazon Managed Blockchain Access Ethereum: https://docs.aws.amazon.com/general/latest/gr/managedblockchain.html#managedblockchain-access +AWS_REGION="us-east-1" # your region of choice -## Common configuration parameters ## -STARKNET_L1_ENDPOINT="wss://ethereum-rpc.publicnode.com" -STARKNET_NETWORK_ID="mainnet" # All options: "mainnet", "sepolia", "sepolia-integration" -STARKNET_NODE_VERSION="v0.11.7" # Current required version of Starknet +## Common configuration parameters # +SUI_NETWORK_ID="testnet" # All options: "mainnet", "testnet" , "devnet" +SUI_INSTANCE_TYPE="m6i.4xlarge" -STARKNET_INSTANCE_TYPE="m6a.2xlarge" # Data volume configuration -STARKNET_DATA_VOL_TYPE="gp3" # Other options: "io1" | "io2" | "gp3" | "instance-store" . IMPORTANT: Use "instance-store" option only with instance types that support that feature, like popular for node im4gn, d3, i3en, and i4i instance families -STARKNET_DATA_VOL_SIZE="250" # Current required data size to keep both smapshot archive and unarchived version of it -STARKNET_DATA_VOL_IOPS="3000" # Max IOPS for EBS volumes (not applicable for "instance-store") -STARKNET_DATA_VOL_THROUGHPUT="700" # Max throughput for EBS gp3 volumes (not applicable for "io1" | "io2" | "instance-store") +SUI_DATA_VOL_TYPE="gp3" # Other options: "io1" | "io2" | "gp3" +SUI_DATA_VOL_SIZE="4000" # Current required data size to keep both snapshot archive and unarchived version of it +SUI_DATA_VOL_IOPS="3000" # Max IOPS for EBS volumes +SUI_DATA_VOL_THROUGHPUT="700" # Max throughput for EBS gp3 volumes (not applicable for "io1" | "io2")