diff --git a/api/types.go b/api/types.go index 29bd7401c01..0582aa2515e 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 79ad17ed7fd..6a46e826f7a 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 4dabb96f7e0..985bfa4820e 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 0c4350d039d..9dfc2d89455 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 a6a58976138..09b0950f411 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-chainwatch/sync.go b/cmd/lotus-chainwatch/sync.go index 59e77e4a077..a3bb57c430c 100644 --- a/cmd/lotus-chainwatch/sync.go +++ b/cmd/lotus-chainwatch/sync.go @@ -61,7 +61,7 @@ type minerStateInfo struct { // miner specific state miner.State - info miner.MinerInfo + info *miner.MinerInfo // tracked by power actor rawPower big.Int @@ -315,7 +315,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, headTs *types. stateroot: c.stateroot, state: miner.State{}, - info: miner.MinerInfo{}, + info: nil, rawPower: big.Zero(), qalPower: big.Zero(), @@ -362,7 +362,11 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, headTs *types. log.Error(err) return } - mi.info = mi.state.Info + mi.info, err = mi.state.GetInfo(&apiIpldStore{ctx, api}) + if err != nil { + log.Error(err) + return + } } // TODO Get the Sector Count diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 08ae9120018..1a5d9aa9696 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -207,12 +207,13 @@ func WriteGenesisMiner(maddr address.Address, sbroot string, gm *genesis.Miner, } func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize abi.SectorSize) error { - for _, sector := range m.Sectors { + for i, sector := range m.Sectors { proposal := &market.DealProposal{ PieceCID: sector.CommD, PieceSize: abi.PaddedPieceSize(ssize), Client: k.Address, Provider: maddr, + Label: fmt.Sprintf("%d", i), StartEpoch: 0, EndEpoch: 9001, StoragePricePerEpoch: big.Zero(), diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index d96bd39f854..79e305fca03 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 4a30d42967c..197add49e68 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/drand/drand v0.9.2-0.20200616080806-a94e9c1636a4 github.com/drand/kyber v1.1.0 github.com/fatih/color v1.8.0 - github.com/filecoin-project/chain-validation v0.0.6-0.20200629051211-dc8dcf0923aa + github.com/filecoin-project/chain-validation v0.0.6-0.20200701165912-3b6aaaa32a66 github.com/filecoin-project/filecoin-ffi v0.26.1-0.20200508175440-05b30afeb00d github.com/filecoin-project/go-address v0.0.2-0.20200504173055-8b6f2fb2b3ef github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200424220931-6263827e49f2 @@ -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 96b068853c6..3145e847392 100644 --- a/go.sum +++ b/go.sum @@ -212,8 +212,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY= github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E= -github.com/filecoin-project/chain-validation v0.0.6-0.20200629051211-dc8dcf0923aa h1:SqbkG8F5DuUHJFMz+UMxNN/uwg6Ot1szP0YXCCumVv0= -github.com/filecoin-project/chain-validation v0.0.6-0.20200629051211-dc8dcf0923aa/go.mod h1:TEHSeSMoZX7agpgOhwEfiF7iP/44sIuNkA2jFYYVFTQ= +github.com/filecoin-project/chain-validation v0.0.6-0.20200701165912-3b6aaaa32a66 h1:LyYxtZe2SA2U0MV+hmDFtUHkLyvYauaahPpPZsF8Fdw= +github.com/filecoin-project/chain-validation v0.0.6-0.20200701165912-3b6aaaa32a66/go.mod h1:Tr0C0rl7WCPkkQOkrOLDR6k1ppFVgoIuj1s4KPs4bzo= github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.2-0.20200504173055-8b6f2fb2b3ef h1:Wi5E+P1QfHP8IF27eUiTx5vYfqQZwfPxzq3oFEq8w8U= @@ -264,8 +264,8 @@ github.com/filecoin-project/specs-actors v0.6.0/go.mod h1:dRdy3cURykh2R8O/DKqy8o github.com/filecoin-project/specs-actors v0.6.1/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY= github.com/filecoin-project/specs-actors v0.7.0 h1:tldjW8pFiJcMtyGPsXmPoFdbN/18mKW3BpEMlO4NJAc= 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 00000000000..14575442d55 --- /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) +} diff --git a/storage/mockstorage/preseal.go b/storage/mockstorage/preseal.go index 740deb6c9dc..ec5f0e1ca48 100644 --- a/storage/mockstorage/preseal.go +++ b/storage/mockstorage/preseal.go @@ -1,6 +1,8 @@ package mockstorage import ( + "fmt" + "github.com/filecoin-project/go-address" commcid "github.com/filecoin-project/go-fil-commcid" "github.com/filecoin-project/sector-storage/mock" @@ -50,6 +52,7 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis PieceSize: abi.PaddedPieceSize(ssize), Client: maddr, Provider: maddr, + Label: fmt.Sprintf("%d", i), StartEpoch: 1, EndEpoch: 10000, StoragePricePerEpoch: big.Zero(),