Skip to content

Commit f4f53aa

Browse files
authored
Merge pull request #195 from aws-samples/base
Base. Fixed setup scripts to reflect recent updates in Base node setu…
2 parents 44cbb2e + d0bb870 commit f4f53aa

18 files changed

+174
-165
lines changed

lib/base/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ aws ssm start-session --target $INSTANCE_ID --region $AWS_REGION
258258
```bash
259259
sudo su bcuser
260260
# Execution client logs:
261-
docker logs --tail 50 node_execution_1 -f
261+
docker logs --tail 50 node-execution-1 -f
262262
# Base client logs:
263-
docker logs --tail 50 node_node_1 -f
263+
docker logs --tail 50 node-node-1 -f
264264
```
265265
2. How to check the logs from the EC2 user-data script?
266266

lib/base/app.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ new BaseCommonStack(app, "base-common", {
1717
});
1818

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

2323
instanceType: config.baseNodeConfig.instanceType,
2424
instanceCpuType: config.baseNodeConfig.instanceCpuType,
2525
baseNetworkId: config.baseNodeConfig.baseNetworkId,
26+
baseClient: config.baseNodeConfig.baseClient,
2627
baseNodeConfiguration: config.baseNodeConfig.baseNodeConfiguration,
2728
restoreFromSnapshot: config.baseNodeConfig.restoreFromSnapshot,
2829
l1ExecutionEndpoint: config.baseNodeConfig.l1ExecutionEndpoint,
@@ -32,12 +33,13 @@ new BaseSingleNodeStack(app, "base-single-node", {
3233
});
3334

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

3839
instanceType: config.baseNodeConfig.instanceType,
3940
instanceCpuType: config.baseNodeConfig.instanceCpuType,
4041
baseNetworkId: config.baseNodeConfig.baseNetworkId,
42+
baseClient: config.baseNodeConfig.baseClient,
4143
baseNodeConfiguration: config.baseNodeConfig.baseNodeConfiguration,
4244
restoreFromSnapshot: config.baseNodeConfig.restoreFromSnapshot,
4345
l1ExecutionEndpoint: config.baseNodeConfig.l1ExecutionEndpoint,

lib/base/lib/assets/instance/storage/restore-from-snapshot-archive-s3.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

lib/base/lib/assets/instance/storage/restore-from-snapshot-http.sh renamed to lib/base/lib/assets/instance/storage/restore-from-snapshot.sh

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,42 @@ SNAPSHOT_DIR=/data
1212
SNAPSHOT_DOWNLOAD_STATUS=-1
1313

1414
if [ "$SNAPSHOT_URL" == "none" ] || [ -z "${SNAPSHOT_URL}" ]; then
15-
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/latest)
16-
SNAPSHOT_URL=https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
15+
16+
case $BASE_CLIENT in
17+
"geth")
18+
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-full-snapshots.base.org/latest)
19+
SNAPSHOT_URL=https://$NETWORK_ID-full-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
20+
;;
21+
"reth")
22+
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-reth-archive-snapshots.base.org/latest)
23+
SNAPSHOT_URL=https://$NETWORK_ID-reth-archive-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
24+
;;
25+
*)
26+
# Geth
27+
LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-full-snapshots.base.org/latest)
28+
SNAPSHOT_URL=https://$NETWORK_ID-full-snapshots.base.org/$LATEST_SNAPSHOT_FILE_NAME
29+
;;
30+
esac
1731
fi
1832

1933
while (( SNAPSHOT_DOWNLOAD_STATUS != 0 ))
2034
do
21-
PIDS=$(pgrep aria2c)
35+
PIDS=$(pgrep wget)
2236
if [ -z "$PIDS" ]; then
23-
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
37+
wget $SNAPSHOT_URL -P $SNAPSHOT_DIR -O $SNAPSHOT_FILE_NAME
2438
fi
2539
SNAPSHOT_DOWNLOAD_STATUS=$?
26-
pid=$(pidof aria2c)
40+
pid=$(pidof wget)
2741
wait $pid
28-
echo "aria2c exit."
42+
echo "wget exit."
2943
case $SNAPSHOT_DOWNLOAD_STATUS in
30-
3)
31-
echo "File does not exist."
32-
exit 3
44+
8)
45+
echo "Server error."
46+
exit 8
3347
;;
34-
9)
48+
3)
3549
echo "No space left on device."
36-
exit 9
50+
exit 3
3751
;;
3852
*)
3953
continue
@@ -46,9 +60,9 @@ sleep 60
4660

4761
echo "Starting snapshot decompression ..."
4862

49-
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
63+
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
5064

51-
echo "Decompresed snapshot, cleaning up..."
65+
echo "Decompressed snapshot, cleaning up..."
5266

5367
mv /data/snapshots/$NETWORK_ID/download/* /data && \
5468
rm -rf /data/snapshots && \

lib/base/lib/assets/node/node-start.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -e
44
source /etc/cdk_environment
55

66
export NETWORK_ENV=".env.$NETWORK_ID"
7-
export CLIENT=geth
7+
export CLIENT="$BASE_CLIENT"
8+
export HOST_DATA_DIR="/data"
89

910
echo "Script is starting client $CLIENT on $NETWORK_ENV"
1011
# Start the node

lib/base/lib/assets/user-data-alinux.sh

Lines changed: 29 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
#!/bin/bash
22
set +e
33

4-
# Set by generic single-node and ha-node CDK components
5-
LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}
6-
AUTOSCALING_GROUP_NAME=${_AUTOSCALING_GROUP_NAME_}
74
RESOURCE_ID=${_NODE_CF_LOGICAL_ID_}
8-
ASSETS_S3_PATH=${_ASSETS_S3_PATH_}
9-
DATA_VOLUME_TYPE=${_DATA_VOLUME_TYPE_}
10-
DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}
11-
12-
# Set by Base-specic CDK components and stacks
13-
AWS_REGION=${_AWS_REGION_}
145
STACK_NAME=${_STACK_NAME_}
156
RESTORE_FROM_SNAPSHOT=${_RESTORE_FROM_SNAPSHOT_}
16-
NETWORK_ID=${_NETWORK_ID_}
17-
NODE_CONFIG=${_NODE_CONFIG_}
18-
L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}
19-
L1_CONSENSUS_ENDPOINT=${_L1_CONSENSUS_ENDPOINT_}
20-
SNAPSHOT_URL=${_SNAPSHOT_URL_}
217

228
{
23-
echo "LIFECYCLE_HOOK_NAME=$LIFECYCLE_HOOK_NAME"
24-
echo "AUTOSCALING_GROUP_NAME=$AUTOSCALING_GROUP_NAME"
25-
echo "ASSETS_S3_PATH=$ASSETS_S3_PATH"
26-
echo "DATA_VOLUME_TYPE=$DATA_VOLUME_TYPE"
27-
echo "DATA_VOLUME_SIZE=$DATA_VOLUME_SIZE"
28-
29-
echo "AWS_REGION=$AWS_REGION"
30-
echo "NETWORK_ID=$NETWORK_ID"
31-
echo "NODE_CONFIG=$NODE_CONFIG"
32-
echo "L1_EXECUTION_ENDPOINT=$L1_EXECUTION_ENDPOINT"
33-
echo "L1_CONSENSUS_ENDPOINT=$L1_CONSENSUS_ENDPOINT"
34-
echo "SNAPSHOT_URL=$SNAPSHOT_URL"
9+
echo "LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}"
10+
echo "AUTOSCALING_GROUP_NAME=${_AUTOSCALING_GROUP_NAME_}"
11+
echo "ASSETS_S3_PATH=${_ASSETS_S3_PATH_}"
12+
echo "DATA_VOLUME_TYPE=${_DATA_VOLUME_TYPE_}"
13+
echo "DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}"
14+
15+
echo "AWS_REGION=${_AWS_REGION_}"
16+
echo "NETWORK_ID=${_NETWORK_ID_}"
17+
echo "BASE_CLIENT=${_BASE_CLIENT_}"
18+
echo "NODE_CONFIG=${_NODE_CONFIG_}"
19+
echo "L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}"
20+
echo "L1_CONSENSUS_ENDPOINT=${_L1_CONSENSUS_ENDPOINT_}"
21+
echo "SNAPSHOT_URL=${_SNAPSHOT_URL_}"
3522
} >> /etc/cdk_environment
3623

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

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

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

64-
echo " Installing aria2 a p2p downloader"
65-
cd /tmp
66-
67-
if [ "$arch" == "x86_64" ]; then
68-
wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
69-
tar jxvf aria2-1.36.0-linux-gnu-64bit-build1.tar.bz2
70-
cd aria2-1.36.0-linux-gnu-64bit-build1/
71-
make install
72-
else
73-
wget https://github.com/q3aql/aria2-static-builds/releases/download/v1.36.0/aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
74-
tar jxvf aria2-1.36.0-linux-gnu-arm-rbpi-build1.tar.bz2
75-
cd aria2-1.36.0-linux-gnu-arm-rbpi-build1/
76-
make install
77-
fi
78-
79-
echo " Installing s5cmd"
80-
cd /opt
81-
wget -q $S5CMD_URI -O s5cmd.tar.gz
82-
tar -xf s5cmd.tar.gz
83-
chmod +x s5cmd
84-
mv s5cmd /usr/bin
85-
s5cmd version
86-
8749
cd /opt
8850

8951
echo "Downloading assets zip file"
@@ -116,7 +78,7 @@ echo "Starting docker"
11678
service docker start
11779
systemctl enable docker
11880

119-
echo "Clonning node repo"
81+
echo "Cloning node repo"
12082
cd /home/bcuser
12183
GIT_URL=https://github.com/base-org/node.git
12284
git clone $GIT_URL
@@ -150,28 +112,12 @@ case $NODE_CONFIG in
150112
;;
151113
esac
152114

153-
case $NETWORK_ID in
154-
"mainnet")
155-
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
156-
sed -i '/.env.mainnet/s/^#//g' /home/bcuser/node/docker-compose.yml
157-
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
158-
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
159-
;;
160-
"sepolia")
161-
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
162-
sed -i "/.env.sepolia/s/^#//g" /home/bcuser/node/docker-compose.yml
163-
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
164-
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
165-
;;
166-
*)
167-
echo "Network id is not valid."
168-
exit 1
169-
;;
170-
esac
171-
172-
echo "OP_NODE_L1_TRUST_RPC=true" >> $OP_CONFIG_FILE_PATH
115+
sed -i "s#<your-preferred-l1-rpc>#$L1_EXECUTION_ENDPOINT#g" $OP_CONFIG_FILE_PATH
116+
sed -i "s#<your-preferred-l1-beacon>#$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
117+
sed -i "s#<your-preferred-l1-beacon-archiver>#$L1_CONSENSUS_ENDPOINT#g" $OP_CONFIG_FILE_PATH
118+
sed -i "s#OP_NODE_L1_TRUST_RPC=\"false\"#OP_NODE_L1_TRUST_RPC=\"true\"#g" $OP_CONFIG_FILE_PATH
173119

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

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

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

245-
if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
246-
echo "Skipping restoration from snapshot. Starting node"
247-
systemctl daemon-reload
248-
systemctl enable --now node
249-
else
250-
echo "Restoring full node from snapshot over http"
251-
chmod +x /opt/instance/storage/restore-from-snapshot-http.sh
252-
echo "/opt/instance/storage/restore-from-snapshot-http.sh" | at now + 1 min
253-
fi
254-
255191
if [[ "$LIFECYCLE_HOOK_NAME" != "none" ]]; then
256192
echo "Signaling ASG lifecycle hook to complete"
257193
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
258194
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id)
259195
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
260196
fi
261197

198+
if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
199+
echo "Skipping restoration from snapshot. Starting node"
200+
systemctl daemon-reload
201+
systemctl enable --now node
202+
else
203+
echo "Restoring full node from snapshot"
204+
chmod +x /opt/instance/storage/restore-from-snapshot.sh
205+
/opt/instance/storage/restore-from-snapshot.sh
206+
fi
207+
262208
echo "All Done!!"
263209
set -e

lib/base/lib/config/baseConfig.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as configTypes from "../../../constructs/config.interface";
22

33
export type BaseNetworkId = "mainnet" | "sepolia";
4+
export type BaseClient = "geth" | "reth";
45
export type BaseNodeConfiguration = "full" | "archive";
56

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

1718
export interface BaseBaseNodeConfig extends configTypes.BaseNodeConfig {
1819
baseNetworkId: BaseNetworkId;
20+
baseClient: BaseClient;
1921
baseNodeConfiguration: BaseNodeConfiguration;
2022
dataVolume: BaseDataVolumeConfig;
2123
restoreFromSnapshot: boolean;

lib/base/lib/config/baseConfig.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@ const parseDataVolumeType = (dataVolumeType: string) => {
1818
}
1919
}
2020

21+
const getClientConfiguration = (client: configTypes.BaseClient, nodeConfiguration: configTypes.BaseNodeConfiguration) => {
22+
switch (client) {
23+
case "reth":
24+
return "archive";
25+
case "geth":
26+
return "full";
27+
default:
28+
return "full";
29+
}
30+
}
31+
2132
export const baseConfig: configTypes.BaseBaseConfig = {
2233
accountId: process.env.AWS_ACCOUNT_ID || "xxxxxxxxxxx",
23-
region: process.env.AWS_REGION || "us-east-2",
34+
region: process.env.AWS_REGION || "us-east-1",
2435
}
2536

2637
export const baseNodeConfig: configTypes.BaseBaseNodeConfig = {
2738
instanceType: new ec2.InstanceType(process.env.BASE_INSTANCE_TYPE ? process.env.BASE_INSTANCE_TYPE : "m7g.2xlarge"),
2839
instanceCpuType: process.env.BASE_CPU_TYPE?.toLowerCase() == "x86_64" ? ec2.AmazonLinuxCpuType.X86_64 : ec2.AmazonLinuxCpuType.ARM_64,
2940
baseNetworkId: <configTypes.BaseNetworkId> process.env.BASE_NETWORK_ID || "mainnet",
30-
baseNodeConfiguration: <configTypes.BaseNodeConfiguration> process.env.BASE_NODE_CONFIGURATION || "full",
41+
baseClient: <configTypes.BaseClient> process.env.BASE_CLIENT || "geth",
42+
baseNodeConfiguration: getClientConfiguration(<configTypes.BaseClient> process.env.BASE_CLIENT, <configTypes.BaseNodeConfiguration> process.env.BASE_NODE_CONFIGURATION),
3143
restoreFromSnapshot: process.env.BASE_RESTORE_FROM_SNAPSHOT?.toLowerCase() == "true" ? true : false,
3244
l1ExecutionEndpoint: process.env.BASE_L1_EXECUTION_ENDPOINT || constants.NoneValue,
3345
l1ConsensusEndpoint: process.env.BASE_L1_CONSENSUS_ENDPOINT || constants.NoneValue,

lib/base/lib/ha-nodes-stack.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface BaseHANodesStackProps extends cdk.StackProps {
1616
instanceType: ec2.InstanceType;
1717
instanceCpuType: ec2.AmazonLinuxCpuType;
1818
baseNetworkId: configTypes.BaseNetworkId;
19+
baseClient: configTypes.BaseClient,
1920
baseNodeConfiguration: configTypes.BaseNodeConfiguration;
2021
restoreFromSnapshot: boolean;
2122
l1ExecutionEndpoint: string,
@@ -40,6 +41,7 @@ export class BaseHANodesStack extends cdk.Stack {
4041
instanceType,
4142
instanceCpuType,
4243
baseNetworkId,
44+
baseClient,
4345
baseNodeConfiguration,
4446
restoreFromSnapshot,
4547
l1ExecutionEndpoint,
@@ -80,6 +82,7 @@ export class BaseHANodesStack extends cdk.Stack {
8082
_DATA_VOLUME_TYPE_: dataVolume.type,
8183
_DATA_VOLUME_SIZE_: dataVolumeSizeBytes.toString(),
8284
_NETWORK_ID_: baseNetworkId,
85+
_BASE_CLIENT_: baseClient,
8386
_NODE_CONFIG_: baseNodeConfiguration,
8487
_LIFECYCLE_HOOK_NAME_: lifecycleHookName,
8588
_AUTOSCALING_GROUP_NAME_: autoScalingGroupName,

0 commit comments

Comments
 (0)