Skip to content

Base. Fixed setup scripts to reflect recent updates in Base node setu… #195

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

Merged
merged 2 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ aws ssm start-session --target $INSTANCE_ID --region $AWS_REGION
```bash
sudo su bcuser
# Execution client logs:
docker logs --tail 50 node_execution_1 -f
docker logs --tail 50 node-execution-1 -f
# Base client logs:
docker logs --tail 50 node_node_1 -f
docker logs --tail 50 node-node-1 -f
```
2. How to check the logs from the EC2 user-data script?

Expand Down
6 changes: 4 additions & 2 deletions lib/base/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ new BaseCommonStack(app, "base-common", {
});

new BaseSingleNodeStack(app, "base-single-node", {
stackName: `base-single-node-${config.baseNodeConfig.baseNodeConfiguration}-${config.baseNodeConfig.baseNetworkId}`,
stackName: `base-single-node-${config.baseNodeConfig.baseClient}-${config.baseNodeConfig.baseNodeConfiguration}-${config.baseNodeConfig.baseNetworkId}`,
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },

instanceType: config.baseNodeConfig.instanceType,
instanceCpuType: config.baseNodeConfig.instanceCpuType,
baseNetworkId: config.baseNodeConfig.baseNetworkId,
baseClient: config.baseNodeConfig.baseClient,
baseNodeConfiguration: config.baseNodeConfig.baseNodeConfiguration,
restoreFromSnapshot: config.baseNodeConfig.restoreFromSnapshot,
l1ExecutionEndpoint: config.baseNodeConfig.l1ExecutionEndpoint,
Expand All @@ -32,12 +33,13 @@ new BaseSingleNodeStack(app, "base-single-node", {
});

new BaseHANodesStack(app, "base-ha-nodes", {
stackName: `base-ha-nodes-${config.baseNodeConfig.baseNodeConfiguration}-${config.baseNodeConfig.baseNetworkId}`,
stackName: `base-ha-nodes-${config.baseNodeConfig.baseClient}-${config.baseNodeConfig.baseNodeConfiguration}-${config.baseNodeConfig.baseNetworkId}`,
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },

instanceType: config.baseNodeConfig.instanceType,
instanceCpuType: config.baseNodeConfig.instanceCpuType,
baseNetworkId: config.baseNodeConfig.baseNetworkId,
baseClient: config.baseNodeConfig.baseClient,
baseNodeConfiguration: config.baseNodeConfig.baseNodeConfiguration,
restoreFromSnapshot: config.baseNodeConfig.restoreFromSnapshot,
l1ExecutionEndpoint: config.baseNodeConfig.l1ExecutionEndpoint,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,42 @@ SNAPSHOT_DIR=/data
SNAPSHOT_DOWNLOAD_STATUS=-1

if [ "$SNAPSHOT_URL" == "none" ] || [ -z "${SNAPSHOT_URL}" ]; then
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/latest)
SNAPSHOT_URL=https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME

case $BASE_CLIENT in
"geth")
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-full-snapshots.base.org/latest)
SNAPSHOT_URL=https://$NETWORK_ID-full-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
;;
"reth")
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-reth-archive-snapshots.base.org/latest)
SNAPSHOT_URL=https://$NETWORK_ID-reth-archive-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
;;
*)
# Geth
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-full-snapshots.base.org/latest)
SNAPSHOT_URL=https://$NETWORK_ID-full-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
;;
esac
fi

while (( SNAPSHOT_DOWNLOAD_STATUS != 0 ))
do
PIDS=$(pgrep aria2c)
PIDS=$(pgrep wget)
if [ -z "$PIDS" ]; then
aria2c --max-connection-per-server=1 $SNAPSHOT_URL -d $SNAPSHOT_DIR -o $SNAPSHOT_FILE_NAME -l /data/download.log --log-level=notice --allow-overwrite=true --allow-piece-length-change=true
wget $SNAPSHOT_URL -P $SNAPSHOT_DIR -O $SNAPSHOT_FILE_NAME
fi
SNAPSHOT_DOWNLOAD_STATUS=$?
pid=$(pidof aria2c)
pid=$(pidof wget)
wait $pid
echo "aria2c exit."
echo "wget exit."
case $SNAPSHOT_DOWNLOAD_STATUS in
3)
echo "File does not exist."
exit 3
8)
echo "Server error."
exit 8
;;
9)
3)
echo "No space left on device."
exit 9
exit 3
;;
*)
continue
Expand All @@ -46,9 +60,9 @@ sleep 60

echo "Starting snapshot decompression ..."

tar --use-compress-program=unzstd -xvf $SNAPSHOT_DIR/$SNAPSHOT_FILE_NAME -C /data 2>&1 | tee unzip.log && echo "decompresed successfully..." || echo "decompression failed..." >> snapshots-decompression.log
tar --use-compress-program=unzstd -xvf $SNAPSHOT_DIR/$SNAPSHOT_FILE_NAME -C /data 2>&1 | tee unzip.log && echo "decompressed successfully..." || echo "decompression failed..." >> snapshots-decompression.log

echo "Decompresed snapshot, cleaning up..."
echo "Decompressed snapshot, cleaning up..."

mv /data/snapshots/$NETWORK_ID/download/* /data && \
rm -rf /data/snapshots && \
Expand Down
3 changes: 2 additions & 1 deletion lib/base/lib/assets/node/node-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -e
source /etc/cdk_environment

export NETWORK_ENV=".env.$NETWORK_ID"
export CLIENT=geth
export CLIENT="$BASE_CLIENT"
export HOST_DATA_DIR="/data"

echo "Script is starting client $CLIENT on $NETWORK_ENV"
# Start the node
Expand Down
112 changes: 29 additions & 83 deletions lib/base/lib/assets/user-data-alinux.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
#!/bin/bash
set +e

# Set by generic single-node and ha-node CDK components
LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}
AUTOSCALING_GROUP_NAME=${_AUTOSCALING_GROUP_NAME_}
RESOURCE_ID=${_NODE_CF_LOGICAL_ID_}
ASSETS_S3_PATH=${_ASSETS_S3_PATH_}
DATA_VOLUME_TYPE=${_DATA_VOLUME_TYPE_}
DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}

# Set by Base-specic CDK components and stacks
AWS_REGION=${_AWS_REGION_}
STACK_NAME=${_STACK_NAME_}
RESTORE_FROM_SNAPSHOT=${_RESTORE_FROM_SNAPSHOT_}
NETWORK_ID=${_NETWORK_ID_}
NODE_CONFIG=${_NODE_CONFIG_}
L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}
L1_CONSENSUS_ENDPOINT=${_L1_CONSENSUS_ENDPOINT_}
SNAPSHOT_URL=${_SNAPSHOT_URL_}

{
echo "LIFECYCLE_HOOK_NAME=$LIFECYCLE_HOOK_NAME"
echo "AUTOSCALING_GROUP_NAME=$AUTOSCALING_GROUP_NAME"
echo "ASSETS_S3_PATH=$ASSETS_S3_PATH"
echo "DATA_VOLUME_TYPE=$DATA_VOLUME_TYPE"
echo "DATA_VOLUME_SIZE=$DATA_VOLUME_SIZE"

echo "AWS_REGION=$AWS_REGION"
echo "NETWORK_ID=$NETWORK_ID"
echo "NODE_CONFIG=$NODE_CONFIG"
echo "L1_EXECUTION_ENDPOINT=$L1_EXECUTION_ENDPOINT"
echo "L1_CONSENSUS_ENDPOINT=$L1_CONSENSUS_ENDPOINT"
echo "SNAPSHOT_URL=$SNAPSHOT_URL"
echo "LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}"
echo "AUTOSCALING_GROUP_NAME=${_AUTOSCALING_GROUP_NAME_}"
echo "ASSETS_S3_PATH=${_ASSETS_S3_PATH_}"
echo "DATA_VOLUME_TYPE=${_DATA_VOLUME_TYPE_}"
echo "DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}"

echo "AWS_REGION=${_AWS_REGION_}"
echo "NETWORK_ID=${_NETWORK_ID_}"
echo "BASE_CLIENT=${_BASE_CLIENT_}"
echo "NODE_CONFIG=${_NODE_CONFIG_}"
echo "L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}"
echo "L1_CONSENSUS_ENDPOINT=${_L1_CONSENSUS_ENDPOINT_}"
echo "SNAPSHOT_URL=${_SNAPSHOT_URL_}"
} >> /etc/cdk_environment

source /etc/cdk_environment
Expand All @@ -45,11 +32,9 @@ echo "Architecture detected: $arch"

if [ "$arch" == "x86_64" ]; then
SSM_AGENT_BINARY_URI=https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
S5CMD_URI=https://github.com/peak/s5cmd/releases/download/v2.1.0/s5cmd_2.1.0_Linux-64bit.tar.gz
YQ_URI=https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
else
SSM_AGENT_BINARY_URI=https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_arm64/amazon-ssm-agent.rpm
S5CMD_URI=https://github.com/peak/s5cmd/releases/download/v2.1.0/s5cmd_2.1.0_Linux-arm64.tar.gz
YQ_URI=https://github.com/mikefarah/yq/releases/latest/download/yq_linux_arm64
fi

Expand All @@ -61,29 +46,6 @@ wget $YQ_URI -O /usr/bin/yq && chmod +x /usr/bin/yq
sudo systemctl enable crond.service
sudo systemctl start crond.service

echo " Installing aria2 a p2p downloader"
cd /tmp

if [ "$arch" == "x86_64" ]; then
wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
tar jxvf aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
cd aria2-1.36.0-linux-gnu-64bit-build1/
make install
else
wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
tar jxvf aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
cd aria2-1.36.0-linux-gnu-arm-rbpi-build1/
make install
fi

echo " Installing s5cmd"
cd /opt
wget -q $S5CMD_URI -O s5cmd.tar.gz
tar -xf s5cmd.tar.gz
chmod +x s5cmd
mv s5cmd /usr/bin
s5cmd version

cd /opt

echo "Downloading assets zip file"
Expand Down Expand Up @@ -116,7 +78,7 @@ echo "Starting docker"
service docker start
systemctl enable docker

echo "Clonning node repo"
echo "Cloning node repo"
cd /home/bcuser
GIT_URL=https://github.com/base-org/node.git
git clone $GIT_URL
Expand Down Expand Up @@ -150,28 +112,12 @@ case $NODE_CONFIG in
;;
esac

case $NETWORK_ID in
"mainnet")
sed -i "s#OP_NODE_L1_ETH_RPC=https://1rpc.io/eth#OP_NODE_L1_ETH_RPC=$L1_EXECUTION_ENDPOINT#g" $OP_CONFIG_FILE_PATH
sed -i '/.env.mainnet/s/^#//g' /home/bcuser/node/docker-compose.yml
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
sed -i "s#OP_NODE_L1_BEACON=https://your.mainnet.beacon.node/endpoint-here#OP_NODE_L1_BEACON=$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
;;
"sepolia")
sed -i "s#OP_NODE_L1_ETH_RPC=https://rpc.sepolia.org#OP_NODE_L1_ETH_RPC=$L1_EXECUTION_ENDPOINT#g" $OP_CONFIG_FILE_PATH
sed -i "/.env.sepolia/s/^#//g" /home/bcuser/node/docker-compose.yml
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
sed -i "s#OP_NODE_L1_BEACON=https://your.sepolia.beacon.node/endpoint-here#OP_NODE_L1_BEACON=$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
;;
*)
echo "Network id is not valid."
exit 1
;;
esac

echo "OP_NODE_L1_TRUST_RPC=true" >> $OP_CONFIG_FILE_PATH
sed -i "s#<your-preferred-l1-rpc>#$L1_EXECUTION_ENDPOINT#g" $OP_CONFIG_FILE_PATH
sed -i "s#<your-preferred-l1-beacon>#$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
sed -i "s#<your-preferred-l1-beacon-archiver>#$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
sed -i "s#OP_NODE_L1_TRUST_RPC=\"false\"#OP_NODE_L1_TRUST_RPC=\"true\"#g" $OP_CONFIG_FILE_PATH

sed -i "s#GETH_HOST_DATA_DIR=./geth-data#GETH_HOST_DATA_DIR=/data/geth#g" /home/bcuser/node/.env
sed -i "s#HOST_DATA_DIR=./$BASE_CLIENT-data#HOST_DATA_DIR=/data#g" /home/bcuser/node/.env

chown -R bcuser:bcuser /home/bcuser/node

Expand Down Expand Up @@ -242,22 +188,22 @@ echo "Starting CloudWatch Agent"
-a fetch-config -c file:/opt/aws/amazon-cloudwatch-agent/etc/custom-amazon-cloudwatch-agent.json -m ec2 -s
systemctl restart amazon-cloudwatch-agent

if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
echo "Skipping restoration from snapshot. Starting node"
systemctl daemon-reload
systemctl enable --now node
else
echo "Restoring full node from snapshot over http"
chmod +x /opt/instance/storage/restore-from-snapshot-http.sh
echo "/opt/instance/storage/restore-from-snapshot-http.sh" | at now + 1 min
fi

if [[ "$LIFECYCLE_HOOK_NAME" != "none" ]]; then
echo "Signaling ASG lifecycle hook to complete"
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)
aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name "$LIFECYCLE_HOOK_NAME" --auto-scaling-group-name "$AUTOSCALING_GROUP_NAME" --region $AWS_REGION
fi

if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
echo "Skipping restoration from snapshot. Starting node"
systemctl daemon-reload
systemctl enable --now node
else
echo "Restoring full node from snapshot"
chmod +x /opt/instance/storage/restore-from-snapshot.sh
/opt/instance/storage/restore-from-snapshot.sh
fi

echo "All Done!!"
set -e
2 changes: 2 additions & 0 deletions lib/base/lib/config/baseConfig.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as configTypes from "../../../constructs/config.interface";

export type BaseNetworkId = "mainnet" | "sepolia";
export type BaseClient = "geth" | "reth";
export type BaseNodeConfiguration = "full" | "archive";

export {AMBEthereumNodeNetworkId} from "../../../constructs/config.interface";
Expand All @@ -16,6 +17,7 @@ export interface BaseBaseConfig extends configTypes.BaseConfig {

export interface BaseBaseNodeConfig extends configTypes.BaseNodeConfig {
baseNetworkId: BaseNetworkId;
baseClient: BaseClient;
baseNodeConfiguration: BaseNodeConfiguration;
dataVolume: BaseDataVolumeConfig;
restoreFromSnapshot: boolean;
Expand Down
16 changes: 14 additions & 2 deletions lib/base/lib/config/baseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@ const parseDataVolumeType = (dataVolumeType: string) => {
}
}

const getClientConfiguration = (client: configTypes.BaseClient, nodeConfiguration: configTypes.BaseNodeConfiguration) => {
switch (client) {
case "reth":
return "archive";
case "geth":
return "full";
default:
return "full";
}
}

export const baseConfig: configTypes.BaseBaseConfig = {
accountId: process.env.AWS_ACCOUNT_ID || "xxxxxxxxxxx",
region: process.env.AWS_REGION || "us-east-2",
region: process.env.AWS_REGION || "us-east-1",
}

export const baseNodeConfig: configTypes.BaseBaseNodeConfig = {
instanceType: new ec2.InstanceType(process.env.BASE_INSTANCE_TYPE ? process.env.BASE_INSTANCE_TYPE : "m7g.2xlarge"),
instanceCpuType: process.env.BASE_CPU_TYPE?.toLowerCase() == "x86_64" ? ec2.AmazonLinuxCpuType.X86_64 : ec2.AmazonLinuxCpuType.ARM_64,
baseNetworkId: <configTypes.BaseNetworkId> process.env.BASE_NETWORK_ID || "mainnet",
baseNodeConfiguration: <configTypes.BaseNodeConfiguration> process.env.BASE_NODE_CONFIGURATION || "full",
baseClient: <configTypes.BaseClient> process.env.BASE_CLIENT || "geth",
baseNodeConfiguration: getClientConfiguration(<configTypes.BaseClient> process.env.BASE_CLIENT, <configTypes.BaseNodeConfiguration> process.env.BASE_NODE_CONFIGURATION),
restoreFromSnapshot: process.env.BASE_RESTORE_FROM_SNAPSHOT?.toLowerCase() == "true" ? true : false,
l1ExecutionEndpoint: process.env.BASE_L1_EXECUTION_ENDPOINT || constants.NoneValue,
l1ConsensusEndpoint: process.env.BASE_L1_CONSENSUS_ENDPOINT || constants.NoneValue,
Expand Down
3 changes: 3 additions & 0 deletions lib/base/lib/ha-nodes-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface BaseHANodesStackProps extends cdk.StackProps {
instanceType: ec2.InstanceType;
instanceCpuType: ec2.AmazonLinuxCpuType;
baseNetworkId: configTypes.BaseNetworkId;
baseClient: configTypes.BaseClient,
baseNodeConfiguration: configTypes.BaseNodeConfiguration;
restoreFromSnapshot: boolean;
l1ExecutionEndpoint: string,
Expand All @@ -40,6 +41,7 @@ export class BaseHANodesStack extends cdk.Stack {
instanceType,
instanceCpuType,
baseNetworkId,
baseClient,
baseNodeConfiguration,
restoreFromSnapshot,
l1ExecutionEndpoint,
Expand Down Expand Up @@ -80,6 +82,7 @@ export class BaseHANodesStack extends cdk.Stack {
_DATA_VOLUME_TYPE_: dataVolume.type,
_DATA_VOLUME_SIZE_: dataVolumeSizeBytes.toString(),
_NETWORK_ID_: baseNetworkId,
_BASE_CLIENT_: baseClient,
_NODE_CONFIG_: baseNodeConfiguration,
_LIFECYCLE_HOOK_NAME_: lifecycleHookName,
_AUTOSCALING_GROUP_NAME_: autoScalingGroupName,
Expand Down
Loading
Loading