lotus-pcr: add blocklist

This commit is contained in:
Travis Person 2020-10-11 19:37:54 +00:00 committed by Łukasz Magiera
parent f5960df544
commit 6fb3dafa95

View File

@ -6,12 +6,14 @@ import (
"context" "context"
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin"
@ -251,6 +253,15 @@ var recoverMinersCmd = &cli.Command{
} }
defer closer() defer closer()
r, err := NewRepo(cctx.String("repo"))
if err != nil {
return err
}
if err := r.Open(); err != nil {
return err
}
from, err := address.NewFromString(cctx.String("from")) from, err := address.NewFromString(cctx.String("from"))
if err != nil { if err != nil {
return xerrors.Errorf("parsing source address (provide correct --from flag!): %w", err) return xerrors.Errorf("parsing source address (provide correct --from flag!): %w", err)
@ -267,6 +278,12 @@ var recoverMinersCmd = &cli.Command{
minerRecoveryCutoff := uint64(cctx.Int("miner-recovery-cutoff")) minerRecoveryCutoff := uint64(cctx.Int("miner-recovery-cutoff"))
minerRecoveryBonus := uint64(cctx.Int("miner-recovery-bonus")) minerRecoveryBonus := uint64(cctx.Int("miner-recovery-bonus"))
blockmap := make(map[address.Address]struct{})
for _, addr := range r.Blocklist() {
blockmap[addr] = struct{}{}
}
rf := &refunder{ rf := &refunder{
api: api, api: api,
wallet: from, wallet: from,
@ -274,6 +291,7 @@ var recoverMinersCmd = &cli.Command{
minerRecoveryRefundPercent: minerRecoveryRefundPercent, minerRecoveryRefundPercent: minerRecoveryRefundPercent,
minerRecoveryCutoff: types.FromFil(minerRecoveryCutoff), minerRecoveryCutoff: types.FromFil(minerRecoveryCutoff),
minerRecoveryBonus: types.FromFil(minerRecoveryBonus), minerRecoveryBonus: types.FromFil(minerRecoveryBonus),
blockmap: blockmap,
} }
refundTipset, err := api.ChainHead(ctx) refundTipset, err := api.ChainHead(ctx)
@ -466,6 +484,12 @@ var runCmd = &cli.Command{
return err return err
} }
blockmap := make(map[address.Address]struct{})
for _, addr := range r.Blocklist() {
blockmap[addr] = struct{}{}
}
rf := &refunder{ rf := &refunder{
api: api, api: api,
wallet: from, wallet: from,
@ -480,6 +504,7 @@ var runCmd = &cli.Command{
publishStorageDealsEnabled: publishStorageDealsEnabled, publishStorageDealsEnabled: publishStorageDealsEnabled,
preFeeCapMax: types.BigInt(preFeeCapMax), preFeeCapMax: types.BigInt(preFeeCapMax),
proveFeeCapMax: types.BigInt(proveFeeCapMax), proveFeeCapMax: types.BigInt(proveFeeCapMax),
blockmap: blockmap,
} }
var refunds *MinersRefund = NewMinersRefund() var refunds *MinersRefund = NewMinersRefund()
@ -487,6 +512,10 @@ var runCmd = &cli.Command{
nextMinerRecovery := r.MinerRecoveryHeight() + minerRecoveryPeriod nextMinerRecovery := r.MinerRecoveryHeight() + minerRecoveryPeriod
for tipset := range tipsetsCh { for tipset := range tipsetsCh {
for k, _ := range rf.blockmap {
fmt.Printf("%s\n", k)
}
refunds, err = rf.ProcessTipset(ctx, tipset, refunds) refunds, err = rf.ProcessTipset(ctx, tipset, refunds)
if err != nil { if err != nil {
return err return err
@ -634,6 +663,7 @@ type refunder struct {
windowedPoStEnabled bool windowedPoStEnabled bool
publishStorageDealsEnabled bool publishStorageDealsEnabled bool
threshold big.Int threshold big.Int
blockmap map[address.Address]struct{}
preFeeCapMax big.Int preFeeCapMax big.Int
proveFeeCapMax big.Int proveFeeCapMax big.Int
@ -738,6 +768,11 @@ func (r *refunder) EnsureMinerMinimums(ctx context.Context, tipset *types.TipSet
} }
for _, maddr := range miners { for _, maddr := range miners {
if _, found := r.blockmap[maddr]; found {
log.Debugw("skipping blocked miner", "height", tipset.Height(), "key", tipset.Key(), "miner", maddr)
continue
}
mact, err := r.api.StateGetActor(ctx, maddr, types.EmptyTSK) mact, err := r.api.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil { if err != nil {
log.Errorw("failed", "err", err, "height", tipset.Height(), "key", tipset.Key(), "miner", maddr) log.Errorw("failed", "err", err, "height", tipset.Height(), "key", tipset.Key(), "miner", maddr)
@ -897,6 +932,11 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t
refundValue := types.NewInt(0) refundValue := types.NewInt(0)
var messageMethod string var messageMethod string
if _, found := r.blockmap[m.To]; found {
log.Debugw("skipping blocked miner", "height", tipset.Height(), "key", tipset.Key(), "miner", m.To)
return false, messageMethod, types.NewInt(0), nil
}
switch m.Method { switch m.Method {
case builtin0.MethodsMiner.SubmitWindowedPoSt: case builtin0.MethodsMiner.SubmitWindowedPoSt:
if !r.windowedPoStEnabled { if !r.windowedPoStEnabled {
@ -1177,6 +1217,7 @@ type Repo struct {
lastHeight abi.ChainEpoch lastHeight abi.ChainEpoch
lastMinerRecoveryHeight abi.ChainEpoch lastMinerRecoveryHeight abi.ChainEpoch
path string path string
blocklist []address.Address
} }
func NewRepo(path string) (*Repo, error) { func NewRepo(path string) (*Repo, error) {
@ -1232,6 +1273,10 @@ func (r *Repo) Open() error {
return err return err
} }
if err := r.loadBlockList(); err != nil {
return err
}
return nil return nil
} }
@ -1257,6 +1302,51 @@ func loadChainEpoch(fn string) (abi.ChainEpoch, error) {
return abi.ChainEpoch(height), nil return abi.ChainEpoch(height), nil
} }
func (r *Repo) loadBlockList() error {
var err error
fpath := filepath.Join(r.path, "blocklist")
f, err := os.OpenFile(fpath, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
defer func() {
err = f.Close()
}()
blocklist := []address.Address{}
input := bufio.NewReader(f)
for {
stra, errR := input.ReadString('\n')
stra = strings.TrimSpace(stra)
if len(stra) == 0 {
if errR == io.EOF {
break
}
continue
}
addr, err := address.NewFromString(stra)
if err != nil {
return err
}
blocklist = append(blocklist, addr)
if errR != nil && errR != io.EOF {
return err
}
if errR == io.EOF {
break
}
}
r.blocklist = blocklist
return nil
}
func (r *Repo) loadHeight() error { func (r *Repo) loadHeight() error {
var err error var err error
r.lastHeight, err = loadChainEpoch(filepath.Join(r.path, "height")) r.lastHeight, err = loadChainEpoch(filepath.Join(r.path, "height"))
@ -1269,6 +1359,10 @@ func (r *Repo) loadMinerRecoveryHeight() error {
return err return err
} }
func (r *Repo) Blocklist() []address.Address {
return r.blocklist
}
func (r *Repo) Height() abi.ChainEpoch { func (r *Repo) Height() abi.ChainEpoch {
return r.lastHeight return r.lastHeight
} }