Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add network ID support to devnet scripts #3262

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions .devnet/.analytics/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async function calculateRoundsInBlocks(baseUrl, latestHeight) {
}
}

async function checkBlockHash(blockHeight) {
async function checkBlockHash(networkName, blockHeight) {
const numNodes = await getAWSNodeCount();
console.log(`Detected ${numNodes} AWS nodes... \n`);

Expand All @@ -125,7 +125,7 @@ async function checkBlockHash(blockHeight) {
// Get the IP address of the AWS node
const ipAddress = await getIPAddress(awsNodeName);
// Define the base URL for the node
const baseUrl = `http://${ipAddress}:3030/mainnet/block`;
const baseUrl = `http://${ipAddress}:3030/${networkName}/block`;

// Fetch the block data
const blockData = await fetchBlockData(baseUrl, blockHeight);
Expand All @@ -138,7 +138,20 @@ async function checkBlockHash(blockHeight) {
}

// Main function to fetch block metrics
async function fetchBlockMetrics(metricType, optionalBlockHeight) {
async function fetchBlockMetrics(metricType, optionalBlockHeight, networkID) {
// Derive the network name based on the network ID.
let networkName;
switch (networkID) {
case 0:
networkName = "mainnet";
break;
case 1:
networkName = "testnet";
break;
default:
throw new Error(`Unknown network ID (${networkID})`);
}

// Function to get the latest block height
async function getLatestBlockHeight(baseUrl) {
try {
Expand All @@ -157,7 +170,7 @@ async function fetchBlockMetrics(metricType, optionalBlockHeight) {
// Get the IP address of the AWS node
const ipAddress = await getIPAddress(awsNodeName);
// Define the base URL for the node.
const baseUrl = `http://${ipAddress}:3030/mainnet/block`;
const baseUrl = `http://${ipAddress}:3030/${networkName}/block`;

console.log(`${dimStart}IP Address: ${ipAddress}${dimEnd}`);
console.log(`${dimStart}Base URL: ${baseUrl}${dimEnd}`);
Expand All @@ -175,7 +188,7 @@ async function fetchBlockMetrics(metricType, optionalBlockHeight) {
} else if (metricType === 'roundsInBlocks') {
calculateRoundsInBlocks(baseUrl, latestHeight);
} else if (metricType === 'checkBlockHash' && optionalBlockHeight) {
checkBlockHash(optionalBlockHeight);
checkBlockHash(networkName, optionalBlockHeight);
} else {
console.error('Invalid metric type. Supported types: "averageBlockTime" or "roundsInBlocks".');
}
Expand All @@ -196,6 +209,13 @@ async function main() {
describe: 'Block height to examine for checkBlockHash metric',
type: 'number',
},
'network-id': {
alias: 'n',
describe: 'Network ID to fetch block metrics from',
demandOption: true,
type: 'number',
choices: [0, 1],
}
})
.check((argv) => {
// Check if metric-type is checkBlockHash and block-height is provided
Expand All @@ -207,7 +227,7 @@ async function main() {
.argv;

// Fetch and output the specified block metric
fetchBlockMetrics(argv['metric-type'], argv['block-height']);
fetchBlockMetrics(argv['metric-type'], argv['block-height'], argv['network-id']);
}

// Run the main function
Expand Down
17 changes: 14 additions & 3 deletions .devnet/analytics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ else
echo "Node.js dependencies already installed."
fi

# Prompt the user to specify a network ID
while true; do
echo "Please specify a network ID (0 for mainnet, 1 for testnet):"
read networkID
if [[ $networkID == 0 || $networkID == 1 ]]; then
break
else
echo "Invalid network ID. Please enter 0 or 1."
fi
done

# Prompt the user to select a metric type
PS3="Select a metric type: "
options=("Average Block Time" "Rounds in Blocks" "Check Block Hash" "Quit")
Expand All @@ -22,12 +33,12 @@ do
case $opt in
"Average Block Time")
echo ""
node analytics.js --metric-type averageBlockTime
node analytics.js --metric-type averageBlockTime --network-id $networkID
break
;;
"Rounds in Blocks")
echo ""
node analytics.js --metric-type roundsInBlocks
node analytics.js --metric-type roundsInBlocks --network-id $networkID
break
;;
"Check Block Hash")
Expand All @@ -39,7 +50,7 @@ do
echo "Error: Block height must be a positive integer."
exit 1
fi
node analytics.js --metric-type checkBlockHash --block-height "$blockHeight"
node analytics.js --metric-type checkBlockHash --block-height "$blockHeight" --network-id $networkID
break
;;
"Quit")
Expand Down
8 changes: 7 additions & 1 deletion .devnet/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ NUM_INSTANCES="${NUM_INSTANCES:-$NODE_ID}"

echo "Using $NUM_INSTANCES AWS EC2 instances for querying."

# Read the network ID from user or use a default value of 1
read -p "Enter the network ID (mainnet = 0, testnet = 1) (default: 1): " NETWORK_ID
NETWORK_ID=${NETWORK_ID:-1}

echo "Using network ID $NETWORK_ID."

# Define a function to terminate the tmux session on a node
terminate_tmux_session() {
local NODE_ID=$1
Expand All @@ -24,7 +30,7 @@ terminate_tmux_session() {
cd \$WORKSPACE

tmux kill-session -t snarkos-session
snarkos clean --dev $NODE_ID
snarkos clean --dev $NODE_ID --network $NETWORK_ID

exit # Exit root user
EOF
Expand Down
8 changes: 7 additions & 1 deletion .devnet/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ NUM_INSTANCES="${NUM_INSTANCES:-$NODE_ID}"

echo "Using $NUM_INSTANCES AWS EC2 instances for querying."

# Read the network ID from user or use a default value of 1
read -p "Enter the network ID (mainnet = 0, testnet = 1) (default: 1): " NETWORK_ID
NETWORK_ID=${NETWORK_ID:-1}

echo "Using network ID $NETWORK_ID."

# Read the verbosity level from the user (default: 1)
read -p "Enter the verbosity level (default: 1): " VERBOSITY
VERBOSITY="${VERBOSITY:-1}"
Expand All @@ -37,7 +43,7 @@ start_snarkos_in_tmux() {
tmux new-session -d -s snarkos-session

# Send the snarkOS start command to the tmux session with the NODE_ID
tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --allow-external-peers --peers $NODE_IP:4130 --validators $NODE_IP:5000 --rest-rps 1000 --verbosity $VERBOSITY --dev $NODE_ID --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m
tmux send-keys -t "snarkos-session" "snarkos start --nodisplay --bft 0.0.0.0:5000 --rest 0.0.0.0:3030 --allow-external-peers --peers $NODE_IP:4130 --validators $NODE_IP:5000 --rest-rps 1000 --verbosity $VERBOSITY --network $NETWORK_ID --dev $NODE_ID --dev-num-validators $NUM_INSTANCES --validator --metrics" C-m

exit # Exit root user
EOF
Expand Down
8 changes: 7 additions & 1 deletion .devnet/start_sync_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ NUM_INSTANCES="${NUM_INSTANCES:-$NODE_ID}"

echo "Using $NUM_INSTANCES AWS EC2 instances for querying."

# Read the network ID from user or use a default value of 1
read -p "Enter the network ID (mainnet = 0, testnet = 1) (default: 1): " NETWORK_ID
NETWORK_ID=${NETWORK_ID:-1}

echo "Using network ID $NETWORK_ID."

# Read the verbosity level from the user (default: 1)
read -p "Enter the verbosity level (default: 1): " VERBOSITY
VERBOSITY="${VERBOSITY:-1}"
Expand All @@ -37,7 +43,7 @@ start_snarkos_in_tmux() {
tmux new-session -d -s snarkos-session

# Send the snarkOS start command to the tmux session with the NODE_ID
tmux send-keys -t "snarkos-session" "snarkos start --client --nocdn --nodisplay --rest 0.0.0.0:3030 --node 0.0.0.0:4130 --verbosity 4 --metrics --logfile "/tmp/snarkos-syncing-range-3.log" --peers 167.71.249.65:4130,157.245.218.195:4130,167.71.249.55:4130" C-m
tmux send-keys -t "snarkos-session" "snarkos start --client --nocdn --nodisplay --rest 0.0.0.0:3030 --node 0.0.0.0:4130 --verbosity 4 --network $NETWORK_ID --metrics --logfile "/tmp/snarkos-syncing-range-3.log" --peers 167.71.249.65:4130,157.245.218.195:4130,167.71.249.55:4130" C-m

exit # Exit root user
EOF
Expand Down