Skip to content

Commit 0ea2ea5

Browse files
committed
Base. Debugging deployments and snapshot download
1 parent d92a21b commit 0ea2ea5

File tree

8 files changed

+138
-49
lines changed

8 files changed

+138
-49
lines changed

lib/base/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ new BaseCommonStack(app, "base-common", {
1515
});
1616

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

2121
instanceType: config.baseNodeConfig.instanceType,
2222
instanceCpuType: config.baseNodeConfig.instanceCpuType,
2323
baseNetworkId: config.baseNodeConfig.baseNetworkId,
24+
baseNodeConfiguration: config.baseNodeConfig.baseNodeConfiguration,
2425
restoreFromSnapshot: config.baseNodeConfig.restoreFromSnapshot,
2526
l1ExecutionEndpoint: config.baseNodeConfig.l1ExecutionEndpoint,
2627
l1ConsensusEndpoint: config.baseNodeConfig.l1ConsensusEndpoint,
28+
snapshotUrl: config.baseNodeConfig.snapshotUrl,
2729
dataVolume: config.baseNodeConfig.dataVolume,
2830
});

lib/base/lib/assets/restore-from-snapshot.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
source /etc/environment
4+
echo "Downloading snpashot"
5+
6+
cd /data
7+
8+
BASE_SNAPSHOT_FILE_NAME=snalshot.tar.gz
9+
BASE_SNAPSHOT_DIR=/data/
10+
BASE_SNAPSHOT_DOWNLOAD_STATUS=-1
11+
BASE_LATEST_SNAPSHOT_FILE_NAME=$(curl https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/latest)
12+
13+
if [ "$SNAPSHOT_URL" == "none" ] || [ -z "${SNAPSHOT_URL}" ]; then
14+
SNAPSHOT_URL=https://$NETWORK_ID-$NODE_CONFIG-snapshots.base.org/$BASE_LATEST_SNAPSHOT_FILE_NAME
15+
fi
16+
17+
while (( BASE_SNAPSHOT_DOWNLOAD_STATUS != 0 ))
18+
do
19+
PIDS=$(pgrep aria2c)
20+
if [ -z "$PIDS" ]; then
21+
aria2c -x3 $SNAPSHOT_URL -d $BASE_SNAPSHOT_DIR -o $BASE_SNAPSHOT_FILE_NAME -l aria2c.log --log-level=warn --allow-piece-length-change=true
22+
fi
23+
BASE_SNAPSHOT_DOWNLOAD_STATUS=$?
24+
pid=$(pidof aria2c)
25+
wait $pid
26+
echo "aria2c exit."
27+
case $BASE_SNAPSHOT_DOWNLOAD_STATUS in
28+
3)
29+
echo "file not exist."
30+
exit 3
31+
;;
32+
9)
33+
echo "No space left on device."
34+
exit 9
35+
;;
36+
*)
37+
continue
38+
;;
39+
esac
40+
done
41+
42+
echo "Downloading snapshot succeed"
43+
44+
sleep 60
45+
# take about 2 hours to decompress the snapshot
46+
echo "Decompression snapshot start ..."
47+
48+
tar -I zstdmt -xf $BASE_SNAPSHOT_DIR/$BASE_SNAPSHOT_FILE_NAME -C /data 2>&1 | tee unzip.log && echo "decompression success..." || echo "decompression failed..." >> snapshots-decompression.log
49+
echo "Decompressing snapshot success ..."
50+
51+
mv /data/snapshots/$NETWORK_ID/download/* /data && \
52+
rm -rf /data/snapshots && \
53+
rm -rf /data/$BASE_SNAPSHOT_FILE_NAME
54+
55+
echo "Snapshot is ready !!!"
56+
57+
chown -R bcuser:bcuser /data && \
58+
sudo su bcuser && \
59+
/usr/local/bin/docker-compose -f /home/bcuser/node/docker-compose.yml up -d

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

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}
66
AUTOSCALING_GROUP_NAME=${_AUTOSCALING_GROUP_NAME_}
77
RESOURCE_ID=${_NODE_CF_LOGICAL_ID_}
88
ASSETS_S3_PATH=${_ASSETS_S3_PATH_}
9-
echo "LIFECYCLE_HOOK_NAME=$LIFECYCLE_HOOK_NAME" >> /etc/environment
10-
echo "AUTOSCALING_GROUP_NAME=$AUTOSCALING_GROUP_NAME" >> /etc/environment
11-
echo "ASSETS_S3_PATH=$ASSETS_S3_PATH" >> /etc/environment
9+
{
10+
echo "LIFECYCLE_HOOK_NAME=$LIFECYCLE_HOOK_NAME"
11+
echo "AUTOSCALING_GROUP_NAME=$AUTOSCALING_GROUP_NAME"
12+
echo "ASSETS_S3_PATH=$ASSETS_S3_PATH"
13+
} >> /etc/environment
1214

1315
arch=$(uname -m)
1416

@@ -55,19 +57,22 @@ unzip -q awscliv2.zip
5557
rm /usr/bin/aws
5658
ln /usr/local/bin/aws /usr/bin/aws
5759

58-
aws configure set default.s3.max_concurrent_requests 50
59-
aws configure set default.s3.multipart_chunksize 256MB
60-
6160
echo 'Installing SSM Agent'
6261
yum install -y $SSM_AGENT_BINARY_URI
6362

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

7277
# Base specific setup starts here
7378

@@ -77,13 +82,19 @@ STACK_NAME=${_STACK_NAME_}
7782
RESTORE_FROM_SNAPSHOT=${_RESTORE_FROM_SNAPSHOT_}
7883
FORMAT_DISK=${_FORMAT_DISK_}
7984
NETWORK_ID=${_NETWORK_ID_}
85+
NODE_CONFIG=${_NODE_CONFIG_}
8086
L1_EXECUTION_ENDPOINT=${_L1_EXECUTION_ENDPOINT_}
8187
L1_CONSENSUS_ENDPOINT=${_L1_CONSENSUS_ENDPOINT_}
88+
SNAPSHOT_URL=${_SNAPSHOT_URL_}
8289

83-
echo "REGION=$REGION" >> /etc/environment
84-
echo "NETWORK_ID=$NETWORK_ID" >> /etc/environment
85-
echo "L1_EXECUTION_ENDPOINT=$L1_EXECUTION_ENDPOINT" >> /etc/environment
86-
echo "L1_CONSENSUS_ENDPOINT=$L1_CONSENSUS_ENDPOINT" >> /etc/environment
90+
{
91+
echo "REGION=$REGION"
92+
echo "NETWORK_ID=$NETWORK_ID"
93+
echo "NODE_CONFIG=$NODE_CONFIG"
94+
echo "L1_EXECUTION_ENDPOINT=$L1_EXECUTION_ENDPOINT"
95+
echo "L1_CONSENSUS_ENDPOINT=$L1_CONSENSUS_ENDPOINT"
96+
echo "SNAPSHOT_URL=$SNAPSHOT_URL"
97+
} >> /etc/environment
8798

8899
GIT_URL=https://github.com/base-org/node.git
89100
SYNC_CHECKER_FILE_NAME=syncchecker-base.sh
@@ -147,16 +158,42 @@ echo "Configuring node"
147158

148159
case $NETWORK_ID in
149160
"mainnet")
150-
sed -i "s#OP_NODE_L1_ETH_RPC=https://1rpc.io/eth#OP_NODE_L1_ETH_RPC=$L1_EXECUTION_ENDPOINT#g" /home/bcuser/node/.env.mainnet
161+
OP_CONFIG_FILE_PATH=/home/bcuser/node/.env.mainnet
162+
;;
163+
"sepolia")
164+
OP_CONFIG_FILE_PATH=/home/bcuser/node/.env.sepolia
165+
;;
166+
*)
167+
echo "Network id is not valid."
168+
exit 1
169+
;;
170+
esac
171+
172+
case $NODE_CONFIG in
173+
"full")
174+
echo "OP_GETH_GCMODE=full" >> $OP_CONFIG_FILE_PATH
175+
;;
176+
"archive")
177+
echo "OP_GETH_GCMODE=archive" >> $OP_CONFIG_FILE_PATH
178+
;;
179+
*)
180+
echo "Network id is not valid."
181+
exit 1
182+
;;
183+
esac
184+
185+
case $NETWORK_ID in
186+
"mainnet")
187+
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
151188
sed -i '/.env.mainnet/s/^#//g' /home/bcuser/node/docker-compose.yml
152-
sed -i '/OP_NODE_L1_BEACON/s/^#//g' /home/bcuser/node/.env.mainnet
153-
sed -i "s#OP_NODE_L1_BEACON=https://your.mainnet.beacon.node/endpoint-here#OP_NODE_L1_BEACON=$L1_CONSENSUS_ENDPOINT#g" /home/bcuser/node/.env.mainnet
189+
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
190+
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
154191
;;
155192
"sepolia")
156-
sed -i "s#OP_NODE_L1_ETH_RPC=https://rpc.sepolia.org#OP_NODE_L1_ETH_RPC=$L1_EXECUTION_ENDPOINT#g" /home/bcuser/node/.env.sepolia
193+
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
157194
sed -i "/.env.sepolia/s/^#//g" /home/bcuser/node/docker-compose.yml
158-
sed -i '/OP_NODE_L1_BEACON/s/^#//g' /home/bcuser/node/.env.sepolia
159-
sed -i "s#OP_NODE_L1_BEACON=https://your.sepolia.beacon.node/endpoint-here#OP_NODE_L1_BEACON=$L1_CONSENSUS_ENDPOINT#g" /home/bcuser/node/.env.sepolia
195+
sed -i '/OP_NODE_L1_BEACON/s/^#//g' $OP_CONFIG_FILE_PATH
196+
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
160197
;;
161198
*)
162199
echo "Network id is not valid."
@@ -217,8 +254,8 @@ if [ "$RESTORE_FROM_SNAPSHOT" == "false" ]; then
217254
echo "sudo su bcuser && /usr/local/bin/docker-compose -f /home/bcuser/node/docker-compose.yml up -d" | at now +3 minutes
218255
else
219256
echo "Restoring data from snapshot"
220-
chmod 766 /opt/restore-from-snapshot.sh
221-
echo "/opt/restore-from-snapshot.sh" | at now +3 minutes
257+
chmod 766 /opt/start-from-snapshot.sh
258+
echo "/opt/start-from-snapshot.sh" | at now +3 minutes
222259
fi
223260

224261
echo "All Done!!"

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

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

3-
export type BaseNetworkId = "mainnet" ;
4-
export type BaseNodeConfiguration = "full" ;
3+
export type BaseNetworkId = "mainnet" | "sepolia";
4+
export type BaseNodeConfiguration = "full" | "archive";
55

66
export {AMBEthereumNodeNetworkId} from "../../../constructs/config.interface";
77

@@ -16,8 +16,10 @@ export interface BaseBaseConfig extends configTypes.BaseConfig {
1616

1717
export interface BaseBaseNodeConfig extends configTypes.BaseNodeConfig {
1818
baseNetworkId: BaseNetworkId;
19+
baseNodeConfiguration: BaseNodeConfiguration;
1920
dataVolume: BaseDataVolumeConfig;
2021
restoreFromSnapshot: boolean;
2122
l1ExecutionEndpoint: string;
2223
l1ConsensusEndpoint: string;
24+
snapshotUrl: string;
2325
}

lib/base/lib/config/baseConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ export const baseNodeConfig: configTypes.BaseBaseNodeConfig = {
2727
instanceType: new ec2.InstanceType(process.env.BASE_INSTANCE_TYPE ? process.env.BASE_INSTANCE_TYPE : "m7g.2xlarge"),
2828
instanceCpuType: process.env.BASE_CPU_TYPE?.toLowerCase() == "x86_64" ? ec2.AmazonLinuxCpuType.X86_64 : ec2.AmazonLinuxCpuType.ARM_64,
2929
baseNetworkId: <configTypes.BaseNetworkId> process.env.BASE_NETWORK_ID || "mainnet",
30+
baseNodeConfiguration: <configTypes.BaseNodeConfiguration> process.env.BASE_NODE_CONFIGURATION || "full",
3031
restoreFromSnapshot: process.env.BASE_RESTORE_FROM_SNAPSHOT?.toLowerCase() == "true" ? true : false,
3132
l1ExecutionEndpoint: process.env.BASE_L1_EXECUTION_ENDPOINT || constants.NoneValue,
3233
l1ConsensusEndpoint: process.env.BASE_L1_CONSENSUS_ENDPOINT || constants.NoneValue,
34+
snapshotUrl: process.env.BASE_SNAPSHOT_URL || constants.NoneValue,
3335
dataVolume: {
3436
sizeGiB: process.env.BASE_DATA_VOL_SIZE ? parseInt(process.env.BASE_DATA_VOL_SIZE): 1000,
3537
type: parseDataVolumeType(process.env.BASE_DATA_VOL_TYPE?.toLowerCase() ? process.env.BASE_DATA_VOL_TYPE?.toLowerCase() : "gp3"),

lib/base/lib/single-node-stack.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ export interface BaseSingleNodeStackProps extends cdk.StackProps {
1717
instanceType: ec2.InstanceType;
1818
instanceCpuType: ec2.AmazonLinuxCpuType;
1919
baseNetworkId: configTypes.BaseNetworkId;
20+
baseNodeConfiguration: configTypes.BaseNodeConfiguration;
2021
restoreFromSnapshot: boolean;
2122
l1ExecutionEndpoint: string,
2223
l1ConsensusEndpoint: string,
24+
snapshotUrl: string,
2325
dataVolume: configTypes.BaseDataVolumeConfig;
2426
}
2527

@@ -39,6 +41,7 @@ export class BaseSingleNodeStack extends cdk.Stack {
3941
instanceType,
4042
instanceCpuType,
4143
baseNetworkId,
44+
baseNodeConfiguration,
4245
restoreFromSnapshot,
4346
l1ExecutionEndpoint,
4447
l1ConsensusEndpoint,
@@ -103,12 +106,14 @@ export class BaseSingleNodeStack extends cdk.Stack {
103106
_DATA_VOLUME_TYPE_: dataVolume.type,
104107
_DATA_VOLUME_SIZE_: dataVolumeSizeBytes.toString(),
105108
_NETWORK_ID_: baseNetworkId,
109+
_NODE_CONFIG_: baseNodeConfiguration,
106110
_LIFECYCLE_HOOK_NAME_: constants.NoneValue,
107111
_AUTOSCALING_GROUP_NAME_: constants.NoneValue,
108112
_RESTORE_FROM_SNAPSHOT_: restoreFromSnapshot.toString(),
109113
_FORMAT_DISK_: "true",
110114
_L1_EXECUTION_ENDPOINT_: l1ExecutionEndpoint,
111115
_L1_CONSENSUS_ENDPOINT_: l1ConsensusEndpoint,
116+
_SNAPSHOT_URL_: props.snapshotUrl,
112117
});
113118

114119
node.instance.addUserData(modifiedInitNodeScript);

lib/base/sample-configs/.env-sample-rpc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ AWS_REGION="us-east-1"
88

99
## Common configuration parameters ##
1010
BASE_NETWORK_ID="sepolia" # All options: "mainnet", "sepolia"
11+
BASE_NODE_CONFIGURATION="full" # All options: "full", "archive"
1112
BASE_INSTANCE_TYPE="m7g.2xlarge"
1213
BASE_CPU_TYPE="ARM_64" # All options: "x86_64", "ARM_64". IMPORTANT: Make sure the CPU type matches the instance type used
1314

@@ -20,6 +21,8 @@ BASE_RESTORE_FROM_SNAPSHOT="true" # Download snapshot to speed up statup ti
2021
BASE_L1_EXECUTION_ENDPOINT="https://ethereum-sepolia-rpc.publicnode.com" # Set your own URL to Ethereum L1 node: https://docs.base.org/tools/node-providers
2122
BASE_L1_CONSENSUS_ENDPOINT="https://ethereum-sepolia-beacon-api.publicnode.com"
2223

24+
BASE_SNAPSHOT_URL="none" # Optionally provide the URL to download snpashot: https://docs.base.org/tutorials/run-a-base-node/#snapshots
25+
2326
# Example for Sepolia:
2427
#BASE_L1_EXECUTION_ENDPOINT=https://ethereum-sepolia-rpc.publicnode.com
2528
#BASE_L1_CONSENSUS_ENDPOINT=https://ethereum-sepolia-beacon-api.publicnode.com

0 commit comments

Comments
 (0)