Merge pull request #4314 from filecoin-project/feat/lotus-pcr-block-list

Add block list to pcr
This commit is contained in:
Łukasz Magiera 2020-10-22 17:59:23 +02:00 committed by GitHub
commit 6fc8550c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,12 +6,14 @@ import (
"context"
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/filecoin-project/lotus/chain/actors/builtin"
@ -249,6 +251,15 @@ var recoverMinersCmd = &cli.Command{
}
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"))
if err != nil {
return xerrors.Errorf("parsing source address (provide correct --from flag!): %w", err)
@ -265,6 +276,12 @@ var recoverMinersCmd = &cli.Command{
minerRecoveryCutoff := uint64(cctx.Int("miner-recovery-cutoff"))
minerRecoveryBonus := uint64(cctx.Int("miner-recovery-bonus"))
blockmap := make(map[address.Address]struct{})
for _, addr := range r.Blocklist() {
blockmap[addr] = struct{}{}
}
rf := &refunder{
api: api,
wallet: from,
@ -272,6 +289,7 @@ var recoverMinersCmd = &cli.Command{
minerRecoveryRefundPercent: minerRecoveryRefundPercent,
minerRecoveryCutoff: types.FromFil(minerRecoveryCutoff),
minerRecoveryBonus: types.FromFil(minerRecoveryBonus),
blockmap: blockmap,
}
refundTipset, err := api.ChainHead(ctx)
@ -464,6 +482,12 @@ var runCmd = &cli.Command{
return err
}
blockmap := make(map[address.Address]struct{})
for _, addr := range r.Blocklist() {
blockmap[addr] = struct{}{}
}
rf := &refunder{
api: api,
wallet: from,
@ -478,13 +502,18 @@ var runCmd = &cli.Command{
publishStorageDealsEnabled: publishStorageDealsEnabled,
preFeeCapMax: types.BigInt(preFeeCapMax),
proveFeeCapMax: types.BigInt(proveFeeCapMax),
blockmap: blockmap,
}
var refunds *MinersRefund = NewMinersRefund()
var rounds int = 0
var refunds = NewMinersRefund()
var rounds = 0
nextMinerRecovery := r.MinerRecoveryHeight() + minerRecoveryPeriod
for tipset := range tipsetsCh {
for k := range rf.blockmap {
fmt.Printf("%s\n", k)
}
refunds, err = rf.ProcessTipset(ctx, tipset, refunds)
if err != nil {
return err
@ -632,6 +661,7 @@ type refunder struct {
windowedPoStEnabled bool
publishStorageDealsEnabled bool
threshold big.Int
blockmap map[address.Address]struct{}
preFeeCapMax big.Int
proveFeeCapMax big.Int
@ -736,6 +766,11 @@ func (r *refunder) EnsureMinerMinimums(ctx context.Context, tipset *types.TipSet
}
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)
if err != nil {
log.Errorw("failed", "err", err, "height", tipset.Height(), "key", tipset.Key(), "miner", maddr)
@ -895,6 +930,11 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t
refundValue := types.NewInt(0)
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 {
case miner.Methods.SubmitWindowedPoSt:
if !r.windowedPoStEnabled {
@ -1175,6 +1215,7 @@ type Repo struct {
lastHeight abi.ChainEpoch
lastMinerRecoveryHeight abi.ChainEpoch
path string
blocklist []address.Address
}
func NewRepo(path string) (*Repo, error) {
@ -1230,6 +1271,10 @@ func (r *Repo) Open() error {
return err
}
if err := r.loadBlockList(); err != nil {
return err
}
return nil
}
@ -1255,6 +1300,51 @@ func loadChainEpoch(fn string) (abi.ChainEpoch, error) {
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 {
var err error
r.lastHeight, err = loadChainEpoch(filepath.Join(r.path, "height"))
@ -1267,6 +1357,10 @@ func (r *Repo) loadMinerRecoveryHeight() error {
return err
}
func (r *Repo) Blocklist() []address.Address {
return r.blocklist
}
func (r *Repo) Height() abi.ChainEpoch {
return r.lastHeight
}