From bfa93bb93308a8e35473c6002ecc3c39f5fe2e26 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 27 Apr 2020 15:26:46 -0700 Subject: [PATCH] add script to run a local devnet, and helper command --- cli/cmd.go | 2 + cli/wait.go | 34 +++++++ lib/lotuslog/levels.go | 1 + scripts/devnet.bash | 196 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 cli/wait.go create mode 100755 scripts/devnet.bash diff --git a/cli/cmd.go b/cli/cmd.go index e5b8faa82..d217656f0 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -215,6 +215,7 @@ var CommonCommands = []*cli.Command{ netCmd, versionCmd, logCmd, + waitApiCmd, } var Commands = []*cli.Command{ @@ -232,4 +233,5 @@ var Commands = []*cli.Command{ versionCmd, walletCmd, logCmd, + waitApiCmd, } diff --git a/cli/wait.go b/cli/wait.go new file mode 100644 index 000000000..ce4c4dccb --- /dev/null +++ b/cli/wait.go @@ -0,0 +1,34 @@ +package cli + +import ( + "fmt" + "time" + + "gopkg.in/urfave/cli.v2" +) + +var waitApiCmd = &cli.Command{ + Name: "wait-api", + Usage: "Wait for lotus api to come online", + Action: func(cctx *cli.Context) error { + for i := 0; i < 30; i++ { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + fmt.Printf("Not online yet... (%s)\n", err) + time.Sleep(time.Second) + continue + } + defer closer() + + ctx := ReqContext(cctx) + + _, err = api.ID(ctx) + if err != nil { + return err + } + + return nil + } + return fmt.Errorf("timed out waiting for api to come online") + }, +} diff --git a/lib/lotuslog/levels.go b/lib/lotuslog/levels.go index 5f92ccc65..faf8fb137 100644 --- a/lib/lotuslog/levels.go +++ b/lib/lotuslog/levels.go @@ -16,5 +16,6 @@ func SetupLogLevels() { logging.SetLogLevel("connmgr", "WARN") logging.SetLogLevel("advmgr", "DEBUG") logging.SetLogLevel("stores", "DEBUG") + logging.SetLogLevel("nat", "INFO") } } diff --git a/scripts/devnet.bash b/scripts/devnet.bash new file mode 100755 index 000000000..ce259e77e --- /dev/null +++ b/scripts/devnet.bash @@ -0,0 +1,196 @@ +#!/usr/bin/env bash + +session="lotus-interop" +wdaemon="daemon" +wminer="miner" +wsetup="setup" +wpledging="pledging" +wcli="cli" +wshell="cli" +faucet="http://t01000.miner.interopnet.kittyhawk.wtf" + + +PLEDGE_COUNT="${1:-20}" + +if [ -z "$BRANCH" ]; then + BRANCH="interopnet" +fi + +if [ -z "$BUILD" ]; then + BUILD="no" +fi + +if [ -z "$DEVNET" ]; then + DEVNET="yes" +fi + +BASEDIR=$(mktemp -d -t "lotus-interopnet.XXXX") + +if [ "$BUILD" == "yes" ]; then + git clone --branch "$BRANCH" https://github.com/filecoin-project/lotus.git "${BASEDIR}/build" +fi + + +mkdir -p "${BASEDIR}/scripts" +mkdir -p "${BASEDIR}/bin" + +cat > "${BASEDIR}/scripts/build.bash" </dev/null 2>&1 && pwd )" +pushd \$SCRIPTDIR/../build + +pwd +env RUSTFLAGS="-C target-cpu=native -g" FFI_BUILD_FROM_SOURCE=1 make clean deps lotus lotus-storage-miner lotus-shed +cp lotus lotus-storage-miner lotus-shed ../bin/ + +popd +EOF + +cat > "${BASEDIR}/scripts/env.fish" < "${BASEDIR}/scripts/env.bash" < "${BASEDIR}/scripts/create_miner.bash" < "${BASEDIR}/scripts/pledge_sectors.bash" < ${PLEDGE_COUNT} )); then + break + fi + + while true; do + state=\$(lotus-storage-miner sectors list | tail -n1 | awk '{print \$2}') + + if [ -z "\$state" ]; then + break + fi + + case \$state in + PreCommit1 | PreCommit2 | Packing | Unsealed | PreCommitting | Committing | CommitWait | FinalizeSector ) sleep 30 ;; + WaitSeed | Proving ) break ;; + * ) echo "Unknown Sector State: \$state" + lotus-storage-miner sectors status --log \$current + break ;; + esac + done + + lotus-storage-miner sectors pledge + + while [ "\$current" == "\$sector" ]; do + sector=\$(lotus-storage-miner sectors list | tail -n1 | awk '{print \$1}' | tr -d ':') + sleep 5 + done + + current="\$sector" +done +EOF + +cat > "${BASEDIR}/scripts/monitor.bash" <&1 | tee -a ${BASEDIR}/daemon.log" C-m + +export LOTUS_PATH="${BASEDIR}/.lotus" +${BASEDIR}/bin/lotus wait-api + +tmux send-keys -t $session:$wminer "${BASEDIR}/scripts/create_miner.bash" C-m +tmux send-keys -t $session:$wminer "lotus-storage-miner run --api 48020 --nosync 2>&1 | tee -a ${BASEDIR}/miner.log" C-m +tmux send-keys -t $session:$wcli "${BASEDIR}/scripts/monitor.bash" C-m +tmux send-keys -t $session:$wpleding "${BASEDIR}/scripts/pledge_sectors.bash" C-m + +tmux select-window -t $session:$wcli + +tmux attach-session -t $session +