2020-10-13 03:00:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-10-13 03:53:14 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-10-13 03:00:29 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-10-13 03:53:14 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
lapi "github.com/filecoin-project/lotus/api"
|
2020-10-13 03:00:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
"github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var postFindCmd = &cli.Command{
|
|
|
|
Name: "post-find",
|
2020-10-13 03:53:14 +00:00
|
|
|
Description: "return addresses of all miners who have over zero power and have posted in the last day",
|
2020-10-13 03:00:29 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "tipset",
|
|
|
|
Usage: "specify tipset state to search on",
|
|
|
|
},
|
2020-10-13 03:59:30 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "verbose",
|
|
|
|
Usage: "get more frequent print updates",
|
|
|
|
},
|
2020-10-13 04:29:43 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "withpower",
|
|
|
|
Usage: "only print addrs of miners with more than zero power",
|
|
|
|
},
|
2020-10-13 03:00:29 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
ctx := lcli.ReqContext(c)
|
2020-10-13 03:59:30 +00:00
|
|
|
verbose := c.Bool("verbose")
|
2020-10-13 04:29:43 +00:00
|
|
|
withpower := c.Bool("withpower")
|
2020-10-13 03:00:29 +00:00
|
|
|
|
|
|
|
ts, err := lcli.LoadTipSet(ctx, c, api)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ts == nil {
|
|
|
|
ts, err = api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oneDayAgo := ts.Height() - abi.ChainEpoch(2880)
|
2020-10-13 03:59:30 +00:00
|
|
|
if verbose {
|
2020-10-13 04:29:43 +00:00
|
|
|
fmt.Printf("Collecting messages between %d and %d\n", ts.Height(), oneDayAgo)
|
2020-10-13 03:59:30 +00:00
|
|
|
}
|
2020-10-13 03:53:14 +00:00
|
|
|
// Get all messages over the last day
|
|
|
|
msgs := make([]*types.Message, 0)
|
|
|
|
for ts.Height() > oneDayAgo {
|
|
|
|
// Get messages on ts parent
|
|
|
|
next, err := api.ChainGetParentMessages(ctx, ts.Cids()[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
msgs = append(msgs, messagesFromAPIMessages(next)...)
|
|
|
|
|
|
|
|
// Next ts
|
|
|
|
ts, err = api.ChainGetTipSet(ctx, ts.Parents())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-13 03:59:30 +00:00
|
|
|
if verbose && int64(ts.Height())%100 == 0 {
|
|
|
|
fmt.Printf("Collected messages back to height %d\n", ts.Height())
|
|
|
|
}
|
2020-10-13 03:53:14 +00:00
|
|
|
}
|
|
|
|
fmt.Printf("Loaded messages to height %d\n", ts.Height())
|
|
|
|
|
2020-10-13 03:00:29 +00:00
|
|
|
mAddrs, err := api.StateListMiners(ctx, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-13 04:29:43 +00:00
|
|
|
minersToCheck := make(map[address.Address]struct{})
|
2020-10-13 03:00:29 +00:00
|
|
|
for _, mAddr := range mAddrs {
|
|
|
|
// if they have no power ignore. This filters out 14k inactive miners
|
|
|
|
// so we can do 100x fewer expensive message queries
|
2020-10-13 04:29:43 +00:00
|
|
|
if withpower {
|
|
|
|
power, err := api.StateMinerPower(ctx, mAddr, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if power.MinerPower.RawBytePower.GreaterThan(big.Zero()) {
|
|
|
|
minersToCheck[mAddr] = struct{}{}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minersToCheck[mAddr] = struct{}{}
|
2020-10-13 03:00:29 +00:00
|
|
|
}
|
2020-10-13 03:53:14 +00:00
|
|
|
}
|
2020-10-13 04:38:15 +00:00
|
|
|
fmt.Printf("Loaded %d miners to check\n", len(minersToCheck))
|
2020-10-13 03:53:14 +00:00
|
|
|
|
|
|
|
postedMiners := make(map[address.Address]struct{})
|
2020-10-13 04:16:51 +00:00
|
|
|
for _, msg := range msgs {
|
2020-10-13 04:29:43 +00:00
|
|
|
_, hasPower := minersToCheck[msg.To]
|
2020-10-13 03:53:14 +00:00
|
|
|
_, seenBefore := postedMiners[msg.To]
|
|
|
|
|
|
|
|
if hasPower && !seenBefore {
|
2020-10-13 03:00:29 +00:00
|
|
|
if msg.Method == builtin.MethodsMiner.SubmitWindowedPoSt {
|
2020-10-13 03:53:14 +00:00
|
|
|
fmt.Printf("%s\n", msg.To)
|
2020-10-13 04:29:43 +00:00
|
|
|
minersToCheck[msg.To] = struct{}{}
|
2020-10-13 03:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-10-13 03:53:14 +00:00
|
|
|
|
|
|
|
func messagesFromAPIMessages(apiMessages []lapi.Message) []*types.Message {
|
|
|
|
messages := make([]*types.Message, len(apiMessages))
|
|
|
|
for i, apiMessage := range apiMessages {
|
|
|
|
messages[i] = apiMessage.Message
|
|
|
|
}
|
|
|
|
return messages
|
|
|
|
}
|