From 5494d737bcc96e7aad2c5cebb061554fa797738f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sat, 11 Mar 2023 15:16:05 +0000 Subject: [PATCH] make StateCompute not write the output state to the blockstore. --- api/api_full.go | 5 ++++- chain/stmgr/utils.go | 4 +++- cmd/lotus-shed/chain.go | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index f0009e4a185..02d9d3f9f63 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/ipfs/go-cid" - blocks "github.com/ipfs/go-libipfs/blocks" + "github.com/ipfs/go-libipfs/blocks" "github.com/libp2p/go-libp2p/core/peer" "github.com/filecoin-project/go-address" @@ -606,6 +606,9 @@ type FullNode interface { // // Messages in the `apply` parameter must have the correct nonces, and gas // values set. + // + // This method does not write the resulting state to the blockstore. Usually + // that state will already exist. StateCompute(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*ComputeStateOutput, error) //perm:read // StateVerifierStatus returns the data cap for the given address. // Returns nil if there is no entry in the data cap table for the diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index c93267d50f8..cf1bd076f42 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -17,6 +17,7 @@ import ( gstStore "github.com/filecoin-project/go-state-types/store" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/blockstore" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/actors/policy" @@ -86,13 +87,14 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, // future. It's not guaranteed to be accurate... but that's fine. } + buf := blockstore.NewBuffered(sm.cs.StateBlockstore()) r := rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, sm.GetNetworkVersion) vmopt := &vm.VMOpts{ StateBase: base, Epoch: height, Timestamp: ts.MinTimestamp(), Rand: r, - Bstore: sm.cs.StateBlockstore(), + Bstore: buf, Actors: sm.tsExec.NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, diff --git a/cmd/lotus-shed/chain.go b/cmd/lotus-shed/chain.go index 9eaa427950a..cd86138d247 100644 --- a/cmd/lotus-shed/chain.go +++ b/cmd/lotus-shed/chain.go @@ -77,6 +77,10 @@ var computeStateRangeCmd = &cli.Command{ return err } + // StateCompute doesn't write the resulting state to the blockstore, + // hence state write overheads that would otherwise apply during block + // validation will not be observed here. + fmt.Printf("computing tipset at height %d (start)\n", startTs.Height()) if _, err := api.StateCompute(ctx, startTs.Height(), nil, startTs.Key()); err != nil { return err