Merge remote-tracking branch 'origin/master' into feat/sector-recovery

This commit is contained in:
Łukasz Magiera 2020-01-23 10:52:10 +01:00
commit f8ec1d9d22
11 changed files with 47 additions and 21 deletions

View File

@ -45,7 +45,7 @@ func setupVMTestEnv(t *testing.T) (*vm.VM, []address.Address, bstore.Blockstore)
t.Fatal(err)
}
stateroot, err := st.Flush()
stateroot, err := st.Flush(context.TODO())
if err != nil {
t.Fatal(err)
}

View File

@ -3,10 +3,11 @@ package actors_test
import (
"bytes"
"context"
"github.com/filecoin-project/go-sectorbuilder"
"math/rand"
"testing"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/ipfs/go-cid"
dstore "github.com/ipfs/go-datastore"
hamt "github.com/ipfs/go-hamt-ipld"
@ -185,7 +186,7 @@ func NewHarness(t *testing.T, options ...HarnessOpt) *Harness {
t.Fatal(err)
}
stateroot, err := st.Flush()
stateroot, err := st.Flush(context.TODO())
if err != nil {
t.Fatal(err)
}

View File

@ -8,7 +8,7 @@ import (
"go.opencensus.io/trace"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-cbor-util"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"

View File

@ -18,7 +18,7 @@ import (
"go.opencensus.io/trace"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-cbor-util"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"

View File

@ -254,7 +254,7 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
return cid.Undef, xerrors.Errorf("set storage market actor: %w", err)
}
return state.Flush()
return state.Flush(context.TODO())
}
type GenMinerCfg struct {
@ -563,7 +563,7 @@ func MakeGenesisBlock(bs bstore.Blockstore, sys *types.VMSyscalls, balances map[
return nil, xerrors.Errorf("make initial state tree failed: %w", err)
}
stateroot, err := state.Flush()
stateroot, err := state.Flush(ctx)
if err != nil {
return nil, xerrors.Errorf("flush state tree failed: %w", err)
}
@ -673,5 +673,5 @@ func AdjustInitActorStartID(ctx context.Context, bs blockstore.Blockstore, state
return cid.Undef, err
}
return tree.Flush()
return tree.Flush(ctx)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
logging "github.com/ipfs/go-log/v2"
"go.opencensus.io/trace"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -116,23 +117,29 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) {
return &act, nil
}
func (st *StateTree) Flush() (cid.Cid, error) {
func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) {
ctx, span := trace.StartSpan(ctx, "stateTree.Flush")
defer span.End()
for addr, act := range st.actorcache {
if err := st.root.Set(context.TODO(), string(addr.Bytes()), act); err != nil {
if err := st.root.Set(ctx, string(addr.Bytes()), act); err != nil {
return cid.Undef, err
}
}
st.actorcache = make(map[address.Address]*types.Actor)
if err := st.root.Flush(context.TODO()); err != nil {
if err := st.root.Flush(ctx); err != nil {
return cid.Undef, err
}
return st.Store.Put(context.TODO(), st.root)
return st.Store.Put(ctx, st.root)
}
func (st *StateTree) Snapshot() error {
ss, err := st.Flush()
func (st *StateTree) Snapshot(ctx context.Context) error {
ctx, span := trace.StartSpan(ctx, "stateTree.SnapShot")
defer span.End()
ss, err := st.Flush(ctx)
if err != nil {
return err
}

View File

@ -1,6 +1,7 @@
package state
import (
"context"
"testing"
address "github.com/filecoin-project/go-address"
@ -60,7 +61,7 @@ func BenchmarkStateTreeSetFlush(b *testing.B) {
if err != nil {
b.Fatal(err)
}
if _, err := st.Flush(); err != nil {
if _, err := st.Flush(context.TODO()); err != nil {
b.Fatal(err)
}
}
@ -88,7 +89,7 @@ func BenchmarkStateTree10kGetActor(b *testing.B) {
}
}
if _, err := st.Flush(); err != nil {
if _, err := st.Flush(context.TODO()); err != nil {
b.Fatal(err)
}

View File

@ -91,7 +91,7 @@ func fixBlizzardAMTBug(ctx context.Context, sm *StateManager, pstate cid.Cid) (c
}
}
return st.Flush()
return st.Flush(ctx)
}
func fixMiner(ctx context.Context, cst *hamt.CborIpldStore, bs blockstore.Blockstore, mscid cid.Cid) (cid.Cid, error) {

View File

@ -59,7 +59,7 @@ func NewState() *StateWrapper {
if err != nil {
panic(err) // Never returns error, the error return should be removed.
}
root, err := treeImpl.Flush()
root, err := treeImpl.Flush(context.TODO())
if err != nil {
panic(err)
}
@ -208,7 +208,7 @@ func (s *StateWrapper) Signer() *keyStore {
// Flushes a state tree to storage and sets this state's root to that tree's root CID.
func (s *StateWrapper) flush(tree *state.StateTree) (err error) {
s.stateRoot, err = tree.Flush()
s.stateRoot, err = tree.Flush(context.TODO())
return
}

View File

@ -430,7 +430,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
}
st := vm.cstate
if err := st.Snapshot(); err != nil {
if err := st.Snapshot(ctx); err != nil {
return nil, xerrors.Errorf("snapshot failed: %w", err)
}
@ -534,7 +534,7 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
from := vm.buf
to := vm.buf.Read()
root, err := vm.cstate.Flush()
root, err := vm.cstate.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}

View File

@ -6,6 +6,7 @@ import (
"context"
"io/ioutil"
"os"
"runtime/pprof"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/go-sectorbuilder"
@ -70,8 +71,24 @@ var DaemonCmd = &cli.Command{
Name: "halt-after-import",
Usage: "halt the process after importing chain from file",
},
&cli.StringFlag{
Name: "pprof",
Usage: "specify name of file for writing cpu profile to",
},
},
Action: func(cctx *cli.Context) error {
if prof := cctx.String("pprof"); prof != "" {
profile, err := os.Create(prof)
if err != nil {
return err
}
if err := pprof.StartCPUProfile(profile); err != nil {
return err
}
defer pprof.StopCPUProfile()
}
ctx := context.Background()
r, err := repo.NewFS(cctx.String("repo"))
if err != nil {