-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bash scripts to build landslideVM and install avalanchego (#10)
* bash scripts to build landslideVM and install avalanchego from github release * * use avalanchego v1.11.2 * refactor VM Shutdown method to prevent nil pointer exception * fix grpc connection (allow insecure connection) * database: don't treat no data as an error "not found" for rpc database (same behaviour as cometbft database) * fix vm error during initialization using landslide-runner * define GOPATH for build script
- Loading branch information
Showing
9 changed files
with
274 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
go_version_minimum="1.20.12" | ||
|
||
go_version() { | ||
go version | sed -nE -e 's/[^0-9.]+([0-9.]+).+/\1/p' | ||
} | ||
|
||
version_lt() { | ||
# Return true if $1 is a lower version than than $2, | ||
local ver1=$1 | ||
local ver2=$2 | ||
# Reverse sort the versions, if the 1st item != ver1 then ver1 < ver2 | ||
if [[ $(echo -e -n "$ver1\n$ver2\n" | sort -rV | head -n1) != "$ver1" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
if version_lt "$(go_version)" "$go_version_minimum"; then | ||
echo "LandslideVM requires Go >= $go_version_minimum, Go $(go_version) found." >&2 | ||
exit 1 | ||
fi | ||
|
||
# Root directory | ||
SUBNET_EVM_PATH=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
cd .. && pwd | ||
) | ||
|
||
# Load the versions | ||
source "$SUBNET_EVM_PATH"/scripts/versions.sh | ||
|
||
# Load the constants | ||
source "$SUBNET_EVM_PATH"/scripts/constants.sh | ||
|
||
if [[ $# -eq 1 ]]; then | ||
BINARY_PATH=$1 | ||
elif [[ $# -eq 0 ]]; then | ||
BINARY_PATH="$GOPATH/src/github.com/ava-labs/avalanchego/build/plugins/pjSL9ksard4YE96omaiTkGL5H6XX2W5VEo3ZgWC9S2P6gzs9A" | ||
else | ||
echo "Invalid arguments to build subnet-evm. Requires zero (default location) or one argument to specify binary location." | ||
exit 1 | ||
fi | ||
|
||
# Build Subnet EVM, which is run as a subprocess | ||
echo "Building Landslide VM at $BINARY_PATH" | ||
go build -o "$BINARY_PATH" "example/countervm/"*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Set the PATHS | ||
GOPATH="$(go env GOPATH)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Load the versions | ||
SUBNET_EVM_PATH=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
cd .. && pwd | ||
) | ||
source "$SUBNET_EVM_PATH"/scripts/versions.sh | ||
|
||
## Load the constants | ||
#source "$SUBNET_EVM_PATH"/scripts/constants.sh | ||
|
||
############################ | ||
# download avalanchego | ||
# https://github.com/ava-labs/avalanchego/releases | ||
GOARCH=$(go env GOARCH) | ||
GOOS=$(go env GOOS) | ||
BASEDIR=${BASEDIR:-"/tmp/avalanchego-release"} | ||
AVALANCHEGO_BUILD_PATH=${AVALANCHEGO_BUILD_PATH:-${BASEDIR}/avalanchego} | ||
|
||
mkdir -p ${BASEDIR} | ||
|
||
AVAGO_DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/${AVALANCHE_VERSION}/avalanchego-linux-${GOARCH}-${AVALANCHE_VERSION}.tar.gz | ||
AVAGO_DOWNLOAD_PATH=${BASEDIR}/avalanchego-linux-${GOARCH}-${AVALANCHE_VERSION}.tar.gz | ||
|
||
if [[ ${GOOS} == "darwin" ]]; then | ||
AVAGO_DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/${AVALANCHE_VERSION}/avalanchego-macos-${AVALANCHE_VERSION}.zip | ||
AVAGO_DOWNLOAD_PATH=${BASEDIR}/avalanchego-macos-${AVALANCHE_VERSION}.zip | ||
fi | ||
|
||
BUILD_DIR=${AVALANCHEGO_BUILD_PATH}-${AVALANCHE_VERSION} | ||
|
||
extract_archive() { | ||
mkdir -p ${BUILD_DIR} | ||
|
||
if [[ ${AVAGO_DOWNLOAD_PATH} == *.tar.gz ]]; then | ||
tar xzvf ${AVAGO_DOWNLOAD_PATH} --directory ${BUILD_DIR} --strip-components 1 | ||
elif [[ ${AVAGO_DOWNLOAD_PATH} == *.zip ]]; then | ||
unzip ${AVAGO_DOWNLOAD_PATH} -d ${BUILD_DIR} | ||
mv ${BUILD_DIR}/build/* ${BUILD_DIR} | ||
rm -rf ${BUILD_DIR}/build/ | ||
fi | ||
} | ||
|
||
# first check if we already have the archive | ||
if [[ -f ${AVAGO_DOWNLOAD_PATH} ]]; then | ||
# if the download path already exists, extract and exit | ||
echo "found avalanchego ${AVALANCHE_VERSION} at ${AVAGO_DOWNLOAD_PATH}" | ||
|
||
extract_archive | ||
else | ||
# try to download the archive if it exists | ||
if curl -s --head --request GET ${AVAGO_DOWNLOAD_URL} | grep "302" > /dev/null; then | ||
echo "${AVAGO_DOWNLOAD_URL} found" | ||
echo "downloading to ${AVAGO_DOWNLOAD_PATH}" | ||
curl -L ${AVAGO_DOWNLOAD_URL} -o ${AVAGO_DOWNLOAD_PATH} | ||
|
||
extract_archive | ||
else | ||
# else the version is a git commitish (or it's invalid) | ||
GIT_CLONE_URL=https://github.com/ava-labs/avalanchego.git | ||
GIT_CLONE_PATH=${BASEDIR}/avalanchego-repo/ | ||
|
||
# check to see if the repo already exists, if not clone it | ||
if [[ ! -d ${GIT_CLONE_PATH} ]]; then | ||
echo "cloning ${GIT_CLONE_URL} to ${GIT_CLONE_PATH}" | ||
git clone --no-checkout ${GIT_CLONE_URL} ${GIT_CLONE_PATH} | ||
fi | ||
|
||
# check to see if the commitish exists in the repo | ||
WORKDIR=$(pwd) | ||
|
||
cd ${GIT_CLONE_PATH} | ||
|
||
git fetch | ||
|
||
echo "checking out ${AVALANCHE_VERSION}" | ||
|
||
set +e | ||
# try to checkout the branch | ||
git checkout origin/${AVALANCHE_VERSION} > /dev/null 2>&1 | ||
CHECKOUT_STATUS=$? | ||
set -e | ||
|
||
# if it's not a branch, try to checkout the commit | ||
if [[ $CHECKOUT_STATUS -ne 0 ]]; then | ||
set +e | ||
git checkout ${AVALANCHE_VERSION} > /dev/null 2>&1 | ||
CHECKOUT_STATUS=$? | ||
set -e | ||
|
||
if [[ $CHECKOUT_STATUS -ne 0 ]]; then | ||
echo | ||
echo "'${VERSION}' is not a valid release tag, commit hash, or branch name" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
COMMIT=$(git rev-parse HEAD) | ||
|
||
# use the commit hash instead of the branch name or tag | ||
BUILD_DIR=${AVALANCHEGO_BUILD_PATH}-${COMMIT} | ||
|
||
# if the build-directory doesn't exist, build avalanchego | ||
if [[ ! -d ${BUILD_DIR} ]]; then | ||
echo "building avalanchego ${COMMIT} to ${BUILD_DIR}" | ||
./scripts/build.sh | ||
mkdir -p ${BUILD_DIR} | ||
|
||
mv ${GIT_CLONE_PATH}/build/* ${BUILD_DIR}/ | ||
fi | ||
|
||
cd $WORKDIR | ||
fi | ||
fi | ||
|
||
AVALANCHEGO_PATH=${AVALANCHEGO_BUILD_PATH}/avalanchego | ||
AVALANCHEGO_PLUGIN_DIR=${AVALANCHEGO_BUILD_PATH}/plugins | ||
|
||
mkdir -p ${AVALANCHEGO_BUILD_PATH} | ||
|
||
cp ${BUILD_DIR}/avalanchego ${AVALANCHEGO_PATH} | ||
|
||
|
||
echo "Installed AvalancheGo release ${AVALANCHE_VERSION}" | ||
echo "AvalancheGo Path: ${AVALANCHEGO_PATH}" | ||
echo "Plugin Dir: ${AVALANCHEGO_PLUGIN_DIR}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Don't export them as they're used in the context of other calls | ||
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.11.2'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package block | ||
|
||
import ( | ||
"github.com/cometbft/cometbft/types" | ||
) | ||
|
||
func BlockParentHash(block *types.Block) [32]byte { | ||
var parentHash [32]byte | ||
if block.LastBlockID.Hash != nil { | ||
parentHash = [32]byte(block.LastBlockID.Hash) | ||
} | ||
|
||
return parentHash | ||
} |
Oops, something went wrong.