specs-actors v0.7.1

This commit is contained in:
Łukasz Magiera 2020-07-01 13:47:40 +02:00
parent 1b0d87cafd
commit 4c422c2d50
9 changed files with 87 additions and 34 deletions

View File

@ -55,7 +55,7 @@ type MinerInfo struct {
WindowPoStPartitionSectors uint64 WindowPoStPartitionSectors uint64
} }
func NewApiMinerInfo(info miner.MinerInfo) MinerInfo { func NewApiMinerInfo(info *miner.MinerInfo) MinerInfo {
mi := MinerInfo{ mi := MinerInfo{
Owner: info.Owner, Owner: info.Owner,
Worker: info.Worker, Worker: info.Worker,

View File

@ -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 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) { 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 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 { if err != nil {
return nil, xerrors.Errorf("getting seal proof type: %w", err) 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 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 var mas miner.State
_, err := sm.LoadActorStateRaw(ctx, maddr, &mas, ts.ParentState()) _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, ts.ParentState())
if err != nil { 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) { 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) 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 { if err != nil {
return nil, xerrors.Errorf("resolving worker address: %w", err) 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, NetworkPower: tpow.QualityAdjPower,
Sectors: sectors, Sectors: sectors,
WorkerKey: worker, WorkerKey: worker,
SectorSize: mas.Info.SectorSize, SectorSize: info.SectorSize,
PrevBeaconEntry: *prev, PrevBeaconEntry: *prev,
BeaconEntries: entries, BeaconEntries: entries,
}, nil }, nil

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"github.com/filecoin-project/lotus/lib/adtutil"
"io" "io"
"os" "os"
"sync" "sync"
@ -885,27 +886,7 @@ func (cs *ChainStore) Blockstore() bstore.Blockstore {
} }
func ActorStore(ctx context.Context, bs blockstore.Blockstore) adt.Store { func ActorStore(ctx context.Context, bs blockstore.Blockstore) adt.Store {
return &astore{ return adtutil.NewStore(ctx, cbor.NewCborStore(bs))
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)
} }
func (cs *ChainStore) Store(ctx context.Context) adt.Store { func (cs *ChainStore) Store(ctx context.Context) adt.Store {

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"github.com/filecoin-project/lotus/lib/adtutil"
"sync" "sync"
"time" "time"
@ -317,7 +318,12 @@ func (bv *BlockValidator) getMinerWorkerKey(ctx context.Context, msg *types.Bloc
return address.Undef, err 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) key, err = bv.stmgr.ResolveToKeyAddress(ctx, worker, ts)
if err != nil { if err != nil {
return address.Undef, err return address.Undef, err

View File

@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types" "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/lotus/lib/sigs"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/miner"
@ -179,8 +180,13 @@ func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error {
return err return err
} }
info, err := mas.GetInfo(adtutil.NewStore(ss.ctx, ss.cst))
if err != nil {
return err
}
// and use to get resolved workerKey // 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 { if err != nil {
return err return err
} }

View File

@ -7,6 +7,7 @@ import (
"text/tabwriter" "text/tabwriter"
"time" "time"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -15,9 +16,11 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/miner" "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/build"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/adtutil"
) )
var provingCmd = &cli.Command{ var provingCmd = &cli.Command{
@ -255,6 +258,7 @@ var provingDeadlinesCmd = &cli.Command{
} }
var mas miner.State var mas miner.State
var info *miner.MinerInfo
{ {
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil { if err != nil {
@ -267,6 +271,11 @@ var provingDeadlinesCmd = &cli.Command{
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
return err 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) tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
@ -278,12 +287,12 @@ var provingDeadlinesCmd = &cli.Command{
return err 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 { if err != nil {
return err return err
} }
partitionCount := (sectorCount + mas.Info.WindowPoStPartitionSectors - 1) / mas.Info.WindowPoStPartitionSectors partitionCount := (sectorCount + info.WindowPoStPartitionSectors - 1) / info.WindowPoStPartitionSectors
var provenPartitions uint64 var provenPartitions uint64
{ {

2
go.mod
View File

@ -29,7 +29,7 @@ require (
github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b 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/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/specs-storage v0.1.1-0.20200622113353-88a9704877ea
github.com/filecoin-project/storage-fsm v0.0.0-20200626155829-408c9a7b3336 github.com/filecoin-project/storage-fsm v0.0.0-20200626155829-408c9a7b3336
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1

2
go.sum
View File

@ -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.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 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-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 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.0/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k=
github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY=

34
lib/adtutil/cststore.go Normal file
View File

@ -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)
}