Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shed/post find #4355

Merged
merged 11 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
importObjectCmd,
commpToCidCmd,
fetchParamCmd,
postFindCmd,
proofsCmd,
verifRegCmd,
miscCmd,
Expand Down
129 changes: 129 additions & 0 deletions cmd/lotus-shed/postfind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package main

import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
lapi "github.com/filecoin-project/lotus/api"
"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",
Description: "return addresses of all miners who have over zero power and have posted in the last day",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tipset",
Usage: "specify tipset state to search on",
},
&cli.BoolFlag{
Name: "verbose",
Usage: "get more frequent print updates",
},
&cli.BoolFlag{
Name: "withpower",
Usage: "only print addrs of miners with more than zero power",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it could well be handy in the future for this to be a continuous parameter rather than a zero/nonzero.

},
&cli.IntFlag{
Name: "lookback",
Usage: "number of past epochs to search for post",
Value: 2880, //default 1 day
},
},
Action: func(c *cli.Context) error {
api, acloser, err := lcli.GetFullNodeAPI(c)
if err != nil {
return err
}
defer acloser()
ctx := lcli.ReqContext(c)
verbose := c.Bool("verbose")
withpower := c.Bool("withpower")

startTs, err := lcli.LoadTipSet(ctx, c, api)
if err != nil {
return err
}
if startTs == nil {
startTs, err = api.ChainHead(ctx)
if err != nil {
return err
}
}
stopEpoch := startTs.Height() - abi.ChainEpoch(c.Int("lookback"))
if verbose {
fmt.Printf("Collecting messages between %d and %d\n", startTs.Height(), stopEpoch)
}
// Get all messages over the last day
ts := startTs
msgs := make([]*types.Message, 0)
for ts.Height() > stopEpoch {
// 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
}
if verbose && int64(ts.Height())%100 == 0 {
fmt.Printf("Collected messages back to height %d\n", ts.Height())
}
}
fmt.Printf("Loaded messages to height %d\n", ts.Height())

mAddrs, err := api.StateListMiners(ctx, startTs.Key())
if err != nil {
return err
}

minersToCheck := make(map[address.Address]struct{})
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
if withpower {
power, err := api.StateMinerPower(ctx, mAddr, startTs.Key())
if err != nil {
return err
}
if power.MinerPower.RawBytePower.GreaterThan(big.Zero()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with the requirements whether you want power (excl faults and miners below min size) or committed bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. FYI no power reqs specified right, I included to see if it makes a difference today and if we should recommend that it be included.

minersToCheck[mAddr] = struct{}{}
}
} else {
minersToCheck[mAddr] = struct{}{}
}
}
fmt.Printf("Loaded %d miners to check\n", len(minersToCheck))

postedMiners := make(map[address.Address]struct{})
for _, msg := range msgs {
_, shouldCheck := minersToCheck[msg.To]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness nit: I think it's possible that a valid WindowedPost was submitted with the msg.To being the miner's robust t2 address, which will not be in the minersToCheck map.

Lotus doesn't do this by default, though, so maybe don't bother _address_ing this.

_, seenBefore := postedMiners[msg.To]

if shouldCheck && !seenBefore {
if msg.Method == builtin.MethodsMiner.SubmitWindowedPoSt {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be true for a window post that is a pre spec actors v2 upgraded window post (with a previous network param)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the SubmitWindowedPoSt method number didn't change.

fmt.Printf("%s\n", msg.To)
postedMiners[msg.To] = struct{}{}
}
}
ZenGround0 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
},
}

func messagesFromAPIMessages(apiMessages []lapi.Message) []*types.Message {
messages := make([]*types.Message, len(apiMessages))
for i, apiMessage := range apiMessages {
messages[i] = apiMessage.Message
}
return messages
}