diff --git a/api/types.go b/api/types.go index 29bd7401c..0582aa251 100644 --- a/api/types.go +++ b/api/types.go @@ -55,7 +55,7 @@ type MinerInfo struct { WindowPoStPartitionSectors uint64 } -func NewApiMinerInfo(info miner.MinerInfo) MinerInfo { +func NewApiMinerInfo(info *miner.MinerInfo) MinerInfo { mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 79ad17ed7..6a46e826f 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -58,7 +58,12 @@ func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr return address.Undef, xerrors.Errorf("load state tree: %w", err) } - return vm.ResolveToKeyAddr(state, cst, mas.Info.Worker) + info, err := mas.GetInfo(sm.cs.Store(ctx)) + if err != nil { + return address.Address{}, err + } + + return vm.ResolveToKeyAddr(state, cst, info.Worker) } func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (power.Claim, power.Claim, error) { @@ -206,7 +211,12 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, nil } - spt, err := ffiwrapper.SealProofTypeFromSectorSize(mas.Info.SectorSize) + info, err := mas.GetInfo(sm.cs.Store(ctx)) + if err != nil { + return nil, err + } + + spt, err := ffiwrapper.SealProofTypeFromSectorSize(info.SectorSize) if err != nil { return nil, xerrors.Errorf("getting seal proof type: %w", err) } @@ -255,14 +265,14 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return out, nil } -func StateMinerInfo(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (miner.MinerInfo, error) { +func StateMinerInfo(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*miner.MinerInfo, error) { var mas miner.State _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, ts.ParentState()) if err != nil { - return miner.MinerInfo{}, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err) + return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err) } - return mas.Info, nil + return mas.GetInfo(sm.cs.Store(ctx)) } func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) { @@ -564,7 +574,12 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcn beacon.RandomBe return nil, xerrors.Errorf("failed to get power: %w", err) } - worker, err := sm.ResolveToKeyAddress(ctx, mas.GetWorker(), ts) + info, err := mas.GetInfo(sm.cs.Store(ctx)) + if err != nil { + return nil, err + } + + worker, err := sm.ResolveToKeyAddress(ctx, info.Worker, ts) if err != nil { return nil, xerrors.Errorf("resolving worker address: %w", err) } @@ -574,7 +589,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcn beacon.RandomBe NetworkPower: tpow.QualityAdjPower, Sectors: sectors, WorkerKey: worker, - SectorSize: mas.Info.SectorSize, + SectorSize: info.SectorSize, PrevBeaconEntry: *prev, BeaconEntries: entries, }, nil diff --git a/chain/store/store.go b/chain/store/store.go index 4dabb96f7..985bfa482 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -5,6 +5,7 @@ import ( "context" "encoding/binary" "encoding/json" + "github.com/filecoin-project/lotus/lib/adtutil" "io" "os" "sync" @@ -885,27 +886,7 @@ func (cs *ChainStore) Blockstore() bstore.Blockstore { } func ActorStore(ctx context.Context, bs blockstore.Blockstore) adt.Store { - return &astore{ - cst: cbor.NewCborStore(bs), - ctx: ctx, - } -} - -type astore struct { - cst cbor.IpldStore - ctx context.Context -} - -func (a *astore) Context() context.Context { - return a.ctx -} - -func (a *astore) Get(ctx context.Context, c cid.Cid, out interface{}) error { - return a.cst.Get(ctx, c, out) -} - -func (a *astore) Put(ctx context.Context, v interface{}) (cid.Cid, error) { - return a.cst.Put(ctx, v) + return adtutil.NewStore(ctx, cbor.NewCborStore(bs)) } func (cs *ChainStore) Store(ctx context.Context) adt.Store { diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 0c4350d03..9dfc2d894 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/filecoin-project/lotus/lib/adtutil" "sync" "time" @@ -317,7 +318,12 @@ func (bv *BlockValidator) getMinerWorkerKey(ctx context.Context, msg *types.Bloc return address.Undef, err } - worker := mst.Info.Worker + info, err := mst.GetInfo(adtutil.NewStore(ctx, cst)) + if err != nil { + return address.Undef, err + } + + worker := info.Worker key, err = bv.stmgr.ResolveToKeyAddress(ctx, worker, ts) if err != nil { return address.Undef, err diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index a6a589761..09b0950f4 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/lib/adtutil" "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -179,8 +180,13 @@ func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error { return err } + info, err := mas.GetInfo(adtutil.NewStore(ss.ctx, ss.cst)) + if err != nil { + return err + } + // and use to get resolved workerKey - waddr, err := ResolveToKeyAddr(ss.cstate, ss.cst, mas.Info.Worker) + waddr, err := ResolveToKeyAddr(ss.cstate, ss.cst, info.Worker) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index d96bd39f8..79e305fca 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -7,6 +7,7 @@ import ( "text/tabwriter" "time" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -15,9 +16,11 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" + "github.com/filecoin-project/lotus/lib/adtutil" ) var provingCmd = &cli.Command{ @@ -255,6 +258,7 @@ var provingDeadlinesCmd = &cli.Command{ } var mas miner.State + var info *miner.MinerInfo { mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) if err != nil { @@ -267,6 +271,11 @@ var provingDeadlinesCmd = &cli.Command{ if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { return err } + + info, err = mas.GetInfo(adtutil.NewStore(ctx, cbor.NewCborStore(apibstore.NewAPIBlockstore(api)))) + if err != nil { + return err + } } tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) @@ -278,12 +287,12 @@ var provingDeadlinesCmd = &cli.Command{ return err } - firstPartition, sectorCount, err := miner.PartitionsForDeadline(deadlines, mas.Info.WindowPoStPartitionSectors, uint64(i)) + firstPartition, sectorCount, err := miner.PartitionsForDeadline(deadlines, info.WindowPoStPartitionSectors, uint64(i)) if err != nil { return err } - partitionCount := (sectorCount + mas.Info.WindowPoStPartitionSectors - 1) / mas.Info.WindowPoStPartitionSectors + partitionCount := (sectorCount + info.WindowPoStPartitionSectors - 1) / info.WindowPoStPartitionSectors var provenPartitions uint64 { diff --git a/go.mod b/go.mod index 7a95c76da..ec8b5b063 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/sector-storage v0.0.0-20200701092105-a2de752a3324 - github.com/filecoin-project/specs-actors v0.7.1-0.20200629045128-8b4965e097bb + github.com/filecoin-project/specs-actors v0.7.1 github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea github.com/filecoin-project/storage-fsm v0.0.0-20200626155829-408c9a7b3336 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index d75d5ded0..8014792d4 100644 --- a/go.sum +++ b/go.sum @@ -266,6 +266,8 @@ github.com/filecoin-project/specs-actors v0.7.0 h1:tldjW8pFiJcMtyGPsXmPoFdbN/18m github.com/filecoin-project/specs-actors v0.7.0/go.mod h1:+z0htZu/wLBDbOLcQTKKUEC2rkUTFzL2KJ/bRAVWkws= github.com/filecoin-project/specs-actors v0.7.1-0.20200629045128-8b4965e097bb h1:09FJswK8kHQSJtVD49ZjwePjoS4wGrqR/Y+tl7TN10w= github.com/filecoin-project/specs-actors v0.7.1-0.20200629045128-8b4965e097bb/go.mod h1:+z0htZu/wLBDbOLcQTKKUEC2rkUTFzL2KJ/bRAVWkws= +github.com/filecoin-project/specs-actors v0.7.1 h1:/zW++MN4gGIPvG+s0zmSI97k0Z/aaeiREjLC10gQbco= +github.com/filecoin-project/specs-actors v0.7.1/go.mod h1:+z0htZu/wLBDbOLcQTKKUEC2rkUTFzL2KJ/bRAVWkws= github.com/filecoin-project/specs-storage v0.1.0 h1:PkDgTOT5W5Ao7752onjDl4QSv+sgOVdJbvFjOnD5w94= github.com/filecoin-project/specs-storage v0.1.0/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY= diff --git a/lib/adtutil/cststore.go b/lib/adtutil/cststore.go new file mode 100644 index 000000000..14575442d --- /dev/null +++ b/lib/adtutil/cststore.go @@ -0,0 +1,34 @@ +package adtutil + +import ( + "context" + + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + + "github.com/filecoin-project/specs-actors/actors/util/adt" +) + +func NewStore(ctx context.Context, cst *cbor.BasicIpldStore) adt.Store { + return &store{ + cst: cst, + ctx: ctx, + } +} + +type store struct { + cst cbor.IpldStore + ctx context.Context +} + +func (a *store) Context() context.Context { + return a.ctx +} + +func (a *store) Get(ctx context.Context, c cid.Cid, out interface{}) error { + return a.cst.Get(ctx, c, out) +} + +func (a *store) Put(ctx context.Context, v interface{}) (cid.Cid, error) { + return a.cst.Put(ctx, v) +}