Replace third_party/solana by solana-test-validator (#197)

We no longer need to carry a patch and build Solana, and can use
solana-test-validator (with sleepy PoH!) instead. This significantly reduces
build times and will make downstream testing much easier.

Also remove the remnants of do.sh and the old BPF toolchain.

Test Plan: Ran E2E tests.
This commit is contained in:
Leopold Schabel 2021-04-07 20:16:19 +02:00 committed by GitHub
parent 6de425a990
commit cc3482a607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 267 deletions

View File

@ -8,15 +8,15 @@
#
# Dockerfile Image ref StatefulSet
# +------------------------------------------------------------------------------+
# rust+1.*
# rust-1.*
# + +-----------------+
# +-> Dockerfile.agent +-> solana-agent +--------+-----> | [agent] |
# | | +--> | guardian-N |
# +-> solana/Dockerfile +-> solana-contract +---+ | | +-- --------------+
# | | | |
# +-> third_party/solana/Dockerfile <--------------+ | |
# + | | +-----------------+
# +--> solana-devnet +-------|-----> | solana-devnet |
# | | |
# | | |
# | | | +-----------------+
# +--|-----> | solana-devnet |
# golang:1.* +-----> | [setup] |
# + | +-----------------+
# +-> bridge/Dockerfile +-> guardiand-image +---------+
@ -24,7 +24,7 @@
#
# node:lts-alpine
# + +-----------------+
# +-> ethereum/Dockerfile +-> eth+node +------------------> | eth|devnet |
# +-> ethereum/Dockerfile +-> eth-node +------------------> | eth-devnet |
# +-----------------+
#
@ -109,12 +109,6 @@ docker_build(
# solana local devnet
docker_build(
ref = "solana-devnet",
context = "third_party/solana",
dockerfile = "third_party/solana/Dockerfile",
)
k8s_yaml_with_ns("devnet/solana-devnet.yaml")
k8s_resource("solana-devnet", port_forwards=[

View File

@ -35,7 +35,13 @@ spec:
terminationGracePeriodSeconds: 1
containers:
- name: devnet
image: solana-devnet
image: solana-contract
command:
- /root/.local/share/solana/install/active_release/bin/solana-test-validator
- --bpf-program
- Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o
- /opt/solana/deps/spl_bridge.so
- --log
ports:
- containerPort: 8001
name: gossip

View File

@ -9,9 +9,7 @@ WORKDIR /usr/src/bridge
RUN sh -c "$(curl -sSfL https://release.solana.com/v1.5.5/install)"
ENV PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
COPY bpf-sdk-install.sh .
COPY do.sh .
ENV RUST_LOG="solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=trace,solana_bpf_loader=debug,solana_rbpf=debug"
COPY bridge bridge
COPY agent agent
@ -24,6 +22,6 @@ RUN --mount=type=cache,target=/usr/local,from=rust,source=/usr/local \
--mount=type=cache,target=bridge/target \
--mount=type=cache,target=target \
--mount=type=cache,target=bin,from=rust,source=bin \
./do.sh build bridge && \
cargo build-bpf --manifest-path "bridge/Cargo.toml" && \
mkdir -p /opt/solana/deps && \
cp target/deploy/spl_bridge_debug.so /opt/solana/deps/spl_bridge.so

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -e
installDir=$1
channel=beta
if [[ -n $2 ]]; then
channel=$2
fi
echo "Installing $channel BPF SDK into $installDir"
set -x
cd "$installDir/"
curl -L --retry 5 --retry-delay 2 -o bpf-sdk.tar.bz2 \
https://solana-sdk.s3.amazonaws.com/"$channel"/bpf-sdk.tar.bz2
rm -rf bpf-sdk
mkdir -p bpf-sdk
tar jxf bpf-sdk.tar.bz2
rm -f bpf-sdk.tar.bz2
bpf-sdk/scripts/install.sh
cat bpf-sdk/version.txt

View File

@ -1,177 +0,0 @@
#!/usr/bin/env bash
# This script is based on Solana's upstream do.sh. If our usage of
# bpf-sdk breaks, it is best to inspect its context and check with
# Solana's latest program build workflow.
cd "$(dirname "$0")"
usage() {
cat <<EOF
Usage: do.sh <action> <project> <action specific arguments>
Supported actions:
build
build-lib
clean
clippy
doc
dump
fmt
test
update
Supported projects:
all
any directory containing a Cargo.toml file
EOF
}
sdkDir=$HOME/.local/share/solana/install/active_release/bin/sdk/bpf
profile=deploy
perform_action() {
set -e
set -x
projectDir="$PWD"/$2
targetDir=target
case "$1" in
build)
if [[ -f "$projectDir"/Xargo.toml ]]; then
# "$sdkDir"/rust/build.sh "$projectDir"
so_path="$targetDir/$profile"
cargo build-bpf --manifest-path "$projectDir/Cargo.toml"
files=`find $so_path -maxdepth 1 -type f \! -name "*_debug.so" -name "*.so"`
echo "pwd: $PWD"
for file in $files
do
cp $file ${file/.so/_debug.so} # Copy with rename
$sdkDir/scripts/strip.sh $file $file
# "$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$file"
done
else
echo "$projectDir does not contain a program, skipping"
fi
;;
build-lib)
(
cd "$projectDir"
echo "build $projectDir"
export RUSTFLAGS="${@:3}"
cargo build
)
;;
clean)
"$sdkDir"/rust/clean.sh "$projectDir"
;;
clippy)
(
cd "$projectDir"
echo "clippy $projectDir"
cargo +nightly clippy --features=program ${@:3}
)
;;
doc)
(
cd "$projectDir"
echo "generating docs $projectDir"
cargo doc ${@:3}
)
;;
dump)
# Dump depends on tools that are not installed by default and must be installed manually
# - greadelf
# - rustfilt
(
pwd
"$0" build "$2"
so_path="$targetDir/$profile"
files=`find $so_path -maxdepth 1 -type f \! -name "*_debug.so" -name "*.so"`
for file in $files
do
dump_filename="${file}_dump"
echo $file
echo $dump_filename
if [ -f "$file" ]; then
ls \
-la \
"$file" \
>"${dump_filename}_mangled.txt"
greadelf \
-aW \
"$file" \
>>"${dump_filename}_mangled.txt"
"$sdkDir/dependencies/llvm-native/bin/llvm-objdump" \
-print-imm-hex \
--source \
--disassemble \
"$file" \
>>"${dump_filename}_mangled.txt"
sed \
s/://g \
<"${dump_filename}_mangled.txt" |
rustfilt \
>"${dump_filename}.txt"
else
echo "Warning: No dump created, cannot find: $file"
fi
done
)
;;
fmt)
(
cd "$projectDir"
echo "formatting $projectDir"
cargo fmt ${@:3}
)
;;
help)
usage
exit
;;
test)
(
cd "$projectDir"
echo "test $projectDir"
cargo test --features=program ${@:3}
)
;;
# update)
# mkdir -p $sdkParentDir
# ./bpf-sdk-install.sh $sdkParentDir
# ;;
*)
echo "Error: Unknown command"
usage
exit
;;
esac
}
set -e
if [[ $1 == "update" ]]; then
perform_action "$1"
exit
else
if [[ "$#" -lt 2 ]]; then
usage
exit
fi
if [[ ! -d "$sdkDir" ]]; then
true
# ./do.sh update
fi
fi
if [[ $2 == "all" ]]; then
# Perform operation on all projects
for project in */; do
if [[ -f "$project"Cargo.toml ]]; then
perform_action "$1" "${project%/}" ${@:3}
else
continue
fi
done
else
# Perform operation on requested project
perform_action "$1" "$2" "${@:3}"
fi

View File

@ -1,17 +0,0 @@
Index: fetch-spl.sh
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- fetch-spl.sh (revision 745a97685408ff4249d96333a7885cd214639b70)
+++ fetch-spl.sh (revision 97144cdb8e9cb4d83943b0b5898d08f57844a4dd)
@@ -40,6 +40,9 @@
fetch_program token 1.0.0 TokenSVp5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o BPFLoader1111111111111111111111111111111111
fetch_program memo 1.0.0 Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo BPFLoader1111111111111111111111111111111111
+# Add bridge
+genesis_args+=(--bpf-program Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o BPFLoader2111111111111111111111111111111111 /opt/solana/deps/spl_bridge.so)
+
echo "${genesis_args[@]}" > spl-genesis-args.sh
echo

View File

@ -1,33 +0,0 @@
# syntax=docker.io/docker/dockerfile:experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44
# Depend on our smart contract build - it's going to be linked directly into Solana as part the patch we carry.
FROM solana-contract as contract
FROM docker.io/library/rust:1.49@sha256:a50165ea96983c21832578afb1c8c028674c965bc1ed43b607871b1f362e06a5
RUN apt-get update && apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang
RUN rustup component add rustfmt
WORKDIR /usr/src/solana
RUN git clone https://github.com/solana-labs/solana --branch master && \
cd solana && git checkout v1.4.25
ADD *.patch .
RUN cd solana && patch -p0 < ../Add_crypto_syscalls.patch
RUN --mount=type=cache,target=/usr/local/cargo,from=rust,source=/usr/local/cargo \
--mount=type=cache,target=solana/target \
cd solana && \
cargo build --release && \
mkdir -p /opt/solana/deps && \
cp $(find ./target/release -maxdepth 1 -type f ! -name "*.*") /opt/solana && \
cp ./target/release/deps/*.so /opt/solana/deps
COPY --from=contract /opt/solana/deps/spl_bridge.so /opt/solana/deps/spl_bridge.so
ENV PATH="/opt/solana:${PATH}"
ENV RUST_LOG="solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=trace,solana_bpf_loader=debug,solana_rbpf=debug"
CMD ["/usr/src/solana/solana/run.sh"]