Skip to content

Commit cc0682e

Browse files
committed
Make pre-migration optional
1 parent cde4b80 commit cc0682e

File tree

5 files changed

+85
-54
lines changed

5 files changed

+85
-54
lines changed

cli/state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOut
13551355
"IsSlow": isSlow,
13561356
"IsVerySlow": isVerySlow,
13571357
"IntExit": func(i exitcode.ExitCode) int64 { return int64(i) },
1358-
"SumGas": sumGas,
1358+
"SumGas": SumGas,
13591359
"CodeStr": codeStr,
13601360
"Call": call,
13611361
"PrintTiming": func() bool { return printTiming },
@@ -1423,7 +1423,7 @@ func isVerySlow(t time.Duration) bool {
14231423
return t > 50*time.Millisecond
14241424
}
14251425

1426-
func sumGas(changes []*types.GasTrace) types.GasTrace {
1426+
func SumGas(changes []*types.GasTrace) types.GasTrace {
14271427
var out types.GasTrace
14281428
for _, gc := range changes {
14291429
out.TotalGas += gc.TotalGas

cmd/lotus-shed/gas-estimation.go

+35-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import (
88
"strconv"
99
"text/tabwriter"
1010

11-
"github.com/filecoin-project/go-state-types/abi"
12-
13-
"github.com/filecoin-project/go-state-types/network"
14-
1511
"github.com/ipfs/go-cid"
1612
"github.com/urfave/cli/v2"
1713
"golang.org/x/xerrors"
1814

15+
"github.com/filecoin-project/go-state-types/abi"
16+
"github.com/filecoin-project/go-state-types/network"
17+
1918
"github.com/filecoin-project/lotus/build"
2019
"github.com/filecoin-project/lotus/chain/beacon"
2120
"github.com/filecoin-project/lotus/chain/beacon/drand"
@@ -29,9 +28,15 @@ import (
2928
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
3029
)
3130

32-
var gasEstimationCmd = &cli.Command{
33-
Name: "estimate-gas",
34-
Description: "replay a message on the specified stateRoot and network version",
31+
// USAGE: Sync a node, then call migrate-nv17 on some old state. Pass in the cid of the migrated state root,
32+
// the epoch you migrated at, the network version you migrated to, and a message hash. You will be able to replay any
33+
// message from between the migration epoch, and where your node originally synced to. Note: You may run into issues
34+
// with nonces, or state that changed between the epoch you migrated at, and when the message was originally processed.
35+
// This can be avoided by replaying messages from close to the migration epoch, or circumvented by using a custom
36+
// FVM bundle.
37+
var gasTraceCmd = &cli.Command{
38+
Name: "trace-gas",
39+
Description: "replay a message on the specified stateRoot and network version to get an execution trace",
3540
ArgsUsage: "[migratedStateRootCid migrationEpoch networkVersion messageHash]",
3641
Flags: []cli.Flag{
3742
&cli.StringFlag{
@@ -131,11 +136,12 @@ var gasEstimationCmd = &cli.Command{
131136
return err
132137
}
133138

134-
tw := tabwriter.NewWriter(os.Stdout, 2, 2, 2, ' ', 0)
139+
tw := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', tabwriter.AlignRight)
135140
res, err := sm.CallAtStateAndVersion(ctx, msg, executionTs, stateRootCid, network.Version(nv))
136141
if err != nil {
137142
return err
138143
}
144+
fmt.Println("Total gas used ", res.MsgRct.GasUsed)
139145
printInternalExecutions(0, []types.ExecutionTrace{res.ExecutionTrace}, tw)
140146

141147
return tw.Flush()
@@ -144,10 +150,29 @@ var gasEstimationCmd = &cli.Command{
144150

145151
func printInternalExecutions(depth int, trace []types.ExecutionTrace, tw *tabwriter.Writer) {
146152
if depth == 0 {
147-
_, _ = fmt.Fprintf(tw, "depth\tFrom\tTo\tValue\tMethod\tGasUsed\tExitCode\tReturn\n")
153+
_, _ = fmt.Fprintf(tw, "Depth\tFrom\tTo\tMethod\tTotalGas\tComputeGas\tStorageGas\t\tExitCode\n")
148154
}
149155
for _, im := range trace {
150-
_, _ = 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)
156+
sumGas := lcli.SumGas(im.GasCharges)
157+
_, _ = fmt.Fprintf(tw, "%d\t%s\t%s\t%d\t%d\t%d\t%d\t\t%d\n", depth, truncateString(im.Msg.From.String(), 10), truncateString(im.Msg.To.String(), 10), im.Msg.Method, sumGas.TotalGas, sumGas.ComputeGas, sumGas.StorageGas, im.MsgRct.ExitCode)
151158
printInternalExecutions(depth+1, im.Subcalls, tw)
152159
}
153160
}
161+
162+
func truncateString(str string, length int) string {
163+
if len(str) <= length {
164+
return str
165+
}
166+
167+
truncated := ""
168+
count := 0
169+
for _, char := range str {
170+
truncated += string(char)
171+
count++
172+
if count >= length {
173+
break
174+
}
175+
}
176+
truncated += "..."
177+
return truncated
178+
}

cmd/lotus-shed/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func main() {
7676
msigCmd,
7777
fip36PollCmd,
7878
invariantsCmd,
79-
gasEstimationCmd,
79+
gasTraceCmd,
8080
}
8181

8282
app := &cli.App{

cmd/lotus-shed/migrations.go

+45-39
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ var migrationsCmd = &cli.Command{
5353
Name: "repo",
5454
Value: "~/.lotus",
5555
},
56+
&cli.BoolFlag{
57+
Name: "skip-pre-migration",
58+
},
5659
&cli.BoolFlag{
5760
Name: "check-invariants",
5861
},
@@ -119,63 +122,66 @@ var migrationsCmd = &cli.Command{
119122
return err
120123
}
121124

122-
ts1, err := cs.GetTipsetByHeight(ctx, blk.Height-240, migrationTs, false)
123-
if err != nil {
124-
return err
125-
}
126-
127125
startTime := time.Now()
128126

129-
err = filcns.PreUpgradeActorsV9(ctx, sm, cache, ts1.ParentState(), ts1.Height()-1, ts1)
127+
newCid2, err := filcns.UpgradeActorsV9(ctx, sm, nv15.NewMemMigrationCache(), nil, blk.ParentStateRoot, blk.Height-1, migrationTs)
130128
if err != nil {
131129
return err
132130
}
133131

134-
preMigration1Time := time.Since(startTime)
132+
uncachedMigrationTime := time.Since(startTime)
135133

136-
ts2, err := cs.GetTipsetByHeight(ctx, blk.Height-15, migrationTs, false)
137-
if err != nil {
138-
return err
139-
}
134+
fmt.Println("migration height ", blk.Height-1)
135+
fmt.Println("old cid ", blk.ParentStateRoot)
136+
fmt.Println("new cid ", newCid2)
137+
fmt.Println("completed round actual (without cache), took ", uncachedMigrationTime)
140138

141-
startTime = time.Now()
139+
if !cctx.IsSet("skip-pre-migration") {
140+
startTime = time.Now()
142141

143-
err = filcns.PreUpgradeActorsV9(ctx, sm, cache, ts2.ParentState(), ts2.Height()-1, ts2)
144-
if err != nil {
145-
return err
146-
}
142+
ts1, err := cs.GetTipsetByHeight(ctx, blk.Height-240, migrationTs, false)
143+
if err != nil {
144+
return err
145+
}
147146

148-
preMigration2Time := time.Since(startTime)
147+
err = filcns.PreUpgradeActorsV9(ctx, sm, cache, ts1.ParentState(), ts1.Height()-1, ts1)
148+
if err != nil {
149+
return err
150+
}
149151

150-
startTime = time.Now()
152+
preMigration1Time := time.Since(startTime)
151153

152-
newCid1, err := filcns.UpgradeActorsV9(ctx, sm, cache, nil, blk.ParentStateRoot, blk.Height-1, migrationTs)
153-
if err != nil {
154-
return err
155-
}
154+
ts2, err := cs.GetTipsetByHeight(ctx, blk.Height-15, migrationTs, false)
155+
if err != nil {
156+
return err
157+
}
156158

157-
cachedMigrationTime := time.Since(startTime)
159+
startTime = time.Now()
158160

159-
startTime = time.Now()
161+
err = filcns.PreUpgradeActorsV9(ctx, sm, cache, ts2.ParentState(), ts2.Height()-1, ts2)
162+
if err != nil {
163+
return err
164+
}
160165

161-
newCid2, err := filcns.UpgradeActorsV9(ctx, sm, nv15.NewMemMigrationCache(), nil, blk.ParentStateRoot, blk.Height-1, migrationTs)
162-
if err != nil {
163-
return err
164-
}
166+
preMigration2Time := time.Since(startTime)
165167

166-
uncachedMigrationTime := time.Since(startTime)
168+
startTime = time.Now()
167169

168-
if newCid1 != newCid2 {
169-
return xerrors.Errorf("got different results with and without the cache: %s, %s", newCid1,
170-
newCid2)
171-
}
170+
newCid1, err := filcns.UpgradeActorsV9(ctx, sm, cache, nil, blk.ParentStateRoot, blk.Height-1, migrationTs)
171+
if err != nil {
172+
return err
173+
}
172174

173-
fmt.Println("migration height ", blk.Height-1)
174-
fmt.Println("new cid ", newCid2)
175-
fmt.Println("completed premigration 1, took ", preMigration1Time)
176-
fmt.Println("completed premigration 2, took ", preMigration2Time)
177-
fmt.Println("completed round actual (with cache), took ", cachedMigrationTime)
178-
fmt.Println("completed round actual (without cache), took ", uncachedMigrationTime)
175+
cachedMigrationTime := time.Since(startTime)
176+
177+
if newCid1 != newCid2 {
178+
return xerrors.Errorf("got different results with and without the cache: %s, %s", newCid1,
179+
newCid2)
180+
}
181+
fmt.Println("completed premigration 1, took ", preMigration1Time)
182+
fmt.Println("completed premigration 2, took ", preMigration2Time)
183+
fmt.Println("completed round actual (with cache), took ", cachedMigrationTime)
184+
}
179185

180186
if cctx.Bool("check-invariants") {
181187
err = checkMigrationInvariants(ctx, blk.ParentStateRoot, newCid2, bs, blk.Height-1)

lib/consensus/raft/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func NewClusterRaftConfig(userRaftConfig *config.UserRaftConfig) *ClusterRaftCon
9797

9898
}
9999

100-
//// Validate checks that this configuration has working values,
101-
//// at least in appearance.
100+
// // Validate checks that this configuration has working values,
101+
// // at least in appearance.
102102
func ValidateConfig(cfg *ClusterRaftConfig) error {
103103
if cfg.RaftConfig == nil {
104104
return xerrors.Errorf("no hashicorp/raft.Config")

0 commit comments

Comments
 (0)