-
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
feat: cli: gas estimation tooling #9654
Merged
+446
−210
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
gas estimation shed command
- Loading branch information
commit cde4b804e3e5b59795977ee409831cd1deff245b
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strconv" | ||
"text/tabwriter" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
|
||
"github.com/filecoin-project/go-state-types/network" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/lotus/build" | ||
"github.com/filecoin-project/lotus/chain/beacon" | ||
"github.com/filecoin-project/lotus/chain/beacon/drand" | ||
"github.com/filecoin-project/lotus/chain/consensus/filcns" | ||
"github.com/filecoin-project/lotus/chain/stmgr" | ||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/chain/vm" | ||
lcli "github.com/filecoin-project/lotus/cli" | ||
"github.com/filecoin-project/lotus/node/repo" | ||
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" | ||
) | ||
|
||
var gasEstimationCmd = &cli.Command{ | ||
Name: "estimate-gas", | ||
Description: "replay a message on the specified stateRoot and network version", | ||
ArgsUsage: "[migratedStateRootCid migrationEpoch networkVersion messageHash]", | ||
geoff-vball marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "repo", | ||
Value: "~/.lotus", | ||
}, | ||
}, | ||
Action: func(cctx *cli.Context) error { | ||
ctx := context.TODO() | ||
|
||
if cctx.NArg() != 4 { | ||
return lcli.IncorrectNumArgs(cctx) | ||
} | ||
|
||
stateRootCid, err := cid.Decode(cctx.Args().Get(0)) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse input: %w", err) | ||
} | ||
|
||
epoch, err := strconv.ParseInt(cctx.Args().Get(1), 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse input: %w", err) | ||
} | ||
|
||
nv, err := strconv.ParseInt(cctx.Args().Get(2), 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse input: %w", err) | ||
} | ||
|
||
messageCid, err := cid.Decode(cctx.Args().Get(3)) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse input: %w", err) | ||
} | ||
|
||
fsrepo, err := repo.NewFS(cctx.String("repo")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
lkrepo, err := fsrepo.Lock(repo.FullNode) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer lkrepo.Close() //nolint:errcheck | ||
|
||
bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) | ||
if err != nil { | ||
return fmt.Errorf("failed to open blockstore: %w", err) | ||
} | ||
|
||
defer func() { | ||
if c, ok := bs.(io.Closer); ok { | ||
if err := c.Close(); err != nil { | ||
log.Warnf("failed to close blockstore: %s", err) | ||
} | ||
} | ||
}() | ||
|
||
mds, err := lkrepo.Datastore(context.Background(), "/metadata") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dcs := build.DrandConfigSchedule() | ||
shd := beacon.Schedule{} | ||
for _, dc := range dcs { | ||
bc, err := drand.NewDrandBeacon(1598306400, build.BlockDelaySecs, nil, dc.Config) | ||
geoff-vball marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return xerrors.Errorf("creating drand beacon: %w", err) | ||
} | ||
shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc}) | ||
} | ||
cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil) | ||
defer cs.Close() //nolint:errcheck | ||
|
||
sm, err := stmgr.NewStateManager(cs, filcns.NewTipSetExecutor(), vm.Syscalls(ffiwrapper.ProofVerifier), filcns.DefaultUpgradeSchedule(), shd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := cs.GetMessage(ctx, messageCid) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Set to block limit so message will not run out of gas | ||
msg.GasLimit = 10_000_000_000 | ||
geoff-vball marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
err = cs.Load(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
executionTs, err := cs.GetTipsetByHeight(ctx, abi.ChainEpoch(epoch), nil, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tw := tabwriter.NewWriter(os.Stdout, 2, 2, 2, ' ', 0) | ||
res, err := sm.CallAtStateAndVersion(ctx, msg, executionTs, stateRootCid, network.Version(nv)) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
printInternalExecutions(0, []types.ExecutionTrace{res.ExecutionTrace}, tw) | ||
|
||
return tw.Flush() | ||
}, | ||
} | ||
|
||
func printInternalExecutions(depth int, trace []types.ExecutionTrace, tw *tabwriter.Writer) { | ||
if depth == 0 { | ||
_, _ = fmt.Fprintf(tw, "depth\tFrom\tTo\tValue\tMethod\tGasUsed\tExitCode\tReturn\n") | ||
} | ||
for _, im := range trace { | ||
_, _ = fmt.Fprintf(tw, "%d\t%s\t%s\t%s\t%d\t%d\t%d\t%x\n", depth, im.Msg.From, im.Msg.To, im.Msg.Value, im.Msg.Method, im.MsgRct.GasUsed, im.MsgRct.ExitCode, im.MsgRct.Return) | ||
printInternalExecutions(depth+1, im.Subcalls, tw) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ func main() { | |
msigCmd, | ||
fip36PollCmd, | ||
invariantsCmd, | ||
gasEstimationCmd, | ||
} | ||
|
||
app := &cli.App{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's going on here?
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.
Due to some weird initialization stuff I do, the old beacon needs that. No idea why, that was the quickest fix for hacky code.
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.
@geoff-vball Can you check if this is needed as part of this PR?
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.
It is needed in the sense that if I remove it everything breaks. Whether or not its the best way to do things another question
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.
For the intrepid commit hunter, here's a summary of the underlying drand problem that needs to be resolved and an explanation for why this was needed here: #11802 (comment)