Skip to content

Commit 6d7e036

Browse files
authored
Merge pull request #114 from aws-samples/stacks
Stacks
2 parents ae95124 + ebe6aca commit 6d7e036

File tree

11 files changed

+93
-21
lines changed

11 files changed

+93
-21
lines changed

lib/stacks/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ echo "NODE_INTERNAL_IP=$NODE_INTERNAL_IP"
142142

143143
``` bash
144144
# IMPORTANT: Run from CloudShell VPC environment tab
145-
curl http://$NODE_INTERNAL_IP:20443/v2/info'
145+
curl http://$NODE_INTERNAL_IP:20443/v2/info
146146
```
147147

148148
You should get a response like this:
@@ -192,13 +192,13 @@ npx cdk deploy stacks-ha-nodes --json --outputs-file ha-nodes-deploy.json
192192
2. Give the new RPC nodes about 90 minutes to initialize and then run the following query against the load balancer behind the RPC node created
193193

194194
```bash
195-
export RPC_ABL_URL=$(cat ha-nodes-deploy.json | jq -r '..|.alburl? | select(. != null)')
195+
export RPC_ALB_URL=$(cat ha-nodes-deploy.json | jq -r '..|.alburl? | select(. != null)')
196196
echo RPC_ALB_URL=$RPC_ALB_URL
197197
```
198198

199199
```bash
200200
# IMPORTANT: Run from CloudShell VPC environment tab
201-
curl http://$RPC_ABL_URL:20443/v2/info' | jq
201+
curl http://$RPC_ALB_URL:20443/v2/info | jq
202202
```
203203

204204
The result should show the status of the blockchain.

lib/stacks/lib/assets/build-binaries.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SOURCE_DIR="$PWD/$STACKS_REPO-$VERSION_TAG"
5252

5353
# Build relevant source code
5454
cd "$SOURCE_DIR" || return
55+
cargo update
5556
cargo build --features monitoring_prom,slog_json --release --workspace
5657

5758
sudo mkdir -p "$START_DIR/bin"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# shellcheck source=/dev/null
4+
source /etc/environment
5+
6+
# Download
7+
STACKS_REPO="stacks-core"
8+
STACKS_ORG="stacks-network"
9+
START_DIR=$PWD
10+
STACKS_BINARIES_FILE_NAME="source.zip"
11+
12+
# Install build dependencies.
13+
sudo yum update
14+
sudo yum -y install clang llvm git
15+
16+
mkdir -p src && cd src || return
17+
18+
if [ -z "$HOME" ]; then
19+
# Set $HOME to /root. $HOME isn't set to be /root when this
20+
# script first runs on the host.
21+
export HOME="/root"
22+
echo "HOME is not set. Setting it to /root."
23+
fi
24+
25+
# Get tag for the latest version.
26+
echo "Getting the source for stable version $STACKS_VERSION"
27+
if [ "$STACKS_VERSION" = "latest" ]; then
28+
echo "Aquiring tag for latest stable release."
29+
VERSION_TAG=$(curl -sL https://api.github.com/repos/$STACKS_ORG/$STACKS_REPO/releases/latest | jq -r .tag_name)
30+
else
31+
VERSION_TAG=$STACKS_VERSION
32+
fi
33+
34+
arch=$(uname -m)
35+
36+
echo "Architecture detected: $arch"
37+
echo "Fetching stacks latest code from stacks release $VERSION_TAG and architecture $arch"
38+
if [ "$arch" == "x86_64" ]; then
39+
wget "https://github.com/$STACKS_ORG/$STACKS_REPO/releases/download/$VERSION_TAG/linux-glibc-x64.zip" -O $STACKS_BINARIES_FILE_NAME
40+
else
41+
wget "https://github.com/$STACKS_ORG/$STACKS_REPO/releases/download/$VERSION_TAG/linux-glibc-arm64.zip" -O $STACKS_BINARIES_FILE_NAME
42+
fi
43+
44+
unzip ./$STACKS_BINARIES_FILE_NAME -d $START_DIR/bin

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ CLOUD_ASSETS_PATH=/var/tmp/assets
3434
echo "DATA_VOLUME_SIZE=${_DATA_VOLUME_SIZE_}"
3535
echo "ASG_NAME=${_ASG_NAME_}"
3636
echo "LIFECYCLE_HOOK_NAME=${_LIFECYCLE_HOOK_NAME_}"
37+
echo "BUILD_FROM_SOURCE=${_BUILD_FROM_SOURCE_}"
38+
echo "DOWNLOAD_CHAINSTATE=${_DOWNLOAD_CHAINSTATE_}"
3739
# Place shared environment variables here.
3840
echo "DATA_VOLUME_PATH=$DATA_VOLUME_PATH"
3941
echo "CLOUD_ASSETS_PATH=$CLOUD_ASSETS_PATH"
@@ -149,26 +151,33 @@ lsblk
149151

150152
# Build Binaries & Download Chainstate -----------------------------------------
151153

152-
(
153-
# Impropperly using the data volume path temporarily because it will have the
154-
# space required to store the compressed chainstate.
155-
sudo mkdir -p $DATA_VOLUME_PATH/tmp
156-
wget -q "$STACKS_CHAINSTATE_ARCHIVE" \
157-
-O "$DATA_VOLUME_PATH/tmp/chainstate.tar.gz"
158-
tar -vxf "$DATA_VOLUME_PATH/tmp/chainstate.tar.gz" \
159-
-C "$DATA_VOLUME_PATH"
160-
rm -rf "$DATA_VOLUME_PATH/tmp"
161-
) &
162-
163-
(
164-
# build-binaries.sh will ensure that the working directory the script is called from
165-
# has a ./src and a ./bin directory and will populate the ./src with the source code
166-
# and the ./bin with the compiled binaries.
154+
if [[ "$DOWNLOAD_CHAINSTATE" = "true" ]]; then
155+
(
156+
# Impropperly using the data volume path temporarily because it will have the
157+
# space required to store the compressed chainstate.
158+
sudo mkdir -p $DATA_VOLUME_PATH/tmp
159+
wget -q "$STACKS_CHAINSTATE_ARCHIVE" \
160+
-O "$DATA_VOLUME_PATH/tmp/chainstate.tar.gz"
161+
tar -vxf "$DATA_VOLUME_PATH/tmp/chainstate.tar.gz" \
162+
-C "$DATA_VOLUME_PATH"
163+
rm -rf "$DATA_VOLUME_PATH/tmp"
164+
) &
165+
fi
166+
167+
if [[ "$BUILD_FROM_SOURCE" = "true" ]]; then
168+
(
169+
# build-binaries.sh will ensure that the working directory the script is called from
170+
# has a ./src and a ./bin directory and will populate the ./src with the source code
171+
# and the ./bin with the compiled binaries.
172+
cd /usr/local || return
173+
"$CLOUD_ASSETS_PATH"/build-binaries.sh
174+
) &
175+
else
167176
cd /usr/local || return
168-
"$CLOUD_ASSETS_PATH"/build-binaries.sh
169-
) &
177+
"$CLOUD_ASSETS_PATH"/download-binaries.sh
178+
fi
170179

171-
wait # Wait for both background processes to finish
180+
wait # Wait for download or build or both to finish in background, if they were started
172181

173182
# No new directories are made at this point; ensure that the stacks
174183
# user has all necessary permissions.

lib/stacks/lib/config/stacksConfig.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface StacksBaseNodeConfig extends StacksNetworkConfig, configTypes.B
2727
stacksNodeConfiguration: StacksNodeConfiguration;
2828
stacksSignerSecretArn: string;
2929
stacksMinerSecretArn: string;
30+
buildFromSource: boolean;
31+
downloadChainstate: boolean;
3032
dataVolume: StacksVolumeConfig;
3133
}
3234

lib/stacks/lib/config/stacksConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const baseNodeConfig: configTypes.StacksBaseNodeConfig = {
4040
stacksNetwork: stacksNetwork,
4141
stacksVersion: process.env.STACKS_VERSION || defaults.stacksVersion,
4242
stacksNodeConfiguration: <configTypes.StacksNodeConfiguration> process.env.STACKS_NODE_CONFIGURATION || defaults.stacksNodeConfiguration,
43+
buildFromSource: process.env.STACKS_BUILD_FROM_SOURCE?.toLowerCase() === "true" ? true : defaults.buildFromSource,
44+
downloadChainstate: process.env.STACKS_DOWNLOAD_CHAINSTATE?.toLowerCase() === "false" ? false : defaults.downloadChainstate,
4345
stacksBootstrapNode: process.env.STACKS_BOOTSTRAP_NODE || defaults.stacksBootstrapNode,
4446
stacksChainstateArchive: process.env.STACKS_CHAINSTATE_ARCHIVE || defaults.stacksChainstateArchive,
4547
stacksP2pPort: process.env.STACKS_P2P_PORT ? parseInt(process.env.STACKS_P2P_PORT) : defaults.stacksP2pPort,

lib/stacks/lib/config/stacksConfigDefaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export function stacksNodeConfigDefaults(
6363
stacksVersion: "latest",
6464
stacksSignerSecretArn: "none",
6565
stacksMinerSecretArn: "none",
66+
buildFromSource: false,
67+
downloadChainstate: true,
6668
dataVolume: defaultDataVolume,
6769
// High availability configs defaults.
6870
albHealthCheckGracePeriodMin: 10,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export class StacksHANodesStack extends cdk.Stack {
3131
stacksNetwork,
3232
stacksVersion,
3333
stacksNodeConfiguration,
34+
buildFromSource,
35+
downloadChainstate,
3436
// Stacks networking
3537
stacksBootstrapNode,
3638
stacksChainstateArchive,
@@ -109,6 +111,8 @@ export class StacksHANodesStack extends cdk.Stack {
109111
_DATA_VOLUME_SIZE_: dataVolumeSizeBytes.toString(),
110112
_LIFECYCLE_HOOK_NAME_: lifecycleHookName,
111113
_ASG_NAME_: autoScalingGroupName,
114+
_BUILD_FROM_SOURCE_: buildFromSource.toString(),
115+
_DOWNLOAD_CHAINSTATE_: downloadChainstate.toString(),
112116
});
113117

114118
// Path on the rpc port that will return a successful status code when the node

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class StacksSingleNodeStack extends cdk.Stack {
3434
stacksNetwork,
3535
stacksVersion,
3636
stacksNodeConfiguration,
37+
buildFromSource,
38+
downloadChainstate,
3739
// Stacks networking
3840
stacksBootstrapNode,
3941
stacksChainstateArchive,
@@ -123,6 +125,8 @@ export class StacksSingleNodeStack extends cdk.Stack {
123125
_ASSETS_S3_PATH_: `s3://${asset.s3BucketName}/${asset.s3ObjectKey}`,
124126
_LIFECYCLE_HOOK_NAME_: constants.NoneValue,
125127
_ASG_NAME_: constants.NoneValue,
128+
_BUILD_FROM_SOURCE_: buildFromSource.toString(),
129+
_DOWNLOAD_CHAINSTATE_: downloadChainstate.toString(),
126130
});
127131
node.instance.addUserData(modifiedInitNodeScript);
128132

lib/stacks/sample-configs/.env-sample-follower

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ AWS_REGION="us-west-2" # AWS region for dep
1212
# STACKS_INSTANCE_TYPE="m5.large" # The type of EC2 instance to use for the Stacks node
1313
# STACKS_CPU_TYPE="x86_64" # CPU architecture: "x86_64", "ARM_64". IMPORTANT: Ensure compatibility with instance type
1414
# STACKS_VERSION="latest" # Stacks node version to deploy. Use "latest" for the most recent version
15+
# STACKS_BUILD_FROM_SOURCE="true" # By default we download binaries from official GitHub. Uncomment to build from source.
16+
# STACKS_DOWNLOAD_CHAINSTATE="true" # Set to "false" to let the node sync data from block 0
1517
STACKS_NODE_CONFIGURATION="follower" # Node configuration type: "follower", "signer", "miner"
1618
# STACKS_BOOTSTRAP_NODE="..." # Address of the bootstrap node for network connection
1719
# STACKS_CHAINSTATE_ARCHIVE="..." # Archive node for initial chain state.

0 commit comments

Comments
 (0)