From 75680ae502a4ad7ec9576167e27d486ae1541940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 13 Oct 2019 09:33:25 +0200 Subject: [PATCH] Quick miner deploy util --- .gitignore | 3 +++ Makefile | 6 +++++ cli/sync.go | 38 ++++++++++++++++++++++++++- cmd/lotus-fountain/main.go | 41 ++++++++++++++++++++++++------ cmd/lotus-fountain/site/index.html | 20 +++++++++++++++ scripts/deploy-miner.sh | 35 +++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 cmd/lotus-fountain/site/index.html create mode 100755 scripts/deploy-miner.sh diff --git a/.gitignore b/.gitignore index 9b0a66bcd..b229b81c6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,11 @@ /lotus-storage-miner /pond /townhall +/fountain /lotuspond/front/node_modules /lotuspond/front/build +/cmd/lotus-townhall/townhall/node_modules +/cmd/lotus-townhall/townhall/build **/*.h **/*.a **/*.pc diff --git a/Makefile b/Makefile index 441bc03fc..669228605 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,12 @@ townhall: go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall .PHONY: townhall +fountain: + rm -f fountain + go build -o fountain ./cmd/lotus-fountain + go run github.com/GeertJohan/go.rice/rice append --exec fountain -i ./cmd/lotus-fountain +.PHONY: fountain + clean: rm -rf $(CLEAN) -$(MAKE) -C $(BLS_PATH) clean diff --git a/cli/sync.go b/cli/sync.go index 868412665..2f9343d78 100644 --- a/cli/sync.go +++ b/cli/sync.go @@ -2,11 +2,13 @@ package cli import ( "fmt" + "time" + cid "github.com/ipfs/go-cid" "gopkg.in/urfave/cli.v2" + "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/chain" - cid "github.com/ipfs/go-cid" ) var syncCmd = &cli.Command{ @@ -14,6 +16,7 @@ var syncCmd = &cli.Command{ Usage: "Inspect or interact with the chain syncer", Subcommands: []*cli.Command{ syncStatusCmd, + syncWaitCmd, }, } @@ -49,3 +52,36 @@ var syncStatusCmd = &cli.Command{ return nil }, } + +var syncWaitCmd = &cli.Command{ + Name: "wait", + Usage: "Wait for sync to be complete", + Action: func(cctx *cli.Context) error { + napi, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + for { + ss, err := napi.SyncState(ctx) + if err != nil { + return err + } + + var target []cid.Cid + if ss.Target != nil { + target = ss.Target.Cids() + } + + fmt.Printf("\r\x1b[2KTarget: %s\tState: %s\tHeight: %d", target, chain.SyncStageString(ss.Stage), ss.Height) + if ss.Stage == api.StageSyncComplete { + fmt.Println("\nDone") + return nil + } + + time.Sleep(1 * time.Second) + } + }, +} diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index f6f8d91fb..40848dd5c 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -6,6 +6,7 @@ import ( "net/http" "os" + rice "github.com/GeertJohan/go.rice" logging "github.com/ipfs/go-log" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" @@ -89,8 +90,9 @@ var runCmd = &cli.Command{ from: from, } - http.HandleFunc("/", h.index) + http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox())) http.HandleFunc("/send", h.send) + http.HandleFunc("/sendcoll", h.sendColl) fmt.Printf("Open http://%s\n", cctx.String("front")) @@ -110,13 +112,6 @@ type handler struct { from address.Address } -func (h *handler) index(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "\nLotus Fountain") - fmt.Fprintf(w, "
Enter destination address: ") - fmt.Fprintf(w, "
") - fmt.Fprintf(w, "
") -} - func (h *handler) send(w http.ResponseWriter, r *http.Request) { to, err := address.NewFromString(r.FormValue("address")) if err != nil { @@ -141,3 +136,33 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { w.Write([]byte(smsg.Cid().String())) } + +func (h *handler) sendColl(w http.ResponseWriter, r *http.Request) { + to, err := address.NewFromString(r.FormValue("address")) + if err != nil { + w.WriteHeader(400) + w.Write([]byte(err.Error())) + return + } + + coll, err := h.api.StatePledgeCollateral(h.ctx, nil) + if err != nil { + return + } + + smsg, err := h.api.MpoolPushMessage(h.ctx, &types.Message{ + Value: coll, + From: h.from, + To: to, + + GasPrice: types.NewInt(0), + GasLimit: types.NewInt(1000), + }) + if err != nil { + w.WriteHeader(400) + w.Write([]byte(err.Error())) + return + } + + w.Write([]byte(smsg.Cid().String())) +} diff --git a/cmd/lotus-fountain/site/index.html b/cmd/lotus-fountain/site/index.html new file mode 100644 index 000000000..0a3d3577b --- /dev/null +++ b/cmd/lotus-fountain/site/index.html @@ -0,0 +1,20 @@ + + + + Lotus Fountain + + + +
+ Enter destination address: + + +
+ + diff --git a/scripts/deploy-miner.sh b/scripts/deploy-miner.sh new file mode 100755 index 000000000..6b6429d5c --- /dev/null +++ b/scripts/deploy-miner.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +HOST=$1 + +# upload binaries +# TODO: destroy + +ssh "$HOST" 'systemctl stop lotus-storage-miner' +ssh "$HOST" 'systemctl stop lotus-daemon' + +ssh "$HOST" 'mkdir -p .lotus .lotusstorage' & +scp "./lotus" "$HOST:/usr/local/bin" & +scp "./lotus-storage-miner" "$HOST:/usr/local/bin" & +scp -C scripts/daemon.service "${HOST}:/etc/systemd/system/lotus-daemon.service" & +scp -C scripts/sminer.service "${HOST}:/etc/systemd/system/lotus-storage-miner.service" & +wait + +ssh "$HOST" 'systemctl daemon-reload' +ssh "$HOST" 'systemctl start lotus-daemon' & +ssh "$HOST" 'systemctl start lotus-storage-miner' & +wait + +ssh "$HOST" 'lotus wallet new bls > addr' +ssh "$HOST" 'curl http://147.75.80.29:777/sendcoll?address=$(cat addr)' & +ssh "$HOST" 'curl http://147.75.80.29:777/sendcoll?address=$(cat addr)' & +ssh "$HOST" 'curl http://147.75.80.29:777/send?address=$(cat addr)' & +wait + +echo "SYNC WAIT" + +ssh "$HOST" 'lotus sync wait' +ssh "$HOST" 'lotus-storage-miner init --owner=$(cat addr)' +ssh "$HOST" 'systemctl start lotus-storage-miner' & + +# setup miner actor