Quick miner deploy util

This commit is contained in:
Łukasz Magiera 2019-10-13 09:33:25 +02:00
parent fa6bf55bf5
commit 75680ae502
6 changed files with 134 additions and 9 deletions

3
.gitignore vendored
View File

@ -2,8 +2,11 @@
/lotus-storage-miner /lotus-storage-miner
/pond /pond
/townhall /townhall
/fountain
/lotuspond/front/node_modules /lotuspond/front/node_modules
/lotuspond/front/build /lotuspond/front/build
/cmd/lotus-townhall/townhall/node_modules
/cmd/lotus-townhall/townhall/build
**/*.h **/*.h
**/*.a **/*.a
**/*.pc **/*.pc

View File

@ -95,6 +95,12 @@ townhall:
go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall
.PHONY: 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: clean:
rm -rf $(CLEAN) rm -rf $(CLEAN)
-$(MAKE) -C $(BLS_PATH) clean -$(MAKE) -C $(BLS_PATH) clean

View File

@ -2,11 +2,13 @@ package cli
import ( import (
"fmt" "fmt"
"time"
cid "github.com/ipfs/go-cid"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain" "github.com/filecoin-project/go-lotus/chain"
cid "github.com/ipfs/go-cid"
) )
var syncCmd = &cli.Command{ var syncCmd = &cli.Command{
@ -14,6 +16,7 @@ var syncCmd = &cli.Command{
Usage: "Inspect or interact with the chain syncer", Usage: "Inspect or interact with the chain syncer",
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{
syncStatusCmd, syncStatusCmd,
syncWaitCmd,
}, },
} }
@ -49,3 +52,36 @@ var syncStatusCmd = &cli.Command{
return nil 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)
}
},
}

View File

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
"os" "os"
rice "github.com/GeertJohan/go.rice"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -89,8 +90,9 @@ var runCmd = &cli.Command{
from: from, from: from,
} }
http.HandleFunc("/", h.index) http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
http.HandleFunc("/send", h.send) http.HandleFunc("/send", h.send)
http.HandleFunc("/sendcoll", h.sendColl)
fmt.Printf("Open http://%s\n", cctx.String("front")) fmt.Printf("Open http://%s\n", cctx.String("front"))
@ -110,13 +112,6 @@ type handler struct {
from address.Address from address.Address
} }
func (h *handler) index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<!DOCTYPE html>\n<html><head><title>Lotus Fountain</title><style>body {font-family: 'monospace';}</style></head><body>")
fmt.Fprintf(w, "<form action='/send' method='get'>Enter destination address: ")
fmt.Fprintf(w, "<input type='text' name='address'><br><button type='submit'>Send</button>")
fmt.Fprintf(w, "</form></body></html>")
}
func (h *handler) send(w http.ResponseWriter, r *http.Request) { func (h *handler) send(w http.ResponseWriter, r *http.Request) {
to, err := address.NewFromString(r.FormValue("address")) to, err := address.NewFromString(r.FormValue("address"))
if err != nil { if err != nil {
@ -141,3 +136,33 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(smsg.Cid().String())) 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()))
}

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Lotus Fountain</title>
<style>
body {
font-family: 'monospace';
background: #1f1f1f;
color: #f0f0f0;
}
</style>
</head>
<body>
<form action='/send' method='get'>
<span>Enter destination address:</span>
<input type='text' name='address' style="width: 300px">
<button type='submit'>Send</button>
</form>
</body>
</html>

35
scripts/deploy-miner.sh Executable file
View File

@ -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