Skip to content

Commit

Permalink
Merge pull request #413 from oasisprotocol/CedarMist/oasis-deposit-mn…
Browse files Browse the repository at this point in the history
…emonic

sapphire-dev: deposit test mnemonic, core-22.2.11, optionally use single compute note
  • Loading branch information
CedarMist authored Aug 16, 2023
2 parents 8e2d308 + 60cdea7 commit f234143
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
6 changes: 5 additions & 1 deletion docker/common/oasis-deposit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ func main() {
os.Exit(1)
}

amount := flag.String("amount", "100_000_000_000_000_000_000", "amount to deposit in ParaTime base units")
amount := flag.String("amount", "100_000_000_000_000_000_000_000", "amount to deposit in ParaTime base units")
sock := flag.String("sock", "", "oasis-node internal UNIX socket address")
rtid := flag.String("rtid", "8000000000000000000000000000000000000000000000000000000000000000", "Runtime ID")
to := flag.String("to", "", "deposit address in 0x or oasis1 format or mnemonic phrase. If none provided, new mnemonic will be generated")
useTestMnemonic := flag.Bool("test-mnemonic", false, "Use the standard test mnemonic (test test test test test test test test test test test junk)")
flag.IntVar(&numMnemonicDerivations, "n", numMnemonicDerivations, "number of addresses to derive from mnemonic")
flag.Parse()

Expand Down Expand Up @@ -191,6 +192,9 @@ func main() {

toAddresses := []string{*to}
toPrivateKeys := []string{}
if *useTestMnemonic {
*to = "test test test test test test test test test test test junk"
}
if *to == "" {
// Address or mnemonic not provided. Generate a short mnemonic.
entropy, _ := bip39.NewEntropy(128)
Expand Down
24 changes: 13 additions & 11 deletions docker/common/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# - OASIS_WEB3_GATEWAY_CONFIG_FILE: path to oasis-web3-gateway config file
# - OASIS_DEPOSIT: path to oasis-deposit binary
# - SAPPHIRE_BACKEND: uses 'mock' backend by default
# - OASIS_SINGLE_COMPUTE_NODE: (default: true) if non-empty only run a single compute node

export OASIS_SINGLE_COMPUTE_NODE=${OASIS_SINGLE_COMPUTE_NODE-1}
OASIS_WEB3_GATEWAY_VERSION=$(${OASIS_WEB3_GATEWAY} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
OASIS_CORE_VERSION=$(${OASIS_NODE} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
VERSION=$(cat /VERSION)
Expand All @@ -33,42 +35,42 @@ function cleanup {

trap cleanup INT TERM EXIT

echo "Starting oasis-net-runner with ${PARATIME_NAME}..."
echo " * Starting oasis-net-runner with ${PARATIME_NAME}"
/spinup-oasis-stack.sh 2>1 &>/var/log/spinup-oasis-stack.log &
OASIS_NODE_PID=$!

echo "Starting postgresql..."
/etc/init.d/postgresql start >/dev/null
chown -R postgres:postgres /etc/postgresql /var/run/postgresql /var/log/postgresql /var/lib/postgresql/
chown postgres:ssl-cert /etc/ssl/private/
chown postgres:postgres /etc/ssl/private/ssl-cert-snakeoil.key
chmod 600 /etc/ssl/private/ssl-cert-snakeoil.key
/etc/init.d/postgresql start

echo "Starting oasis-web3-gateway..."
echo " * Starting oasis-web3-gateway"
# Wait for oasis-node socket before starting web3 gateway.
while ! [[ -S ${OASIS_NODE_SOCKET} ]]; do sleep 1; done

${OASIS_WEB3_GATEWAY} --config ${OASIS_WEB3_GATEWAY_CONFIG_FILE} 2>1 &>/var/log/oasis-web3-gateway.log &
OASIS_WEB3_GATEWAY_PID=$!

if [[ ${SAPPHIRE_BACKEND} == 'mock' ]]; then
echo -n "Bootstrapping network and populating account(s) (this might take a minute)"
echo -n " * Bootstrapping network (this might take a minute)"

# Wait for at least 2 compute nodes
echo -n .
${OASIS_NODE} debug control wait-nodes -n 2 -a unix:${OASIS_NODE_SOCKET}

echo -n .
${OASIS_NODE} debug control set-epoch --epoch 1 -a unix:${OASIS_NODE_SOCKET}
sleep 1

echo .
${OASIS_NODE} debug control set-epoch --epoch 2 -a unix:${OASIS_NODE_SOCKET}
sleep 1
echo
else
echo "Bootstrapping network and populating account(s) (this might take a minute)..."
echo
echo " * Bootstrapping network (this might take a minute)"
# Wait for compute nodes before initiating deposit.
${OASIS_NODE} debug control wait-ready -a unix:${OASIS_NODE_SOCKET}
fi

echo " * Populating accounts"
echo ""
${OASIS_DEPOSIT} -sock unix:${OASIS_NODE_SOCKET} "$@"

echo
Expand Down
13 changes: 9 additions & 4 deletions docker/sapphire-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN git clone https://github.com/oasisprotocol/oasis-core.git --branch stable/22
FROM ubuntu:22.04

# Docker-specific variables
ENV OASIS_CORE_VERSION=22.2.8
ENV OASIS_CORE_VERSION=22.2.11
ENV PARATIME_VERSION=0.5.2
ENV PARATIME_NAME=sapphire
ENV GATEWAY__CHAIN_ID=0x5afd
Expand Down Expand Up @@ -70,9 +70,14 @@ RUN unzip "paratime.orc" \
# Write VERSION information.
RUN echo "${VERSION}" > /VERSION

USER postgres
RUN /etc/init.d/postgresql start \
&& psql --command "ALTER USER postgres WITH SUPERUSER PASSWORD 'postgres';"
# Initialize PostgreSQL database, permissions need to be setup
USER root
RUN chown -R postgres:postgres /etc/postgresql /var/run/postgresql /var/log/postgresql /var/lib/postgresql/ \
&& chown postgres:ssl-cert /etc/ssl/private/ \
&& chown postgres:postgres /etc/ssl/private/ssl-cert-snakeoil.key \
&& chmod 600 /etc/ssl/private/ssl-cert-snakeoil.key \
&& /etc/init.d/postgresql start \
&& su -c "psql --command \"ALTER USER postgres WITH SUPERUSER PASSWORD 'postgres';\"" postgres

# Web3 gateway http and ws ports.
EXPOSE 8545/tcp
Expand Down
11 changes: 11 additions & 0 deletions tests/tools/spinup-oasis-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set -euo pipefail
# - PARATIME_VERSION: version of the binary. e.g. 3.0.0
# - OASIS_NODE_DATADIR: path to temporary oasis-node data dir e.g. /tmp/oasis-localnet
# - KEYMANAGER_BINARY: path to key manager binary e.g. simple-keymanager
# - OASIS_SINGLE_COMPUTE_NODE: Only run a single compute node

function paratime_ver {
echo $PARATIME_VERSION | cut -d \- -f 1 | cut -d + -f 1 | cut -d . -f $1
Expand Down Expand Up @@ -40,6 +41,16 @@ if [ ! -z "${KEYMANAGER_BINARY:-}" ]; then
RT_IDX=1
fi

# Use only one compute node
if [[ ! -z "${OASIS_SINGLE_COMPUTE_NODE:-}" ]]; then
jq "
.compute_workers = [.compute_workers[0]] |
.runtimes[1].executor.group_size = 1 |
.runtimes[1].executor.group_backup_size = 0
" "$FIXTURE_FILE" >"$FIXTURE_FILE.tmp"
mv "$FIXTURE_FILE.tmp" "$FIXTURE_FILE"
fi

# Enable expensive queries for testing.
jq "
.clients[0].runtime_config.\"${RT_IDX}\".estimate_gas_by_simulating_contracts = true |
Expand Down

0 comments on commit f234143

Please sign in to comment.