From b7c8f65af5c474310d988b59da0d036b9d252a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 7 Oct 2020 01:15:19 +0200 Subject: [PATCH 1/3] stmgr: Make v2 upgrade faster --- chain/stmgr/forks.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index d5d0dbf7e..8143524c0 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -4,6 +4,9 @@ import ( "bytes" "context" "encoding/binary" + "github.com/filecoin-project/lotus/chain/store" + bstore "github.com/filecoin-project/lotus/lib/blockstore" + "github.com/filecoin-project/lotus/lib/bufbstore" "math" "github.com/filecoin-project/go-address" @@ -490,7 +493,8 @@ func UpgradeIgnition(ctx context.Context, sm *StateManager, cb ExecCallback, roo } func UpgradeActorsV2(ctx context.Context, sm *StateManager, cb ExecCallback, root cid.Cid, ts *types.TipSet) (cid.Cid, error) { - store := sm.cs.Store(ctx) + buf := bufbstore.NewTieredBstore(sm.cs.Blockstore(), bstore.NewTemporarySync()) + store := store.ActorStore(ctx, buf) epoch := ts.Height() - 1 @@ -538,6 +542,15 @@ func UpgradeActorsV2(ctx context.Context, sm *StateManager, cb ExecCallback, roo return cid.Undef, xerrors.Errorf("failed to load init actor after upgrade: %w", err) } + { + from := buf + to := buf.Read() + + if err := vm.Copy(ctx, from, to, newRoot); err != nil { + return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) + } + } + return newRoot, nil } From 3b12a9f425c81715bf9fe0ad8087b6b880aee437 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 6 Oct 2020 16:38:31 -0700 Subject: [PATCH 2/3] Add flag to accept previous output of compute-state as input --- cli/state.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cli/state.go b/cli/state.go index cb1c974a7..b2beb8ffb 100644 --- a/cli/state.go +++ b/cli/state.go @@ -7,6 +7,7 @@ import ( "fmt" "html/template" "io" + "io/ioutil" "os" "reflect" "sort" @@ -32,6 +33,7 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/lotus/api" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" @@ -823,6 +825,10 @@ var stateComputeStateCmd = &cli.Command{ Name: "json", Usage: "generate json output", }, + &cli.StringFlag{ + Name: "compute-state-output", + Usage: "a json file containing pre-existing compute-state output, to generate html reports without rerunning state changes", + }, }, Action: func(cctx *cli.Context) error { api, closer, err := GetFullNodeAPI(cctx) @@ -862,9 +868,26 @@ var stateComputeStateCmd = &cli.Command{ } } - stout, err := api.StateCompute(ctx, h, msgs, ts.Key()) - if err != nil { - return err + var stout *lapi.ComputeStateOutput + if csofile := cctx.String("compute-state-output"); csofile != "" { + data, err := ioutil.ReadFile(csofile) + if err != nil { + return err + } + + var o lapi.ComputeStateOutput + if err := json.Unmarshal(data, &o); err != nil { + return err + } + + stout = &o + } else { + o, err := api.StateCompute(ctx, h, msgs, ts.Key()) + if err != nil { + return err + } + + stout = o } if cctx.Bool("json") { From d6fa64497446d8f8337b16411e840bcdaa46ded4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 7 Oct 2020 14:10:23 +0200 Subject: [PATCH 3/3] Fix lint --- chain/stmgr/forks.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 8143524c0..2c2304a1f 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -4,9 +4,6 @@ import ( "bytes" "context" "encoding/binary" - "github.com/filecoin-project/lotus/chain/store" - bstore "github.com/filecoin-project/lotus/lib/blockstore" - "github.com/filecoin-project/lotus/lib/bufbstore" "math" "github.com/filecoin-project/go-address" @@ -33,8 +30,11 @@ import ( init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/state" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" + bstore "github.com/filecoin-project/lotus/lib/blockstore" + "github.com/filecoin-project/lotus/lib/bufbstore" ) type UpgradeFunc func(context.Context, *StateManager, ExecCallback, cid.Cid, *types.TipSet) (cid.Cid, error) @@ -547,7 +547,7 @@ func UpgradeActorsV2(ctx context.Context, sm *StateManager, cb ExecCallback, roo to := buf.Read() if err := vm.Copy(ctx, from, to, newRoot); err != nil { - return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) + return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) } }