-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Shed/post find #4355
Changes from all commits
a3e2623
79d94c4
768d2db
c9955c0
448ca6e
0b9499a
5466144
0e88f32
619ee1e
20c57fc
2613e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
}, | ||
&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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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.