Merge pull request #559 from filecoin-project/feat/faucet-miner-wait
Better miner create waiting logic in fountain
This commit is contained in:
commit
b6f4e53d43
@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
peer "github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -101,7 +102,7 @@ var runCmd = &cli.Command{
|
|||||||
WalletRate: 15 * time.Minute,
|
WalletRate: 15 * time.Minute,
|
||||||
WalletBurst: 1,
|
WalletBurst: 1,
|
||||||
}),
|
}),
|
||||||
colLimiter: NewLimiter(LimiterConfig{
|
minerLimiter: NewLimiter(LimiterConfig{
|
||||||
TotalRate: time.Second,
|
TotalRate: time.Second,
|
||||||
TotalBurst: 20,
|
TotalBurst: 20,
|
||||||
IPRate: 10 * time.Minute,
|
IPRate: 10 * time.Minute,
|
||||||
@ -114,6 +115,8 @@ var runCmd = &cli.Command{
|
|||||||
http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
|
http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
|
||||||
http.HandleFunc("/send", h.send)
|
http.HandleFunc("/send", h.send)
|
||||||
http.HandleFunc("/mkminer", h.mkminer)
|
http.HandleFunc("/mkminer", h.mkminer)
|
||||||
|
http.HandleFunc("/msgwait", h.msgwait)
|
||||||
|
http.HandleFunc("/msgwaitaddr", h.msgwaitaddr)
|
||||||
|
|
||||||
fmt.Printf("Open http://%s\n", cctx.String("front"))
|
fmt.Printf("Open http://%s\n", cctx.String("front"))
|
||||||
|
|
||||||
@ -132,8 +135,8 @@ type handler struct {
|
|||||||
|
|
||||||
from address.Address
|
from address.Address
|
||||||
|
|
||||||
limiter *Limiter
|
limiter *Limiter
|
||||||
colLimiter *Limiter
|
minerLimiter *Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -202,35 +205,35 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize, err := strconv.ParseInt(r.FormValue("sectorSize"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if owner.Protocol() != address.BLS {
|
if owner.Protocol() != address.BLS {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte("Miner address must use BLS"))
|
w.Write([]byte("Miner address must use BLS"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("mkactor on %s", owner)
|
ssize, err := strconv.ParseInt(r.FormValue("sectorSize"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("%s: create actor start", owner)
|
||||||
|
|
||||||
// Limit based on wallet address
|
// Limit based on wallet address
|
||||||
limiter := h.colLimiter.GetWalletLimiter(owner.String())
|
limiter := h.minerLimiter.GetWalletLimiter(owner.String())
|
||||||
if !limiter.Allow() {
|
if !limiter.Allow() {
|
||||||
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit based on IP
|
// Limit based on IP
|
||||||
limiter = h.colLimiter.GetIPLimiter(r.RemoteAddr)
|
limiter = h.minerLimiter.GetIPLimiter(r.RemoteAddr)
|
||||||
if !limiter.Allow() {
|
if !limiter.Allow() {
|
||||||
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// General limiter owner allow throttling all messages that can make it into the mpool
|
// General limiter owner allow throttling all messages that can make it into the mpool
|
||||||
if !h.colLimiter.Allow() {
|
if !h.minerLimiter.Allow() {
|
||||||
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -255,22 +258,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte("pushfunds: " + err.Error()))
|
w.Write([]byte("pushfunds: " + err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("push funds to %s: %s", owner, smsg.Cid())
|
log.Infof("%s: push funds %s", owner, smsg.Cid())
|
||||||
|
|
||||||
mw, err := h.api.StateWaitMsg(r.Context(), smsg.Cid())
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if mw.Receipt.ExitCode != 0 {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
w.Write([]byte(xerrors.Errorf("create storage miner failed: exit code %d", mw.Receipt.ExitCode).Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("sendto %s ok", owner)
|
|
||||||
|
|
||||||
params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
|
params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
@ -303,9 +291,20 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("smc %s", owner)
|
log.Infof("%s: create miner msg: %s", owner, signed.Cid())
|
||||||
|
|
||||||
mw, err = h.api.StateWaitMsg(r.Context(), signed.Cid())
|
http.Redirect(w, r, fmt.Sprintf("/wait.html?f=%s&m=%s&o=%s", signed.Cid(), smsg.Cid(), owner), 303)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) msgwait(w http.ResponseWriter, r *http.Request) {
|
||||||
|
c, err := cid.Parse(r.FormValue("cid"))
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mw, err := h.api.StateWaitMsg(r.Context(), c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
@ -317,6 +316,30 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(xerrors.Errorf("create storage miner failed: exit code %d", mw.Receipt.ExitCode).Error()))
|
w.Write([]byte(xerrors.Errorf("create storage miner failed: exit code %d", mw.Receipt.ExitCode).Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
w.WriteHeader(200)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) msgwaitaddr(w http.ResponseWriter, r *http.Request) {
|
||||||
|
c, err := cid.Parse(r.FormValue("cid"))
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mw, err := h.api.StateWaitMsg(r.Context(), c)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if mw.Receipt.ExitCode != 0 {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
w.Write([]byte(xerrors.Errorf("create storage miner failed: exit code %d", mw.Receipt.ExitCode).Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(200)
|
||||||
|
|
||||||
addr, err := address.NewFromBytes(mw.Receipt.Return)
|
addr, err := address.NewFromBytes(mw.Receipt.Return)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -325,8 +348,5 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
fmt.Fprintf(w, "{\"addr\": \"%s\"}", addr)
|
||||||
w.WriteHeader(200)
|
|
||||||
fmt.Fprintf(w, "New storage miners address is: %s\n", addr)
|
|
||||||
fmt.Fprintf(w, "Run lotus-storage-miner init --actor=%s --owner=%s", addr, owner)
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,10 @@ body {
|
|||||||
grid-template-columns: auto 40vw auto;
|
grid-template-columns: auto 40vw auto;
|
||||||
grid-template-rows: auto auto auto 3em;
|
grid-template-rows: auto auto auto 3em;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
". . ."
|
". . . ."
|
||||||
". main ."
|
". main main ."
|
||||||
". . ."
|
". . . ."
|
||||||
"footer footer footer";
|
"footer footer footer footer";
|
||||||
}
|
}
|
||||||
.Index-footer {
|
.Index-footer {
|
||||||
background: #2a2a2a;
|
background: #2a2a2a;
|
||||||
|
@ -45,4 +45,4 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
69
cmd/lotus-fountain/site/wait.html
Normal file
69
cmd/lotus-fountain/site/wait.html
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Sending Funds - Lotus Fountain</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="main.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="Index">
|
||||||
|
<div class="Index-nodes">
|
||||||
|
<div class="Index-node">
|
||||||
|
[CREATING STORAGE MINER]
|
||||||
|
</div>
|
||||||
|
<div class="Index-node">
|
||||||
|
Gas Funds: <span id="fcid"></span> - <span id="fstate">WAIT</span>
|
||||||
|
</div>
|
||||||
|
<div class="Index-node">
|
||||||
|
Miner Actor: <span id="mcid"></span> - <span id="mstate">WAIT</span>
|
||||||
|
</div>
|
||||||
|
<div class="Index-node" style="display: none" id="fwait">
|
||||||
|
New storage miners address is: <b id="actaddr">t</b>
|
||||||
|
</div>
|
||||||
|
<div class="Index-node" style="display: none" id="mwait">
|
||||||
|
<div style="padding-bottom: 1em">To initialize the storage miner run the following command:</div>
|
||||||
|
<div style="overflow-x: visible; white-space: nowrap; background: #353500">
|
||||||
|
<code>lotus-storage-miner init --actor=<span id="actaddr2">t</span> --owner=<span id="owner">t3</span></code>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="Index-footer">
|
||||||
|
<div>
|
||||||
|
<a href="index.html">[Back]</a>
|
||||||
|
<span style="float: right">Not dispensing real Filecoin tokens</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
const fcid = document.getElementById('fcid')
|
||||||
|
const mcid = document.getElementById('mcid')
|
||||||
|
|
||||||
|
fcid.innerText = params.get('f')
|
||||||
|
mcid.innerText = params.get('m')
|
||||||
|
|
||||||
|
async function waitFunds() {
|
||||||
|
await fetch('/msgwait?cid=' + params.get('f'))
|
||||||
|
document.getElementById('fstate').innerText = "OK"
|
||||||
|
|
||||||
|
document.getElementById('fwait').style.display = 'block'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitMiner() {
|
||||||
|
const resp = await fetch('/msgwaitaddr?cid=' + params.get('f'))
|
||||||
|
document.getElementById('mstate').innerText = "OK"
|
||||||
|
|
||||||
|
const addr = (await resp.json()).addr
|
||||||
|
|
||||||
|
document.getElementById('actaddr').innerText = addr
|
||||||
|
document.getElementById('actaddr2').innerText = addr
|
||||||
|
document.getElementById('owner').innerText = params.get('o')
|
||||||
|
|
||||||
|
document.getElementById('mwait').style.display = 'block'
|
||||||
|
}
|
||||||
|
|
||||||
|
waitFunds()
|
||||||
|
waitMiner()
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user