Skip to content

Commit 721112e

Browse files
authored
Merge pull request #167 from aws-samples/ethereum
Ethereum. Refactoring, parametrised network ID & Reth support
2 parents 921ce8e + c651a30 commit 721112e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1059
-596
lines changed

lib/ethereum/.env-sample

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

lib/ethereum/README.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This is the Well-Architected checklist for Ethereum nodes implementation of the
5959

6060
### Open AWS CloudShell
6161

62-
To begin, ensure you login to your AWS account with permissions to create and modify resources in IAM, EC2, EBS, VPC, S3, KMS, and Secrets Manager.
62+
To begin, ensure you login to your AWS account with permissions to create and modify resources in IAM, EC2, EBS, VPC, and S3.
6363

6464
From the AWS Management Console, open the [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html), a web-based shell environment. If unfamiliar, review the [2-minute YouTube video](https://youtu.be/fz4rbjRaiQM) for an overview and check out [CloudShell with VPC environment](https://docs.aws.amazon.com/cloudshell/latest/userguide/creating-vpc-environment.html) that we'll use to test nodes API from internal IP address space.
6565

@@ -73,9 +73,7 @@ cd aws-blockchain-node-runners
7373
npm install
7474
```
7575

76-
> **NOTE:** *In this tutorial we will set all major configuration through environment variables, but you also can modify parameters in `config/config.ts`.*
77-
78-
### Prepare to deploy nodes
76+
### Prepare AWS account to deploy nodes
7977

8078
1. Make sure you are in the root directory of the cloned repository
8179

@@ -89,11 +87,11 @@ aws ec2 create-default-vpc
8987
9088
> **NOTE:** *The default VPC must have at least two public subnets in different Availability Zones, and public subnet must set `Auto-assign public IPv4 address` to `YES`*
9189
92-
3. With the [Node Runners blueprints for Ethereum](https://github.com/aws-samples/aws-blockchain-node-runners/tree/main/lib/ethereum), you can deploy both single Ethereum nodes and multi-node high-availability configurations on AWS. Furthermore, Node Runners is designed to support client diversity, with configurations available for a variety of client combinations for the Execution Layer (EL) and Consensus Layer (CL).
90+
### Configure your setup
9391

94-
Configure your setup.
92+
#### Execution and Consensus Layer Client Options
9593

96-
### Execution and Consensus Layer Client Options
94+
With the [Node Runners blueprints for Ethereum](https://github.com/aws-samples/aws-blockchain-node-runners/tree/main/lib/ethereum), you can deploy both single Ethereum nodes and multi-node high-availability configurations on AWS. Furthermore, Node Runners is designed to support client diversity, with configurations available for a variety of client combinations for the Execution Layer (EL) and Consensus Layer (CL).
9795

9896
<details>
9997

@@ -135,17 +133,17 @@ nano .env
135133

136134
<details>
137135

138-
<summary>Erigon Prysm</summary>
136+
<summary>Reth Lighthouse</summary>
139137
<br/>
140138

141-
**Configure your Node Runners Ethereum - Erigon Prysm**
139+
**Configure your Node Runners Ethereum - Reth Lighthouse**
142140

143-
To specify the Ethereum client combination you wish to deploy, create your own copy of `.env` file and edit it using your preferred text editor. The contents of your file for a Erigon / Prysm node deployment is as follows, which uses a sample config from the repository:
141+
To specify the Ethereum client combination you wish to deploy, create your own copy of `.env` file and edit it using your preferred text editor. The contents of your file for a Reth / Lighthouse node deployment is as follows, which uses a sample config from the repository:
144142
```bash
145143
# Make sure you are in aws-blockchain-node-runners/lib/ethereum
146144
cd lib/ethereum
147145
pwd
148-
cp ./sample-configs/.env-erigon-prysm .env
146+
cp ./sample-configs/.env-erigon-lighthouse .env
149147
nano .env
150148
```
151149
> **NOTE:** *You can find more examples inside the `sample-configs` directory, which illustrate other Ethereum client combinations.*
@@ -201,9 +199,32 @@ pwd
201199
npx cdk deploy eth-common
202200
```
203201

204-
### Option 1: Single RPC Node
202+
### [OPTIONAL] (required only when ETH_SNAPSHOT_TYPE="s3") Deploy Sync Node
203+
204+
Sync node will sync with the network and periodically create data snapshots on S3 to speed up RPC nodes setup when `ETH_SNAPSHOT_TYPE="s3"`. It has no effect if `ETH_SNAPSHOT_TYPE="none"`.
205+
206+
1. Deploy `eth-sync-node` stack
207+
208+
```bash
209+
pwd
210+
# Make sure you are in aws-blockchain-node-runners/lib/ethereum
211+
npx cdk deploy eth-sync-node --json --outputs-file sync-node-deploy.json
212+
```
213+
214+
2. After starting the node you need to wait for the inital syncronization process to finish. It may take from half a day to about 6-10 days depending on the client combination and the state of the network. You can use Amazon CloudWatch to track the progress. There is a script that publishes CloudWatch metrics every 5 minutes, where you can watch `sync distance` for consensus client and `blocks behind` for execution client. When the node is fully synced those two metrics shold show 0. To see them:
215+
216+
- Navigate to [CloudWatch service](https://console.aws.amazon.com/cloudwatch/) (make sure you are in the region you have specified for `AWS_REGION`)
217+
- Open `Dashboards` and select `eth-sync-node-<your-eth-client-combination>` from the list of dashboards.
218+
219+
Once synchronization process is over, the script will automatically stop both clients and copy all the contents of the `/data` directory to your snapshot S3 bucket. That may take from 30 minutes to about 2 hours. During the process on the dashboard you will see lower CPU and RAM utilization but high data disc throughput and outbound network traffic. The script will automatically start the clients after the process is done.
220+
221+
> **Note:** *The snapshot backup process will automatically run ever day at midnight time of the time zone were the sync node runs. To change the schedule, modify `crontab` of the root user on the node's EC2 instance.*
222+
223+
### Deploy Standalone RPC Node
224+
225+
> **NOTE:** *If `ETH_SNAPSHOT_TYPE="s3"` make sure you [deployed the Sync Node first](#optional-required-only-when-eth_snapshot_types3-deploy-sync-node).*
205226
206-
1. Deploy Single RPC Node
227+
1. Deploy `eth-single-node` stack
207228

208229
```bash
209230
pwd
@@ -212,12 +233,12 @@ npx cdk deploy eth-single-node --json --outputs-file single-node-deploy.json
212233
```
213234
> **NOTE:** *The default VPC must have at least two public subnets in different Availability Zones, and public subnet must set `Auto-assign public IPv4 address` to `YES`*
214235
215-
2. After starting the node you need to wait for the inital syncronization process to finish. It may take from half a day to about 6-10 days depending on the client combination and the state of the network. You can use Amazon CloudWatch to track the progress. There is a script that publishes CloudWatch metrics every 5 minutes, where you can watch `sync distance` for consensus client and `blocks behind` for execution client. When the node is fully synced those two metrics shold show 0. To see them:
236+
2. If you haven't used `ETH_SNAPSHOT_TYPE="s3"` with Sync Node, then your node will start syncing by itself. In that case, after starting the node you need to wait for the inital syncronization process to finish. It may take from half a day to about 6-10 days depending on the client combination and the state of the network. You can use Amazon CloudWatch to track the progress. There is a script that publishes CloudWatch metrics every 5 minutes, where you can watch `sync distance` for consensus client and `blocks behind` for execution client. When the node is fully synced those two metrics shold show 0. To see them:
216237

217238
- Navigate to [CloudWatch service](https://console.aws.amazon.com/cloudwatch/) (make sure you are in the region you have specified for `AWS_REGION`)
218-
- Open `Dashboards` and select `eth-sync-node-<your-eth-client-combination>` from the list of dashboards.
239+
- Open `Dashboards` and select `eth-single-node-<your-eth-client-combination>` from the list of dashboards.
219240

220-
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. Turn the following query against the private IP of the single RPC node you deployed:
241+
3. 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. Turn the following query against the private IP of the single RPC node you deployed:
221242

222243
```bash
223244
INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.node-instance-id? | select(. != null)')
@@ -240,35 +261,25 @@ The result should be like this (the actual balance might change):
240261
{"jsonrpc":"2.0","id":1,"result":"0xe791d050f91d9949d344d"}
241262
```
242263

243-
### Option 2: Highly Available RPC Nodes
244-
245-
1. Deploy Sync Node
246-
247-
```bash
248-
pwd
249-
# Make sure you are in aws-blockchain-node-runners/lib/ethereum
250-
npx cdk deploy eth-sync-node --json --outputs-file sync-node-deploy.json
251-
```
252-
**NOTE:** *The default VPC must have at least two public subnets in different Availability Zones, and public subnet must set `Auto-assign public IPv4 address` to `YES`*
264+
### Deploy Highly Available RPC Nodes
253265

254-
2. After starting the node you need to wait for the inital syncronization process to finish. It may take from half a day to about 6-10 days depending on the client combination and the state of the network. You can use Amazon CloudWatch to track the progress. There is a script that publishes CloudWatch metrics every 5 minutes, where you can watch `sync distance` for consensus client and `blocks behind` for execution client. When the node is fully synced those two metrics shold show 0. To see them:
266+
> **NOTE:** *If `ETH_SNAPSHOT_TYPE="s3"` make sure you [deployed the Sync Node first](#optional-required-only-when-eth_snapshot_types3-deploy-sync-node).*
255267
256-
- Navigate to [CloudWatch service](https://console.aws.amazon.com/cloudwatch/) (make sure you are in the region you have specified for `AWS_REGION`)
257-
- Open `Dashboards` and select `eth-sync-node-<your-eth-client-combination>` from the list of dashboards.
268+
> **NOTE:** *The default VPC must have at least two public subnets in different Availability Zones, and public subnet must set `Auto-assign public IPv4 address` to `YES`*
258269
259-
Once synchronization process is over, the script will automatically stop both clients and copy all the contents of the `/data` directory to your snapshot S3 bucket. That may take from 30 minutes to about 2 hours. During the process on the dashboard you will see lower CPU and RAM utilization but high data disc throughput and outbound network traffic. The script will automatically start the clients after the process is done.
270+
1. Deploy Sync Node
260271

261-
> **Note:** *The snapshot backup process will automatically run ever day at midnight time of the time zone were the sync node runs. To change the schedule, modify `crontab` of the root user on the node's EC2 instance.*
272+
Use instructions from earlier: [Deploy Sync Node](#optional-required-only-when-eth_snapshot_types3-deploy-sync-node)
262273

263-
3. Configure and deploy 2 RPC Nodes
274+
2. Deploy `eth-rpc-nodes` stack
264275

265276
```bash
266277
pwd
267278
# Make sure you are in aws-blockchain-node-runners/lib/ethereum
268279
npx cdk deploy eth-rpc-nodes --json --outputs-file rpc-node-deploy.json
269280
```
270281

271-
4. Give the new RPC nodes about 30 minutes (up to 2 hours for Erigon) to initialize and then run the following query against the load balancer behind the RPC node created
282+
3. Give the new RPC nodes about 30 minutes (up to 2 hours for Erigon) to initialize and then run the following query against the load balancer in front of your nods:
272283

273284
```bash
274285
export ETH_RPC_ABL_URL=$(cat rpc-node-deploy.json | jq -r '..|.alburl? | select(. != null)')
@@ -288,7 +299,7 @@ The result should be like this (the actual balance might change):
288299
{"jsonrpc":"2.0","id":1,"result":"0xe791d050f91d9949d344d"}
289300
```
290301

291-
If the nodes are still starting and catching up with the chain, you will see the following repsonse:
302+
If the nodes are still starting and catching up with the chain, you will see the following response:
292303

293304
```HTML
294305
<html>
@@ -298,7 +309,7 @@ The result should be like this (the actual balance might change):
298309
</body>
299310
```
300311

301-
> **NOTE:** By default and for security reasons the load balancer is available only from within the default VPC in the region where it is deployed. It is not available from the Internet and is not open for external connections. Before opening it up please make sure you protect your RPC APIs.
312+
> **NOTE:** *By default and for security reasons the load balancer is available only from within the default VPC in the region where it is deployed. It is not available from the Internet and is not open for external connections. Before opening it up please make sure you protect your RPC APIs.*
302313
303314
### Clearing up and undeploying everything
304315

lib/ethereum/app.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,71 @@ import 'dotenv/config'
33
import "source-map-support/register";
44
import * as cdk from "aws-cdk-lib";
55
import * as nag from "cdk-nag";
6-
import * as config from "./lib/config/ethConfig";
7-
import { EthNodeRole } from "./lib/config/ethConfig.interface";
6+
import * as config from "./lib/config/node-config";
7+
import { EthNodeRole } from "./lib/config/node-config.interface";
88

99
import { EthSingleNodeStack } from "./lib/single-node-stack";
1010
import { EthCommonStack } from "./lib/common-stack";
1111
import { EthRpcNodesStack } from "./lib/rpc-nodes-stack";
1212

1313
const app = new cdk.App();
14-
cdk.Tags.of(app).add("Project", "Ethereum");
14+
cdk.Tags.of(app).add("Project", "AWSEthereum");
1515

1616
new EthCommonStack(app, "eth-common", {
17-
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
1817
stackName: `eth-nodes-common`,
18+
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
19+
snapshotType: config.baseConfig.snapshotType,
1920
});
2021

2122
new EthSingleNodeStack(app, "eth-sync-node", {
2223
stackName: `eth-sync-node-${config.baseConfig.clientCombination}`,
2324

2425
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
2526
ethClientCombination: config.baseConfig.clientCombination,
27+
network: config.baseConfig.network,
28+
snapshotType: config.baseConfig.snapshotType,
29+
consensusSnapshotURL: config.baseConfig.consensusSnapshotURL,
30+
executionSnapshotURL: config.baseConfig.executionSnapshotURL,
31+
consensusCheckpointSyncURL: config.baseConfig.consensusCheckpointSyncURL,
2632
nodeRole: <EthNodeRole> "sync-node",
2733
instanceType: config.syncNodeConfig.instanceType,
2834
instanceCpuType: config.syncNodeConfig.instanceCpuType,
29-
dataVolumes: config.syncNodeConfig.dataVolumes,
35+
dataVolume: config.syncNodeConfig.dataVolumes[0],
3036
});
3137

3238
new EthSingleNodeStack(app, "eth-single-node", {
3339
stackName: `eth-single-node-${config.baseConfig.clientCombination}`,
3440

3541
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
3642
ethClientCombination: config.baseConfig.clientCombination,
43+
network: config.baseConfig.network,
44+
snapshotType: config.baseConfig.snapshotType,
45+
consensusSnapshotURL: config.baseConfig.consensusSnapshotURL,
46+
executionSnapshotURL: config.baseConfig.executionSnapshotURL,
47+
consensusCheckpointSyncURL: config.baseConfig.consensusCheckpointSyncURL,
3748
nodeRole: <EthNodeRole> "single-node",
38-
instanceType: config.syncNodeConfig.instanceType,
39-
instanceCpuType: config.syncNodeConfig.instanceCpuType,
40-
dataVolumes: config.syncNodeConfig.dataVolumes,
49+
instanceType: config.rpcNodeConfig.instanceType,
50+
instanceCpuType: config.rpcNodeConfig.instanceCpuType,
51+
dataVolume: config.rpcNodeConfig.dataVolumes[0],
4152
});
4253

4354
new EthRpcNodesStack(app, "eth-rpc-nodes", {
4455
stackName: `eth-rpc-nodes-${config.baseConfig.clientCombination}`,
4556

4657
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
4758
ethClientCombination: config.baseConfig.clientCombination,
59+
network: config.baseConfig.network,
60+
snapshotType: config.baseConfig.snapshotType,
61+
consensusSnapshotURL: config.baseConfig.consensusSnapshotURL,
62+
executionSnapshotURL: config.baseConfig.executionSnapshotURL,
63+
consensusCheckpointSyncURL: config.baseConfig.consensusCheckpointSyncURL,
4864
nodeRole: <EthNodeRole> "rpc-node",
4965
instanceType: config.rpcNodeConfig.instanceType,
5066
instanceCpuType: config.rpcNodeConfig.instanceCpuType,
5167
numberOfNodes: config.rpcNodeConfig.numberOfNodes,
5268
albHealthCheckGracePeriodMin: config.rpcNodeConfig.albHealthCheckGracePeriodMin,
5369
heartBeatDelayMin: config.rpcNodeConfig.heartBeatDelayMin,
54-
dataVolumes: config.syncNodeConfig.dataVolumes,
70+
dataVolume: config.syncNodeConfig.dataVolumes[0],
5571
});
5672

5773

lib/ethereum/lib/assets/copy-data-to-s3.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[cfn-auto-reloader-hook]
2+
triggers=post.update
3+
path=Resources.WebServerHost.Metadata.AWS::CloudFormation::Init
4+
action=/opt/aws/bin/cfn-init -v --stack __AWS_STACK_NAME__ --resource WebServerHost --region __AWS_REGION__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[main]
2+
stack=__AWS_STACK_ID__
3+
region=__AWS_REGION__
4+
# The interval used to check for changes to the resource metadata in minutes. Default is 15
5+
interval=2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=cfn-hup daemon
3+
[Service]
4+
Type=simple
5+
ExecStart=/usr/local/bin/cfn-hup
6+
Restart=always
7+
[Install]
8+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)