From d3594835c4a790026e4747badedf87af11d191f8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 11 Sep 2020 20:07:52 -0700 Subject: [PATCH 001/104] [WIP] Network upgrade support This patch starts adding support for network upgrades. * It adds an actors abstraction layer for loading abstract (cross-version) actors. * It starts switching over to a shared deadline type. * It adds an abstraction for ADTs (hamt/amt). * It removes the callback-based API in the StateManager (difficult to abstract across actor versions). * It _does not_ actually add support for actors v2. We can do that in a followup patch but that should be relatively easy. This patch is heavily WIP and does not compile. Feel free to push changes directly to this branch. Notes: * State tree access now needs a network version, because the HAMT type will change. * I haven't figured out a nice way to abstract over changes to the _message_ types. However, many of them will be type aliased to actors v0 in actors v2 so we can likely continue using the v0 versions (or use the v2 versions everywhere). I've been renaming imports to `v0*` to make it clear that we're importing types from a _specific_ actors version. TODO: * Consider merging incremental improvements? We'd have to get this compiling again first but we could merge in the new abstractions, and slowly switch over. * Finish migrating to the new abstractions. * Remove all actor state types from the public API. See `miner.State.Info()` for the planned approach here. * Fix the tests. This is likely going to be a massive pain. --- api/api_full.go | 7 +- api/types.go | 47 +------- chain/actors/adt/adt.go | 57 ++++++++++ chain/actors/adt/store.go | 17 +++ chain/actors/builtin/README.md | 29 +++++ chain/actors/builtin/builtin.go | 23 ++++ chain/actors/builtin/init/init.go | 32 ++++++ chain/actors/builtin/init/v0.go | 22 ++++ chain/actors/builtin/market/market.go | 32 ++++++ chain/actors/builtin/market/v0.go | 25 ++++ chain/actors/builtin/miner/miner.go | 59 ++++++++++ chain/actors/builtin/miner/v0.go | 112 ++++++++++++++++++ chain/actors/builtin/power/power.go | 28 +++++ chain/actors/builtin/power/v0.go | 16 +++ chain/actors/version.go | 24 ++++ chain/messagepool/provider.go | 4 +- chain/state/statetree.go | 31 ++--- chain/stmgr/read.go | 138 ++++------------------ chain/stmgr/stmgr.go | 30 ++--- chain/stmgr/utils.go | 24 ---- chain/sub/incoming.go | 16 +-- chain/sync.go | 3 +- chain/vm/invoker.go | 1 + cmd/lotus-shed/balances.go | 5 +- cmd/lotus-shed/genesis-verify.go | 2 +- cmd/lotus-storage-miner/proving.go | 157 +++++++++++--------------- extern/storage-sealing/checks.go | 4 +- go.mod | 4 +- go.sum | 6 + node/impl/full/state.go | 46 ++++---- storage/adapter_storage_miner.go | 13 +-- storage/wdpost_run.go | 103 ++++++++++++----- storage/wdpost_sched.go | 6 +- 33 files changed, 733 insertions(+), 390 deletions(-) create mode 100644 chain/actors/adt/adt.go create mode 100644 chain/actors/adt/store.go create mode 100644 chain/actors/builtin/README.md create mode 100644 chain/actors/builtin/builtin.go create mode 100644 chain/actors/builtin/init/init.go create mode 100644 chain/actors/builtin/init/v0.go create mode 100644 chain/actors/builtin/market/market.go create mode 100644 chain/actors/builtin/market/v0.go create mode 100644 chain/actors/builtin/miner/miner.go create mode 100644 chain/actors/builtin/miner/v0.go create mode 100644 chain/actors/builtin/power/power.go create mode 100644 chain/actors/builtin/power/v0.go create mode 100644 chain/actors/version.go diff --git a/api/api_full.go b/api/api_full.go index 9d1d7ab63ec..e5147db471e 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -18,6 +18,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/paych" @@ -312,15 +313,11 @@ type FullNode interface { StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*ChainSectorInfo, error) // StateMinerProvingDeadline calculates the deadline at some epoch for a proving period // and returns the deadline-related calculations. - StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*miner.DeadlineInfo, error) + StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) // StateMinerPower returns the power of the indicated miner StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) // StateMinerInfo returns info about the indicated miner StateMinerInfo(context.Context, address.Address, types.TipSetKey) (MinerInfo, error) - // StateMinerDeadlines returns all the proving deadlines for the given miner - StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) - // StateMinerPartitions loads miner partitions for the specified miner/deadline - StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]*miner.Partition, error) // StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) // StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset diff --git a/api/types.go b/api/types.go index dc843281805..4133a710562 100644 --- a/api/types.go +++ b/api/types.go @@ -8,9 +8,10 @@ import ( datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-cid" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" ma "github.com/multiformats/go-multiaddr" @@ -49,48 +50,6 @@ type PubsubScore struct { Score *pubsub.PeerScoreSnapshot } -type MinerInfo struct { - Owner address.Address // Must be an ID-address. - Worker address.Address // Must be an ID-address. - NewWorker address.Address // Must be an ID-address. - ControlAddresses []address.Address // Must be an ID-addresses. - WorkerChangeEpoch abi.ChainEpoch - PeerId *peer.ID - Multiaddrs []abi.Multiaddrs - SealProofType abi.RegisteredSealProof - SectorSize abi.SectorSize - WindowPoStPartitionSectors uint64 -} - -func NewApiMinerInfo(info *miner.MinerInfo) MinerInfo { - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - - mi := MinerInfo{ - Owner: info.Owner, - Worker: info.Worker, - ControlAddresses: info.ControlAddresses, - - NewWorker: address.Undef, - WorkerChangeEpoch: -1, - - PeerId: pid, - Multiaddrs: info.Multiaddrs, - SealProofType: info.SealProofType, - SectorSize: info.SectorSize, - WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, - } - - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - - return mi -} - type MessageSendSpec struct { MaxFee abi.TokenAmount } @@ -151,3 +110,5 @@ func NewDataTransferChannel(hostID peer.ID, channelState datatransfer.ChannelSta } return channel } + +type diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go new file mode 100644 index 00000000000..144150659e3 --- /dev/null +++ b/chain/actors/adt/adt.go @@ -0,0 +1,57 @@ +package adt + +import ( + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" +) + +type Map interface { + Root() (cid.Cid, error) + + Put(k abi.Keyer, v cbor.Marshaler) error + Get(k abi.Keyer, v cbor.Unmarshaler) (bool, error) + Delete(k abi.Keyer) error + + ForEach(v cbor.Unmarshaler, fn func(key string) error) error +} + +func AsMap(store Store, root cid.Cid, version network.Version) (Map, error) { + switch builtin.VersionForNetwork(version) { + case builtin.Version0: + return v0adt.AsMap(store, root) + } + return nil, xerrors.Errorf("unknown network version: %d", version) +} + +func NewMap(store Store, version network.Version) (Map, error) { + switch builtin.VersionForNetwork(version) { + case builtin.Version0: + return v0adt.MakeEmptyMap(store) + } + return nil, xerrors.Errorf("unknown network version: %d", version) +} + +type Array interface { + Root() (cid.Cid, error) + + Set(idx uint64, v cbor.Marshaler) error + Get(idx uint64, v cbor.Unmarshaler) (bool, error) + Delete(idx uint64) error + Length() uint64 + + ForEach(v cbor.Unmarshaler, fn func(idx int) error) error +} + +func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) { + switch builtin.VersionForNetwork(version) { + case builtin.Version0: + return v0adt.AsArray(store, root) + } + return nil, xerrors.Errorf("unknown network version: %d", version) +} diff --git a/chain/actors/adt/store.go b/chain/actors/adt/store.go new file mode 100644 index 00000000000..8dd9841a150 --- /dev/null +++ b/chain/actors/adt/store.go @@ -0,0 +1,17 @@ +package adt + +import ( + "context" + + adt "github.com/filecoin-project/specs-actors/actors/util/adt" + cbor "github.com/ipfs/go-ipld-cbor" +) + +type Store interface { + Context() context.Context + cbor.IpldStore +} + +func WrapStore(ctx context.Context, store cbor.IpldStore) Store { + return adt.WrapStore(ctx, store) +} diff --git a/chain/actors/builtin/README.md b/chain/actors/builtin/README.md new file mode 100644 index 00000000000..21b3fd38f11 --- /dev/null +++ b/chain/actors/builtin/README.md @@ -0,0 +1,29 @@ +# Actors + +This package contains shims for abstracting over different actor versions. + +## Design + +Shims in this package follow a few common design principles. + +### Structure Agnostic + +Shims interfaces defined in this package should (ideally) not change even if the +structure of the underlying data changes. For example: + +* All shims store an internal "store" object. That way, state can be moved into + a separate object without needing to add a store to the function signature. +* All functions must return an error, even if unused for now. + +### Minimal + +These interfaces should be expanded only as necessary to reduce maintenance burden. + +### Queries, not field assessors. + +When possible, functions should query the state instead of simply acting as +field assessors. These queries are more likely to remain stable across +specs-actor upgrades than specific state fields. + +Note: there is a trade-off here. Avoid implementing _complicated_ query logic +inside these shims, as it will need to be replicated in every shim. diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go new file mode 100644 index 00000000000..173f50ba678 --- /dev/null +++ b/chain/actors/builtin/builtin.go @@ -0,0 +1,23 @@ +package builtin + +import ( + "fmt" + + "github.com/filecoin-project/go-state-types/network" +) + +type Version int + +const ( + Version0 = iota +) + +// Converts a network version into a specs-actors version. +func VersionForNetwork(version network.Version) Version { + switch version { + case network.Version0, network.Version1: + return Version + default: + panic(fmt.Sprintf("unsupported network version %d", version)) + } +} diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go new file mode 100644 index 00000000000..de71a032c3e --- /dev/null +++ b/chain/actors/builtin/init/init.go @@ -0,0 +1,32 @@ +package init + +import ( + "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/cbor" + "golang.org/x/xerrors" + + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +func Load(store adt.Store, act *types.Actor) (State, error) { + switch act.Code { + case v0builtin.InitActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + ResolveAddress(address addr.Address) (address.Address, bool, error) + MapAddressToNewID(address addr.Address) (address.Address, error) +} diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go new file mode 100644 index 00000000000..3a94f59f088 --- /dev/null +++ b/chain/actors/builtin/init/v0.go @@ -0,0 +1,22 @@ +package init + +import ( + "github.com/filecoin-project/go-address" + + "github.com/filecoin-project/specs-actors/actors/builtin/init" + + "github.com/filecoin-project/lotus/chain/actors/adt" +) + +type v0State struct { + init.State + store adt.Store +} + +func (s *v0State) ResolveAddress(address address.Address) (address.Address, bool, error) { + return s.State.ResolveAddress(s.store, address) +} + +func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, error) { + return s.State.MapAddressToNewID(s.store, address) +} diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go new file mode 100644 index 00000000000..663fa0e8391 --- /dev/null +++ b/chain/actors/builtin/market/market.go @@ -0,0 +1,32 @@ +package market + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" + "github.com/ipfs/go-cid" +) + +func Load(store adt.Store, act *types.Actor) (st State, err error) { + switch act.Code { + case v0builtin.MarketActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + EscrowTable() (BalanceTable, error) + LockedTable() (BalanceTable, error) + TotalLocked() (abi.TokenAmount, error) +} + +type BalanceTable interface { + Get(key address.Address) (abi.TokenAmount, error) +} diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go new file mode 100644 index 00000000000..23f33e3d326 --- /dev/null +++ b/chain/actors/builtin/market/v0.go @@ -0,0 +1,25 @@ +package market + +import ( + "github.com/filecoin-project/specs-actors/actors/builtin/market" + "github.com/filecoin-project/specs-actors/actors/util/adt" +) + +type v0State struct { + market.State + store adt.Store +} + +func (s *v0State) TotalLocked() (abi.TokenAmount, error) { + fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) + fml = types.BigAdd(fml, s.TotalClientStorageFee) + return fml, nil +} + +func (s *v0State) EscrowTable() (BalanceTable, error) { + return adt.AsBalanceTable(s.store, s.State.EscrowTable) +} + +func (s *v0State) Lockedtable() (BalanceTable, error) { + return adt.AsBalanceTable(s.store, s.State.LockedTable) +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go new file mode 100644 index 00000000000..50453827daf --- /dev/null +++ b/chain/actors/builtin/miner/miner.go @@ -0,0 +1,59 @@ +package miner + +import ( + "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/abi" + "golang.org/x/xerrors" + + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +func Load(store adt.Store, act *types.Actor) (st State, err error) { + switch act.Code { + case v0builtin.StorageMinerActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + LoadDeadline(idx uint64) (Deadline, error) + ForEachDeadline(cb func(idx uint64, dl Deadline) error) error + NumDeadlines() (uint64, error) +} + +type Deadline interface { + LoadPartition(idx uint64) (Partition, error) + ForEachPartition(cb func(idx uint64, part Partition) error) error +} + +type Partition interface { + AllSectors() (bitfield.BitField, error) + FaultySectors() (bitfield.BitField, error) + RecoveringSectors() (bitfield.BitField, error) + LiveSectors() (bitfield.BitField, error) + ActiveSectors() (bitfield.BitField, error) +} + +type MinerInfo struct { + Owner address.Address // Must be an ID-address. + Worker address.Address // Must be an ID-address. + NewWorker address.Address // Must be an ID-address. + ControlAddresses []address.Address // Must be an ID-addresses. + WorkerChangeEpoch abi.ChainEpoch + PeerId *peer.ID + Multiaddrs []abi.Multiaddrs + SealProofType abi.RegisteredSealProof + SectorSize abi.SectorSize + WindowPoStPartitionSectors uint64 +} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go new file mode 100644 index 00000000000..8898a26a5c2 --- /dev/null +++ b/chain/actors/builtin/miner/v0.go @@ -0,0 +1,112 @@ +package miner + +import ( + "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/libp2p/go-libp2p-core/peer" + + "github.com/filecoin-project/specs-actors/actors/builtin/miner" +) + +type v0State struct { + miner.State + store adt.Store +} + +type v0Deadline struct { + miner.Deadline + store adt.Store +} + +type v0Partition struct { + miner.Partition + store adt.Store +} + +func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + dl, err := dls.LoadDeadline(s.store, idx) + if err != nil { + return nil, err + } + return &v0Deadline{*dl, s.store}, nil +} + +func (s *v0State) ForEachDeadline(cb func(uint64, Deadline) error) error { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + return dls.ForEach(s.store, func(i uint64, dl *miner.Deadline) error { + return cb(i, &v0Deadline{*dl, s.store}) + }) +} + +func (s *v0State) NumDeadlines() (uint64, error) { + return miner.WPoStPeriodDeadlines, nil +} + +func (s *v0State) Info() (MinerInfo, error) { + info, err := s.State.GetInfo(s.store) + + var pid *peer.ID + if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { + pid = &peerID + } + + mi := MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + + NewWorker: address.Undef, + WorkerChangeEpoch: -1, + + PeerId: pid, + Multiaddrs: info.Multiaddrs, + SealProofType: info.SealProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + } + + if info.PendingWorkerKey != nil { + mi.NewWorker = info.PendingWorkerKey.NewWorker + mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt + } + + return mi +} + +func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { + p, err := d.Deadline.LoadPartition(d.store, idx) + if err != nil { + return nil, err + } + return &v0Partition{*p, d.store}, nil +} + +func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { + ps, err := d.Deadline.PartitionsArray(d.store) + if err != nil { + return err + } + var part miner.Partition + return ps.ForEach(&part, func(i int64) error { + return cb(uint64(i), &v0Partition{part, d.store}) + }) +} + +func (p *v0Partition) AllSectors() (bitfield.BitField, error) { + return p.Partition.Sectors, nil +} + +func (p *v0Partition) FaultySectors() (bitfield.BitField, error) { + return p.Partition.Faults, nil +} + +func (p *v0Partition) RecoveringSectors() (bitfield.BitField, error) { + return p.Partition.Recoveries, nil +} diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go new file mode 100644 index 00000000000..7671877e352 --- /dev/null +++ b/chain/actors/builtin/power/power.go @@ -0,0 +1,28 @@ +package power + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" + "golang.org/x/xerrors" +) + +func Load(store adt.Store, act *types.Actor) (st State, err error) { + switch act.Code { + case v0builtin.PowerActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + TotalLocked() (abi.TokenAmount, error) +} diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go new file mode 100644 index 00000000000..8851080e623 --- /dev/null +++ b/chain/actors/builtin/power/v0.go @@ -0,0 +1,16 @@ +package power + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/specs-actors/actors/builtin/power" +) + +type v0State struct { + power.State + store adt.Store +} + +func (s *v0State) TotalLocked() (abi.TokenAmount, error) { + return s.TotalPledgeCollateral, nil +} diff --git a/chain/actors/version.go b/chain/actors/version.go new file mode 100644 index 00000000000..99cc59eaad0 --- /dev/null +++ b/chain/actors/version.go @@ -0,0 +1,24 @@ +package actors + +import ( + "fmt" + + "github.com/filecoin-project/go-state-types/network" +) + +type Version int + +const ( + Version0 = iota + Version1 +) + +// VersionForNetwork resolves the network version into an specs-actors version. +func VersionForNetwork(v network.Version) Version { + switch v { + case network.Version0, network.Version1: + return Version0 + default: + panic(fmt.Sprintf("unimplemented network version: %d", v)) + } +} diff --git a/chain/messagepool/provider.go b/chain/messagepool/provider.go index 80b9a4297e9..d67468d9a9c 100644 --- a/chain/messagepool/provider.go +++ b/chain/messagepool/provider.go @@ -52,8 +52,8 @@ func (mpp *mpoolProvider) GetActorAfter(addr address.Address, ts *types.TipSet) if err != nil { return nil, xerrors.Errorf("computing tipset state for GetActor: %w", err) } - - return &act, mpp.sm.WithStateTree(stcid, mpp.sm.WithActor(addr, stmgr.GetActor(&act))) + version := mpp.sm.GetNtwkVersion(context.TODO(), ts.Height()) + return &act, mpp.sm.WithStateTree(stcid, version, mpp.sm.WithActor(addr, stmgr.GetActor(&act))) } func (mpp *mpoolProvider) StateAccountKey(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { diff --git a/chain/state/statetree.go b/chain/state/statetree.go index c083f1817e0..684e6ce5d9d 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -4,10 +4,12 @@ import ( "context" "fmt" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin/init" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -22,7 +24,7 @@ var log = logging.Logger("statetree") // StateTree stores actors state by their ID. type StateTree struct { - root *adt.Map + root adt.Map Store cbor.IpldStore snaps *stateSnaps @@ -115,17 +117,18 @@ func (ss *stateSnaps) deleteActor(addr address.Address) { ss.layers[len(ss.layers)-1].actors[addr] = streeOp{Delete: true} } -func NewStateTree(cst cbor.IpldStore) (*StateTree, error) { +func NewStateTree(cst cbor.IpldStore, version network.Version) (*StateTree, error) { return &StateTree{ - root: adt.MakeEmptyMap(adt.WrapStore(context.TODO(), cst)), + root: adt.NewMap(adt.WrapStore(context.TODO(), cst), version), Store: cst, snaps: newStateSnaps(), }, nil } -func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { - nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), c) +func LoadStateTree(cst cbor.IpldStore, c cid.Cid, version network.Version) (*StateTree, error) { + // NETUPGRADE: switch map adt type on version upgrade. + nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), c, version) if err != nil { log.Errorf("loading hamt node %s failed: %s", c, err) return nil, err @@ -165,12 +168,12 @@ func (st *StateTree) LookupID(addr address.Address) (address.Address, error) { return address.Undef, xerrors.Errorf("getting init actor: %w", err) } - var ias init_.State - if err := st.Store.Get(context.TODO(), act.Head, &ias); err != nil { + ias, err := init.Load(&AdtStore{st.Store}, &act) + if err != nil { return address.Undef, xerrors.Errorf("loading init actor state: %w", err) } - a, found, err := ias.ResolveAddress(&AdtStore{st.Store}, addr) + a, found, err := ias.ResolveAddress(addr) if err == nil && !found { err = types.ErrActorNotFound } @@ -283,18 +286,18 @@ func (st *StateTree) ClearSnapshot() { func (st *StateTree) RegisterNewAddress(addr address.Address) (address.Address, error) { var out address.Address err := st.MutateActor(builtin.InitActorAddr, func(initact *types.Actor) error { - var ias init_.State - if err := st.Store.Get(context.TODO(), initact.Head, &ias); err != nil { + ias, err := init.Load(&AdtStore{st.Store}, initact) + if err != nil { return err } - oaddr, err := ias.MapAddressToNewID(&AdtStore{st.Store}, addr) + oaddr, err := ias.MapAddressToNewID(addr) if err != nil { return err } out = oaddr - ncid, err := st.Store.Put(context.TODO(), &ias) + ncid, err := st.Store.Put(context.TODO(), ias) if err != nil { return err } diff --git a/chain/stmgr/read.go b/chain/stmgr/read.go index c707b51954e..2daa9f79d5a 100644 --- a/chain/stmgr/read.go +++ b/chain/stmgr/read.go @@ -10,146 +10,54 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" ) -type StateTreeCB func(state *state.StateTree) error - -func (sm *StateManager) WithParentStateTsk(tsk types.TipSetKey, cb StateTreeCB) error { +func (sm *StateManager) ParentStateTsk(tsk types.TipSetKey) (*state.StateTree, error) { ts, err := sm.cs.GetTipSetFromKey(tsk) if err != nil { - return xerrors.Errorf("loading tipset %s: %w", tsk, err) - } - - cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, sm.parentState(ts)) - if err != nil { - return xerrors.Errorf("load state tree: %w", err) + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - - return cb(state) + return sm.ParentState(ts, cb) } -func (sm *StateManager) WithParentState(ts *types.TipSet, cb StateTreeCB) error { +func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, sm.parentState(ts)) + version := sm.GetNtwkVersion(context.TODO(), ts.Height()-1) + state, err := state.LoadStateTree(cst, sm.parentState(ts), version) if err != nil { - return xerrors.Errorf("load state tree: %w", err) + return nil, xerrors.Errorf("load state tree: %w", err) } - return cb(state) + return state, nil } -func (sm *StateManager) WithStateTree(st cid.Cid, cb StateTreeCB) error { +func (sm *StateManager) StateTree(st cid.Cid, ntwkVersion network.Version) (*state.StateTree, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, st) + state, err := state.LoadStateTree(cst, st, ntwkVersion) if err != nil { - return xerrors.Errorf("load state tree: %w", err) - } - - return cb(state) -} - -type ActorCB func(act *types.Actor) error - -func GetActor(out *types.Actor) ActorCB { - return func(act *types.Actor) error { - *out = *act - return nil + return nil, xerrors.Errorf("load state tree: %w", err) } -} -func (sm *StateManager) WithActor(addr address.Address, cb ActorCB) StateTreeCB { - return func(state *state.StateTree) error { - act, err := state.GetActor(addr) - if err != nil { - return xerrors.Errorf("get actor: %w", err) - } - - return cb(act) - } + return state, nil } -// WithActorState usage: -// Option 1: WithActorState(ctx, idAddr, func(store adt.Store, st *ActorStateType) error {...}) -// Option 2: WithActorState(ctx, idAddr, actorStatePtr) -func (sm *StateManager) WithActorState(ctx context.Context, out interface{}) ActorCB { - return func(act *types.Actor) error { - store := sm.cs.Store(ctx) - - outCallback := reflect.TypeOf(out).Kind() == reflect.Func - - var st reflect.Value - if outCallback { - st = reflect.New(reflect.TypeOf(out).In(1).Elem()) - } else { - st = reflect.ValueOf(out) - } - if err := store.Get(ctx, act.Head, st.Interface()); err != nil { - return xerrors.Errorf("read actor head: %w", err) - } - - if outCallback { - out := reflect.ValueOf(out).Call([]reflect.Value{reflect.ValueOf(store), st}) - if !out[0].IsNil() && out[0].Interface().(error) != nil { - return out[0].Interface().(error) - } - } - - return nil - } -} - -type DeadlinesCB func(store adt.Store, deadlines *miner.Deadlines) error - -func (sm *StateManager) WithDeadlines(cb DeadlinesCB) func(store adt.Store, mas *miner.State) error { - return func(store adt.Store, mas *miner.State) error { - deadlines, err := mas.LoadDeadlines(store) - if err != nil { - return err - } - - return cb(store, deadlines) - } -} - -type DeadlineCB func(store adt.Store, idx uint64, deadline *miner.Deadline) error - -func (sm *StateManager) WithDeadline(idx uint64, cb DeadlineCB) DeadlinesCB { - return func(store adt.Store, deadlines *miner.Deadlines) error { - d, err := deadlines.LoadDeadline(store, idx) - if err != nil { - return err - } - - return cb(store, idx, d) - } -} - -func (sm *StateManager) WithEachDeadline(cb DeadlineCB) DeadlinesCB { - return func(store adt.Store, deadlines *miner.Deadlines) error { - return deadlines.ForEach(store, func(dlIdx uint64, dl *miner.Deadline) error { - return cb(store, dlIdx, dl) - }) +func (sm *StateManager) LoadActor(_ context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, error) { + state, err := sm.ParentState(ts) + if err != nil { + return nil, err } + return state.GetActor(addr) } -type PartitionCB func(store adt.Store, idx uint64, partition *miner.Partition) error - -func (sm *StateManager) WithEachPartition(cb PartitionCB) DeadlineCB { - return func(store adt.Store, idx uint64, deadline *miner.Deadline) error { - parts, err := deadline.PartitionsArray(store) - if err != nil { - return err - } - - var partition miner.Partition - return parts.ForEach(&partition, func(i int64) error { - p := partition - return cb(store, uint64(i), &p) - }) +func (sm *StateManager) LoadActorTsk(_ context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) { + state, err := sm.ParentStateTsk(tsk) + if err != nil { + return nil, err } + return state.GetActor(addr) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 929c9daf778..fa4b08147b1 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -7,14 +7,14 @@ import ( "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -201,6 +200,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp for i := parentEpoch; i < epoch; i++ { // handle state forks + // XXX: The state tre err = sm.handleStateForks(ctx, vmi.StateTree(), i, ts) if err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err) @@ -711,11 +711,14 @@ func (sm *StateManager) ListAllActors(ctx context.Context, ts *types.TipSet) ([] } func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, ts *types.TipSet) (api.MarketBalance, error) { - var state market.State - _, err := sm.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts) + st, err := sm.ParentState(ts) if err != nil { return api.MarketBalance{}, err } + act, err := st.GetActor(builtin.StorageMarketActorAddr) + if err != nil { + return nil, err + } addr, err = sm.LookupID(ctx, addr, ts) if err != nil { @@ -1016,19 +1019,17 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err } func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { - mactor, err := st.GetActor(builtin.StorageMarketActorAddr) + act, err := st.GetActor(builtin.StorageMarketActorAddr) if err != nil { return big.Zero(), xerrors.Errorf("failed to load market actor: %w", err) } - var mst market.State - if err := st.Store.Get(ctx, mactor.Head, &mst); err != nil { + mst, err := market.Load(adt.WrapStore(ctx, st.Store), act) + if err != nil { return big.Zero(), xerrors.Errorf("failed to load market state: %w", err) } - fml := types.BigAdd(mst.TotalClientLockedCollateral, mst.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, mst.TotalClientStorageFee) - return fml, nil + return mst.TotalLocked() } func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { @@ -1037,11 +1038,12 @@ func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmoun return big.Zero(), xerrors.Errorf("failed to load power actor: %w", err) } - var pst power.State - if err := st.Store.Get(ctx, pactor.Head, &pst); err != nil { + pst, err := power.Load(adt.WrapStore(ctx, st.Store), act) + if err != nil { return big.Zero(), xerrors.Errorf("failed to load power state: %w", err) } - return pst.TotalPledgeCollateral, nil + + return pst.TotalLocked(), nil } func (sm *StateManager) GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index b21400da688..a137afb51ee 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -56,30 +56,6 @@ func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.N return dtypes.NetworkName(state.NetworkName), nil } -func (sm *StateManager) LoadActorState(ctx context.Context, addr address.Address, out interface{}, ts *types.TipSet) (*types.Actor, error) { - var a *types.Actor - if err := sm.WithParentState(ts, sm.WithActor(addr, func(act *types.Actor) error { - a = act - return sm.WithActorState(ctx, out)(act) - })); err != nil { - return nil, err - } - - return a, nil -} - -func (sm *StateManager) LoadActorStateRaw(ctx context.Context, addr address.Address, out interface{}, st cid.Cid) (*types.Actor, error) { - var a *types.Actor - if err := sm.WithStateTree(st, sm.WithActor(addr, func(act *types.Actor) error { - a = act - return sm.WithActorState(ctx, out)(act) - })); err != nil { - return nil, err - } - - return a, nil -} - func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) { var mas miner.State _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, st) diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 34dde227fa7..7c672bee290 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -11,7 +11,6 @@ import ( "golang.org/x/xerrors" address "github.com/filecoin-project/go-address" - miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" lru "github.com/hashicorp/golang-lru" blocks "github.com/ipfs/go-block-format" @@ -28,6 +27,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" @@ -432,9 +432,10 @@ func (bv *BlockValidator) checkPowerAndGetWorkerKey(ctx context.Context, bh *typ if err != nil { return address.Undef, err } + buf := bufbstore.NewBufferedBstore(bv.chain.Blockstore()) cst := cbor.NewCborStore(buf) - state, err := state.LoadStateTree(cst, st) + state, err := state.LoadStateTree(cst, st, bv.stmgr.GetNtwkVersion(ctx, ts.Height())) if err != nil { return address.Undef, err } @@ -443,19 +444,12 @@ func (bv *BlockValidator) checkPowerAndGetWorkerKey(ctx context.Context, bh *typ return address.Undef, err } - blk, err := bv.chain.Blockstore().Get(act.Head) - if err != nil { - return address.Undef, err - } - aso := blk.RawData() - - var mst miner.State - err = mst.UnmarshalCBOR(bytes.NewReader(aso)) + mst, err := miner.Load(bv.chain.Store(ctx), act) if err != nil { return address.Undef, err } - info, err := mst.GetInfo(adt.WrapStore(ctx, cst)) + info, err := mst.Info() if err != nil { return address.Undef, err } diff --git a/chain/sync.go b/chain/sync.go index d2cf08b925b..d5bd777b754 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1027,9 +1027,10 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock if err != nil { return err } + nwVersion := syncer.sm.GetNtwkVersion(ctx, baseTs.Height()) cst := cbor.NewCborStore(syncer.store.Blockstore()) - st, err := state.LoadStateTree(cst, stateroot) + st, err := state.LoadStateTree(cst, stateroot, nwVersion) if err != nil { return xerrors.Errorf("failed to load base state tree: %w", err) } diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 2ec56a9dbe9..8583b0438a0 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -47,6 +47,7 @@ func NewInvoker() *Invoker { } // add builtInCode using: register(cid, singleton) + // NETUPGRADE: register code IDs for v2, etc. inv.Register(builtin.SystemActorCodeID, system.Actor{}, adt.EmptyValue{}) inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{}) inv.Register(builtin.RewardActorCodeID, reward.Actor{}, reward.State{}) diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index aad3217834c..f3ffd140fb9 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -12,6 +12,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -170,7 +171,9 @@ var chainBalanceStateCmd = &cli.Command{ sm := stmgr.NewStateManager(cs) - tree, err := state.LoadStateTree(cst, sroot) + // NETUPGRADE: FIXME. + // Options: (a) encode the version in the chain or (b) pass a flag. + tree, err := state.LoadStateTree(cst, sroot, network.Version0) if err != nil { return err } diff --git a/cmd/lotus-shed/genesis-verify.go b/cmd/lotus-shed/genesis-verify.go index 043cb72bb8b..62808db9ba2 100644 --- a/cmd/lotus-shed/genesis-verify.go +++ b/cmd/lotus-shed/genesis-verify.go @@ -79,7 +79,7 @@ var genesisVerifyCmd = &cli.Command{ cst := cbor.NewCborStore(bs) - stree, err := state.LoadStateTree(cst, ts.ParentState()) + stree, err := state.LoadStateTree(cst, ts.ParentState(), sm.GetNtwkVersion()) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index b5087556db5..d9bf813763c 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -12,9 +12,11 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/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/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) @@ -49,54 +51,41 @@ var provingFaultsCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) + stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(api)) + maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) if err != nil { return err } - var mas miner.State - { - mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) - if err != nil { - return err - } - rmas, err := api.ChainReadObj(ctx, mact.Head) - if err != nil { - return err - } - if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { - return err - } - } - - fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) - - head, err := api.ChainHead(ctx) + mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) if err != nil { - return xerrors.Errorf("getting chain head: %w", err) + return err } - deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key()) + + mas, err := miner.Load(stor, mact) if err != nil { - return xerrors.Errorf("getting miner deadlines: %w", err) + return err } + + fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) + tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) _, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors") - for dlIdx := range deadlines { - partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK) - if err != nil { - return xerrors.Errorf("loading partitions for deadline %d: %w", dlIdx, err) - } - - for partIdx, partition := range partitions { - faulty, err := partition.Faults.All(10000000) + err = mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { + dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + faults, err := part.Faults() if err != nil { return err } - - for _, num := range faulty { + faults.ForEach(func(num uint64) error { _, _ = fmt.Fprintf(tw, "%d\t%d\t%d\n", dlIdx, partIdx, num) - } - } + return nil + }) + }) + }) + if err != nil { + return err } return tw.Flush() }, @@ -132,67 +121,61 @@ var provingInfoCmd = &cli.Command{ return xerrors.Errorf("getting chain head: %w", err) } - cd, err := api.StateMinerProvingDeadline(ctx, maddr, head.Key()) + mact, err := api.StateGetActor(ctx, maddr, head.Key()) if err != nil { - return xerrors.Errorf("getting miner info: %w", err) + return err } - deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key()) + stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(api)) + + mas, err := miner.Load(stor, mact) if err != nil { - return xerrors.Errorf("getting miner deadlines: %w", err) + return err } - fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) - - var mas miner.State - { - mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) - if err != nil { - return err - } - rmas, err := api.ChainReadObj(ctx, mact.Head) - if err != nil { - return err - } - if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { - return err - } + cd, err := api.StateMinerProvingDeadline(ctx, maddr, head.Key()) + if err != nil { + return xerrors.Errorf("getting miner info: %w", err) } - parts := map[uint64][]*miner.Partition{} - for dlIdx := range deadlines { - part, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK) - if err != nil { - return xerrors.Errorf("getting miner partition: %w", err) - } - - parts[uint64(dlIdx)] = part - } + fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) proving := uint64(0) faults := uint64(0) recovering := uint64(0) + curDeadlineSectors := uint64(0) - for _, partitions := range parts { - for _, partition := range partitions { - sc, err := partition.Sectors.Count() - if err != nil { - return xerrors.Errorf("count partition sectors: %w", err) + if err := mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { + return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + if bf, err := part.LiveSectors(); err != nil { + return err + } else if count, err := bf.Count(); err != nil { + return err + } else { + proving += count + if dlIdx == cd.Index { + curDeadlineSectors += count + } } - proving += sc - fc, err := partition.Faults.Count() - if err != nil { - return xerrors.Errorf("count partition faults: %w", err) + if bf, err := part.Faults(); err != nil { + return err + } else if count, err := bf.Count(); err != nil { + return err + } else { + faults += count } - faults += fc - rc, err := partition.Recoveries.Count() - if err != nil { - return xerrors.Errorf("count partition recoveries: %w", err) + if bf, err := part.Recovering(); err != nil { + return err + } else if count, err := bf.Count(); err != nil { + return err + } else { + recovering += count } - recovering += rc - } + }) + }); err != nil { + return xerrors.Errorf("walking miner deadlines and partitions: %w", err) } var faultPerc float64 @@ -202,28 +185,15 @@ var provingInfoCmd = &cli.Command{ fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch) - fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod) + fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%cd.WPoStProvingPeriod) fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart)) - fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart+miner.WPoStProvingPeriod)) + fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart+cd.WPoStProvingPeriod)) fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc) fmt.Printf("Recovering: %d\n", recovering) fmt.Printf("Deadline Index: %d\n", cd.Index) - - if cd.Index < miner.WPoStPeriodDeadlines { - curDeadlineSectors := uint64(0) - for _, partition := range parts[cd.Index] { - sc, err := partition.Sectors.Count() - if err != nil { - return xerrors.Errorf("counting current deadline sectors: %w", err) - } - curDeadlineSectors += sc - } - - fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors) - } - + fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors) fmt.Printf("Deadline Open: %s\n", epochTime(cd.CurrentEpoch, cd.Open)) fmt.Printf("Deadline Close: %s\n", epochTime(cd.CurrentEpoch, cd.Close)) fmt.Printf("Deadline Challenge: %s\n", epochTime(cd.CurrentEpoch, cd.Challenge)) @@ -286,6 +256,7 @@ var provingDeadlinesCmd = &cli.Command{ if err != nil { return err } + miner.Load rmas, err := api.ChainReadObj(ctx, mact.Head) if err != nil { return err diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index 906c9c106cf..074c4cfcff9 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -4,7 +4,7 @@ import ( "bytes" "context" - saproof "github.com/filecoin-project/specs-actors/actors/runtime/proof" + v0proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" "golang.org/x/xerrors" @@ -170,7 +170,7 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte, log.Warn("on-chain sealed CID doesn't match!") } - ok, err := m.verif.VerifySeal(saproof.SealVerifyInfo{ + ok, err := m.verif.VerifySeal(v0proof.SealVerifyInfo{ SectorID: m.minerSector(si.SectorNumber), SealedCID: pci.Info.SealedCID, SealProof: spt, diff --git a/go.mod b/go.mod index bc4067d67e6..9a7c5403bf3 100644 --- a/go.mod +++ b/go.mod @@ -34,11 +34,11 @@ require ( github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 - github.com/filecoin-project/go-state-types v0.0.0-20200905071437-95828685f9df + github.com/filecoin-project/go-state-types v0.0.0-20200911004822-964d6c679cfc github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370 github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b - github.com/filecoin-project/specs-actors v0.9.7 + github.com/filecoin-project/specs-actors v0.9.9-0.20200911231631-727cd8845d30 github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 github.com/filecoin-project/test-vectors/schema v0.0.1 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 0fa13fe70e2..106814b0220 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,8 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1 github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-markets v0.6.0 h1:gfxMweUHo4u+2BZh2Q7/7+cV0/ttikuJfhkkxLRsE2Q= github.com/filecoin-project/go-fil-markets v0.6.0/go.mod h1:LhSFYLkjaoe0vFRKABGYyw1Jz+9jCpF1sPA7yOftLTw= +github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= +github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 h1:FXtCp0ybqdQL9knb3OGDpkNTaBbPxgkqPeWKotUwkH0= github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0DzzQwqsL0XarpnI= @@ -238,6 +240,8 @@ github.com/filecoin-project/go-state-types v0.0.0-20200903145444-247639ffa6ad/go github.com/filecoin-project/go-state-types v0.0.0-20200904021452-1883f36ca2f4/go.mod h1:IQ0MBPnonv35CJHtWSN3YY1Hz2gkPru1Q9qoaYLxx9I= github.com/filecoin-project/go-state-types v0.0.0-20200905071437-95828685f9df h1:m2esXSuGBkuXlRyCsl1a/7/FkFam63o1OzIgzaHtOfI= github.com/filecoin-project/go-state-types v0.0.0-20200905071437-95828685f9df/go.mod h1:IQ0MBPnonv35CJHtWSN3YY1Hz2gkPru1Q9qoaYLxx9I= +github.com/filecoin-project/go-state-types v0.0.0-20200911004822-964d6c679cfc h1:1vr/LoqGq5m5g37Q3sNSAjfwF1uJY0zmiHcvnxY6hik= +github.com/filecoin-project/go-state-types v0.0.0-20200911004822-964d6c679cfc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-statemachine v0.0.0-20200714194326-a77c3ae20989/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370 h1:Jbburj7Ih2iaJ/o5Q9A+EAeTabME6YII7FLi9SKUf5c= github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= @@ -248,6 +252,8 @@ github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/ github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4= github.com/filecoin-project/specs-actors v0.9.7 h1:7PAZ8kdqwBdmgf/23FCkQZLCXcVu02XJrkpkhBikiA8= github.com/filecoin-project/specs-actors v0.9.7/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU= +github.com/filecoin-project/specs-actors v0.9.9-0.20200911231631-727cd8845d30 h1:6Kn6y3TpJbk5BsvhVha+3jr7C3gAAJq0rCnwUYOWRl0= +github.com/filecoin-project/specs-actors v0.9.9-0.20200911231631-727cd8845d30/go.mod h1:czlvLQGEX0fjLLfdNHD7xLymy6L3n7aQzRWzsYGf+ys= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 h1:dJsTPWpG2pcTeojO2pyn0c6l+x/3MZYCBgo/9d11JEk= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.1 h1:5fNF76nl4qolEvcIsjc0kUADlTMVHO73tW4kXXPnsus= diff --git a/node/impl/full/state.go b/node/impl/full/state.go index c068bab93ac..e9e290fd2ec 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -20,7 +20,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" @@ -33,6 +32,7 @@ import ( "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" @@ -112,6 +112,8 @@ func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, ts return api.MinerInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } + a.StateManager.LoadActorStateRaw(ctx context.Context, addr address.Address, out interface{}, st cid.Cid) + mi, err := stmgr.StateMinerInfo(ctx, a.StateManager, ts, actor) if err != nil { return api.MinerInfo{}, err @@ -119,17 +121,28 @@ func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, ts return api.NewApiMinerInfo(mi), nil } -func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { +func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]miner.Deadline, error) { var out []*miner.Deadline - return out, a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(m, - a.StateManager.WithActorState(ctx, - a.StateManager.WithDeadlines( - a.StateManager.WithEachDeadline( - func(store adt.Store, idx uint64, deadline *miner.Deadline) error { - out = append(out, deadline) - return nil - }))))) + state, err := a.StateManager.LoadParentStateTsk(tsk) + if err != nil { + return nil, err + } + act, err := state.GetActor(addr) + if err != nil { + return nil, err + } + mas, err := miner.Load(a.Chain.Store(ctx), act) + if err != nil { + return nil, err + } + var deadlines []miner.Deadline + if err := mas.ForEachDeadline(func(_ uint64, dl miner.Deadline) error { + deadlines = append(deadlines, dl) + return nil + }); err != nil { + return err + } + return deadlines, nil } func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]*miner.Partition, error) { @@ -302,7 +315,7 @@ func (a *StateAPI) stateForTs(ctx context.Context, ts *types.TipSet) (*state.Sta buf := bufbstore.NewBufferedBstore(a.Chain.Blockstore()) cst := cbor.NewCborStore(buf) - return state.LoadStateTree(cst, st) + return state.LoadStateTree(cst, st, a.StateManager.GetNtwkVersion(ctx, ts.Height())) } func (a *StateAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) { @@ -1169,16 +1182,9 @@ func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetK return api.CirculatingSupply{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - st, _, err := a.StateManager.TipSetState(ctx, ts) - if err != nil { - return api.CirculatingSupply{}, err - } - - cst := cbor.NewCborStore(a.Chain.Blockstore()) - sTree, err := state.LoadStateTree(cst, st) + sTree, err := a.stateForTs(ctx, ts) if err != nil { return api.CirculatingSupply{}, err } - return a.StateManager.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree) } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 2869e48e5cb..706cd6e04d4 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -16,13 +16,13 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" @@ -179,14 +179,11 @@ func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr a return nil, xerrors.Errorf("handleSealFailed(%d): temp error: %+v", sectorNumber, err) } - st, err := s.delegate.ChainReadObj(ctx, act.Head) - if err != nil { - return nil, xerrors.Errorf("handleSealFailed(%d): temp error: %+v", sectorNumber, err) - } + stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.delegate)) - var state miner.State - if err := state.UnmarshalCBOR(bytes.NewReader(st)); err != nil { - return nil, xerrors.Errorf("handleSealFailed(%d): temp error: unmarshaling miner state: %+v", sectorNumber, err) + state, err := miner.Load(stor, act) + if err != nil { + return nil, xerrors.Errorf("handleSealFailed(%d): temp error: loading miner state: %+v", sectorNumber, err) } stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.delegate)) precommits, err := adt.AsMap(stor, state.PreCommittedSectors) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 51d71e331d6..0f215048a97 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -6,28 +6,32 @@ import ( "errors" "time" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "go.opencensus.io/trace" "golang.org/x/xerrors" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" ) var errNoPartitions = errors.New("no partitions") -func (s *WindowPoStScheduler) failPost(deadline *miner.DeadlineInfo) { +func (s *WindowPoStScheduler) failPost(deadline *dline.Info) { log.Errorf("TODO") /*s.failLk.Lock() if eps > s.failed { @@ -36,7 +40,7 @@ func (s *WindowPoStScheduler) failPost(deadline *miner.DeadlineInfo) { s.failLk.Unlock()*/ } -func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *miner.DeadlineInfo, ts *types.TipSet) { +func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *dline.Info, ts *types.TipSet) { ctx, abort := context.WithCancel(ctx) s.abort = abort @@ -111,18 +115,26 @@ func (s *WindowPoStScheduler) checkSectors(ctx context.Context, check bitfield.B return sbf, nil } -func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []*miner.Partition) error { +func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []miner.Partition) error { ctx, span := trace.StartSpan(ctx, "storage.checkNextRecoveries") defer span.End() - params := &miner.DeclareFaultsRecoveredParams{ - Recoveries: []miner.RecoveryDeclaration{}, + params := &v0miner.DeclareFaultsRecoveredParams{ + Recoveries: []v0miner.RecoveryDeclaration{}, } faulty := uint64(0) for partIdx, partition := range partitions { - unrecovered, err := bitfield.SubtractBitField(partition.Faults, partition.Recoveries) + faults, err := partition.FaultySectors() + if err != nil { + return xerrors.Errorf("getting faults: %w", err) + } + recovering, err := partition.RecoveringSectors() + if err != nil { + return xerrors.Errorf("getting recovering: %w", err) + } + unrecovered, err := bitfield.SubtractBitField(faults, recovering) if err != nil { return xerrors.Errorf("subtracting recovered set from fault set: %w", err) } @@ -153,7 +165,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin continue } - params.Recoveries = append(params.Recoveries, miner.RecoveryDeclaration{ + params.Recoveries = append(params.Recoveries, v0miner.RecoveryDeclaration{ Deadline: dlIdx, Partition: uint64(partIdx), Sectors: recovered, @@ -202,17 +214,17 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin return nil } -func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []*miner.Partition) error { +func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []miner.Partition) error { ctx, span := trace.StartSpan(ctx, "storage.checkNextFaults") defer span.End() - params := &miner.DeclareFaultsParams{ - Faults: []miner.FaultDeclaration{}, + params := &v0miner.DeclareFaultsParams{ + Faults: []v0miner.FaultDeclaration{}, } bad := uint64(0) - for partIdx, partition := range partitions { + for _, partition := range partitions { toCheck, err := partition.ActiveSectors() if err != nil { return xerrors.Errorf("getting active sectors: %w", err) @@ -239,7 +251,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, bad += c - params.Faults = append(params.Faults, miner.FaultDeclaration{ + params.Faults = append(params.Faults, v0miner.FaultDeclaration{ Deadline: dlIdx, Partition: uint64(partIdx), Sectors: faulty, @@ -286,20 +298,40 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, return nil } -func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo, ts *types.TipSet) (*miner.SubmitWindowedPoStParams, error) { +func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *types.TipSet) (*v0miner.SubmitWindowedPoStParams, error) { ctx, span := trace.StartSpan(ctx, "storage.runPost") defer span.End() + stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.api)) + act, err := s.api.StateGetActor(context.TODO(), s.actor, ts.Key()) + if err != nil { + return nil, xerrors.Errorf("resolving actor: %w", err) + } + + mas, err := miner.Load(stor, act) + if err != nil { + return nil, xerrors.Errorf("getting miner state: %w", err) + } + go func() { // TODO: extract from runPost, run on fault cutoff boundaries // check faults / recoveries for the *next* deadline. It's already too // late to declare them for this deadline - declDeadline := (di.Index + 2) % miner.WPoStPeriodDeadlines + declDeadline := (di.Index + 2) % di.WPoStPeriodDeadlines - partitions, err := s.api.StateMinerPartitions(context.TODO(), s.actor, declDeadline, ts.Key()) + dl, err := mas.LoadDeadline(declDeadline) + if err != nil { + log.Errorf("loading deadline: %v", err) + return + } + var partitions []miner.Partition + err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + partitions = append(partitions, part) + return nil + }) if err != nil { - log.Errorf("getting partitions: %v", err) + log.Errorf("loading partitions: %v", err) return } @@ -324,18 +356,27 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; deadline=%d): %w", ts.Height(), di, err) } - partitions, err := s.api.StateMinerPartitions(ctx, s.actor, di.Index, ts.Key()) + dl, err := mas.LoadDeadline(di.Index) + if err != nil { + return nil, xerrors.Errorf("loading deadline: %w", err) + } + + var partitions []miner.Partitions + err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + partitions = apppend(partitions, part) + return nil + }) if err != nil { - return nil, xerrors.Errorf("getting partitions: %w", err) + return nil, xerrors.Errorf("loading partitions: %w", err) } - params := &miner.SubmitWindowedPoStParams{ + params := &v0miner.SubmitWindowedPoStParams{ Deadline: di.Index, - Partitions: make([]miner.PoStPartition, 0, len(partitions)), + Partitions: make([]v0miner.PoStPartition, 0, len(partitions)), Proofs: nil, } - var sinfos []proof.SectorInfo + var sinfos []v0proof.SectorInfo sidToPart := map[abi.SectorNumber]uint64{} skipCount := uint64(0) @@ -382,7 +423,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo sidToPart[si.SectorNumber] = uint64(partIdx) } - params.Partitions = append(params.Partitions, miner.PoStPartition{ + params.Partitions = append(params.Partitions, v0miner.PoStPartition{ Index: uint64(partIdx), Skipped: skipped, }) @@ -436,7 +477,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo return params, nil } -func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, allSectors bitfield.BitField, ts *types.TipSet) ([]proof.SectorInfo, error) { +func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, allSectors bitfield.BitField, ts *types.TipSet) ([]v0proof.SectorInfo, error) { sset, err := s.api.StateMinerSectors(ctx, s.actor, &goodSectors, false, ts.Key()) if err != nil { return nil, err @@ -446,22 +487,22 @@ func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, return nil, nil } - substitute := proof.SectorInfo{ + substitute := v0proof.SectorInfo{ SectorNumber: sset[0].ID, SealedCID: sset[0].Info.SealedCID, SealProof: sset[0].Info.SealProof, } - sectorByID := make(map[uint64]proof.SectorInfo, len(sset)) + sectorByID := make(map[uint64]v0proof.SectorInfo, len(sset)) for _, sector := range sset { - sectorByID[uint64(sector.ID)] = proof.SectorInfo{ + sectorByID[uint64(sector.ID)] = v0proof.SectorInfo{ SectorNumber: sector.ID, SealedCID: sector.Info.SealedCID, SealProof: sector.Info.SealProof, } } - proofSectors := make([]proof.SectorInfo, 0, len(sset)) + proofSectors := make([]v0proof.SectorInfo, 0, len(sset)) if err := allSectors.ForEach(func(sectorNo uint64) error { if info, found := sectorByID[sectorNo]; found { proofSectors = append(proofSectors, info) @@ -476,7 +517,7 @@ func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, return proofSectors, nil } -func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.SubmitWindowedPoStParams) error { +func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *v0miner.SubmitWindowedPoStParams) error { ctx, span := trace.StartSpan(ctx, "storage.commitPost") defer span.End() diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index b238a490d54..7f7c6492644 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" @@ -37,7 +37,7 @@ type WindowPoStScheduler struct { cur *types.TipSet // if a post is in progress, this indicates for which ElectionPeriodStart - activeDeadline *miner.DeadlineInfo + activeDeadline *dline.Info abort context.CancelFunc //failed abi.ChainEpoch // eps @@ -68,7 +68,7 @@ func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, sb }, nil } -func deadlineEquals(a, b *miner.DeadlineInfo) bool { +func deadlineEquals(a, b *dline.Info) bool { if a == nil || b == nil { return b == a } From 38f87981c1c5c2a60d65acb22df75a4058b41334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 14 Sep 2020 13:14:06 +0200 Subject: [PATCH 002/104] Fix some build errors --- api/api_full.go | 6 +++--- api/apistruct/struct.go | 20 ++++++------------- api/types.go | 5 +---- build/version.go | 2 +- chain/actors/adt/adt.go | 4 ++-- chain/actors/builtin/builtin.go | 2 +- chain/actors/builtin/init/init.go | 8 ++++---- chain/actors/builtin/init/v0.go | 4 ++-- chain/actors/builtin/market/market.go | 9 +++++++-- chain/actors/builtin/market/v0.go | 4 +++- chain/actors/builtin/miner/miner.go | 7 +++++-- chain/actors/builtin/miner/v0.go | 6 +++++- chain/actors/builtin/power/power.go | 7 +++++-- chain/state/statetree.go | 28 +++++++++++++++------------ go.sum | 7 ------- 15 files changed, 61 insertions(+), 58 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index e5147db471e..8c7340971ab 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -5,8 +5,6 @@ import ( "fmt" "time" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" @@ -24,7 +22,9 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -317,7 +317,7 @@ type FullNode interface { // StateMinerPower returns the power of the indicated miner StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) // StateMinerInfo returns info about the indicated miner - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (MinerInfo, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) // StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) // StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 3cf9a0add92..45c3f7d6305 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -2,6 +2,8 @@ package apistruct import ( "context" + "github.com/filecoin-project/go-state-types/dline" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "io" "time" @@ -160,11 +162,9 @@ type FullNodeStruct struct { StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` - StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*miner.DeadlineInfo, error) `perm:"read"` + StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` - StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) `perm:"read"` - StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) `perm:"read"` - StateMinerPartitions func(context.Context, address.Address, uint64, types.TipSetKey) ([]*miner.Partition, error) `perm:"read"` + StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` @@ -724,7 +724,7 @@ func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr addre return c.Internal.StateMinerActiveSectors(ctx, addr, tsk) } -func (c *FullNodeStruct) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*miner.DeadlineInfo, error) { +func (c *FullNodeStruct) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) { return c.Internal.StateMinerProvingDeadline(ctx, addr, tsk) } @@ -732,18 +732,10 @@ func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, return c.Internal.StateMinerPower(ctx, a, tsk) } -func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) { +func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner2.MinerInfo, error) { return c.Internal.StateMinerInfo(ctx, actor, tsk) } -func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { - return c.Internal.StateMinerDeadlines(ctx, m, tsk) -} - -func (c *FullNodeStruct) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]*miner.Partition, error) { - return c.Internal.StateMinerPartitions(ctx, m, dlIdx, tsk) -} - func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { return c.Internal.StateMinerFaults(ctx, actor, tsk) } diff --git a/api/types.go b/api/types.go index 4133a710562..53c0fe203d1 100644 --- a/api/types.go +++ b/api/types.go @@ -4,14 +4,11 @@ import ( "encoding/json" "fmt" - "github.com/filecoin-project/go-address" datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/build" "github.com/ipfs/go-cid" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" ma "github.com/multiformats/go-multiaddr" @@ -111,4 +108,4 @@ func NewDataTransferChannel(hostID peer.ID, channelState datatransfer.ChannelSta return channel } -type +// type TODO (stebalien): this was here, why was this here? diff --git a/build/version.go b/build/version.go index 338be1263ed..1e55b988986 100644 --- a/build/version.go +++ b/build/version.go @@ -53,7 +53,7 @@ func (ve Version) EqMajorMinor(v2 Version) bool { } // APIVersion is a semver version of the rpc api exposed -var APIVersion Version = newVer(0, 14, 0) +var APIVersion Version = newVer(0, 15, 0) //nolint:varcheck,deadcode const ( diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index 144150659e3..179c73b339c 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -32,7 +32,7 @@ func AsMap(store Store, root cid.Cid, version network.Version) (Map, error) { func NewMap(store Store, version network.Version) (Map, error) { switch builtin.VersionForNetwork(version) { case builtin.Version0: - return v0adt.MakeEmptyMap(store) + return v0adt.MakeEmptyMap(store), nil } return nil, xerrors.Errorf("unknown network version: %d", version) } @@ -45,7 +45,7 @@ type Array interface { Delete(idx uint64) error Length() uint64 - ForEach(v cbor.Unmarshaler, fn func(idx int) error) error + ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error } func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) { diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 173f50ba678..accc4e7e6ec 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -16,7 +16,7 @@ const ( func VersionForNetwork(version network.Version) Version { switch version { case network.Version0, network.Version1: - return Version + return Version0 default: panic(fmt.Sprintf("unsupported network version %d", version)) } diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index de71a032c3e..a96c0dfd637 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -1,10 +1,10 @@ package init import ( - "github.com/filecoin-project/go-bitfield" - "github.com/filecoin-project/go-state-types/cbor" "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -27,6 +27,6 @@ func Load(store adt.Store, act *types.Actor) (State, error) { type State interface { cbor.Marshaler - ResolveAddress(address addr.Address) (address.Address, bool, error) - MapAddressToNewID(address addr.Address) (address.Address, error) + ResolveAddress(address address.Address) (address.Address, bool, error) + MapAddressToNewID(address address.Address) (address.Address, error) } diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index 3a94f59f088..5001e98065c 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -3,13 +3,13 @@ package init import ( "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/builtin/init" + init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/adt" ) type v0State struct { - init.State + init_.State store adt.Store } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 663fa0e8391..3d12ac9a80e 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -1,15 +1,20 @@ package market import ( + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" ) func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.MarketActorCodeID: + case v0builtin.StorageMarketActorCodeID: out := v0State{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 23f33e3d326..da86cda0fe2 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -1,6 +1,8 @@ package market import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -20,6 +22,6 @@ func (s *v0State) EscrowTable() (BalanceTable, error) { return adt.AsBalanceTable(s.store, s.State.EscrowTable) } -func (s *v0State) Lockedtable() (BalanceTable, error) { +func (s *v0State) LockedTable() (BalanceTable, error) { return adt.AsBalanceTable(s.store, s.State.LockedTable) } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 50453827daf..11dc3158a84 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -1,10 +1,13 @@ package miner import ( - "github.com/filecoin-project/go-bitfield" - "github.com/filecoin-project/go-state-types/abi" + "github.com/libp2p/go-libp2p-core/peer" "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 8898a26a5c2..1d8a68183eb 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -1,6 +1,7 @@ package miner import ( + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/libp2p/go-libp2p-core/peer" @@ -51,6 +52,9 @@ func (s *v0State) NumDeadlines() (uint64, error) { func (s *v0State) Info() (MinerInfo, error) { info, err := s.State.GetInfo(s.store) + if err != nil { + return MinerInfo{}, err + } var pid *peer.ID if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { @@ -77,7 +81,7 @@ func (s *v0State) Info() (MinerInfo, error) { mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt } - return mi + return mi, nil } func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 7671877e352..b7bb9329e10 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -1,16 +1,19 @@ package power import ( + "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" - "golang.org/x/xerrors" ) func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.PowerActorCodeID: + case v0builtin.StoragePowerActorCodeID: out := v0State{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 684e6ce5d9d..7aa7701fd73 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -4,12 +4,6 @@ import ( "context" "fmt" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/chain/actors/builtin/init" - init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin" - - "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -17,6 +11,12 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/network" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" ) @@ -118,9 +118,13 @@ func (ss *stateSnaps) deleteActor(addr address.Address) { } func NewStateTree(cst cbor.IpldStore, version network.Version) (*StateTree, error) { + root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), version) + if err != nil { + return nil, err + } return &StateTree{ - root: adt.NewMap(adt.WrapStore(context.TODO(), cst), version), + root: root, Store: cst, snaps: newStateSnaps(), }, nil @@ -168,7 +172,7 @@ func (st *StateTree) LookupID(addr address.Address) (address.Address, error) { return address.Undef, xerrors.Errorf("getting init actor: %w", err) } - ias, err := init.Load(&AdtStore{st.Store}, &act) + ias, err := init_.Load(&AdtStore{st.Store}, act) if err != nil { return address.Undef, xerrors.Errorf("loading init actor state: %w", err) } @@ -212,7 +216,7 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) { } var act types.Actor - if found, err := st.root.Get(adt.AddrKey(addr), &act); err != nil { + if found, err := st.root.Get(abi.AddrKey(addr), &act); err != nil { return nil, xerrors.Errorf("hamt find failed: %w", err) } else if !found { return nil, types.ErrActorNotFound @@ -257,11 +261,11 @@ func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) { for addr, sto := range st.snaps.layers[0].actors { if sto.Delete { - if err := st.root.Delete(adt.AddrKey(addr)); err != nil { + if err := st.root.Delete(abi.AddrKey(addr)); err != nil { return cid.Undef, err } } else { - if err := st.root.Put(adt.AddrKey(addr), &sto.Act); err != nil { + if err := st.root.Put(abi.AddrKey(addr), &sto.Act); err != nil { return cid.Undef, err } } @@ -286,7 +290,7 @@ func (st *StateTree) ClearSnapshot() { func (st *StateTree) RegisterNewAddress(addr address.Address) (address.Address, error) { var out address.Address err := st.MutateActor(builtin.InitActorAddr, func(initact *types.Actor) error { - ias, err := init.Load(&AdtStore{st.Store}, initact) + ias, err := init_.Load(&AdtStore{st.Store}, initact) if err != nil { return err } diff --git a/go.sum b/go.sum index 106814b0220..0ae61535a83 100644 --- a/go.sum +++ b/go.sum @@ -249,11 +249,6 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8= -github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4= -github.com/filecoin-project/specs-actors v0.9.7 h1:7PAZ8kdqwBdmgf/23FCkQZLCXcVu02XJrkpkhBikiA8= -github.com/filecoin-project/specs-actors v0.9.7/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU= -github.com/filecoin-project/specs-actors v0.9.9-0.20200911231631-727cd8845d30 h1:6Kn6y3TpJbk5BsvhVha+3jr7C3gAAJq0rCnwUYOWRl0= -github.com/filecoin-project/specs-actors v0.9.9-0.20200911231631-727cd8845d30/go.mod h1:czlvLQGEX0fjLLfdNHD7xLymy6L3n7aQzRWzsYGf+ys= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 h1:dJsTPWpG2pcTeojO2pyn0c6l+x/3MZYCBgo/9d11JEk= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.1 h1:5fNF76nl4qolEvcIsjc0kUADlTMVHO73tW4kXXPnsus= @@ -503,8 +498,6 @@ github.com/ipfs/go-fs-lock v0.0.6/go.mod h1:OTR+Rj9sHiRubJh3dRhD15Juhd/+w6VPOY28 github.com/ipfs/go-graphsync v0.1.0/go.mod h1:jMXfqIEDFukLPZHqDPp8tJMbHO9Rmeb9CEGevngQbmE= github.com/ipfs/go-graphsync v0.1.2 h1:25Ll9kIXCE+DY0dicvfS3KMw+U5sd01b/FJbA7KAbhg= github.com/ipfs/go-graphsync v0.1.2/go.mod h1:sLXVXm1OxtE2XYPw62MuXCdAuNwkAdsbnfrmos5odbA= -github.com/ipfs/go-hamt-ipld v0.1.1 h1:0IQdvwnAAUKmDE+PMJa5y1QiwOPHpI9+eAbQEEEYthk= -github.com/ipfs/go-hamt-ipld v0.1.1/go.mod h1:1EZCr2v0jlCnhpa+aZ0JZYp8Tt2w16+JJOAVz17YcDk= github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08= github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw= github.com/ipfs/go-ipfs-blockstore v0.1.4/go.mod h1:Jxm3XMVjh6R17WvxFEiyKBLUGr86HgIYJW/D/MwqeYQ= From 68097132fe64dd9454aae00ae86bf6f4b2b36f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 14 Sep 2020 13:45:20 +0200 Subject: [PATCH 003/104] Fix vm build --- chain/gen/genesis/genesis.go | 7 +- chain/gen/genesis/miners.go | 4 +- chain/stmgr/stmgr.go | 37 +++++----- chain/vm/invoker.go | 8 +-- chain/vm/runtime.go | 129 ++++++++++++++++------------------- chain/vm/vm.go | 28 ++++---- 6 files changed, 95 insertions(+), 118 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index ac22b5b1942..3c463243752 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -6,8 +6,6 @@ import ( "encoding/json" "fmt" - "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" cbor "github.com/ipfs/go-ipld-cbor" @@ -19,6 +17,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -406,8 +405,8 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci verifNeeds := make(map[address.Address]abi.PaddedPieceSize) var sum abi.PaddedPieceSize - nwv := func(context.Context, abi.ChainEpoch) runtime.NetworkVersion { - return runtime.NetworkVersion1 + nwv := func(context.Context, abi.ChainEpoch) network.Version { + return network.Version1 } vmopt := vm.VMOpts{ diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index d8441c66cd4..6d041bb4dd6 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -61,8 +61,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return big.Zero(), nil } - nwv := func(context.Context, abi.ChainEpoch) runtime.NetworkVersion { - return runtime.NetworkVersion1 + nwv := func(context.Context, abi.ChainEpoch) network.Version { + return network.Version1 } vmopt := &vm.VMOpts{ diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index fa4b08147b1..f5b043dc524 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,11 +5,22 @@ import ( "fmt" "sync" - "github.com/filecoin-project/specs-actors/actors/runtime" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + logging "github.com/ipfs/go-log/v2" + cbg "github.com/whyrusleeping/cbor-gen" + "go.opencensus.io/trace" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" @@ -19,20 +30,6 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/actors/util/adt" - - "golang.org/x/xerrors" - - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - logging "github.com/ipfs/go-log/v2" - cbg "github.com/whyrusleeping/cbor-gen" - "go.opencensus.io/trace" ) var log = logging.Logger("statemgr") @@ -1126,14 +1123,14 @@ func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.Cha return csi.FilCirculating, nil } -func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoch) runtime.NetworkVersion { +func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoch) network.Version { if build.UpgradeBreezeHeight == 0 { - return runtime.NetworkVersion1 + return network.Version1 } if height <= build.UpgradeBreezeHeight { - return runtime.NetworkVersion0 + return network.Version0 } - return runtime.NetworkVersion1 + return network.Version1 } diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 8583b0438a0..9f5f8e2d9c7 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -15,6 +15,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/cron" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" @@ -27,9 +28,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/system" "github.com/filecoin-project/specs-actors/actors/runtime" vmr "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/util/adt" - - "github.com/filecoin-project/lotus/chain/actors/aerrors" ) type Invoker struct { @@ -48,7 +46,7 @@ func NewInvoker() *Invoker { // add builtInCode using: register(cid, singleton) // NETUPGRADE: register code IDs for v2, etc. - inv.Register(builtin.SystemActorCodeID, system.Actor{}, adt.EmptyValue{}) + inv.Register(builtin.SystemActorCodeID, system.Actor{}, abi.EmptyValue{}) inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{}) inv.Register(builtin.RewardActorCodeID, reward.Actor{}, reward.State{}) inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{}) @@ -67,7 +65,7 @@ func (inv *Invoker) Invoke(codeCid cid.Cid, rt runtime.Runtime, method abi.Metho code, ok := inv.builtInCode[codeCid] if !ok { - log.Errorf("no code for actor %s (Addr: %s)", codeCid, rt.Message().Receiver()) + log.Errorf("no code for actor %s (Addr: %s)", codeCid, rt.Receiver()) return nil, aerrors.Newf(exitcode.SysErrorIllegalActor, "no code for actor %s(%d)(%s)", codeCid, method, hex.EncodeToString(params)) } if method >= abi.MethodNum(len(code)) || code[method] == nil { diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 043ea3a45f4..87d91e2307c 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -8,20 +8,23 @@ import ( gruntime "runtime" "time" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + cbg "github.com/whyrusleeping/cbor-gen" + "go.opencensus.io/trace" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + statecbor "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/go-state-types/network" + rtt "github.com/filecoin-project/go-state-types/rt" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/runtime" vmr "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - cbg "github.com/whyrusleeping/cbor-gen" - "go.opencensus.io/trace" - "golang.org/x/xerrors" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/aerrors" @@ -34,15 +37,15 @@ type Runtime struct { vm *VM state *state.StateTree - vmsg vmr.Message height abi.ChainEpoch cst cbor.IpldStore pricelist Pricelist + vmr.Message gasAvailable int64 gasUsed int64 - sys runtime.Syscalls + runtime.Syscalls // address that started invoke chain origin address.Address @@ -56,7 +59,7 @@ type Runtime struct { lastGasCharge *types.GasTrace } -func (rt *Runtime) NetworkVersion() vmr.NetworkVersion { +func (rt *Runtime) NetworkVersion() network.Version { return rt.vm.GetNtwkVersion(rt.ctx, rt.CurrEpoch()) } @@ -84,7 +87,7 @@ type notFoundErr interface { IsNotFound() bool } -func (rt *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool { +func (rt *Runtime) StoreGet(c cid.Cid, o statecbor.Unmarshaler) bool { if err := rt.cst.Get(context.TODO(), c, o); err != nil { var nfe notFoundErr if xerrors.As(err, &nfe) && nfe.IsNotFound() { @@ -99,7 +102,7 @@ func (rt *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool { return true } -func (rt *Runtime) Put(x vmr.CBORMarshaler) cid.Cid { +func (rt *Runtime) StorePut(x statecbor.Marshaler) cid.Cid { c, err := rt.cst.Put(context.TODO(), x) if err != nil { if xerrors.As(err, new(cbor.SerializationError)) { @@ -136,7 +139,7 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act switch ret := ret.(type) { case []byte: return ret, nil - case *adt.EmptyValue: + case *abi.EmptyValue: return nil, nil case cbg.CBORMarshaler: buf := new(bytes.Buffer) @@ -151,17 +154,13 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act } } -func (rt *Runtime) Message() vmr.Message { - return rt.vmsg -} - func (rt *Runtime) ValidateImmediateCallerAcceptAny() { rt.abortIfAlreadyValidated() return } func (rt *Runtime) CurrentBalance() abi.TokenAmount { - b, err := rt.GetBalance(rt.Message().Receiver()) + b, err := rt.GetBalance(rt.Receiver()) if err != nil { rt.Abortf(err.RetCode(), "get current balance: %v", err) } @@ -257,7 +256,7 @@ func (rt *Runtime) CreateActor(codeID cid.Cid, address address.Address) { // May only be called by the actor itself. func (rt *Runtime) DeleteActor(beneficiary address.Address) { rt.chargeGas(rt.Pricelist().OnDeleteActor()) - act, err := rt.state.GetActor(rt.Message().Receiver()) + act, err := rt.state.GetActor(rt.Receiver()) if err != nil { if xerrors.Is(err, types.ErrActorNotFound) { rt.Abortf(exitcode.SysErrorIllegalActor, "failed to load actor in delete actor: %s", err) @@ -266,36 +265,32 @@ func (rt *Runtime) DeleteActor(beneficiary address.Address) { } if !act.Balance.IsZero() { // Transfer the executing actor's balance to the beneficiary - if err := rt.vm.transfer(rt.Message().Receiver(), beneficiary, act.Balance); err != nil { + if err := rt.vm.transfer(rt.Receiver(), beneficiary, act.Balance); err != nil { panic(aerrors.Fatalf("failed to transfer balance to beneficiary actor: %s", err)) } } // Delete the executing actor - if err := rt.state.DeleteActor(rt.Message().Receiver()); err != nil { + if err := rt.state.DeleteActor(rt.Receiver()); err != nil { panic(aerrors.Fatalf("failed to delete actor: %s", err)) } _ = rt.chargeGasSafe(gasOnActorExec) } -func (rt *Runtime) Syscalls() vmr.Syscalls { - return rt.sys -} - -func (rt *Runtime) StartSpan(name string) vmr.TraceSpan { +func (rt *Runtime) StartSpan(name string) func() { panic("implement me") } func (rt *Runtime) ValidateImmediateCallerIs(as ...address.Address) { rt.abortIfAlreadyValidated() - imm := rt.Message().Caller() + imm := rt.Caller() for _, a := range as { if imm == a { return } } - rt.Abortf(exitcode.SysErrForbidden, "caller %s is not one of %s", rt.Message().Caller(), as) + rt.Abortf(exitcode.SysErrForbidden, "caller %s is not one of %s", rt.Caller(), as) } func (rt *Runtime) Context() context.Context { @@ -313,7 +308,7 @@ func (rt *Runtime) AbortStateMsg(msg string) { func (rt *Runtime) ValidateImmediateCallerType(ts ...cid.Cid) { rt.abortIfAlreadyValidated() - callerCid, ok := rt.GetActorCodeCID(rt.Message().Caller()) + callerCid, ok := rt.GetActorCodeCID(rt.Caller()) if !ok { panic(aerrors.Fatalf("failed to lookup code cid for caller")) } @@ -329,15 +324,7 @@ func (rt *Runtime) CurrEpoch() abi.ChainEpoch { return rt.height } -type dumbWrapperType struct { - val []byte -} - -func (dwt *dumbWrapperType) Into(um vmr.CBORUnmarshaler) error { - return um.UnmarshalCBOR(bytes.NewReader(dwt.val)) -} - -func (rt *Runtime) Send(to address.Address, method abi.MethodNum, m vmr.CBORMarshaler, value abi.TokenAmount) (vmr.SendReturn, exitcode.ExitCode) { +func (rt *Runtime) Send(to address.Address, method abi.MethodNum, m statecbor.Marshaler, value abi.TokenAmount, out statecbor.Er) exitcode.ExitCode { if !rt.allowInternal { rt.Abortf(exitcode.SysErrorIllegalActor, "runtime.Send() is currently disallowed") } @@ -350,16 +337,22 @@ func (rt *Runtime) Send(to address.Address, method abi.MethodNum, m vmr.CBORMars params = buf.Bytes() } - ret, err := rt.internalSend(rt.Message().Receiver(), to, method, value, params) + ret, err := rt.internalSend(rt.Receiver(), to, method, value, params) if err != nil { if err.IsFatal() { panic(err) } log.Warnf("vmctx send failed: to: %s, method: %d: ret: %d, err: %s", to, method, ret, err) - return &dumbWrapperType{nil}, err.RetCode() + return err.RetCode() } _ = rt.chargeGasSafe(gasOnActorExec) - return &dumbWrapperType{ret}, 0 + + if err := out.UnmarshalCBOR(bytes.NewReader(ret)); err != nil { + // REVIEW: always fatal? + panic(err) + } + + return 0 } func (rt *Runtime) internalSend(from, to address.Address, method abi.MethodNum, value types.BigInt, params []byte) ([]byte, aerrors.ActorError) { @@ -398,54 +391,46 @@ func (rt *Runtime) internalSend(from, to address.Address, method abi.MethodNum, if subrt != nil { rt.numActorsCreated = subrt.numActorsCreated + rt.executionTrace.Subcalls = append(rt.executionTrace.Subcalls, subrt.executionTrace) } - rt.executionTrace.Subcalls = append(rt.executionTrace.Subcalls, subrt.executionTrace) return ret, errSend } -func (rt *Runtime) State() vmr.StateHandle { - return &shimStateHandle{rt: rt} -} - -type shimStateHandle struct { - rt *Runtime -} - -func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) { - c := ssh.rt.Put(obj) - err := ssh.rt.stateCommit(EmptyObjectCid, c) +func (rt *Runtime) StateCreate(obj statecbor.Marshaler) { + c := rt.StorePut(obj) + err := rt.stateCommit(EmptyObjectCid, c) if err != nil { panic(fmt.Errorf("failed to commit state after creating object: %w", err)) } } -func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) { - act, err := ssh.rt.state.GetActor(ssh.rt.Message().Receiver()) +func (rt *Runtime) StateReadonly(obj statecbor.Unmarshaler) { + act, err := rt.state.GetActor(rt.Receiver()) if err != nil { - ssh.rt.Abortf(exitcode.SysErrorIllegalArgument, "failed to get actor for Readonly state: %s", err) + rt.Abortf(exitcode.SysErrorIllegalArgument, "failed to get actor for Readonly state: %s", err) } - ssh.rt.Get(act.Head, obj) + rt.StoreGet(act.Head, obj) } -func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func()) { +func (rt *Runtime) StateTransaction(obj statecbor.Er, f func()) { if obj == nil { - ssh.rt.Abortf(exitcode.SysErrorIllegalActor, "Must not pass nil to Transaction()") + rt.Abortf(exitcode.SysErrorIllegalActor, "Must not pass nil to Transaction()") } - act, err := ssh.rt.state.GetActor(ssh.rt.Message().Receiver()) + act, err := rt.state.GetActor(rt.Receiver()) if err != nil { - ssh.rt.Abortf(exitcode.SysErrorIllegalActor, "failed to get actor for Transaction: %s", err) + rt.Abortf(exitcode.SysErrorIllegalActor, "failed to get actor for Transaction: %s", err) } baseState := act.Head - ssh.rt.Get(baseState, obj) + rt.StoreGet(baseState, obj) - ssh.rt.allowInternal = false + rt.allowInternal = false f() - ssh.rt.allowInternal = true + rt.allowInternal = true - c := ssh.rt.Put(obj) + c := rt.StorePut(obj) - err = ssh.rt.stateCommit(baseState, c) + err = rt.stateCommit(baseState, c) if err != nil { panic(fmt.Errorf("failed to commit state after transaction: %w", err)) } @@ -465,7 +450,7 @@ func (rt *Runtime) GetBalance(a address.Address) (types.BigInt, aerrors.ActorErr func (rt *Runtime) stateCommit(oldh, newh cid.Cid) aerrors.ActorError { // TODO: we can make this more efficient in the future... - act, err := rt.state.GetActor(rt.Message().Receiver()) + act, err := rt.state.GetActor(rt.Receiver()) if err != nil { return aerrors.Escalate(err, "failed to get actor to commit state") } @@ -476,7 +461,7 @@ func (rt *Runtime) stateCommit(oldh, newh cid.Cid) aerrors.ActorError { act.Head = newh - if err := rt.state.SetActor(rt.Message().Receiver(), act); err != nil { + if err := rt.state.SetActor(rt.Receiver(), act); err != nil { return aerrors.Fatalf("failed to set actor in commit state: %s", err) } @@ -571,15 +556,15 @@ func (rt *Runtime) abortIfAlreadyValidated() { rt.callerValidated = true } -func (rt *Runtime) Log(level vmr.LogLevel, msg string, args ...interface{}) { +func (rt *Runtime) Log(level rtt.LogLevel, msg string, args ...interface{}) { switch level { - case vmr.DEBUG: + case rtt.DEBUG: actorLog.Debugf(msg, args...) - case vmr.INFO: + case rtt.INFO: actorLog.Infof(msg, args...) - case vmr.WARN: + case rtt.WARN: actorLog.Warnf(msg, args...) - case vmr.ERROR: + case rtt.ERROR: actorLog.Errorf(msg, args...) } } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index eb6c2f354a0..a125df05324 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -7,13 +7,6 @@ import ( "reflect" "time" - "github.com/filecoin-project/specs-actors/actors/runtime" - - bstore "github.com/filecoin-project/lotus/lib/blockstore" - - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - block "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" @@ -25,8 +18,11 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/lotus/build" @@ -34,6 +30,7 @@ import ( "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/blockstore" + bstore "github.com/filecoin-project/lotus/lib/blockstore" "github.com/filecoin-project/lotus/lib/bufbstore" ) @@ -116,7 +113,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres Blocks: &gasChargingBlocks{rt.chargeGasFunc(2), rt.pricelist, vm.cst.Blocks}, Atlas: vm.cst.Atlas, } - rt.sys = pricedSyscalls{ + rt.Syscalls = pricedSyscalls{ under: vm.Syscalls(ctx, vm.cstate, rt.cst), chargeGas: rt.chargeGasFunc(1), pl: rt.pricelist, @@ -128,7 +125,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres rt.Abortf(exitcode.SysErrInvalidReceiver, "resolve msg.From address failed") } vmm.From = resF - rt.vmsg = &vmm + rt.Message = &vmm return rt } @@ -142,7 +139,7 @@ func (vm *UnsafeVM) MakeRuntime(ctx context.Context, msg *types.Message, origin } type CircSupplyCalculator func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) -type NtwkVersionGetter func(context.Context, abi.ChainEpoch) runtime.NetworkVersion +type NtwkVersionGetter func(context.Context, abi.ChainEpoch) network.Version type VM struct { cstate *state.StateTree @@ -170,10 +167,11 @@ type VMOpts struct { BaseFee abi.TokenAmount } -func NewVM(opts *VMOpts) (*VM, error) { +func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) { buf := bufbstore.NewBufferedBstore(opts.Bstore) cst := cbor.NewCborStore(buf) - state, err := state.LoadStateTree(cst, opts.StateBase) + nwv := opts.NtwkVersion(ctx, opts.Epoch) // TODO: why do we need a context for this? + state, err := state.LoadStateTree(cst, opts.StateBase, nwv) if err != nil { return nil, err } @@ -700,9 +698,9 @@ func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params defer span.End() if span.IsRecordingEvents() { span.AddAttributes( - trace.StringAttribute("to", rt.Message().Receiver().String()), + trace.StringAttribute("to", rt.Receiver().String()), trace.Int64Attribute("method", int64(method)), - trace.StringAttribute("value", rt.Message().ValueReceived().String()), + trace.StringAttribute("value", rt.ValueReceived().String()), ) } @@ -722,7 +720,7 @@ func (vm *VM) SetInvoker(i *Invoker) { vm.inv = i } -func (vm *VM) GetNtwkVersion(ctx context.Context, ce abi.ChainEpoch) runtime.NetworkVersion { +func (vm *VM) GetNtwkVersion(ctx context.Context, ce abi.ChainEpoch) network.Version { return vm.ntwkVersion(ctx, ce) } From 683a58195ec966757e1360a5fe0a2d973791d053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 14 Sep 2020 14:17:45 +0200 Subject: [PATCH 004/104] More terraforming in chain/ --- chain/actors/builtin/power/power.go | 2 ++ chain/actors/builtin/power/v0.go | 5 ++++ chain/gen/genesis/genesis.go | 11 +++------ chain/gen/genesis/miners.go | 8 ++----- chain/gen/genesis/util.go | 6 +++++ chain/stmgr/call.go | 4 ++-- chain/stmgr/forks.go | 28 ++++++++++------------ chain/stmgr/read.go | 6 +---- chain/stmgr/stmgr.go | 37 +++++++++++++++++------------ chain/stmgr/utils.go | 11 ++++++--- chain/store/store.go | 22 ++++++++++++++++- chain/store/weight.go | 2 +- chain/vm/vm.go | 2 +- 13 files changed, 86 insertions(+), 58 deletions(-) diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index b7bb9329e10..0fcbaf971e2 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -1,6 +1,7 @@ package power import ( + "github.com/filecoin-project/go-address" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" @@ -28,4 +29,5 @@ type State interface { cbor.Marshaler TotalLocked() (abi.TokenAmount, error) + MinerNominalPowerMeetsConsensusMinimum(adt.Store, address.Address) (bool, error) } diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 8851080e623..879e3e446f4 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -1,6 +1,7 @@ package power import ( + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/specs-actors/actors/builtin/power" @@ -14,3 +15,7 @@ type v0State struct { func (s *v0State) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } + +func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(st adt.Store, a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(st, a) +} diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 3c463243752..d726dfa5015 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -17,7 +17,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -115,7 +114,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("putting empty object: %w", err) } - state, err := state.NewStateTree(cst) + state, err := state.NewStateTree(cst, GenesisNetworkVersion) if err != nil { return nil, nil, xerrors.Errorf("making new state tree: %w", err) } @@ -405,10 +404,6 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci verifNeeds := make(map[address.Address]abi.PaddedPieceSize) var sum abi.PaddedPieceSize - nwv := func(context.Context, abi.ChainEpoch) network.Version { - return network.Version1 - } - vmopt := vm.VMOpts{ StateBase: stateroot, Epoch: 0, @@ -416,10 +411,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci Bstore: cs.Blockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: nil, - NtwkVersion: nwv, + NtwkVersion: genesisNetworkVersion, BaseFee: types.NewInt(0), } - vm, err := vm.NewVM(&vmopt) + vm, err := vm.NewVM(ctx, &vmopt) if err != nil { return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) } diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 6d041bb4dd6..ff4668d7f97 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -61,10 +61,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return big.Zero(), nil } - nwv := func(context.Context, abi.ChainEpoch) network.Version { - return network.Version1 - } - vmopt := &vm.VMOpts{ StateBase: sroot, Epoch: 0, @@ -72,11 +68,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Bstore: cs.Blockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: csc, - NtwkVersion: nwv, + NtwkVersion: genesisNetworkVersion, BaseFee: types.NewInt(0), } - vm, err := vm.NewVM(vmopt) + vm, err := vm.NewVM(ctx, vmopt) if err != nil { return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) } diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 67a4e9579a7..54fc4abfe9b 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -2,6 +2,7 @@ package genesis import ( "context" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -46,3 +47,8 @@ func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value return ret.Return, nil } + +var GenesisNetworkVersion = network.Version1 +func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version { + return GenesisNetworkVersion // TODO: Get from build/ +} diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 4b83842b4d1..f4dfc7115f9 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -33,7 +33,7 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate BaseFee: types.NewInt(0), } - vmi, err := vm.NewVM(vmopt) + vmi, err := vm.NewVM(ctx, vmopt) if err != nil { return nil, xerrors.Errorf("failed to set up vm: %w", err) } @@ -134,7 +134,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri NtwkVersion: sm.GetNtwkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, } - vmi, err := vm.NewVM(vmopt) + vmi, err := vm.NewVM(ctx, vmopt) if err != nil { return nil, xerrors.Errorf("failed to set up vm: %w", err) } diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index addaba90f92..6505367183b 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -7,11 +7,10 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -96,11 +95,8 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types return xerrors.Errorf("failed to get tipset at lookback height: %w", err) } - var lbtree *state.StateTree - if err = sm.WithStateTree(lbts.ParentState(), func(state *state.StateTree) error { - lbtree = state - return nil - }); err != nil { + lbtree, err := sm.ParentState(lbts) + if err != nil { return xerrors.Errorf("loading state tree failed: %w", err) } @@ -139,8 +135,8 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types }) } case builtin.StorageMinerActorCodeID: - var st miner.State - if err := sm.WithActorState(ctx, &st)(act); err != nil { + var st v0miner.State + if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } @@ -176,7 +172,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types } // pull up power table to give miners back some funds proportional to their power - var ps power.State + var ps v0power.State powAct, err := tree.GetActor(builtin.StoragePowerActorAddr) if err != nil { return xerrors.Errorf("failed to load power actor: %w", err) @@ -215,12 +211,12 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types }) } case builtin.StorageMinerActorCodeID: - var st miner.State - if err := sm.WithActorState(ctx, &st)(act); err != nil { + var st v0miner.State + if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } - var minfo miner.MinerInfo + var minfo v0miner.MinerInfo if err := cst.Get(ctx, st.Info, &minfo); err != nil { return xerrors.Errorf("failed to get miner info: %w", err) } @@ -244,8 +240,8 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types // Now make sure to give each miner who had power at the lookback some FIL lbact, err := lbtree.GetActor(addr) if err == nil { - var lbst miner.State - if err := sm.WithActorState(ctx, &lbst)(lbact); err != nil { + var lbst v0miner.State + if err := sm.ChainStore().Store(ctx).Get(ctx, lbact.Head, &lbst); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } diff --git a/chain/stmgr/read.go b/chain/stmgr/read.go index 2daa9f79d5a..7bf757fb8d6 100644 --- a/chain/stmgr/read.go +++ b/chain/stmgr/read.go @@ -2,8 +2,6 @@ package stmgr import ( "context" - "reflect" - "golang.org/x/xerrors" "github.com/ipfs/go-cid" @@ -13,8 +11,6 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/util/adt" ) func (sm *StateManager) ParentStateTsk(tsk types.TipSetKey) (*state.StateTree, error) { @@ -22,7 +18,7 @@ func (sm *StateManager) ParentStateTsk(tsk types.TipSetKey) (*state.StateTree, e if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - return sm.ParentState(ts, cb) + return sm.ParentState(ts) } func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error) { diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index f5b043dc524..489eaab3d24 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -41,7 +41,7 @@ type StateManager struct { compWait map[string]chan struct{} stlk sync.Mutex genesisMsigLk sync.Mutex - newVM func(*vm.VMOpts) (*vm.VM, error) + newVM func(context.Context, *vm.VMOpts) (*vm.VM, error) genInfo *genesisInfo } @@ -156,7 +156,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp BaseFee: baseFee, } - vmi, err := sm.newVM(vmopt) + vmi, err := sm.newVM(ctx, vmopt) if err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err) } @@ -383,7 +383,7 @@ func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Ad } cst := cbor.NewCborStore(sm.cs.Blockstore()) - tree, err := state.LoadStateTree(cst, st) + tree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, ts.Height())) if err != nil { return address.Undef, xerrors.Errorf("failed to load state tree") } @@ -406,7 +406,7 @@ func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Addres func (sm *StateManager) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, sm.parentState(ts)) + state, err := state.LoadStateTree(cst, sm.parentState(ts), sm.GetNtwkVersion(ctx, ts.Height())) if err != nil { return address.Undef, xerrors.Errorf("load state tree: %w", err) } @@ -598,10 +598,9 @@ func (sm *StateManager) searchBackForMsg(ctx context.Context, from *types.TipSet default: } - var act types.Actor - err := sm.WithParentState(cur, sm.WithActor(m.VMMessage().From, GetActor(&act))) + act, err := sm.LoadActor(ctx, m.VMMessage().From, cur) if err != nil { - return nil, nil, cid.Undef, err + return nil, nil, cid.Cid{}, err } // we either have no messages from the sender, or the latest message we found has a lower nonce than the one being searched for, @@ -712,9 +711,15 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, if err != nil { return api.MarketBalance{}, err } + act, err := st.GetActor(builtin.StorageMarketActorAddr) if err != nil { - return nil, err + return api.MarketBalance{}, err + } + + mstate, err := market.Load(sm.cs.Store(ctx), act) + if err != nil { + return api.MarketBalance{}, err } addr, err = sm.LookupID(ctx, addr, ts) @@ -724,7 +729,7 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, var out api.MarketBalance - et, err := adt.AsBalanceTable(sm.cs.Store(ctx), state.EscrowTable) + et, err := mstate.EscrowTable() if err != nil { return api.MarketBalance{}, err } @@ -733,7 +738,7 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, return api.MarketBalance{}, xerrors.Errorf("getting escrow balance: %w", err) } - lt, err := adt.AsBalanceTable(sm.cs.Store(ctx), state.LockedTable) + lt, err := mstate.LockedTable() if err != nil { return api.MarketBalance{}, err } @@ -774,7 +779,7 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err return nil } -func (sm *StateManager) SetVMConstructor(nvm func(*vm.VMOpts) (*vm.VM, error)) { +func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (*vm.VM, error)) { sm.newVM = nvm } @@ -812,7 +817,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { } cst := cbor.NewCborStore(sm.cs.Blockstore()) - sTree, err := state.LoadStateTree(cst, st) + sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height())) if err != nil { return xerrors.Errorf("loading state tree: %w", err) } @@ -918,7 +923,7 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error { } cst := cbor.NewCborStore(sm.cs.Blockstore()) - sTree, err := state.LoadStateTree(cst, st) + sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height())) if err != nil { return xerrors.Errorf("loading state tree: %w", err) } @@ -1035,12 +1040,12 @@ func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmoun return big.Zero(), xerrors.Errorf("failed to load power actor: %w", err) } - pst, err := power.Load(adt.WrapStore(ctx, st.Store), act) + pst, err := power.Load(adt.WrapStore(ctx, st.Store), pactor) if err != nil { return big.Zero(), xerrors.Errorf("failed to load power state: %w", err) } - return pst.TotalLocked(), nil + return pst.TotalLocked() } func (sm *StateManager) GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { @@ -1124,6 +1129,8 @@ func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.Cha } func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoch) network.Version { + // TODO: move hard fork epoch checks to a schedule defined in build/ + if build.UpgradeBreezeHeight == 0 { return network.Version1 } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index a137afb51ee..a6fdce31ea5 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -21,6 +21,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" + power2 "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" @@ -670,17 +671,21 @@ func GetReturnType(ctx context.Context, sm *StateManager, to address.Address, me } func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Address, ts *types.TipSet) (bool, error) { - var ps power.State - _, err := sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &ps, ts) + pact, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) if err != nil { return false, xerrors.Errorf("loading power actor state: %w", err) } + ps, err := power2.Load(sm.cs.Store(ctx), pact) + if err != nil { + return false, err + } + return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr) } func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) { - str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState()) + str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState(), sm.GetNtwkVersion(ctx, ts.Height())) if err != nil { return abi.TokenAmount{}, err } diff --git a/chain/store/store.go b/chain/store/store.go index e0a9976864c..39024229473 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -5,6 +5,8 @@ import ( "context" "encoding/binary" "encoding/json" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/build" "io" "os" "strconv" @@ -741,11 +743,29 @@ type BlockMessages struct { WinCount int64 } +// TODO: temp hack until #3682 is merged +func hackgetNtwkVersionhack(ctx context.Context, height abi.ChainEpoch) network.Version { + // TODO: move hard fork epoch checks to a schedule defined in build/ + + if build.UpgradeBreezeHeight == 0 { + return network.Version1 + } + + if height <= build.UpgradeBreezeHeight { + return network.Version0 + } + + return network.Version1 +} + func (cs *ChainStore) BlockMsgsForTipset(ts *types.TipSet) ([]BlockMessages, error) { applied := make(map[address.Address]uint64) cst := cbor.NewCborStore(cs.bs) - st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot) + + nv := hackgetNtwkVersionhack(context.TODO(), ts.Height()) // TODO: part of the temp hack from above + + st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot, nv) if err != nil { return nil, xerrors.Errorf("failed to load state tree") } diff --git a/chain/store/weight.go b/chain/store/weight.go index 5249df0112b..e27d3fd3738 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -29,7 +29,7 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn tpow := big2.Zero() { cst := cbor.NewCborStore(cs.Blockstore()) - state, err := state.LoadStateTree(cst, ts.ParentState()) + state, err := state.LoadStateTree(cst, ts.ParentState(), hackgetNtwkVersionhack(nil, ts.Height())) // TODO: hackgetNtwkVersionhack: HELP if err != nil { return types.NewInt(0), xerrors.Errorf("load state tree: %w", err) } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index a125df05324..ced11e04d51 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -163,7 +163,7 @@ type VMOpts struct { Bstore bstore.Blockstore Syscalls SyscallBuilder CircSupplyCalc CircSupplyCalculator - NtwkVersion NtwkVersionGetter + NtwkVersion NtwkVersionGetter // TODO: stebalien: In what cases do we actually need this? It seems like even when creating new networks we want to use the 'global'/build-default version getter BaseFee abi.TokenAmount } From fb3f7105238ff59ff91fed05aec4eee5ae391dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 14 Sep 2020 15:17:00 +0200 Subject: [PATCH 005/104] Some post-master merge fixes --- api/apistruct/struct.go | 8 +++----- chain/gen/genesis/miners.go | 7 +------ chain/gen/genesis/util.go | 13 ++++++++++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 151e7d99aa1..1eac858a029 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -2,13 +2,9 @@ package apistruct import ( "context" - "github.com/filecoin-project/go-state-types/dline" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "io" "time" - "github.com/filecoin-project/go-state-types/dline" - "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -25,6 +21,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -37,6 +34,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" ) @@ -168,7 +166,7 @@ type FullNodeStruct struct { StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` - StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` + StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 6c1fec23cd9..3bed1c1a913 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -6,12 +6,6 @@ import ( "fmt" "math/rand" - "github.com/filecoin-project/lotus/build" - - "github.com/filecoin-project/go-state-types/network" - - "github.com/filecoin-project/lotus/chain/state" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" cbg "github.com/whyrusleeping/cbor-gen" @@ -29,6 +23,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/runtime" + "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 54fc4abfe9b..6a27f2f293f 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -3,6 +3,7 @@ package genesis import ( "context" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -48,7 +49,13 @@ func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value return ret.Return, nil } -var GenesisNetworkVersion = network.Version1 -func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version { +var GenesisNetworkVersion = func() network.Version {// TODO: Get from build/ + if build.UseNewestNetwork() {// TODO: Get from build/ + return build.NewestNetworkVersion// TODO: Get from build/ + }// TODO: Get from build/ + return network.Version1// TODO: Get from build/ +}()// TODO: Get from build/ + +func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version {// TODO: Get from build/ return GenesisNetworkVersion // TODO: Get from build/ -} +}// TODO: Get from build/ From 2088335b9df1362f4a4cfba16c1a9d9dcec406dd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 14 Sep 2020 14:40:52 -0700 Subject: [PATCH 006/104] rename to simplify merge --- storage/wdpost_run.go | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index f314dce9a3f..083c793e8d1 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -17,14 +17,14 @@ import ( "go.opencensus.io/trace" "golang.org/x/xerrors" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + iminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" ) @@ -115,12 +115,12 @@ func (s *WindowPoStScheduler) checkSectors(ctx context.Context, check bitfield.B return sbf, nil } -func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []miner.Partition) error { +func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []iminer.Partition) error { ctx, span := trace.StartSpan(ctx, "storage.checkNextRecoveries") defer span.End() - params := &v0miner.DeclareFaultsRecoveredParams{ - Recoveries: []v0miner.RecoveryDeclaration{}, + params := &miner.DeclareFaultsRecoveredParams{ + Recoveries: []miner.RecoveryDeclaration{}, } faulty := uint64(0) @@ -165,7 +165,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin continue } - params.Recoveries = append(params.Recoveries, v0miner.RecoveryDeclaration{ + params.Recoveries = append(params.Recoveries, miner.RecoveryDeclaration{ Deadline: dlIdx, Partition: uint64(partIdx), Sectors: recovered, @@ -214,12 +214,12 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin return nil } -func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []miner.Partition) error { +func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []iminer.Partition) error { ctx, span := trace.StartSpan(ctx, "storage.checkNextFaults") defer span.End() - params := &v0miner.DeclareFaultsParams{ - Faults: []v0miner.FaultDeclaration{}, + params := &miner.DeclareFaultsParams{ + Faults: []miner.FaultDeclaration{}, } bad := uint64(0) @@ -251,7 +251,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, bad += c - params.Faults = append(params.Faults, v0miner.FaultDeclaration{ + params.Faults = append(params.Faults, miner.FaultDeclaration{ Deadline: dlIdx, Partition: uint64(partIdx), Sectors: faulty, @@ -298,7 +298,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, return nil } -func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *types.TipSet) (*v0miner.SubmitWindowedPoStParams, error) { +func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *types.TipSet) (*miner.SubmitWindowedPoStParams, error) { ctx, span := trace.StartSpan(ctx, "storage.runPost") defer span.End() @@ -308,7 +308,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("resolving actor: %w", err) } - mas, err := miner.Load(stor, act) + mas, err := iminer.Load(stor, act) if err != nil { return nil, xerrors.Errorf("getting miner state: %w", err) } @@ -325,8 +325,8 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty log.Errorf("loading deadline: %v", err) return } - var partitions []miner.Partition - err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + var partitions []iminer.Partition + err = dl.ForEachPartition(func(_ uint64, part iminer.Partition) error { partitions = append(partitions, part) return nil }) @@ -361,8 +361,8 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("loading deadline: %w", err) } - var partitions []miner.Partitions - err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + var partitions []iminer.Partitions + err = dl.ForEachPartition(func(_ uint64, part iminer.Partition) error { partitions = apppend(partitions, part) return nil }) @@ -370,9 +370,9 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("loading partitions: %w", err) } - params := &v0miner.SubmitWindowedPoStParams{ + params := &miner.SubmitWindowedPoStParams{ Deadline: di.Index, - Partitions: make([]v0miner.PoStPartition, 0, len(partitions)), + Partitions: make([]miner.PoStPartition, 0, len(partitions)), Proofs: nil, } @@ -432,7 +432,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty sidToPart[si.SectorNumber] = partIdx } - params.Partitions = append(params.Partitions, v0miner.PoStPartition{ + params.Partitions = append(params.Partitions, miner.PoStPartition{ Index: uint64(partIdx), Skipped: skipped, }) @@ -497,7 +497,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return params, nil } -func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, allSectors bitfield.BitField, ts *types.TipSet) ([]v0proof.SectorInfo, error) { +func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, allSectors bitfield.BitField, ts *types.TipSet) ([]proof.SectorInfo, error) { sset, err := s.api.StateMinerSectors(ctx, s.actor, &goodSectors, false, ts.Key()) if err != nil { return nil, err @@ -507,22 +507,22 @@ func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, return nil, nil } - substitute := v0proof.SectorInfo{ + substitute := proof.SectorInfo{ SectorNumber: sset[0].ID, SealedCID: sset[0].Info.SealedCID, SealProof: sset[0].Info.SealProof, } - sectorByID := make(map[uint64]v0proof.SectorInfo, len(sset)) + sectorByID := make(map[uint64]proof.SectorInfo, len(sset)) for _, sector := range sset { - sectorByID[uint64(sector.ID)] = v0proof.SectorInfo{ + sectorByID[uint64(sector.ID)] = proof.SectorInfo{ SectorNumber: sector.ID, SealedCID: sector.Info.SealedCID, SealProof: sector.Info.SealProof, } } - proofSectors := make([]v0proof.SectorInfo, 0, len(sset)) + proofSectors := make([]proof.SectorInfo, 0, len(sset)) if err := allSectors.ForEach(func(sectorNo uint64) error { if info, found := sectorByID[sectorNo]; found { proofSectors = append(proofSectors, info) @@ -537,7 +537,7 @@ func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, return proofSectors, nil } -func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *v0miner.SubmitWindowedPoStParams) error { +func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.SubmitWindowedPoStParams) error { ctx, span := trace.StartSpan(ctx, "storage.commitPost") defer span.End() From cc4d5306ebc363fa912310a2b2f96c4db2486c53 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 14 Sep 2020 15:43:12 -0700 Subject: [PATCH 007/104] Progress --- chain/actors/adt/adt.go | 8 ++-- chain/actors/builtin/init/init.go | 4 ++ chain/actors/builtin/init/v0.go | 5 +++ chain/actors/builtin/miner/miner.go | 2 + chain/actors/builtin/power/power.go | 12 ++++- chain/actors/builtin/power/v0.go | 28 ++++++++++-- chain/actors/version.go | 24 ---------- chain/gen/genesis/genesis.go | 63 +++++++++++++------------- chain/state/statetree.go | 70 ++++++++++++++++++++++------- chain/stmgr/read.go | 16 ++++--- chain/stmgr/stmgr.go | 8 ++-- chain/stmgr/utils.go | 60 ++++++++++++------------- chain/store/store.go | 21 +-------- chain/store/weight.go | 2 +- chain/sub/incoming.go | 2 +- chain/sync.go | 3 +- chain/types/state.go | 15 +++++++ chain/vm/vm.go | 3 +- cmd/lotus-shed/balances.go | 3 +- cmd/lotus-shed/genesis-verify.go | 2 +- gen/main.go | 2 + node/impl/full/state.go | 2 +- 22 files changed, 205 insertions(+), 150 deletions(-) delete mode 100644 chain/actors/version.go create mode 100644 chain/types/state.go diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index 179c73b339c..ebf32c3c4bf 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -21,16 +21,16 @@ type Map interface { ForEach(v cbor.Unmarshaler, fn func(key string) error) error } -func AsMap(store Store, root cid.Cid, version network.Version) (Map, error) { - switch builtin.VersionForNetwork(version) { +func AsMap(store Store, root cid.Cid, version builtin.Version) (Map, error) { + switch version { case builtin.Version0: return v0adt.AsMap(store, root) } return nil, xerrors.Errorf("unknown network version: %d", version) } -func NewMap(store Store, version network.Version) (Map, error) { - switch builtin.VersionForNetwork(version) { +func NewMap(store Store, version builtin.Version) (Map, error) { + switch version { case builtin.Version0: return v0adt.MakeEmptyMap(store), nil } diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index a96c0dfd637..3b1a49564b2 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -9,8 +9,11 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/node/modules/dtypes" ) +var Address = v0builtin.InitActorAddr + func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case v0builtin.InitActorCodeID: @@ -29,4 +32,5 @@ type State interface { ResolveAddress(address address.Address) (address.Address, bool, error) MapAddressToNewID(address address.Address) (address.Address, error) + NetworkName() (dtypes.NetworkName, error) } diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index 5001e98065c..711b702e25f 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -6,6 +6,7 @@ import ( init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/node/modules/dtypes" ) type v0State struct { @@ -20,3 +21,7 @@ func (s *v0State) ResolveAddress(address address.Address) (address.Address, bool func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, error) { return s.State.MapAddressToNewID(s.store, address) } + +func (s *v0State) NetworkName() (dtypes.NetworkName, error) { + return dtypes.NetworkName(s.State.NetworkName), nil +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 11dc3158a84..76503d80ea6 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -14,6 +14,8 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +var Address = v0builtin.InitActorAddr + func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case v0builtin.StorageMinerActorCodeID: diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 0fcbaf971e2..7588615a6e8 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -29,5 +29,15 @@ type State interface { cbor.Marshaler TotalLocked() (abi.TokenAmount, error) - MinerNominalPowerMeetsConsensusMinimum(adt.Store, address.Address) (bool, error) + TotalPower() (Claim, error) + MinerPower(address.Address) (Claim, error) + MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) +} + +type Claim struct { + // Sum of raw byte power for a miner's sectors. + RawBytePower abi.StoragePower + + // Sum of quality adjusted power for a miner's sectors. + QualityAdjPower abi.StoragePower } diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 879e3e446f4..f3152eb6a62 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -3,8 +3,8 @@ package power import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/specs-actors/actors/builtin/power" + "github.com/filecoin-project/specs-actors/actors/util/adt" ) type v0State struct { @@ -16,6 +16,28 @@ func (s *v0State) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } -func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(st adt.Store, a address.Address) (bool, error) { - return s.State.MinerNominalPowerMeetsConsensusMinimum(st, a) +func (s *v0State) TotalPower() (Claim, error) { + return Claim{ + RawBytePower: s.TotalRawBytePower, + QualityAdjPower: s.TotalQualityAdjPower, + }, nil +} + +func (s *v0State) MinerPower(addr address.Address) (Claim, error) { + claims, err := adt.AsMap(s.store, s.Claims) + if err != nil { + return Claim{}, err + } + var claim power.Claim + if _, err := claims.Get(abi.AddrKey(addr), &claim); err != nil { + return Claim{}, err + } + return Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }, nil +} + +func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) } diff --git a/chain/actors/version.go b/chain/actors/version.go deleted file mode 100644 index 99cc59eaad0..00000000000 --- a/chain/actors/version.go +++ /dev/null @@ -1,24 +0,0 @@ -package actors - -import ( - "fmt" - - "github.com/filecoin-project/go-state-types/network" -) - -type Version int - -const ( - Version0 = iota - Version1 -) - -// VersionForNetwork resolves the network version into an specs-actors version. -func VersionForNetwork(v network.Version) Version { - switch v { - case network.Version0, network.Version1: - return Version0 - default: - panic(fmt.Sprintf("unimplemented network version: %d", v)) - } -} diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index d726dfa5015..be2ed70aaf3 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -17,13 +17,14 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/actors/util/adt" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0account "github.com/filecoin-project/specs-actors/actors/builtin/account" + v0multisig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -114,7 +115,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("putting empty object: %w", err) } - state, err := state.NewStateTree(cst, GenesisNetworkVersion) + state, err := state.NewStateTree(cst, builtin.Version0) if err != nil { return nil, nil, xerrors.Errorf("making new state tree: %w", err) } @@ -125,7 +126,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - if err := state.SetActor(builtin.SystemActorAddr, sysact); err != nil { + if err := state.SetActor(v0builtin.SystemActorAddr, sysact); err != nil { return nil, nil, xerrors.Errorf("set init actor: %w", err) } @@ -135,7 +136,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - if err := state.SetActor(builtin.InitActorAddr, initact); err != nil { + if err := state.SetActor(v0builtin.InitActorAddr, initact); err != nil { return nil, nil, xerrors.Errorf("set init actor: %w", err) } @@ -146,7 +147,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - err = state.SetActor(builtin.RewardActorAddr, rewact) + err = state.SetActor(v0builtin.RewardActorAddr, rewact) if err != nil { return nil, nil, xerrors.Errorf("set network account actor: %w", err) } @@ -156,7 +157,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup cron actor: %w", err) } - if err := state.SetActor(builtin.CronActorAddr, cronact); err != nil { + if err := state.SetActor(v0builtin.CronActorAddr, cronact); err != nil { return nil, nil, xerrors.Errorf("set cron actor: %w", err) } @@ -165,7 +166,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(builtin.StoragePowerActorAddr, spact); err != nil { + if err := state.SetActor(v0builtin.StoragePowerActorAddr, spact); err != nil { return nil, nil, xerrors.Errorf("set storage market actor: %w", err) } @@ -174,7 +175,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(builtin.StorageMarketActorAddr, marketact); err != nil { + if err := state.SetActor(v0builtin.StorageMarketActorAddr, marketact); err != nil { return nil, nil, xerrors.Errorf("set market actor: %w", err) } @@ -183,20 +184,20 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(builtin.VerifiedRegistryActorAddr, verifact); err != nil { + if err := state.SetActor(v0builtin.VerifiedRegistryActorAddr, verifact); err != nil { return nil, nil, xerrors.Errorf("set market actor: %w", err) } - burntRoot, err := cst.Put(ctx, &account.State{ - Address: builtin.BurntFundsActorAddr, + burntRoot, err := cst.Put(ctx, &v0account.State{ + Address: v0builtin.BurntFundsActorAddr, }) if err != nil { return nil, nil, xerrors.Errorf("failed to setup burnt funds actor state: %w", err) } // Setup burnt-funds - err = state.SetActor(builtin.BurntFundsActorAddr, &types.Actor{ - Code: builtin.AccountActorCodeID, + err = state.SetActor(v0builtin.BurntFundsActorAddr, &types.Actor{ + Code: v0builtin.AccountActorCodeID, Balance: types.NewInt(0), Head: burntRoot, }) @@ -261,13 +262,13 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, err } - verifierState, err := cst.Put(ctx, &account.State{Address: verifierAd}) + verifierState, err := cst.Put(ctx, &v0account.State{Address: verifierAd}) if err != nil { return nil, nil, err } err = state.SetActor(verifierId, &types.Actor{ - Code: builtin.AccountActorCodeID, + Code: v0builtin.AccountActorCodeID, Balance: types.NewInt(0), Head: verifierState, }) @@ -314,7 +315,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - st, err := cst.Put(ctx, &account.State{Address: ainfo.Owner}) + st, err := cst.Put(ctx, &v0account.State{Address: ainfo.Owner}) if err != nil { return err } @@ -325,7 +326,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St } err = state.SetActor(ida, &types.Actor{ - Code: builtin.AccountActorCodeID, + Code: v0builtin.AccountActorCodeID, Balance: info.Balance, Head: st, }) @@ -343,7 +344,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root() + pending, err := v0adt.MakeEmptyMap(v0adt.WrapStore(ctx, cst)).Root() if err != nil { return xerrors.Errorf("failed to create empty map: %v", err) } @@ -363,12 +364,12 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I continue } - st, err := cst.Put(ctx, &account.State{Address: e}) + st, err := cst.Put(ctx, &v0account.State{Address: e}) if err != nil { return err } err = state.SetActor(idAddress, &types.Actor{ - Code: builtin.AccountActorCodeID, + Code: v0builtin.AccountActorCodeID, Balance: types.NewInt(0), Head: st, }) @@ -378,7 +379,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I signers = append(signers, idAddress) } - st, err := cst.Put(ctx, &multisig.State{ + st, err := cst.Put(ctx, &v0multisig.State{ Signers: signers, NumApprovalsThreshold: uint64(ainfo.Threshold), StartEpoch: abi.ChainEpoch(ainfo.VestingStart), @@ -390,7 +391,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I return err } err = state.SetActor(ida, &types.Actor{ - Code: builtin.MultisigActorCodeID, + Code: v0builtin.MultisigActorCodeID, Balance: info.Balance, Head: st, }) @@ -441,7 +442,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci return cid.Undef, err } - _, err = doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg.AddVerifierParams{ + _, err = doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&v0verifreg.AddVerifierParams{ Address: verifier, Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough @@ -452,7 +453,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci } for c, amt := range verifNeeds { - _, err := doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&verifreg.AddVerifiedClientParams{ + _, err := doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&v0verifreg.AddVerifiedClientParams{ Address: c, Allowance: abi.NewStoragePower(int64(amt)), })) @@ -494,8 +495,8 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB return nil, xerrors.Errorf("setup miners failed: %w", err) } - store := adt.WrapStore(ctx, cbor.NewCborStore(bs)) - emptyroot, err := adt.MakeEmptyArray(store).Root() + store := v0adt.WrapStore(ctx, cbor.NewCborStore(bs)) + emptyroot, err := v0adt.MakeEmptyArray(store).Root() if err != nil { return nil, xerrors.Errorf("amt build failed: %w", err) } @@ -543,7 +544,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB } b := &types.BlockHeader{ - Miner: builtin.SystemActorAddr, + Miner: v0builtin.SystemActorAddr, Ticket: genesisticket, Parents: []cid.Cid{filecoinGenesisCid}, Height: 0, diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 7aa7701fd73..b3a3b7cee53 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -12,9 +12,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -24,8 +23,10 @@ var log = logging.Logger("statetree") // StateTree stores actors state by their ID. type StateTree struct { - root adt.Map - Store cbor.IpldStore + root adt.Map + version builtin.Version // TODO + info cid.Cid + Store cbor.IpldStore snaps *stateSnaps } @@ -117,31 +118,57 @@ func (ss *stateSnaps) deleteActor(addr address.Address) { ss.layers[len(ss.layers)-1].actors[addr] = streeOp{Delete: true} } -func NewStateTree(cst cbor.IpldStore, version network.Version) (*StateTree, error) { +func NewStateTree(cst cbor.IpldStore, version builtin.Version) (*StateTree, error) { + var info cid.Cid + switch version { + case builtin.Version0: + // info is undefined + default: + return nil, xerrors.Errorf("unsupported state tree version: %d", version) + } root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), version) if err != nil { return nil, err } return &StateTree{ - root: root, - Store: cst, - snaps: newStateSnaps(), + root: root, + info: info, + version: version, + Store: cst, + snaps: newStateSnaps(), }, nil } -func LoadStateTree(cst cbor.IpldStore, c cid.Cid, version network.Version) (*StateTree, error) { - // NETUPGRADE: switch map adt type on version upgrade. - nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), c, version) +func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) { + var root types.StateRoot + // Try loading as a new-style state-tree (version/actors tuple). + if err := cst.Get(context.TODO(), c, &root); err != nil { + // We failed to decode as the new version, must be an old version. + root.Actors = c + root.Version = builtin.Version0 + } + + // If that fails, load as an old-style state-tree (direct hampt, version 0. + nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), root.Actors, builtin.Version(root.Version)) if err != nil { log.Errorf("loading hamt node %s failed: %s", c, err) return nil, err } + switch root.Version { + case builtin.Version0: + // supported + default: + return nil, xerrors.Errorf("unsupported state tree version: %d", root.Version) + } + return &StateTree{ - root: nd, - Store: cst, - snaps: newStateSnaps(), + root: nd, + info: root.Info, + version: builtin.Version(root.Version), + Store: cst, + snaps: newStateSnaps(), }, nil } @@ -167,7 +194,7 @@ func (st *StateTree) LookupID(addr address.Address) (address.Address, error) { return resa, nil } - act, err := st.GetActor(builtin.InitActorAddr) + act, err := st.GetActor(init_.Address) if err != nil { return address.Undef, xerrors.Errorf("getting init actor: %w", err) } @@ -271,7 +298,16 @@ func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) { } } - return st.root.Root() + root, err := st.root.Root() + if err != nil { + return cid.Undef, xerrors.Errorf("failed to flush state-tree hamt: %w", err) + } + // If we're version 0, return a raw tree. + if st.version == builtin.Version0 { + return root, nil + } + // Otherwise, return a versioned tree. + return st.Store.Put(ctx, &types.StateRoot{Version: uint64(st.version), Actors: root, Info: st.info}) } func (st *StateTree) Snapshot(ctx context.Context) error { @@ -289,7 +325,7 @@ func (st *StateTree) ClearSnapshot() { func (st *StateTree) RegisterNewAddress(addr address.Address) (address.Address, error) { var out address.Address - err := st.MutateActor(builtin.InitActorAddr, func(initact *types.Actor) error { + err := st.MutateActor(init_.Address, func(initact *types.Actor) error { ias, err := init_.Load(&AdtStore{st.Store}, initact) if err != nil { return err diff --git a/chain/stmgr/read.go b/chain/stmgr/read.go index 7bf757fb8d6..53eb8d384ed 100644 --- a/chain/stmgr/read.go +++ b/chain/stmgr/read.go @@ -8,7 +8,6 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" ) @@ -23,8 +22,7 @@ func (sm *StateManager) ParentStateTsk(tsk types.TipSetKey) (*state.StateTree, e func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - version := sm.GetNtwkVersion(context.TODO(), ts.Height()-1) - state, err := state.LoadStateTree(cst, sm.parentState(ts), version) + state, err := state.LoadStateTree(cst, sm.parentState(ts)) if err != nil { return nil, xerrors.Errorf("load state tree: %w", err) } @@ -32,9 +30,9 @@ func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error) return state, nil } -func (sm *StateManager) StateTree(st cid.Cid, ntwkVersion network.Version) (*state.StateTree, error) { +func (sm *StateManager) StateTree(st cid.Cid) (*state.StateTree, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, st, ntwkVersion) + state, err := state.LoadStateTree(cst, st) if err != nil { return nil, xerrors.Errorf("load state tree: %w", err) } @@ -57,3 +55,11 @@ func (sm *StateManager) LoadActorTsk(_ context.Context, addr address.Address, ts } return state.GetActor(addr) } + +func (sm *StateManager) LoadActorRaw(_ context.Context, addr address.Address, st cid.Cid) (*types.Actor, error) { + state, err := sm.StateTree(st) + if err != nil { + return nil, err + } + return state.GetActor(addr) +} diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 23e8e92a0c1..f71b788c8f2 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -383,7 +383,7 @@ func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Ad } cst := cbor.NewCborStore(sm.cs.Blockstore()) - tree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, ts.Height())) + tree, err := state.LoadStateTree(cst, st) if err != nil { return address.Undef, xerrors.Errorf("failed to load state tree") } @@ -406,7 +406,7 @@ func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Addres func (sm *StateManager) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, sm.parentState(ts), sm.GetNtwkVersion(ctx, ts.Height())) + state, err := state.LoadStateTree(cst, sm.parentState(ts)) if err != nil { return address.Undef, xerrors.Errorf("load state tree: %w", err) } @@ -817,7 +817,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { } cst := cbor.NewCborStore(sm.cs.Blockstore()) - sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height())) + sTree, err := state.LoadStateTree(cst, st) if err != nil { return xerrors.Errorf("loading state tree: %w", err) } @@ -923,7 +923,7 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error { } cst := cbor.NewCborStore(sm.cs.Blockstore()) - sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height())) + sTree, err := state.LoadStateTree(cst, st) if err != nil { return xerrors.Errorf("loading state tree: %w", err) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 81bcb090012..63e3e0f74a6 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -21,23 +21,22 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" - power2 "github.com/filecoin-project/lotus/chain/actors/builtin/power" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" @@ -48,8 +47,11 @@ import ( ) func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.NetworkName, error) { - var state init_.State - err := sm.WithStateTree(st, sm.WithActor(builtin.InitActorAddr, sm.WithActorState(ctx, &state))) + act, err := sm.LoadActorRaw(ctx, init_.Address, st) + if err != nil { + return "", err + } + ias, err := init_.Load(sm.cs.Store(ctx), act) if err != nil { return "", err } @@ -58,21 +60,18 @@ func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.N } func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) { - var mas miner.State - _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, st) + act, err := sm.LoadActorRaw(ctx, sm, maddr, st) if err != nil { return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - - cst := cbor.NewCborStore(sm.cs.Blockstore()) - state, err := state.LoadStateTree(cst, st) + mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { return address.Undef, xerrors.Errorf("load state tree: %w", err) } - info, err := mas.GetInfo(sm.cs.Store(ctx)) + info, err := mas.Info() if err != nil { - return address.Address{}, err + return address.Undef, xerrors.Errorf("failed to load actor info: %w", err) } return vm.ResolveToKeyAddr(state, cst, info.Worker) @@ -83,36 +82,35 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add } func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, error) { - var ps power.State - _, err := sm.LoadActorStateRaw(ctx, builtin.StoragePowerActorAddr, &ps, st) + act, err := sm.LoadActorRaw(ctx, builtin.StoragePowerActorAddr, st) if err != nil { return power.Claim{}, power.Claim{}, xerrors.Errorf("(get sset) failed to load power actor state: %w", err) } + mas, err := power.Load(sm.cs.Store(ctx), act) + if err != nil { + return power.Claim{}, power.Claim{}, err + } + + tpow, err := mas.TotalPower() + if err != nil { + return power.Claim{}, power.Claim{}, err + } + var mpow power.Claim if maddr != address.Undef { - cm, err := adt.AsMap(sm.cs.Store(ctx), ps.Claims) + mpow, err = mas.MinerPower(maddr) if err != nil { return power.Claim{}, power.Claim{}, err } - - var claim power.Claim - if _, err := cm.Get(abi.AddrKey(maddr), &claim); err != nil { - return power.Claim{}, power.Claim{}, err - } - - mpow = claim } - return mpow, power.Claim{ - RawBytePower: ps.TotalRawBytePower, - QualityAdjPower: ps.TotalQualityAdjPower, - }, nil + return mpow, tpow, nil } func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (miner.SectorPreCommitOnChainInfo, error) { var mas miner.State - _, err := sm.LoadActorState(ctx, maddr, &mas, ts) + act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } @@ -676,16 +674,16 @@ func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Addres return false, xerrors.Errorf("loading power actor state: %w", err) } - ps, err := power2.Load(sm.cs.Store(ctx), pact) + ps, err := power.Load(sm.cs.Store(ctx), pact) if err != nil { return false, err } - return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr) + return ps.MinerNominalPowerMeetsConsensusMinimum(addr) } func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) { - str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState(), sm.GetNtwkVersion(ctx, ts.Height())) + str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState()) if err != nil { return abi.TokenAmount{}, err } diff --git a/chain/store/store.go b/chain/store/store.go index 2c97e2de53d..66e31569ba1 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -5,8 +5,6 @@ import ( "context" "encoding/binary" "encoding/json" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/build" "io" "os" "strconv" @@ -766,29 +764,12 @@ type BlockMessages struct { WinCount int64 } -// TODO: temp hack until #3682 is merged -func hackgetNtwkVersionhack(ctx context.Context, height abi.ChainEpoch) network.Version { - // TODO: move hard fork epoch checks to a schedule defined in build/ - - if build.UpgradeBreezeHeight == 0 { - return network.Version1 - } - - if height <= build.UpgradeBreezeHeight { - return network.Version0 - } - - return network.Version1 -} - func (cs *ChainStore) BlockMsgsForTipset(ts *types.TipSet) ([]BlockMessages, error) { applied := make(map[address.Address]uint64) cst := cbor.NewCborStore(cs.bs) - nv := hackgetNtwkVersionhack(context.TODO(), ts.Height()) // TODO: part of the temp hack from above - - st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot, nv) + st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot) if err != nil { return nil, xerrors.Errorf("failed to load state tree") } diff --git a/chain/store/weight.go b/chain/store/weight.go index e27d3fd3738..5249df0112b 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -29,7 +29,7 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn tpow := big2.Zero() { cst := cbor.NewCborStore(cs.Blockstore()) - state, err := state.LoadStateTree(cst, ts.ParentState(), hackgetNtwkVersionhack(nil, ts.Height())) // TODO: hackgetNtwkVersionhack: HELP + state, err := state.LoadStateTree(cst, ts.ParentState()) if err != nil { return types.NewInt(0), xerrors.Errorf("load state tree: %w", err) } diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 7c672bee290..1af5d8188af 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -435,7 +435,7 @@ func (bv *BlockValidator) checkPowerAndGetWorkerKey(ctx context.Context, bh *typ buf := bufbstore.NewBufferedBstore(bv.chain.Blockstore()) cst := cbor.NewCborStore(buf) - state, err := state.LoadStateTree(cst, st, bv.stmgr.GetNtwkVersion(ctx, ts.Height())) + state, err := state.LoadStateTree(cst, st) if err != nil { return address.Undef, err } diff --git a/chain/sync.go b/chain/sync.go index 1d8e456d8fe..bb3e50bdbb4 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1045,10 +1045,9 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock if err != nil { return err } - nwVersion := syncer.sm.GetNtwkVersion(ctx, baseTs.Height()) cst := cbor.NewCborStore(syncer.store.Blockstore()) - st, err := state.LoadStateTree(cst, stateroot, nwVersion) + st, err := state.LoadStateTree(cst, stateroot) if err != nil { return xerrors.Errorf("failed to load base state tree: %w", err) } diff --git a/chain/types/state.go b/chain/types/state.go new file mode 100644 index 00000000000..b99eb19c2fb --- /dev/null +++ b/chain/types/state.go @@ -0,0 +1,15 @@ +package types + +import "github.com/ipfs/go-cid" + +type StateRoot struct { + // State root version. Versioned along with actors (for now). + Version uint64 + // Actors tree. The structure depends on the state root version. + Actors cid.Cid + // Info. The structure depends on the state root version. + Info cid.Cid +} + +// TODO: version this. +type StateInfo struct{} diff --git a/chain/vm/vm.go b/chain/vm/vm.go index aa334aad50c..5afde5f498d 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -170,8 +170,7 @@ type VMOpts struct { func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) { buf := bufbstore.NewBufferedBstore(opts.Bstore) cst := cbor.NewCborStore(buf) - nwv := opts.NtwkVersion(ctx, opts.Epoch) // TODO: why do we need a context for this? - state, err := state.LoadStateTree(cst, opts.StateBase, nwv) + state, err := state.LoadStateTree(cst, opts.StateBase) if err != nil { return nil, err } diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index f3ffd140fb9..7dbfe2eb7a9 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -171,9 +171,8 @@ var chainBalanceStateCmd = &cli.Command{ sm := stmgr.NewStateManager(cs) - // NETUPGRADE: FIXME. // Options: (a) encode the version in the chain or (b) pass a flag. - tree, err := state.LoadStateTree(cst, sroot, network.Version0) + tree, err := state.LoadStateTree(cst, sroot) if err != nil { return err } diff --git a/cmd/lotus-shed/genesis-verify.go b/cmd/lotus-shed/genesis-verify.go index 62808db9ba2..043cb72bb8b 100644 --- a/cmd/lotus-shed/genesis-verify.go +++ b/cmd/lotus-shed/genesis-verify.go @@ -79,7 +79,7 @@ var genesisVerifyCmd = &cli.Command{ cst := cbor.NewCborStore(bs) - stree, err := state.LoadStateTree(cst, ts.ParentState(), sm.GetNtwkVersion()) + stree, err := state.LoadStateTree(cst, ts.ParentState()) if err != nil { return err } diff --git a/gen/main.go b/gen/main.go index e7586a92a89..be227663c17 100644 --- a/gen/main.go +++ b/gen/main.go @@ -26,6 +26,8 @@ func main() { types.BlockMsg{}, types.ExpTipSet{}, types.BeaconEntry{}, + types.StateRoot{}, + types.StateInfo{}, ) if err != nil { fmt.Println(err) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 38e62f9051c..75f06e636b5 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -317,7 +317,7 @@ func (a *StateAPI) stateForTs(ctx context.Context, ts *types.TipSet) (*state.Sta buf := bufbstore.NewBufferedBstore(a.Chain.Blockstore()) cst := cbor.NewCborStore(buf) - return state.LoadStateTree(cst, st, a.StateManager.GetNtwkVersion(ctx, ts.Height())) + return state.LoadStateTree(cst, st) } func (a *StateAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) { From 7fa6c1e8d04c3a68c1a37928af3c10c44b5fcff6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 14 Sep 2020 15:45:00 -0700 Subject: [PATCH 008/104] add info method to miner state API --- chain/actors/builtin/miner/miner.go | 1 + 1 file changed, 1 insertion(+) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 76503d80ea6..1546489869f 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -35,6 +35,7 @@ type State interface { LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) + Info() (MinerInfo, error) } type Deadline interface { From 36f920bcd7487c0bb0fb81326109882fda9b98b9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 14 Sep 2020 21:55:49 -0700 Subject: [PATCH 009/104] progress --- api/api_full.go | 2 +- chain/actors/builtin/miner/miner.go | 8 ++++++ chain/actors/builtin/miner/v0.go | 19 +++++++++++++ chain/stmgr/utils.go | 42 +++++++++++++---------------- extern/storage-sealing/sealing.go | 1 - storage/miner.go | 2 -- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index a5cf2423d09..035c7de430c 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -17,8 +17,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 1546489869f..eb70d145771 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -32,6 +33,9 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler + GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) + GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) + LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) @@ -51,6 +55,10 @@ type Partition interface { ActiveSectors() (bitfield.BitField, error) } +type SectorOnChainInfo = v0miner.SectorOnChainInfo +type SectorPreCommitInfo = v0miner.SectorPreCommitInfo +type SectorPreCommitOnChainInfo = v0miner.SectorPreCommitOnChainInfo + type MinerInfo struct { Owner address.Address // Must be an ID-address. Worker address.Address // Must be an ID-address. diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 1d8a68183eb..40b9e4cc6bb 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -3,6 +3,7 @@ package miner import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/libp2p/go-libp2p-core/peer" @@ -24,6 +25,24 @@ type v0Partition struct { store adt.Store } +func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { + info, ok, err := s.State.GetSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + return info, nil +} + +func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { + info, ok, err := s.State.GetPrecommittedSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + return info, nil +} + func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 63e3e0f74a6..11eedb5125d 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -56,17 +56,21 @@ func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.N return "", err } - return dtypes.NetworkName(state.NetworkName), nil + return ias.NetworkName() } func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) { - act, err := sm.LoadActorRaw(ctx, sm, maddr, st) + state, err := sm.StateTree(st) if err != nil { - return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) + return address.Undef, xerrors.Errorf("(get sset) failed to load state tree: %w", err) + } + act, err := state.GetActor(maddr) + if err != nil { + return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) } mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { - return address.Undef, xerrors.Errorf("load state tree: %w", err) + return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } info, err := mas.Info() @@ -74,7 +78,7 @@ func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr return address.Undef, xerrors.Errorf("failed to load actor info: %w", err) } - return vm.ResolveToKeyAddr(state, cst, info.Worker) + return vm.ResolveToKeyAddr(state, sm.cs.Store(ctx), info.Worker) } func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (power.Claim, power.Claim, error) { @@ -108,40 +112,32 @@ func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr addres return mpow, tpow, nil } -func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (miner.SectorPreCommitOnChainInfo, error) { - var mas miner.State +func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorPreCommitOnChainInfo, error) { act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { - return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) + return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) } - i, ok, err := mas.GetPrecommittedSector(sm.cs.Store(ctx), sid) + mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { - return miner.SectorPreCommitOnChainInfo{}, err - } - if !ok { - return miner.SectorPreCommitOnChainInfo{}, xerrors.New("precommit not found") + return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - return *i, nil + return mas.GetPrecommittedSector(sid) } func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorOnChainInfo, error) { - var mas miner.State - _, err := sm.LoadActorState(ctx, maddr, &mas, ts) + act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { - return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) + return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) } - sectorInfo, ok, err := mas.GetSector(sm.cs.Store(ctx), sid) + mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { - return nil, err - } - if !ok { - return nil, nil + return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - return sectorInfo, nil + return mas.GetSector(sid) } func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, filter *bitfield.BitField, filterOut bool) ([]*api.ChainSectorInfo, error) { diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index cb73182d39c..533333860b1 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -50,7 +50,6 @@ type SealingAPI interface { StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok TipSetToken) (*SectorLocation, error) StateMinerSectorSize(context.Context, address.Address, TipSetToken) (abi.SectorSize, error) StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok TipSetToken) (address.Address, error) - StateMinerDeadlines(ctx context.Context, maddr address.Address, tok TipSetToken) ([]*miner.Deadline, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error) diff --git a/storage/miner.go b/storage/miner.go index bf026fc30e7..d2af4be2c70 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -67,8 +67,6 @@ type SealingStateEvt struct { type storageMinerApi interface { // Call a read only method on actors (no interaction with the chain required) StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) - StateMinerDeadlines(ctx context.Context, maddr address.Address, tok types.TipSetKey) ([]*miner.Deadline, error) - StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]*miner.Partition, error) StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) From 4dabab5ce649137ee0f240122e1dbbbea1e84182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 15 Sep 2020 13:04:45 +0200 Subject: [PATCH 010/104] state manager progress --- api/api_full.go | 9 +- api/apistruct/struct.go | 30 ++--- chain/actors/builtin/miner/miner.go | 6 + chain/actors/builtin/miner/utils.go | 28 +++++ chain/actors/builtin/miner/v0.go | 39 +++++++ chain/stmgr/utils.go | 165 ++++++++++++++-------------- node/impl/full/state.go | 8 +- storage/miner.go | 3 +- 8 files changed, 177 insertions(+), 111 deletions(-) create mode 100644 chain/actors/builtin/miner/utils.go diff --git a/api/api_full.go b/api/api_full.go index 035c7de430c..c76b9038c95 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -315,9 +315,9 @@ type FullNode interface { // StateMinerSectors returns info about the given miner's sectors. If the filter bitfield is nil, all sectors are included. // If the filterOut boolean is set to true, any sectors in the filter are excluded. // If false, only those sectors in the filter are included. - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) // StateMinerActiveSectors returns info about sectors that a given miner is actively proving. - StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*ChainSectorInfo, error) + StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) // StateMinerProvingDeadline calculates the deadline at some epoch for a proving period // and returns the deadline-related calculations. StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) @@ -538,11 +538,6 @@ type Message struct { Message *types.Message } -type ChainSectorInfo struct { - Info miner.SectorOnChainInfo - ID abi.SectorNumber -} - type ActorState struct { Balance types.BigInt State interface{} diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 1eac858a029..ea8c311a002 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -161,19 +161,19 @@ type FullNodeStruct struct { ClientDataTransferUpdates func(ctx context.Context) (<-chan api.DataTransferChannel, error) `perm:"write"` ClientRetrieveTryRestartInsufficientFunds func(ctx context.Context, paymentChannel address.Address) error `perm:"write"` - StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` - StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` - StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` - StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` - StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` - StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` - StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` - StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateMinerPreCommitDepositForPower func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateMinerInitialPledgeCollateral func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` + StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` + StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) `perm:"read"` + StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) `perm:"read"` + StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` + StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` + StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` + StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` + StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` + StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` + StateMinerPreCommitDepositForPower func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateMinerInitialPledgeCollateral func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorExpiration, error) `perm:"read"` StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorLocation, error) `perm:"read"` @@ -730,11 +730,11 @@ func (c *FullNodeStruct) StateNetworkName(ctx context.Context) (dtypes.NetworkNa return c.Internal.StateNetworkName(ctx) } -func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { +func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner2.ChainSectorInfo, error) { return c.Internal.StateMinerSectors(ctx, addr, filter, filterOut, tsk) } -func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { +func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*miner2.ChainSectorInfo, error) { return c.Internal.StateMinerActiveSectors(ctx, addr, tsk) } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index eb70d145771..6f3bbe4bbaa 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -35,6 +35,7 @@ type State interface { GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) + LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error) LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error @@ -71,3 +72,8 @@ type MinerInfo struct { SectorSize abi.SectorSize WindowPoStPartitionSectors uint64 } + +type ChainSectorInfo struct { + Info SectorOnChainInfo + ID abi.SectorNumber +} diff --git a/chain/actors/builtin/miner/utils.go b/chain/actors/builtin/miner/utils.go new file mode 100644 index 00000000000..052d2da60a1 --- /dev/null +++ b/chain/actors/builtin/miner/utils.go @@ -0,0 +1,28 @@ +package miner + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-bitfield" +) + +func AllPartSectors(mas State, sget func(Partition) (bitfield.BitField, error)) (bitfield.BitField, error) { + var parts []bitfield.BitField + + err := mas.ForEachDeadline(func(dlidx uint64, dl Deadline) error { + return dl.ForEachPartition(func(partidx uint64, part Partition) error { + s, err := sget(part) + if err != nil { + return xerrors.Errorf("getting sector list (dl: %d, part %d): %w", dlidx, partidx, err) + } + + parts = append(parts, s) + return nil + }) + }) + if err != nil { + return bitfield.BitField{}, err + } + + return bitfield.MultiMerge(parts...) +} \ No newline at end of file diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 40b9e4cc6bb..0fb75795c85 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -5,7 +5,11 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/adt" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) @@ -43,6 +47,41 @@ func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitO return info, nil } +func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error) { + a, err := v0adt.AsArray(s.store, s.State.Sectors) + if err != nil { + return nil, err + } + + var sset []*ChainSectorInfo + var v cbg.Deferred + if err := a.ForEach(&v, func(i int64) error { + if filter != nil { + set, err := filter.IsSet(uint64(i)) + if err != nil { + return xerrors.Errorf("filter check error: %w", err) + } + if set == filterOut { + return nil + } + } + + var oci miner.SectorOnChainInfo + if err := cbor.DecodeInto(v.Raw, &oci); err != nil { + return err + } + sset = append(sset, &ChainSectorInfo{ + Info: oci, + ID: abi.SectorNumber(i), + }) + return nil + }); err != nil { + return nil, err + } + + return sset, nil +} + func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 11eedb5125d..0217bd91e40 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -140,60 +140,35 @@ func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Addres return mas.GetSector(sid) } -func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, filter *bitfield.BitField, filterOut bool) ([]*api.ChainSectorInfo, error) { - var mas miner.State - _, err := sm.LoadActorState(ctx, maddr, &mas, ts) +func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, filter *bitfield.BitField, filterOut bool) ([]*miner.ChainSectorInfo, error) { + act, err := sm.LoadActor(ctx, maddr, ts) + if err != nil { + return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) + } + + mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - return LoadSectorsFromSet(ctx, sm.ChainStore().Blockstore(), mas.Sectors, filter, filterOut) + return mas.LoadSectorsFromSet(filter, filterOut) } func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]proof.SectorInfo, error) { - var partsProving []bitfield.BitField - var mas *miner.State - var info *miner.MinerInfo - - err := sm.WithStateTree(st, sm.WithActor(maddr, sm.WithActorState(ctx, func(store adt.Store, mst *miner.State) error { - var err error - - mas = mst - - info, err = mas.GetInfo(store) - if err != nil { - return xerrors.Errorf("getting miner info: %w", err) - } - - deadlines, err := mas.LoadDeadlines(store) - if err != nil { - return xerrors.Errorf("loading deadlines: %w", err) - } - - return deadlines.ForEach(store, func(dlIdx uint64, deadline *miner.Deadline) error { - partitions, err := deadline.PartitionsArray(store) - if err != nil { - return xerrors.Errorf("getting partition array: %w", err) - } - - var partition miner.Partition - return partitions.ForEach(&partition, func(partIdx int64) error { - p, err := bitfield.SubtractBitField(partition.Sectors, partition.Faults) - if err != nil { - return xerrors.Errorf("subtract faults from partition sectors: %w", err) - } - - partsProving = append(partsProving, p) + act, err := sm.LoadActorRaw(ctx, maddr, st) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor: %w", err) + } - return nil - }) - }) - }))) + mas, err := miner.Load(sm.cs.Store(ctx), act) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } - provingSectors, err := bitfield.MultiMerge(partsProving...) + // TODO (!!): This was partition.Sectors-partition.Faults originally, which was likely very wrong, and will need to be an upgrade + // ^ THE CURRENT THING HERE WON'T SYNC v + + provingSectors, err := miner.AllPartSectors(mas, miner.Partition.ActiveSectors) if err != nil { return nil, xerrors.Errorf("merge partition proving sets: %w", err) } @@ -208,6 +183,11 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, nil } + info, err := mas.Info() + if err != nil { + return nil, xerrors.Errorf("getting miner info: %w", err) + } + spt, err := ffiwrapper.SealProofTypeFromSectorSize(info.SectorSize) if err != nil { return nil, xerrors.Errorf("getting seal proof type: %w", err) @@ -228,31 +208,19 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, xerrors.Errorf("generating winning post challenges: %w", err) } - sectors, err := provingSectors.All(miner.SectorsMax) - if err != nil { - return nil, xerrors.Errorf("failed to enumerate all sector IDs: %w", err) - } - - sectorAmt, err := adt.AsArray(sm.cs.Store(ctx), mas.Sectors) + sectors, err := mas.LoadSectorsFromSet(&provingSectors, false) if err != nil { - return nil, xerrors.Errorf("failed to load sectors amt: %w", err) + return nil, xerrors.Errorf("loading proving sectors: %w", err) } out := make([]proof.SectorInfo, len(ids)) for i, n := range ids { - sid := sectors[n] - - var sinfo miner.SectorOnChainInfo - if found, err := sectorAmt.Get(sid, &sinfo); err != nil { - return nil, xerrors.Errorf("failed to get sector %d: %w", sid, err) - } else if !found { - return nil, xerrors.Errorf("failed to find sector %d", sid) - } + s := sectors[n] out[i] = proof.SectorInfo{ SealProof: spt, - SectorNumber: sinfo.SectorNumber, - SealedCID: sinfo.SealedCID, + SectorNumber: s.ID, + SealedCID: s.Info.SealedCID, } } @@ -260,20 +228,33 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S } 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()) + act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { - return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err) + return nil, xerrors.Errorf("failed to load miner actor: %w", err) } - return mas.GetInfo(sm.cs.Store(ctx)) + mas, err := miner.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) + } + + mi, err := mas.Info() + if err != nil { + return nil, err + } + + return &mi, err } func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) { - var spas power.State - _, err := sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &spas, ts) + act, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) + if err != nil { + return false, xerrors.Errorf("failed to load power actor: %w", err) + } + + spas, err := power.Load(sm.cs.Store(ctx), act) if err != nil { - return false, xerrors.Errorf("(get miner slashed) failed to load power actor state") + return false, xerrors.Errorf("failed to load power actor state: %w", err) } store := sm.cs.Store(ctx) @@ -295,10 +276,16 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma } func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) { - var state market.State - if _, err := sm.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts); err != nil { - return nil, err + act, err := sm.LoadActor(ctx, builtin.StorageMarketActorAddr, ts) + if err != nil { + return nil, xerrors.Errorf("failed to load market actor: %w", err) + } + + state, err := market.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load market actor state: %w", err) } + store := sm.ChainStore().Store(ctx) da, err := adt.AsArray(store, state.Proposals) @@ -338,9 +325,14 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts } func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([]address.Address, error) { - var state power.State - if _, err := sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &state, ts); err != nil { - return nil, err + act, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) + if err != nil { + return nil, xerrors.Errorf("failed to load power actor: %w", err) + } + + state, err := power.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load power actor state: %w", err) } m, err := adt.AsMap(sm.cs.Store(ctx), state.Claims) @@ -364,13 +356,13 @@ func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([ return miners, nil } -func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid, filter *bitfield.BitField, filterOut bool) ([]*api.ChainSectorInfo, error) { +func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid, filter *bitfield.BitField, filterOut bool) ([]*miner.ChainSectorInfo, error) { a, err := adt.AsArray(store.ActorStore(ctx, bs), ssc) if err != nil { return nil, err } - var sset []*api.ChainSectorInfo + var sset []*miner.ChainSectorInfo var v cbg.Deferred if err := a.ForEach(&v, func(i int64) error { if filter != nil { @@ -387,7 +379,7 @@ func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.C if err := cbor.DecodeInto(v.Raw, &oci); err != nil { return err } - sset = append(sset, &api.ChainSectorInfo{ + sset = append(sset, &miner.ChainSectorInfo{ Info: oci, ID: abi.SectorNumber(i), }) @@ -420,7 +412,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, NtwkVersion: sm.GetNtwkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, } - vmi, err := vm.NewVM(vmopt) + vmi, err := vm.NewVM(ctx, vmopt) if err != nil { return cid.Undef, nil, err } @@ -508,9 +500,14 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, err } - var mas miner.State - if _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, lbst); err != nil { - return nil, err + act, err := sm.LoadActorRaw(ctx, maddr, lbst) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor: %w", err) + } + + mas, err := miner.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } buf := new(bytes.Buffer) @@ -537,7 +534,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, xerrors.Errorf("failed to get power: %w", err) } - info, err := mas.GetInfo(sm.cs.Store(ctx)) + info, err := mas.Info() if err != nil { return nil, err } @@ -652,9 +649,9 @@ func init() { } func GetReturnType(ctx context.Context, sm *StateManager, to address.Address, method abi.MethodNum, ts *types.TipSet) (cbg.CBORUnmarshaler, error) { - var act types.Actor - if err := sm.WithParentState(ts, sm.WithActor(to, GetActor(&act))); err != nil { - return nil, xerrors.Errorf("getting actor: %w", err) + act, err := sm.LoadActor(ctx, to, ts) + if err != nil { + return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) } m, found := MethodsMap[act.Code][method] diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 75f06e636b5..f61ebea4975 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -30,11 +30,11 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" @@ -62,7 +62,7 @@ func (a *StateAPI) StateNetworkName(ctx context.Context) (dtypes.NetworkName, er return stmgr.GetNetworkName(ctx, a.StateManager, a.Chain.GetHeaviestTipSet().ParentState()) } -func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { +func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) @@ -70,8 +70,8 @@ func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, addr, filter, filterOut) } -func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { - var out []*api.ChainSectorInfo +func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { // TODO: only used in cli + var out []*miner.ChainSectorInfo err := a.StateManager.WithParentStateTsk(tsk, a.StateManager.WithActor(maddr, diff --git a/storage/miner.go b/storage/miner.go index d2af4be2c70..47f50ce71c5 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -3,6 +3,7 @@ package storage import ( "context" "errors" + miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "time" "github.com/filecoin-project/go-state-types/dline" @@ -67,7 +68,7 @@ type SealingStateEvt struct { type storageMinerApi interface { // Call a read only method on actors (no interaction with the chain required) StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*api.SectorLocation, error) From 441985019597030eff05ac316d1a873432806e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 15 Sep 2020 15:29:25 +0200 Subject: [PATCH 011/104] state api impl fixes --- api/api_full.go | 2 +- chain/actors/builtin/miner/miner.go | 3 + chain/actors/builtin/miner/v0.go | 5 + chain/actors/builtin/power/power.go | 2 +- chain/actors/builtin/power/v0.go | 11 +- chain/stmgr/utils.go | 12 +- node/impl/full/state.go | 163 +++++++++++++--------------- 7 files changed, 95 insertions(+), 103 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index c76b9038c95..6625ae7f522 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -20,11 +20,11 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime/proof" miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/node/modules/dtypes" diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 6f3bbe4bbaa..9824ce61c5b 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -1,6 +1,7 @@ package miner import ( + "github.com/filecoin-project/go-state-types/dline" "github.com/libp2p/go-libp2p-core/peer" "golang.org/x/xerrors" @@ -41,6 +42,8 @@ type State interface { ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) Info() (MinerInfo, error) + + DeadlineInfo(epoch abi.ChainEpoch) *dline.Info } type Deadline interface { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 0fb75795c85..a7ed66fbdd1 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -4,6 +4,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/chain/actors/adt" v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" @@ -142,6 +143,10 @@ func (s *v0State) Info() (MinerInfo, error) { return mi, nil } +func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { + return s.State.DeadlineInfo(epoch) +} + func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 7588615a6e8..fa0400f2eeb 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -30,7 +30,7 @@ type State interface { TotalLocked() (abi.TokenAmount, error) TotalPower() (Claim, error) - MinerPower(address.Address) (Claim, error) + MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) } diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index f3152eb6a62..12eb318e5f6 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -23,19 +23,20 @@ func (s *v0State) TotalPower() (Claim, error) { }, nil } -func (s *v0State) MinerPower(addr address.Address) (Claim, error) { +func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { claims, err := adt.AsMap(s.store, s.Claims) if err != nil { - return Claim{}, err + return Claim{}, false, err } var claim power.Claim - if _, err := claims.Get(abi.AddrKey(addr), &claim); err != nil { - return Claim{}, err + ok, err := claims.Get(abi.AddrKey(addr), &claim) + if err != nil { + return Claim{}, false, err } return Claim{ RawBytePower: claim.RawBytePower, QualityAdjPower: claim.QualityAdjPower, - }, nil + }, ok, nil } func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 0217bd91e40..4dc21015483 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -26,7 +26,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/cron" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/reward" @@ -36,6 +35,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/state" @@ -257,17 +257,11 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma return false, xerrors.Errorf("failed to load power actor state: %w", err) } - store := sm.cs.Store(ctx) - - claims, err := adt.AsMap(store, spas.Claims) + _, ok, err := spas.MinerPower(maddr) if err != nil { - return false, err + return false, xerrors.Errorf("getting miner power: %w", err) } - ok, err := claims.Get(abi.AddrKey(maddr), nil) - if err != nil { - return false, err - } if !ok { return true, nil } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index f61ebea4975..98c9ed2e0dc 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -71,127 +71,121 @@ func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, } func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { // TODO: only used in cli - var out []*miner.ChainSectorInfo - - err := a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(maddr, - a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error { - var allActive []bitfield.BitField - - err := a.StateManager.WithDeadlines( - a.StateManager.WithEachDeadline( - a.StateManager.WithEachPartition(func(store adt.Store, partIdx uint64, partition *miner.Partition) error { - active, err := partition.ActiveSectors() - if err != nil { - return xerrors.Errorf("partition.ActiveSectors: %w", err) - } - - allActive = append(allActive, active) - return nil - })))(store, mas) - if err != nil { - return xerrors.Errorf("with deadlines: %w", err) - } + act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor: %w", err) + } - active, err := bitfield.MultiMerge(allActive...) - if err != nil { - return xerrors.Errorf("merging active sector bitfields: %w", err) - } + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) + } - out, err = stmgr.LoadSectorsFromSet(ctx, a.Chain.Blockstore(), mas.Sectors, &active, false) - return err - }))) + activeSectors, err := miner.AllPartSectors(mas, miner.Partition.ActiveSectors) if err != nil { - return nil, xerrors.Errorf("getting active sectors from partitions: %w", err) + return nil, xerrors.Errorf("merge partition active sets: %w", err) } - return out, nil + return mas.LoadSectorsFromSet(&activeSectors, false) } -func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) { - ts, err := a.Chain.GetTipSetFromKey(tsk) +func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { + act, err := a.StateManager.LoadActorTsk(ctx, actor, tsk) if err != nil { - return api.MinerInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err) } - a.StateManager.LoadActorStateRaw(ctx context.Context, addr address.Address, out interface{}, st cid.Cid) - - mi, err := stmgr.StateMinerInfo(ctx, a.StateManager, ts, actor) + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return api.MinerInfo{}, err + return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err) } - return api.NewApiMinerInfo(mi), nil + + return mas.Info() } func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]miner.Deadline, error) { - var out []*miner.Deadline - state, err := a.StateManager.LoadParentStateTsk(tsk) + act, err := a.StateManager.LoadActorTsk(ctx, m, tsk) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load miner actor: %w", err) } - act, err := state.GetActor(addr) + + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } - mas, err := miner.Load(a.Chain.Store(ctx), act) + + deadlines, err := mas.NumDeadlines() if err != nil { - return nil, err + return nil, xerrors.Errorf("getting deadline count: %w", err) } - var deadlines []miner.Deadline - if err := mas.ForEachDeadline(func(_ uint64, dl miner.Deadline) error { - deadlines = append(deadlines, dl) + + out := make([]miner.Deadline, deadlines) + if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error { + out[i] = dl return nil }); err != nil { - return err + return nil, err } - return deadlines, nil + return out, nil } func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]*miner.Partition, error) { + act, err := a.StateManager.LoadActorTsk(ctx, m, tsk) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor: %w", err) + } + + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) + } + + dl, err := mas.LoadDeadline(dlIdx) + if err != nil { + return nil, xerrors.Errorf("failed to load the deadline: %w", err) + } + var out []*miner.Partition - return out, a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(m, - a.StateManager.WithActorState(ctx, - a.StateManager.WithDeadlines( - a.StateManager.WithDeadline(dlIdx, - a.StateManager.WithEachPartition(func(store adt.Store, partIdx uint64, partition *miner.Partition) error { - out = append(out, partition) - return nil - })))))) + err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + p := part + out = append(out, &p) + return nil + }) + + return out, err } func (a *StateAPI) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) { - ts, err := a.Chain.GetTipSetFromKey(tsk) + ts, err := a.StateManager.ChainStore().GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var mas miner.State - _, err = a.StateManager.LoadActorState(ctx, addr, &mas, ts) + act, err := a.StateManager.LoadActor(ctx, addr, ts) if err != nil { - return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) + return nil, xerrors.Errorf("failed to load miner actor: %w", err) + } + + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } return mas.DeadlineInfo(ts.Height()).NextNotElapsed(), nil } func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { - out := bitfield.New() + act, err := a.StateManager.LoadActorTsk(ctx, addr, tsk) + if err != nil { + return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor: %w", err) + } - err := a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(addr, - a.StateManager.WithActorState(ctx, - a.StateManager.WithDeadlines( - a.StateManager.WithEachDeadline( - a.StateManager.WithEachPartition(func(store adt.Store, idx uint64, partition *miner.Partition) (err error) { - out, err = bitfield.MergeBitFields(out, partition.Faults) - return err - })))))) + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return bitfield.BitField{}, err + return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor state: %w", err) } - return out, err + return miner.AllPartSectors(mas, miner.Partition.FaultySectors) } func (a *StateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, endTsk types.TipSetKey) ([]*api.Fault, error) { @@ -238,22 +232,17 @@ func (a *StateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEp } func (a *StateAPI) StateMinerRecoveries(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { - out := bitfield.New() + act, err := a.StateManager.LoadActorTsk(ctx, addr, tsk) + if err != nil { + return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor: %w", err) + } - err := a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(addr, - a.StateManager.WithActorState(ctx, - a.StateManager.WithDeadlines( - a.StateManager.WithEachDeadline( - a.StateManager.WithEachPartition(func(store adt.Store, idx uint64, partition *miner.Partition) (err error) { - out, err = bitfield.MergeBitFields(out, partition.Recoveries) - return err - })))))) + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return bitfield.BitField{}, err + return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor state: %w", err) } - return out, err + return miner.AllPartSectors(mas, miner.Partition.RecoveringSectors) } func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*api.MinerPower, error) { From 9dad38c9a5a4fb834c0a479486875ee04988ca59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 15 Sep 2020 15:29:39 +0200 Subject: [PATCH 012/104] gofmt --- api/apistruct/struct.go | 50 ++++++++++++++--------------- chain/actors/builtin/miner/utils.go | 2 +- chain/gen/genesis/util.go | 18 +++++------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ea8c311a002..d0bdd14d359 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -174,31 +174,31 @@ type FullNodeStruct struct { StateMinerInitialPledgeCollateral func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` - StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` - StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorExpiration, error) `perm:"read"` - StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorLocation, error) `perm:"read"` - StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` - StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"` - StateGetActor func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) `perm:"read"` - StateReadState func(context.Context, address.Address, types.TipSetKey) (*api.ActorState, error) `perm:"read"` - StateWaitMsg func(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) `perm:"read"` - StateSearchMsg func(context.Context, cid.Cid) (*api.MsgLookup, error) `perm:"read"` - StateListMiners func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` - StateListActors func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` - StateMarketBalance func(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) `perm:"read"` - StateMarketParticipants func(context.Context, types.TipSetKey) (map[string]api.MarketBalance, error) `perm:"read"` - StateMarketDeals func(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) `perm:"read"` - StateMarketStorageDeal func(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) `perm:"read"` - StateLookupID func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` - StateAccountKey func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` - StateChangedActors func(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) `perm:"read"` - StateGetReceipt func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` - StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` - StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` - StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` - StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` - StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` - StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` + StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` + StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorExpiration, error) `perm:"read"` + StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorLocation, error) `perm:"read"` + StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` + StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"` + StateGetActor func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) `perm:"read"` + StateReadState func(context.Context, address.Address, types.TipSetKey) (*api.ActorState, error) `perm:"read"` + StateWaitMsg func(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) `perm:"read"` + StateSearchMsg func(context.Context, cid.Cid) (*api.MsgLookup, error) `perm:"read"` + StateListMiners func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` + StateListActors func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` + StateMarketBalance func(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) `perm:"read"` + StateMarketParticipants func(context.Context, types.TipSetKey) (map[string]api.MarketBalance, error) `perm:"read"` + StateMarketDeals func(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) `perm:"read"` + StateMarketStorageDeal func(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) `perm:"read"` + StateLookupID func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` + StateAccountKey func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` + StateChangedActors func(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) `perm:"read"` + StateGetReceipt func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` + StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` + StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` + StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` + StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` + StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` + StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` MsigGetVested func(context.Context, address.Address, types.TipSetKey, types.TipSetKey) (types.BigInt, error) `perm:"read"` diff --git a/chain/actors/builtin/miner/utils.go b/chain/actors/builtin/miner/utils.go index 052d2da60a1..f9c6b3da332 100644 --- a/chain/actors/builtin/miner/utils.go +++ b/chain/actors/builtin/miner/utils.go @@ -25,4 +25,4 @@ func AllPartSectors(mas State, sget func(Partition) (bitfield.BitField, error)) } return bitfield.MultiMerge(parts...) -} \ No newline at end of file +} diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 6a27f2f293f..d8750020675 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -49,13 +49,13 @@ func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value return ret.Return, nil } -var GenesisNetworkVersion = func() network.Version {// TODO: Get from build/ - if build.UseNewestNetwork() {// TODO: Get from build/ - return build.NewestNetworkVersion// TODO: Get from build/ - }// TODO: Get from build/ - return network.Version1// TODO: Get from build/ -}()// TODO: Get from build/ - -func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version {// TODO: Get from build/ +var GenesisNetworkVersion = func() network.Version { // TODO: Get from build/ + if build.UseNewestNetwork() { // TODO: Get from build/ + return build.NewestNetworkVersion // TODO: Get from build/ + } // TODO: Get from build/ + return network.Version1 // TODO: Get from build/ +}() // TODO: Get from build/ + +func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version { // TODO: Get from build/ return GenesisNetworkVersion // TODO: Get from build/ -}// TODO: Get from build/ +} // TODO: Get from build/ From 00c6397ec96170efd2124ef9c3bc9432090750f1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 10:44:44 -0700 Subject: [PATCH 013/104] more progress --- api/api_full.go | 13 ----- chain/actors/builtin/miner/miner.go | 15 +++++ chain/actors/builtin/miner/v0.go | 83 ++++++++++++++++++++++++++ node/impl/full/state.go | 91 ++++------------------------- 4 files changed, 109 insertions(+), 93 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 6625ae7f522..a5af175d834 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -473,19 +473,6 @@ type MinerSectors struct { Active uint64 } -type SectorExpiration struct { - OnTime abi.ChainEpoch - - // non-zero if sector is faulty, epoch at which it will be permanently - // removed if it doesn't recover - Early abi.ChainEpoch -} - -type SectorLocation struct { - Deadline uint64 - Partition uint64 -} - type ImportRes struct { Root cid.Cid ImportID multistore.StoreID diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 9824ce61c5b..5ad8db39ebb 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -35,6 +35,8 @@ type State interface { cbor.Marshaler GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) + FindSector(abi.SectorNumber) (*SectorLocation, error) + GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error) @@ -80,3 +82,16 @@ type ChainSectorInfo struct { Info SectorOnChainInfo ID abi.SectorNumber } + +type SectorExpiration struct { + OnTime abi.ChainEpoch + + // non-zero if sector is faulty, epoch at which it will be permanently + // removed if it doesn't recover + Early abi.ChainEpoch +} + +type SectorLocation struct { + Deadline uint64 + Partition uint64 +} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index a7ed66fbdd1..1a4bd380027 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -1,6 +1,8 @@ package miner import ( + "errors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -39,6 +41,87 @@ func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { return info, nil } +func (s *v0State) FindSector(num abi.SectorNumber) (*SectorLocation, error) { + dlIdx, partIdx, err := s.State.FindSector(s.store, num) + if err != nil { + return nil, err + } + return &SectorLocation{ + Deadline: dlIdx, + Partition: partIdx, + }, nil +} + +// GetSectorExpiration returns the effective expiration of the given sector. +// +// If the sector isn't found or has already been terminated, this method returns +// nil and no error. If the sector does not expire early, the Early expiration +// field is 0. +func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpiration, err error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + // NOTE: this can be optimized significantly. + // 1. If the sector is non-faulty, it will either expire on-time (can be + // learned from the sector info), or in the next quantized expiration + // epoch (i.e., the first element in the partition's expiration queue. + // 2. If it's faulty, it will expire early within the first 14 entries + // of the expiration queue. + stopErr := errors.New("stop") + err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner.Deadline) error { + partitions, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + quant := s.State.QuantSpecForDeadline(dlIdx) + var part miner.Partition + return partitions.ForEach(&part, func(partIdx int64) error { + if found, err := part.Sectors.IsSet(uint64(num)); err != nil { + return err + } else if !found { + return nil + } + if found, err := part.Terminated.IsSet(uint64(num)); err != nil { + return err + } else if found { + // already terminated + return stopErr + } + + q, err := miner.LoadExpirationQueue(s.store, part.EarlyTerminated, quant) + if err != nil { + return err + } + var exp miner.ExpirationSet + return q.ForEach(&exp, func(epoch int64) error { + if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { + return err + } else if early { + out.Early = abi.ChainEpoch(epoch) + return nil + } + if onTime, err := exp.OnTime.IsSet(uint64(num)); err != nil { + return err + } else if onTime { + out.OnTime = epoch + return stopErr + } + }) + }) + }) + if err == stopErr { + err = nil + } + if err != nil { + return nil, err + } + if out.Early == 0 && out.OnTime == 0 { + return nil, nil + } + return out, nil +} + func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 98c9ed2e0dc..73ab7bc4d18 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -698,97 +698,28 @@ func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address return stmgr.MinerSectorInfo(ctx, a.StateManager, maddr, n, ts) } -type sectorPartitionCb func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error - -func (a *StateAPI) sectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey, cb sectorPartitionCb) error { - return a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(maddr, - a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error { - return a.StateManager.WithDeadlines(func(store adt.Store, deadlines *miner.Deadlines) error { - err := a.StateManager.WithEachDeadline(func(store adt.Store, di uint64, deadline *miner.Deadline) error { - return a.StateManager.WithEachPartition(func(store adt.Store, pi uint64, partition *miner.Partition) error { - set, err := partition.Sectors.IsSet(uint64(sectorNumber)) - if err != nil { - return xerrors.Errorf("is set: %w", err) - } - if set { - if err := cb(store, mas, di, pi, partition); err != nil { - return err - } - - return errBreakForeach - } - return nil - })(store, di, deadline) - })(store, deadlines) - if err == errBreakForeach { - err = nil - } - return err - })(store, mas) - }))) -} - func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) { - var onTimeEpoch, earlyEpoch abi.ChainEpoch - - err := a.sectorPartition(ctx, maddr, sectorNumber, tsk, func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error { - quant := mas.QuantSpecForDeadline(di) - expirations, err := miner.LoadExpirationQueue(store, part.ExpirationsEpochs, quant) - if err != nil { - return xerrors.Errorf("loading expiration queue: %w", err) - } - - var eset miner.ExpirationSet - return expirations.Array.ForEach(&eset, func(epoch int64) error { - set, err := eset.OnTimeSectors.IsSet(uint64(sectorNumber)) - if err != nil { - return xerrors.Errorf("checking if sector is in onTime set: %w", err) - } - if set { - onTimeEpoch = abi.ChainEpoch(epoch) - } - - set, err = eset.EarlySectors.IsSet(uint64(sectorNumber)) - if err != nil { - return xerrors.Errorf("checking if sector is in early set: %w", err) - } - if set { - earlyEpoch = abi.ChainEpoch(epoch) - } - - return nil - }) - }) + act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) if err != nil { return nil, err } - - if onTimeEpoch == 0 { - return nil, xerrors.Errorf("expiration for sector %d not found", sectorNumber) + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return nil, err } - - return &api.SectorExpiration{ - OnTime: onTimeEpoch, - Early: earlyEpoch, - }, nil + return mas.GetSectorExpiration(sectorNumber) } func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorLocation, error) { - var found *api.SectorLocation - - err := a.sectorPartition(ctx, maddr, sectorNumber, tsk, func(store adt.Store, mas *miner.State, di, pi uint64, partition *miner.Partition) error { - found = &api.SectorLocation{ - Deadline: di, - Partition: pi, - } - return errBreakForeach - }) + act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) if err != nil { return nil, err } - - return found, nil + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return nil, err + } + return mas.FindSector(sectorNumber) } func (a *StateAPI) StateListMessages(ctx context.Context, match *types.Message, tsk types.TipSetKey, toheight abi.ChainEpoch) ([]cid.Cid, error) { From 6bf7976add095e8544e28f67517985dfb5e6591e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 10:51:18 -0700 Subject: [PATCH 014/104] fix decode --- chain/actors/builtin/miner/v0.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 1a4bd380027..c0712a0c2af 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -1,6 +1,7 @@ package miner import ( + "bytes" "errors" "github.com/filecoin-project/go-address" @@ -151,7 +152,7 @@ func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) } var oci miner.SectorOnChainInfo - if err := cbor.DecodeInto(v.Raw, &oci); err != nil { + if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { return err } sset = append(sset, &ChainSectorInfo{ From 4cd92d8576aeb31044b821d09ef1d333e2a24f0c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 10:57:32 -0700 Subject: [PATCH 015/104] remove final WithStateTree --- chain/messagepool/provider.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chain/messagepool/provider.go b/chain/messagepool/provider.go index d67468d9a9c..347e90044d5 100644 --- a/chain/messagepool/provider.go +++ b/chain/messagepool/provider.go @@ -47,13 +47,15 @@ func (mpp *mpoolProvider) PubSubPublish(k string, v []byte) error { } func (mpp *mpoolProvider) GetActorAfter(addr address.Address, ts *types.TipSet) (*types.Actor, error) { - var act types.Actor stcid, _, err := mpp.sm.TipSetState(context.TODO(), ts) if err != nil { return nil, xerrors.Errorf("computing tipset state for GetActor: %w", err) } - version := mpp.sm.GetNtwkVersion(context.TODO(), ts.Height()) - return &act, mpp.sm.WithStateTree(stcid, version, mpp.sm.WithActor(addr, stmgr.GetActor(&act))) + st, err := mpp.sm.StateTree(stcid) + if err != nil { + return nil, xerrors.Errorf("failed to load state tree: %w", err) + } + return st.GetActor(addr) } func (mpp *mpoolProvider) StateAccountKey(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { From 53384e83d7c6d5488c0ec605959666dee49dc248 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 11:16:35 -0700 Subject: [PATCH 016/104] migrate wallet access --- node/impl/full/wallet.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/node/impl/full/wallet.go b/node/impl/full/wallet.go index af786085baa..bda8824e70c 100644 --- a/node/impl/full/wallet.go +++ b/node/impl/full/wallet.go @@ -36,16 +36,13 @@ func (a *WalletAPI) WalletList(ctx context.Context) ([]address.Address, error) { } func (a *WalletAPI) WalletBalance(ctx context.Context, addr address.Address) (types.BigInt, error) { - var bal types.BigInt - err := a.StateManager.WithParentStateTsk(types.EmptyTSK, a.StateManager.WithActor(addr, func(act *types.Actor) error { - bal = act.Balance - return nil - })) - + act, err := a.StateManager.LoadActorTsk(ctx, addr, types.EmptyTSK) if xerrors.Is(err, types.ErrActorNotFound) { return big.Zero(), nil + } else if err != nil { + return big.Zero(), err } - return bal, err + return act.Balance, nil } func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) { From c64f983900f8a0e2b7c1800dd2a4b1b96b201d1b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 12:09:39 -0700 Subject: [PATCH 017/104] migrate StateMinserSectorCount --- api/api_full.go | 8 ++- api/apistruct/struct.go | 88 ++++++++++++++++----------------- cmd/lotus-storage-miner/info.go | 21 +++----- node/impl/full/state.go | 85 +++++++++++++++---------------- storage/miner.go | 7 ++- 5 files changed, 99 insertions(+), 110 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index a5af175d834..d3b6556342b 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -469,8 +469,12 @@ type FileRef struct { } type MinerSectors struct { - Sectors uint64 - Active uint64 + // Live sectors that should be proven. + Live uint64 + // Sectors actively contributing to power. + Active uint64 + // Sectors with failed proofs. + Faulty uint64 } type ImportRes struct { diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index d0bdd14d359..a554d2a5fa0 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -34,7 +34,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" ) @@ -161,44 +161,44 @@ type FullNodeStruct struct { ClientDataTransferUpdates func(ctx context.Context) (<-chan api.DataTransferChannel, error) `perm:"write"` ClientRetrieveTryRestartInsufficientFunds func(ctx context.Context, paymentChannel address.Address) error `perm:"write"` - StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` - StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) `perm:"read"` - StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) `perm:"read"` - StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` - StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` - StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) `perm:"read"` - StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` - StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateMinerPreCommitDepositForPower func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateMinerInitialPledgeCollateral func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` - StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` - StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` - StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorExpiration, error) `perm:"read"` - StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorLocation, error) `perm:"read"` - StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` - StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"` - StateGetActor func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) `perm:"read"` - StateReadState func(context.Context, address.Address, types.TipSetKey) (*api.ActorState, error) `perm:"read"` - StateWaitMsg func(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) `perm:"read"` - StateSearchMsg func(context.Context, cid.Cid) (*api.MsgLookup, error) `perm:"read"` - StateListMiners func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` - StateListActors func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` - StateMarketBalance func(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) `perm:"read"` - StateMarketParticipants func(context.Context, types.TipSetKey) (map[string]api.MarketBalance, error) `perm:"read"` - StateMarketDeals func(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) `perm:"read"` - StateMarketStorageDeal func(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) `perm:"read"` - StateLookupID func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` - StateAccountKey func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` - StateChangedActors func(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) `perm:"read"` - StateGetReceipt func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` - StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` - StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` - StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` - StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` - StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` - StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` + StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` + StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) `perm:"read"` + StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*miner.ChainSectorInfo, error) `perm:"read"` + StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` + StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` + StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` + StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` + StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` + StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` + StateMinerPreCommitDepositForPower func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateMinerInitialPledgeCollateral func(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` + StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` + StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` + StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorExpiration, error) `perm:"read"` + StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorLocation, error) `perm:"read"` + StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` + StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"` + StateGetActor func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) `perm:"read"` + StateReadState func(context.Context, address.Address, types.TipSetKey) (*api.ActorState, error) `perm:"read"` + StateWaitMsg func(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) `perm:"read"` + StateSearchMsg func(context.Context, cid.Cid) (*api.MsgLookup, error) `perm:"read"` + StateListMiners func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` + StateListActors func(context.Context, types.TipSetKey) ([]address.Address, error) `perm:"read"` + StateMarketBalance func(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) `perm:"read"` + StateMarketParticipants func(context.Context, types.TipSetKey) (map[string]api.MarketBalance, error) `perm:"read"` + StateMarketDeals func(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) `perm:"read"` + StateMarketStorageDeal func(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) `perm:"read"` + StateLookupID func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` + StateAccountKey func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` + StateChangedActors func(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) `perm:"read"` + StateGetReceipt func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` + StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` + StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` + StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` + StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` + StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` + StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` MsigGetVested func(context.Context, address.Address, types.TipSetKey, types.TipSetKey) (types.BigInt, error) `perm:"read"` @@ -730,11 +730,11 @@ func (c *FullNodeStruct) StateNetworkName(ctx context.Context) (dtypes.NetworkNa return c.Internal.StateNetworkName(ctx) } -func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner2.ChainSectorInfo, error) { +func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { return c.Internal.StateMinerSectors(ctx, addr, filter, filterOut, tsk) } -func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*miner2.ChainSectorInfo, error) { +func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { return c.Internal.StateMinerActiveSectors(ctx, addr, tsk) } @@ -746,7 +746,7 @@ func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, return c.Internal.StateMinerPower(ctx, a, tsk) } -func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner2.MinerInfo, error) { +func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { return c.Internal.StateMinerInfo(ctx, actor, tsk) } @@ -782,11 +782,11 @@ func (c *FullNodeStruct) StateSectorGetInfo(ctx context.Context, maddr address.A return c.Internal.StateSectorGetInfo(ctx, maddr, n, tsk) } -func (c *FullNodeStruct) StateSectorExpiration(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) { +func (c *FullNodeStruct) StateSectorExpiration(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorExpiration, error) { return c.Internal.StateSectorExpiration(ctx, maddr, n, tsk) } -func (c *FullNodeStruct) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*api.SectorLocation, error) { +func (c *FullNodeStruct) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) { return c.Internal.StateSectorPartition(ctx, maddr, sectorNumber, tok) } diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 55ef024f30d..c47a22b0e66 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -112,26 +112,19 @@ func infoCmdAct(cctx *cli.Context) error { if err != nil { return err } - faults, err := api.StateMinerFaults(ctx, maddr, types.EmptyTSK) - if err != nil { - return err - } - - nfaults, err := faults.Count() - if err != nil { - return xerrors.Errorf("counting faults: %w", err) - } - fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Sectors), types.NewInt(uint64(mi.SectorSize))))) + proving := secCounts.Active + secCounts.Faulty + nfaults := secCounts.Faulty + fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Live), types.NewInt(uint64(mi.SectorSize))))) if nfaults == 0 { - fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Active), types.NewInt(uint64(mi.SectorSize))))) + fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize))))) } else { var faultyPercentage float64 - if secCounts.Sectors != 0 { - faultyPercentage = float64(10000*nfaults/secCounts.Sectors) / 100. + if secCounts.Live != 0 { + faultyPercentage = float64(10000*nfaults/secCounts.Live) / 100. } fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n", - types.SizeStr(types.BigMul(types.NewInt(secCounts.Sectors), types.NewInt(uint64(mi.SectorSize)))), + types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize)))), types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))), faultyPercentage) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 73ab7bc4d18..d1490af6465 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -635,57 +635,50 @@ func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid. } func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MinerSectors, error) { - var out api.MinerSectors - - err := a.StateManager.WithParentStateTsk(tsk, - a.StateManager.WithActor(addr, - a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error { - var allActive []bitfield.BitField - - err := a.StateManager.WithDeadlines( - a.StateManager.WithEachDeadline( - a.StateManager.WithEachPartition(func(store adt.Store, partIdx uint64, partition *miner.Partition) error { - active, err := partition.ActiveSectors() - if err != nil { - return xerrors.Errorf("partition.ActiveSectors: %w", err) - } - - allActive = append(allActive, active) - return nil - })))(store, mas) - if err != nil { - return xerrors.Errorf("with deadlines: %w", err) - } - - active, err := bitfield.MultiMerge(allActive...) - if err != nil { - return xerrors.Errorf("merging active sector bitfields: %w", err) - } - - out.Active, err = active.Count() - if err != nil { - return xerrors.Errorf("counting active sectors: %w", err) - } - - sarr, err := adt.AsArray(store, mas.Sectors) - if err != nil { - return err - } - - out.Sectors = sarr.Length() - return nil - }))) + act, err := a.StateManager.LoadActorTsk(ctx, addr, tsk) if err != nil { return api.MinerSectors{}, err } - - return out, nil + mas, err := miner.Load(a.Chain.Store(ctx), act) + if err != nil { + return api.MinerSectors{}, err + } + var activeCount, liveCount, faultyCount uint64 + if err := mas.ForEachDeadline(func(_ uint64, dl miner.Deadline) error { + return dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + if active, err := part.ActiveSectors(); err != nil { + return err + } else if count, err := active.Count(); err != nil { + return err + } else { + activeCount += count + } + if live, err := part.LiveSectors(); err != nil { + return err + } else if count, err := live.Count(); err != nil { + return err + } else { + liveCount += count + } + if faulty, err := part.FaultySectors(); err != nil { + return err + } else if count, err := faulty.Count(); err != nil { + return err + } else { + faultyCount += count + } + return nil + }) + }); err != nil { + return api.MinerSectors{}, err + } + return api.MinerSectors{Live: liveCount, Active: activeCount, Faulty: faultyCount}, nil } -func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) { +func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorPreCommitOnChainInfo, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { - return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } return stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts) } @@ -698,7 +691,7 @@ func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address return stmgr.MinerSectorInfo(ctx, a.StateManager, maddr, n, ts) } -func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) { +func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorExpiration, error) { act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) if err != nil { return nil, err @@ -710,7 +703,7 @@ func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Addr return mas.GetSectorExpiration(sectorNumber) } -func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorLocation, error) { +func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorLocation, error) { act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) if err != nil { return nil, err diff --git a/storage/miner.go b/storage/miner.go index 47f50ce71c5..3485dba03c4 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -3,7 +3,6 @@ package storage import ( "context" "errors" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "time" "github.com/filecoin-project/go-state-types/dline" @@ -22,11 +21,11 @@ import ( "github.com/filecoin-project/go-state-types/crypto" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/types" @@ -68,10 +67,10 @@ type SealingStateEvt struct { type storageMinerApi interface { // Call a read only method on actors (no interaction with the chain required) StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) - StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*api.SectorLocation, error) + StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) From 91e9573863b8161b417910c253fdb994624ba211 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 12:13:13 -0700 Subject: [PATCH 018/104] Compile fixes --- api/api_full.go | 4 ++-- api/apistruct/struct.go | 1 - chain/actors/builtin/miner/v0.go | 8 ++++---- chain/stmgr/utils.go | 6 ++++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index d3b6556342b..88496d669ac 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -344,9 +344,9 @@ type FullNode interface { // expiration epoch StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) // StateSectorExpiration returns epoch at which given sector will expire - StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*SectorExpiration, error) + StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorExpiration, error) // StateSectorPartition finds deadline/partition with the specified sector - StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*SectorLocation, error) + StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) // StateSearchMsg searches for a message in the chain, and returns its receipt and the tipset where it was executed StateSearchMsg(context.Context, cid.Cid) (*MsgLookup, error) // StateWaitMsg looks back in the chain for a message. If not found, it blocks until the diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index a554d2a5fa0..1fcd5e0f347 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -27,7 +27,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" marketevents "github.com/filecoin-project/lotus/markets/loggers" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-storage/storage" diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index c0712a0c2af..e1ef9c51f24 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/chain/actors/adt" v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" - cbor "github.com/ipfs/go-ipld-cbor" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -70,7 +69,7 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati // 2. If it's faulty, it will expire early within the first 14 entries // of the expiration queue. stopErr := errors.New("stop") - err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner.Deadline) error { + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner.Deadline) error { partitions, err := dl.PartitionsArray(s.store) if err != nil { return err @@ -102,12 +101,13 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati out.Early = abi.ChainEpoch(epoch) return nil } - if onTime, err := exp.OnTime.IsSet(uint64(num)); err != nil { + if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil { return err } else if onTime { - out.OnTime = epoch + out.OnTime = abi.ChainEpoch(epoch) return stopErr } + return nil }) }) }) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 4dc21015483..88275f019b0 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -103,8 +103,10 @@ func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr addres var mpow power.Claim if maddr != address.Undef { - mpow, err = mas.MinerPower(maddr) - if err != nil { + var found bool + mpow, found, err = mas.MinerPower(maddr) + if err != nil || !found { + // TODO: return an error when not found? return power.Claim{}, power.Claim{}, err } } From 4e01fad0d47faafbf799eb7a0e6ee14e065018b2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 14:44:03 -0700 Subject: [PATCH 019/104] start multisig abstraction --- chain/actors/builtin/multisig/multisig.go | 31 +++++++++++++ chain/actors/builtin/multisig/v0.go | 16 +++++++ node/impl/full/state.go | 55 +++++++++-------------- 3 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 chain/actors/builtin/multisig/multisig.go create mode 100644 chain/actors/builtin/multisig/v0.go diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go new file mode 100644 index 00000000000..676dbe75f42 --- /dev/null +++ b/chain/actors/builtin/multisig/multisig.go @@ -0,0 +1,31 @@ +package multisig + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +func Load(store adt.Store, act *types.Actor) (State, error) { + switch act.Code { + case v0builtin.MultisigActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error) +} diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go new file mode 100644 index 00000000000..3bc7e70b28d --- /dev/null +++ b/chain/actors/builtin/multisig/v0.go @@ -0,0 +1,16 @@ +package multisig + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/specs-actors/actors/builtin/multisig" +) + +type v0State struct { + multisig.State + store adt.Store +} + +func (s *v0State) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.State.AmountLocked(currEpoch - s.StartEpoch), nil +} diff --git a/node/impl/full/state.go b/node/impl/full/state.go index d1490af6465..10b5de82b03 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -22,7 +22,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -31,6 +30,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/state" @@ -790,28 +790,19 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var st samsig.State - act, err := a.StateManager.LoadActorState(ctx, addr, &st, ts) + act, err := a.StateManager.LoadActor(ctx, addr, ts) if err != nil { - return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state: %w", err) - } - - if act.Code != builtin.MultisigActorCodeID { - return types.EmptyInt, fmt.Errorf("given actor was not a multisig") + return types.EmptyInt, xerrors.Errorf("failed to load multisig actor: %w", err) } - - if st.UnlockDuration == 0 { - return act.Balance, nil + msas, err := multisig.Load(a.Chain.Store(ctx), act) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state: %w", err) } - - offset := ts.Height() - st.StartEpoch - if offset > st.UnlockDuration { - return act.Balance, nil + locked, err := msas.LockedBalance(ts.Height()) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to compute locked multisig balance: %w", err) } - - minBalance := types.BigDiv(st.InitialBalance, types.NewInt(uint64(st.UnlockDuration))) - minBalance = types.BigMul(minBalance, types.NewInt(uint64(offset))) - return types.BigSub(act.Balance, minBalance), nil + return types.BigSub(act.Balance, locked), nil } func (a *StateAPI) MsigGetVested(ctx context.Context, addr address.Address, start types.TipSetKey, end types.TipSetKey) (types.BigInt, error) { @@ -831,29 +822,27 @@ func (a *StateAPI) MsigGetVested(ctx context.Context, addr address.Address, star return big.Zero(), nil } - var mst samsig.State - act, err := a.StateManager.LoadActorState(ctx, addr, &mst, endTs) + act, err := a.StateManager.LoadActor(ctx, addr, endTs) if err != nil { - return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state at end epoch: %w", err) + return types.EmptyInt, xerrors.Errorf("failed to load multisig actor at end epoch: %w", err) } - if act.Code != builtin.MultisigActorCodeID { - return types.EmptyInt, fmt.Errorf("given actor was not a multisig") + msas, err := multisig.Load(a.Chain.Store(ctx), act) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state: %w", err) } - if mst.UnlockDuration == 0 || - mst.InitialBalance.IsZero() || - mst.StartEpoch+mst.UnlockDuration <= startTs.Height() || - mst.StartEpoch >= endTs.Height() { - return big.Zero(), nil + startLk, err := msas.LockedBalance(startTs.Height()) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to compute locked balance at start height: %w", err) } - startLk := mst.InitialBalance - if startTs.Height() > mst.StartEpoch { - startLk = mst.AmountLocked(startTs.Height() - mst.StartEpoch) + endLk, err := msas.LockedBalance(endTs.Height()) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to compute locked balance at end height: %w", err) } - return big.Sub(startLk, mst.AmountLocked(endTs.Height()-mst.StartEpoch)), nil + return types.BigSub(startLk, endLk), nil } var initialPledgeNum = types.NewInt(110) From e1ba4eb5c449c9686c96d50aacd68d403d1370e0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 14:55:48 -0700 Subject: [PATCH 020/104] sub reward actor --- chain/actors/builtin/reward/reward.go | 30 +++++++++++++++++++++++++++ chain/actors/builtin/reward/v0.go | 11 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 chain/actors/builtin/reward/reward.go create mode 100644 chain/actors/builtin/reward/v0.go diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go new file mode 100644 index 00000000000..a1a7cac5d6e --- /dev/null +++ b/chain/actors/builtin/reward/reward.go @@ -0,0 +1,30 @@ +package reward + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +var Address = v0builtin.RewardActorAddr + +func Load(store adt.Store, act *types.Actor) (st State, err error) { + switch act.Code { + case v0builtin.RewardActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler +} diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go new file mode 100644 index 00000000000..8fef3756c81 --- /dev/null +++ b/chain/actors/builtin/reward/v0.go @@ -0,0 +1,11 @@ +package reward + +import ( + "github.com/filecoin-project/specs-actors/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/actors/util/adt" +) + +type v0State struct { + reward.State + store adt.Store +} From 02bc5fab268579539224af39e85b4a960209dbc2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 14:56:00 -0700 Subject: [PATCH 021/104] add power actor address alias --- chain/actors/builtin/power/power.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index fa0400f2eeb..9e35e52ab3e 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -12,6 +12,8 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +var Address = v0builtin.StoragePowerActorAddr + func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case v0builtin.StoragePowerActorCodeID: From 92471d41d6923032eb807b857c02461e66d225b6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 16:47:58 -0700 Subject: [PATCH 022/104] migrate precommit deposit function --- chain/actors/builtin/builtin.go | 5 ++ chain/actors/builtin/market/market.go | 5 ++ chain/actors/builtin/market/v0.go | 7 ++ chain/actors/builtin/power/power.go | 3 + chain/actors/builtin/power/v0.go | 5 ++ chain/actors/builtin/reward/reward.go | 3 + chain/actors/builtin/reward/v0.go | 5 ++ node/impl/full/state.go | 103 +++++++++++--------------- 8 files changed, 77 insertions(+), 59 deletions(-) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index accc4e7e6ec..517f0d70c44 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/filecoin-project/go-state-types/network" + + v0smoothing "github.com/filecoin-project/specs-actors/actors/util/smoothing" ) type Version int @@ -21,3 +23,6 @@ func VersionForNetwork(version network.Version) Version { panic(fmt.Sprintf("unsupported network version %d", version)) } } + +// TODO: find some way to abstract over this. +type FilterEstimate = v0smoothing.FilterEstimate diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 3d12ac9a80e..99cca98797b 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -12,6 +12,8 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +var Address = v0builtin.StorageMarketActorAddr + func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case v0builtin.StorageMarketActorCodeID: @@ -30,6 +32,9 @@ type State interface { EscrowTable() (BalanceTable, error) LockedTable() (BalanceTable, error) TotalLocked() (abi.TokenAmount, error) + VerifyDealsForActivation( + minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, + ) (weight, verifiedWeight abi.DealWeight, err error) } type BalanceTable interface { diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index da86cda0fe2..fb67902da21 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -1,6 +1,7 @@ package market import ( + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/market" @@ -25,3 +26,9 @@ func (s *v0State) EscrowTable() (BalanceTable, error) { func (s *v0State) LockedTable() (BalanceTable, error) { return adt.AsBalanceTable(s.store, s.State.LockedTable) } + +func (s *v0State) VerifyDealsForActivation( + minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, +) (weight, verifiedWeight abi.DealWeight, err error) { + return market.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) +} diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 9e35e52ab3e..07399e1bf83 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -9,6 +9,7 @@ import ( v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) @@ -32,6 +33,8 @@ type State interface { TotalLocked() (abi.TokenAmount, error) TotalPower() (Claim, error) + TotalPowerSmoothed() (builtin.FilterEstimate, error) + MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) } diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 12eb318e5f6..45dd570f616 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -3,6 +3,7 @@ package power import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -42,3 +43,7 @@ func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) } + +func (s *v0State) TotalPowerSmoothed() (builtin.FilterEstimate, error) { + return *s.State.ThisEpochQAPowerSmoothed, nil +} diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index a1a7cac5d6e..ba03feceda4 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -7,6 +7,7 @@ import ( v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) @@ -27,4 +28,6 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler + + RewardSmoothed() (builtin.FilterEstimate, error) } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 8fef3756c81..a894fa75261 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -1,6 +1,7 @@ package reward import ( + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -9,3 +10,7 @@ type v0State struct { reward.State store adt.Store } + +func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) { + return *s.State.ThisEpochRewardSmoothed, nil +} diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 10b5de82b03..3ea40388fff 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -21,16 +21,17 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/state" @@ -41,6 +42,7 @@ import ( "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/lib/bufbstore" "github.com/filecoin-project/lotus/node/modules/dtypes" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" ) var errBreakForeach = errors.New("break") @@ -854,74 +856,57 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var minerState miner.State - var powerState power.State - var rewardState reward.State - - err = a.StateManager.WithParentStateTsk(tsk, func(state *state.StateTree) error { - if err := a.StateManager.WithActor(maddr, a.StateManager.WithActorState(ctx, &minerState))(state); err != nil { - return xerrors.Errorf("getting miner state: %w", err) - } - - if err := a.StateManager.WithActor(builtin.StoragePowerActorAddr, a.StateManager.WithActorState(ctx, &powerState))(state); err != nil { - return xerrors.Errorf("getting power state: %w", err) - } - - if err := a.StateManager.WithActor(builtin.RewardActorAddr, a.StateManager.WithActorState(ctx, &rewardState))(state); err != nil { - return xerrors.Errorf("getting reward state: %w", err) - } - - return nil - }) + state, err := a.StateManager.ParentState(ts) if err != nil { - return types.EmptyInt, err + return types.EmptyInt, xerrors.Errorf("loading state %s: %w", tsk, err) } - dealWeights := market.VerifyDealsForActivationReturn{ - DealWeight: big.Zero(), - VerifiedDealWeight: big.Zero(), + ssize, err := pci.SealProof.SectorSize() + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to get resolve size: %w", err) } - if len(pci.DealIDs) != 0 { - var err error - params, err := actors.SerializeParams(&market.VerifyDealsForActivationParams{ - DealIDs: pci.DealIDs, - SectorExpiry: pci.Expiration, - }) - if err != nil { - return types.EmptyInt, err - } + store := a.Chain.Store(ctx) - ret, err := a.StateManager.Call(ctx, &types.Message{ - From: maddr, - To: builtin.StorageMarketActorAddr, - Method: builtin.MethodsMarket.VerifyDealsForActivation, - Params: params, - }, ts) - if err != nil { - return types.EmptyInt, err - } + var sectorWeight abi.StoragePower + if act, err := state.GetActor(market.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor %s: %w", maddr, err) + } else s, err := market.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading market actor state %s: %w", maddr, err) + } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { + return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) + } else { + // NB: not exactly accurate, but should always lead us to *over* estimate, not under + duration := pci.Expiration - ts.Height() - if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret.MsgRct.Return)); err != nil { - return types.BigInt{}, err - } + // TODO: handle changes to this function across actor upgrades. + sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw) } - mi, err := a.StateMinerInfo(ctx, maddr, tsk) - if err != nil { - return types.EmptyInt, err + var powerSmoothed smoothing.FilterEstimate + if act, err := state.GetActor(power.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) + } else s, err := power.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err) + } else p, err := s.TotalPowerSmoothed(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine total power: %w", err) + } else { + powerSmoothed = p } - ssize := mi.SectorSize - - duration := pci.Expiration - ts.Height() // NB: not exactly accurate, but should always lead us to *over* estimate, not under + var rewardSmoothed smoothing.FilterEstimate + if act, err := state.GetActor(reward.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) + } else s, err := reward.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) + } else r, err := s.RewardSmoothed(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) + } else { + rewardSmoothed = r + } - sectorWeight := miner.QAPowerForWeight(ssize, duration, dealWeights.DealWeight, dealWeights.VerifiedDealWeight) - deposit := miner.PreCommitDepositForPower( - rewardState.ThisEpochRewardSmoothed, - powerState.ThisEpochQAPowerSmoothed, - sectorWeight, - ) + // TODO: abstract over network upgrades. + deposit := v0miner.PreCommitDepositForPower(rewardSmoothed, powerSmoothed, sectorWeight) return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil } From 454c382e7ec024d2de7c7a91f83e6e0d71d78b8b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 15 Sep 2020 18:05:33 -0700 Subject: [PATCH 023/104] migrate StateMinerInitialPledgeCollateral --- chain/stmgr/utils.go | 2 +- node/impl/full/state.go | 109 ++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 88275f019b0..1bbc9ccc423 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -30,10 +30,10 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/adt" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 3ea40388fff..d69ba0a419a 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -912,85 +912,86 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr } func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) { + // TODO: this repeats a lot of the previous function. Fix that. ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var minerState miner.State - var powerState power.State - var rewardState reward.State - - err = a.StateManager.WithParentStateTsk(tsk, func(state *state.StateTree) error { - if err := a.StateManager.WithActor(maddr, a.StateManager.WithActorState(ctx, &minerState))(state); err != nil { - return xerrors.Errorf("getting miner state: %w", err) - } - - if err := a.StateManager.WithActor(builtin.StoragePowerActorAddr, a.StateManager.WithActorState(ctx, &powerState))(state); err != nil { - return xerrors.Errorf("getting power state: %w", err) - } - - if err := a.StateManager.WithActor(builtin.RewardActorAddr, a.StateManager.WithActorState(ctx, &rewardState))(state); err != nil { - return xerrors.Errorf("getting reward state: %w", err) - } - - return nil - }) + state, err := a.StateManager.ParentState(ts) if err != nil { - return types.EmptyInt, err + return types.EmptyInt, xerrors.Errorf("loading state %s: %w", tsk, err) } - dealWeights := market.VerifyDealsForActivationReturn{ - DealWeight: big.Zero(), - VerifiedDealWeight: big.Zero(), + ssize, err := pci.SealProof.SectorSize() + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to get resolve size: %w", err) } - if len(pci.DealIDs) != 0 { - var err error - params, err := actors.SerializeParams(&market.VerifyDealsForActivationParams{ - DealIDs: pci.DealIDs, - SectorExpiry: pci.Expiration, - }) - if err != nil { - return types.EmptyInt, err - } + store := a.Chain.Store(ctx) - ret, err := a.StateManager.Call(ctx, &types.Message{ - From: maddr, - To: builtin.StorageMarketActorAddr, - Method: builtin.MethodsMarket.VerifyDealsForActivation, - Params: params, - }, ts) - if err != nil { - return types.EmptyInt, err - } + var sectorWeight abi.StoragePower + if act, err := state.GetActor(market.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor %s: %w", maddr, err) + } else s, err := market.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading market actor state %s: %w", maddr, err) + } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { + return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) + } else { + // NB: not exactly accurate, but should always lead us to *over* estimate, not under + duration := pci.Expiration - ts.Height() - if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret.MsgRct.Return)); err != nil { - return types.BigInt{}, err - } + // TODO: handle changes to this function across actor upgrades. + sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw) } - mi, err := a.StateMinerInfo(ctx, maddr, tsk) - if err != nil { - return types.EmptyInt, err + var ( + powerSmoothed smoothing.FilterEstimate + pledgeCollerateral abi.TokenAmount + ) + if act, err := state.GetActor(power.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) + } else s, err := power.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err) + } else p, err := s.TotalPowerSmoothed(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine total power: %w", err) + } else c, err := s.TotalLocked(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine pledge collateral: %w", err) + } else { + powerSmoothed = p + pledgeCollateral = c } - ssize := mi.SectorSize + var ( + rewardSmoothed smoothing.FilterEstimate + baselinePower abi.StoragePower + ) + if act, err := state.GetActor(reward.Address); err != nil { + return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) + } else s, err := reward.Load(store, act); err != nil { + return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) + } else r, err := s.RewardSmoothed(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) + } else p, err := s.BaselinePower(); err != nil { + return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) + } else { + rewardSmoothed = r + baselinePower = p + } - duration := pci.Expiration - ts.Height() // NB: not exactly accurate, but should always lead us to *over* estimate, not under + // TODO: abstract over network upgrades. circSupply, err := a.StateCirculatingSupply(ctx, ts.Key()) if err != nil { return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err) } - sectorWeight := miner.QAPowerForWeight(ssize, duration, dealWeights.DealWeight, dealWeights.VerifiedDealWeight) initialPledge := miner.InitialPledgeForPower( sectorWeight, - rewardState.ThisEpochBaselinePower, - powerState.ThisEpochPledgeCollateral, - rewardState.ThisEpochRewardSmoothed, - powerState.ThisEpochQAPowerSmoothed, + baselinePower, + pledgeCollateral, + rewardSmoothed, + powerSmoothed, circSupply.FilCirculating, ) From 05c11531b1d9cfb2edb3062e22602e9446474fcf Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Tue, 15 Sep 2020 21:06:04 -0700 Subject: [PATCH 024/104] feat(paych): convert paych actor build abstraction for paych actor and switch to using it in payment channel manager and state predicates --- chain/actors/builtin/paych/mock/mock.go | 89 ++++++++++++ chain/actors/builtin/paych/paych.go | 56 ++++++++ chain/actors/builtin/paych/v0.go | 89 ++++++++++++ chain/events/state/predicates.go | 47 +++--- chain/events/state/predicates_test.go | 2 +- chain/stmgr/stmgr.go | 19 +++ cli/paych_test.go | 8 +- paychmgr/manager.go | 37 +++-- paychmgr/mock_test.go | 60 +++----- paychmgr/msglistener_test.go | 2 - paychmgr/paych.go | 97 ++++++------- paychmgr/paych_test.go | 183 +++++++----------------- paychmgr/paychget_test.go | 43 ++---- paychmgr/simple.go | 17 +-- paychmgr/state.go | 41 ++---- 15 files changed, 452 insertions(+), 338 deletions(-) create mode 100644 chain/actors/builtin/paych/mock/mock.go create mode 100644 chain/actors/builtin/paych/paych.go create mode 100644 chain/actors/builtin/paych/v0.go diff --git a/chain/actors/builtin/paych/mock/mock.go b/chain/actors/builtin/paych/mock/mock.go new file mode 100644 index 00000000000..31f7fba93b1 --- /dev/null +++ b/chain/actors/builtin/paych/mock/mock.go @@ -0,0 +1,89 @@ +package mock + +import ( + "io" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" +) + +type mockState struct { + from address.Address + to address.Address + settlingAt abi.ChainEpoch + toSend abi.TokenAmount + lanes map[uint64]paych.LaneState +} + +type mockLaneState struct { + redeemed big.Int + nonce uint64 +} + +// NewMockPayChState constructs a state for a payment channel with the set fixed values +// that satisfies the paych.State interface. +func NewMockPayChState(from address.Address, + to address.Address, + settlingAt abi.ChainEpoch, + toSend abi.TokenAmount, + lanes map[uint64]paych.LaneState, +) paych.State { + return &mockState{from, to, settlingAt, toSend, lanes} +} + +// NewMockLaneState constructs a state for a payment channel lane with the set fixed values +// that satisfies the paych.LaneState interface. Useful for populating lanes when +// calling NewMockPayChState +func NewMockLaneState(redeemed big.Int, nonce uint64) paych.LaneState { + return &mockLaneState{redeemed, nonce} +} + +func (ms *mockState) MarshalCBOR(io.Writer) error { + panic("not implemented") +} + +// Channel owner, who has funded the actor +func (ms *mockState) From() address.Address { + return ms.from +} + +// Recipient of payouts from channel +func (ms *mockState) To() address.Address { + return ms.to +} + +// Height at which the channel can be `Collected` +func (ms *mockState) SettlingAt() abi.ChainEpoch { + return ms.settlingAt +} + +// Amount successfully redeemed through the payment channel, paid out on `Collect()` +func (ms *mockState) ToSend() abi.TokenAmount { + return ms.toSend +} + +// Get total number of lanes +func (ms *mockState) LaneCount() (uint64, error) { + return uint64(len(ms.lanes)), nil +} + +// Iterate lane states +func (ms *mockState) ForEachLaneState(cb func(idx uint64, dl paych.LaneState) error) error { + var lastErr error + for lane, state := range ms.lanes { + if err := cb(lane, state); err != nil { + lastErr = err + } + } + return lastErr +} + +func (mls *mockLaneState) Redeemed() big.Int { + return mls.redeemed +} + +func (mls *mockLaneState) Nonce() uint64 { + return mls.nonce +} diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go new file mode 100644 index 00000000000..974d64fde11 --- /dev/null +++ b/chain/actors/builtin/paych/paych.go @@ -0,0 +1,56 @@ +package paych + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + big "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +// Load returns an abstract copy of payment channel state, irregardless of actor version +func Load(store adt.Store, act *types.Actor) (State, error) { + switch act.Code { + case v0builtin.PaymentChannelActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +// State is an abstract version of payment channel state that works across +// versions +type State interface { + cbor.Marshaler + // Channel owner, who has funded the actor + From() address.Address + // Recipient of payouts from channel + To() address.Address + + // Height at which the channel can be `Collected` + SettlingAt() abi.ChainEpoch + + // Amount successfully redeemed through the payment channel, paid out on `Collect()` + ToSend() abi.TokenAmount + + // Get total number of lanes + LaneCount() (uint64, error) + + // Iterate lane states + ForEachLaneState(cb func(idx uint64, dl LaneState) error) error +} + +// LaneState is an abstract copy of the state of a single lane +type LaneState interface { + Redeemed() big.Int + Nonce() uint64 +} diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go new file mode 100644 index 00000000000..16a65bc9bf1 --- /dev/null +++ b/chain/actors/builtin/paych/v0.go @@ -0,0 +1,89 @@ +package paych + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + big "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/specs-actors/actors/builtin/paych" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" +) + +type v0State struct { + paych.State + store adt.Store + lsAmt *v0adt.Array +} + +// Channel owner, who has funded the actor +func (s *v0State) From() address.Address { + return s.State.From +} + +// Recipient of payouts from channel +func (s *v0State) To() address.Address { + return s.State.From +} + +// Height at which the channel can be `Collected` +func (s *v0State) SettlingAt() abi.ChainEpoch { + return s.State.SettlingAt +} + +// Amount successfully redeemed through the payment channel, paid out on `Collect()` +func (s *v0State) ToSend() abi.TokenAmount { + return s.State.ToSend +} + +func (s *v0State) getOrLoadLsAmt() (*v0adt.Array, error) { + if s.lsAmt != nil { + return s.lsAmt, nil + } + + // Get the lane state from the chain + lsamt, err := v0adt.AsArray(s.store, s.State.LaneStates) + if err != nil { + return nil, err + } + + s.lsAmt = lsamt + return lsamt, nil +} + +// Get total number of lanes +func (s *v0State) LaneCount() (uint64, error) { + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return 0, err + } + return lsamt.Length(), nil +} + +// Iterate lane states +func (s *v0State) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { + // Get the lane state from the chain + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return err + } + + // Note: we use a map instead of an array to store laneStates because the + // client sets the lane ID (the index) and potentially they could use a + // very large index. + var ls paych.LaneState + return lsamt.ForEach(&ls, func(i int64) error { + return cb(uint64(i), &v0LaneState{ls}) + }) +} + +type v0LaneState struct { + paych.LaneState +} + +func (ls *v0LaneState) Redeemed() big.Int { + return ls.LaneState.Redeemed +} + +func (ls *v0LaneState) Nonce() uint64 { + return ls.LaneState.Nonce +} diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 0858793d893..e5caa41d243 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -7,13 +7,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" typegen "github.com/whyrusleeping/cbor-gen" @@ -49,7 +48,7 @@ func NewStatePredicates(api ChainAPI) *StatePredicates { // - err type DiffTipSetKeyFunc func(ctx context.Context, oldState, newState types.TipSetKey) (changed bool, user UserData, err error) -type DiffActorStateFunc func(ctx context.Context, oldActorStateHead, newActorStateHead cid.Cid) (changed bool, user UserData, err error) +type DiffActorStateFunc func(ctx context.Context, oldActorState *types.Actor, newActorState *types.Actor) (changed bool, user UserData, err error) // OnActorStateChanged calls diffStateFunc when the state changes for the given actor func (sp *StatePredicates) OnActorStateChanged(addr address.Address, diffStateFunc DiffActorStateFunc) DiffTipSetKeyFunc { @@ -66,7 +65,7 @@ func (sp *StatePredicates) OnActorStateChanged(addr address.Address, diffStateFu if oldActor.Head.Equals(newActor.Head) { return false, nil, nil } - return diffStateFunc(ctx, oldActor.Head, newActor.Head) + return diffStateFunc(ctx, oldActor, newActor) } } @@ -74,13 +73,13 @@ type DiffStorageMarketStateFunc func(ctx context.Context, oldState *market.State // OnStorageMarketActorChanged calls diffStorageMarketState when the state changes for the market actor func (sp *StatePredicates) OnStorageMarketActorChanged(diffStorageMarketState DiffStorageMarketStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(builtin.StorageMarketActorAddr, func(ctx context.Context, oldActorStateHead, newActorStateHead cid.Cid) (changed bool, user UserData, err error) { + return sp.OnActorStateChanged(builtin.StorageMarketActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { var oldState market.State - if err := sp.cst.Get(ctx, oldActorStateHead, &oldState); err != nil { + if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { return false, nil, err } var newState market.State - if err := sp.cst.Get(ctx, newActorStateHead, &newState); err != nil { + if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { return false, nil, err } return diffStorageMarketState(ctx, &oldState, &newState) @@ -408,13 +407,13 @@ func (sp *StatePredicates) AvailableBalanceChangedForAddresses(getAddrs func() [ type DiffMinerActorStateFunc func(ctx context.Context, oldState *miner.State, newState *miner.State) (changed bool, user UserData, err error) func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(builtin.InitActorAddr, func(ctx context.Context, oldActorStateHead, newActorStateHead cid.Cid) (changed bool, user UserData, err error) { + return sp.OnActorStateChanged(builtin.InitActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { var oldState init_.State - if err := sp.cst.Get(ctx, oldActorStateHead, &oldState); err != nil { + if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { return false, nil, err } var newState init_.State - if err := sp.cst.Get(ctx, newActorStateHead, &newState); err != nil { + if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { return false, nil, err } return diffInitActorState(ctx, &oldState, &newState) @@ -423,13 +422,13 @@ func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorSta } func (sp *StatePredicates) OnMinerActorChange(minerAddr address.Address, diffMinerActorState DiffMinerActorStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(minerAddr, func(ctx context.Context, oldActorStateHead, newActorStateHead cid.Cid) (changed bool, user UserData, err error) { + return sp.OnActorStateChanged(minerAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { var oldState miner.State - if err := sp.cst.Get(ctx, oldActorStateHead, &oldState); err != nil { + if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { return false, nil, err } var newState miner.State - if err := sp.cst.Get(ctx, newActorStateHead, &newState); err != nil { + if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { return false, nil, err } return diffMinerActorState(ctx, &oldState, &newState) @@ -608,20 +607,20 @@ func (sp *StatePredicates) OnMinerPreCommitChange() DiffMinerActorStateFunc { } // DiffPaymentChannelStateFunc is function that compares two states for the payment channel -type DiffPaymentChannelStateFunc func(ctx context.Context, oldState *paych.State, newState *paych.State) (changed bool, user UserData, err error) +type DiffPaymentChannelStateFunc func(ctx context.Context, oldState paych.State, newState paych.State) (changed bool, user UserData, err error) // OnPaymentChannelActorChanged calls diffPaymentChannelState when the state changes for the the payment channel actor func (sp *StatePredicates) OnPaymentChannelActorChanged(paychAddr address.Address, diffPaymentChannelState DiffPaymentChannelStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(paychAddr, func(ctx context.Context, oldActorStateHead, newActorStateHead cid.Cid) (changed bool, user UserData, err error) { - var oldState paych.State - if err := sp.cst.Get(ctx, oldActorStateHead, &oldState); err != nil { + return sp.OnActorStateChanged(paychAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { + oldState, err := paych.Load(adt.WrapStore(ctx, sp.cst), oldActorState) + if err != nil { return false, nil, err } - var newState paych.State - if err := sp.cst.Get(ctx, newActorStateHead, &newState); err != nil { + newState, err := paych.Load(adt.WrapStore(ctx, sp.cst), newActorState) + if err != nil { return false, nil, err } - return diffPaymentChannelState(ctx, &oldState, &newState) + return diffPaymentChannelState(ctx, oldState, newState) }) } @@ -633,13 +632,13 @@ type PayChToSendChange struct { // OnToSendAmountChanges monitors changes on the total amount to send from one party to the other on a payment channel func (sp *StatePredicates) OnToSendAmountChanges() DiffPaymentChannelStateFunc { - return func(ctx context.Context, oldState *paych.State, newState *paych.State) (changed bool, user UserData, err error) { - if oldState.ToSend.Equals(newState.ToSend) { + return func(ctx context.Context, oldState paych.State, newState paych.State) (changed bool, user UserData, err error) { + if oldState.ToSend().Equals(newState.ToSend()) { return false, nil, nil } return true, &PayChToSendChange{ - OldToSend: oldState.ToSend, - NewToSend: newState.ToSend, + OldToSend: oldState.ToSend(), + NewToSend: newState.ToSend(), }, nil } } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index a1dccfadc41..7117a96cc4a 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -221,7 +221,7 @@ func TestMarketPredicates(t *testing.T) { // Test that OnActorStateChanged does not call the callback if the state has not changed mockAddr, err := address.NewFromString("t01") require.NoError(t, err) - actorDiffFn := preds.OnActorStateChanged(mockAddr, func(context.Context, cid.Cid, cid.Cid) (bool, UserData, error) { + actorDiffFn := preds.OnActorStateChanged(mockAddr, func(context.Context, *types.Actor, *types.Actor) (bool, UserData, error) { t.Fatal("No state change so this should not be called") return false, nil, nil }) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index f71b788c8f2..ae8b47bce08 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -25,6 +25,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" @@ -1145,3 +1146,21 @@ func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoc return build.NewestNetworkVersion } + +func (sm *StateManager) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) { + st, err := sm.ParentState(ts) + if err != nil { + return nil, nil, err + } + + act, err := st.GetActor(addr) + if err != nil { + return nil, nil, err + } + + actState, err := paych.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, nil, err + } + return act, actState, nil +} diff --git a/cli/paych_test.go b/cli/paych_test.go index cccc80ff420..1497a54a6b6 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -24,7 +24,8 @@ import ( "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/api/apibstore" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/go-address" @@ -88,7 +89,7 @@ func TestPaymentChannels(t *testing.T) { // Wait for the chain to reach the settle height chState := getPaychState(ctx, t, paymentReceiver, chAddr) - waitForHeight(ctx, t, paymentReceiver, chState.SettlingAt) + waitForHeight(ctx, t, paymentReceiver, chState.SettlingAt()) // receiver: paych collect cmd = []string{chAddr.String()} @@ -540,8 +541,7 @@ func getPaychState(ctx context.Context, t *testing.T, node test.TestNode, chAddr require.NoError(t, err) store := cbor.NewCborStore(apibstore.NewAPIBlockstore(node)) - var chState paych.State - err = store.Get(ctx, act.Head, &chState) + chState, err := paych.Load(adt.WrapStore(ctx, store), act) require.NoError(t, err) return chState diff --git a/paychmgr/manager.go b/paychmgr/manager.go index 4b102f062f7..4556c37be5c 100644 --- a/paychmgr/manager.go +++ b/paychmgr/manager.go @@ -4,28 +4,23 @@ import ( "context" "sync" - "github.com/filecoin-project/go-state-types/crypto" - - "github.com/filecoin-project/lotus/node/modules/helpers" - - "github.com/ipfs/go-datastore" - - xerrors "golang.org/x/xerrors" - - "github.com/filecoin-project/lotus/api" - - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/ipfs/go-cid" + "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" "go.uber.org/fx" + xerrors "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/crypto" + v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/full" + "github.com/filecoin-project/lotus/node/modules/helpers" ) var log = logging.Logger("paych") @@ -40,9 +35,9 @@ type PaychAPI struct { // stateManagerAPI defines the methods needed from StateManager type stateManagerAPI interface { - LoadActorState(ctx context.Context, a address.Address, out interface{}, ts *types.TipSet) (*types.Actor, error) + ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) + GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) - AdtStore(ctx context.Context) adt.Store } // paychAPI defines the API methods needed by the payment channel manager @@ -226,7 +221,7 @@ func (pm *Manager) GetChannelInfo(addr address.Address) (*ChannelInfo, error) { return ca.getChannelInfo(addr) } -func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher paych.SignedVoucher) (*api.VoucherCreateResult, error) { +func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher v0paych.SignedVoucher) (*api.VoucherCreateResult, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return nil, err @@ -238,7 +233,7 @@ func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, vouche // CheckVoucherValid checks if the given voucher is valid (is or could become spendable at some point). // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { +func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) error { // Get an accessor for the channel, creating it from state if necessary ca, err := pm.inboundChannelAccessor(ctx, ch) if err != nil { @@ -250,7 +245,7 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv } // CheckVoucherSpendable checks if the given voucher is currently spendable -func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return false, err @@ -261,7 +256,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address // AddVoucherOutbound adds a voucher for an outbound channel. // Returns an error if the channel is not already in the store. -func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return types.NewInt(0), err @@ -272,7 +267,7 @@ func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, s // AddVoucherInbound adds a voucher for an inbound channel. // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { // Get an accessor for the channel, creating it from state if necessary ca, err := pm.inboundChannelAccessor(ctx, ch) if err != nil { @@ -341,7 +336,7 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address) return pm.store.TrackChannel(stateCi) } -func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return cid.Undef, err diff --git a/paychmgr/mock_test.go b/paychmgr/mock_test.go index bc19de2239c..c761221d2ad 100644 --- a/paychmgr/mock_test.go +++ b/paychmgr/mock_test.go @@ -2,23 +2,18 @@ package paychmgr import ( "context" - "fmt" + "errors" "sync" - "github.com/filecoin-project/lotus/lib/sigs" + "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/crypto" - cbornode "github.com/ipfs/go-ipld-cbor" - - "github.com/filecoin-project/specs-actors/actors/util/adt" - - "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/ipfs/go-cid" + "github.com/filecoin-project/lotus/lib/sigs" ) type mockManagerAPI struct { @@ -40,29 +35,23 @@ type mockPchState struct { type mockStateManager struct { lk sync.Mutex - accountState map[address.Address]account.State + accountState map[address.Address]address.Address paychState map[address.Address]mockPchState - store adt.Store response *api.InvocResult lastCall *types.Message } func newMockStateManager() *mockStateManager { return &mockStateManager{ - accountState: make(map[address.Address]account.State), + accountState: make(map[address.Address]address.Address), paychState: make(map[address.Address]mockPchState), - store: adt.WrapStore(context.Background(), cbornode.NewMemCborStore()), } } -func (sm *mockStateManager) AdtStore(ctx context.Context) adt.Store { - return sm.store -} - -func (sm *mockStateManager) setAccountState(a address.Address, state account.State) { +func (sm *mockStateManager) setAccountAddress(a address.Address, lookup address.Address) { sm.lk.Lock() defer sm.lk.Unlock() - sm.accountState[a] = state + sm.accountState[a] = lookup } func (sm *mockStateManager) setPaychState(a address.Address, actor *types.Actor, state paych.State) { @@ -71,31 +60,24 @@ func (sm *mockStateManager) setPaychState(a address.Address, actor *types.Actor, sm.paychState[a] = mockPchState{actor, state} } -func (sm *mockStateManager) storeLaneStates(laneStates map[uint64]paych.LaneState) (cid.Cid, error) { - arr := adt.MakeEmptyArray(sm.store) - for i, ls := range laneStates { - ls := ls - if err := arr.Set(i, &ls); err != nil { - return cid.Undef, err - } +func (sm *mockStateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { + sm.lk.Lock() + defer sm.lk.Unlock() + keyAddr, ok := sm.accountState[addr] + if !ok { + return address.Undef, errors.New("not found") } - return arr.Root() + return keyAddr, nil } -func (sm *mockStateManager) LoadActorState(ctx context.Context, a address.Address, out interface{}, ts *types.TipSet) (*types.Actor, error) { +func (sm *mockStateManager) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) { sm.lk.Lock() defer sm.lk.Unlock() - - if outState, ok := out.(*account.State); ok { - *outState = sm.accountState[a] - return nil, nil - } - if outState, ok := out.(*paych.State); ok { - info := sm.paychState[a] - *outState = info.state - return info.actor, nil + info, ok := sm.paychState[addr] + if !ok { + return nil, nil, errors.New("not found") } - panic(fmt.Sprintf("unexpected state type %v", out)) + return info.actor, info.state, nil } func (sm *mockStateManager) setCallResponse(response *api.InvocResult) { diff --git a/paychmgr/msglistener_test.go b/paychmgr/msglistener_test.go index 2c3ae16e4a5..4b8ae6f30b1 100644 --- a/paychmgr/msglistener_test.go +++ b/paychmgr/msglistener_test.go @@ -4,9 +4,7 @@ import ( "testing" "github.com/ipfs/go-cid" - "github.com/stretchr/testify/require" - "golang.org/x/xerrors" ) diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 20d76b7fd87..53f16b4fce5 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -5,22 +5,20 @@ import ( "context" "fmt" - "github.com/filecoin-project/lotus/api" - - "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/ipfs/go-cid" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/specs-actors/actors/builtin" + v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "golang.org/x/xerrors" ) // insufficientFundsErr indicates that there are not enough funds in the @@ -45,6 +43,19 @@ func (e *ErrInsufficientFunds) Shortfall() types.BigInt { return e.shortfall } +type laneState struct { + redeemed big.Int + nonce uint64 +} + +func (ls laneState) Redeemed() big.Int { + return ls.redeemed +} + +func (ls laneState) Nonce() uint64 { + return ls.nonce +} + // channelAccessor is used to simplify locking when accessing a channel type channelAccessor struct { from address.Address @@ -92,7 +103,7 @@ func (ca *channelAccessor) outboundActiveByFromTo(from, to address.Address) (*Ch // nonce, signing the voucher and storing it in the local datastore. // If there are not enough funds in the channel to create the voucher, returns // the shortfall in funds. -func (ca *channelAccessor) createVoucher(ctx context.Context, ch address.Address, voucher paych.SignedVoucher) (*api.VoucherCreateResult, error) { +func (ca *channelAccessor) createVoucher(ctx context.Context, ch address.Address, voucher v0paych.SignedVoucher) (*api.VoucherCreateResult, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -151,14 +162,14 @@ func (ca *channelAccessor) nextNonceForLane(ci *ChannelInfo, lane uint64) uint64 return maxnonce + 1 } -func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]*paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) (map[uint64]paych.LaneState, error) { ca.lk.Lock() defer ca.lk.Unlock() return ca.checkVoucherValidUnlocked(ctx, ch, sv) } -func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]*paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) (map[uint64]paych.LaneState, error) { if sv.ChannelAddr != ch { return nil, xerrors.Errorf("voucher ChannelAddr doesn't match channel address, got %s, expected %s", sv.ChannelAddr, ch) } @@ -170,12 +181,10 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add } // Load channel "From" account actor state - var actState account.State - _, err = ca.api.LoadActorState(ctx, pchState.From, &actState, nil) + from, err := ca.api.ResolveToKeyAddress(ctx, pchState.From(), nil) if err != nil { return nil, err } - from := actState.Address // verify voucher signature vb, err := sv.SigningBytes() @@ -199,12 +208,12 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add // If the new voucher nonce value is less than the highest known // nonce for the lane ls, lsExists := laneStates[sv.Lane] - if lsExists && sv.Nonce <= ls.Nonce { + if lsExists && sv.Nonce <= ls.Nonce() { return nil, fmt.Errorf("nonce too low") } // If the voucher amount is less than the highest known voucher amount - if lsExists && sv.Amount.LessThanEqual(ls.Redeemed) { + if lsExists && sv.Amount.LessThanEqual(ls.Redeemed()) { return nil, fmt.Errorf("voucher amount is lower than amount for voucher with lower nonce") } @@ -230,7 +239,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add // Total required balance = total redeemed + toSend // Must not exceed actor balance - newTotal := types.BigAdd(totalRedeemed, pchState.ToSend) + newTotal := types.BigAdd(totalRedeemed, pchState.ToSend()) if act.Balance.LessThan(newTotal) { return nil, newErrInsufficientFunds(types.BigSub(newTotal, act.Balance)) } @@ -242,7 +251,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add return laneStates, nil } -func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -281,7 +290,7 @@ func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address } } - enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{ + enc, err := actors.SerializeParams(&v0paych.UpdateChannelStateParams{ Sv: *sv, Secret: secret, Proof: proof, @@ -308,22 +317,22 @@ func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address } func (ca *channelAccessor) getPaychRecipient(ctx context.Context, ch address.Address) (address.Address, error) { - var state paych.State - if _, err := ca.api.LoadActorState(ctx, ch, &state, nil); err != nil { + _, state, err := ca.api.GetPaychState(ctx, ch, nil) + if err != nil { return address.Address{}, err } - return state.To, nil + return state.To(), nil } -func (ca *channelAccessor) addVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (ca *channelAccessor) addVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ca.lk.Lock() defer ca.lk.Unlock() return ca.addVoucherUnlocked(ctx, ch, sv, proof, minDelta) } -func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ci, err := ca.store.ByAddress(ch) if err != nil { return types.BigInt{}, err @@ -367,7 +376,7 @@ func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Ad laneState, exists := laneStates[sv.Lane] redeemed := big.NewInt(0) if exists { - redeemed = laneState.Redeemed + redeemed = laneState.Redeemed() } delta := types.BigSub(sv.Amount, redeemed) @@ -387,7 +396,7 @@ func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Ad return delta, ca.store.putChannelInfo(ci) } -func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -428,7 +437,7 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address } } - enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{ + enc, err := actors.SerializeParams(&v0paych.UpdateChannelStateParams{ Sv: *sv, Secret: secret, Proof: proof, @@ -487,13 +496,11 @@ func (ca *channelAccessor) listVouchers(ctx context.Context, ch address.Address) // laneState gets the LaneStates from chain, then applies all vouchers in // the data store over the chain state -func (ca *channelAccessor) laneState(ctx context.Context, state *paych.State, ch address.Address) (map[uint64]*paych.LaneState, error) { +func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch address.Address) (map[uint64]paych.LaneState, error) { // TODO: we probably want to call UpdateChannelState with all vouchers to be fully correct // (but technically dont't need to) - // Get the lane state from the chain - store := ca.api.AdtStore(ctx) - lsamt, err := adt.AsArray(store, state.LaneStates) + laneCount, err := state.LaneCount() if err != nil { return nil, err } @@ -501,11 +508,9 @@ func (ca *channelAccessor) laneState(ctx context.Context, state *paych.State, ch // Note: we use a map instead of an array to store laneStates because the // client sets the lane ID (the index) and potentially they could use a // very large index. - var ls paych.LaneState - laneStates := make(map[uint64]*paych.LaneState, lsamt.Length()) - err = lsamt.ForEach(&ls, func(i int64) error { - current := ls - laneStates[uint64(i)] = ¤t + laneStates := make(map[uint64]paych.LaneState, laneCount) + err = state.ForEachLaneState(func(idx uint64, ls paych.LaneState) error { + laneStates[idx] = ls return nil }) if err != nil { @@ -526,27 +531,19 @@ func (ca *channelAccessor) laneState(ctx context.Context, state *paych.State, ch // If there's a voucher for a lane that isn't in chain state just // create it ls, ok := laneStates[v.Voucher.Lane] - if !ok { - ls = &paych.LaneState{ - Redeemed: types.NewInt(0), - Nonce: 0, - } - laneStates[v.Voucher.Lane] = ls - } - if v.Voucher.Nonce < ls.Nonce { + if ok && v.Voucher.Nonce < ls.Nonce() { continue } - ls.Nonce = v.Voucher.Nonce - ls.Redeemed = v.Voucher.Amount + laneStates[v.Voucher.Lane] = laneState{v.Voucher.Amount, v.Voucher.Nonce} } return laneStates, nil } // Get the total redeemed amount across all lanes, after applying the voucher -func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]*paych.LaneState, sv *paych.SignedVoucher) (big.Int, error) { +func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]paych.LaneState, sv *v0paych.SignedVoucher) (big.Int, error) { // TODO: merges if len(sv.Merges) != 0 { return big.Int{}, xerrors.Errorf("dont currently support paych lane merges") @@ -554,17 +551,17 @@ func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]*paych total := big.NewInt(0) for _, ls := range laneStates { - total = big.Add(total, ls.Redeemed) + total = big.Add(total, ls.Redeemed()) } lane, ok := laneStates[sv.Lane] if ok { // If the voucher is for an existing lane, and the voucher nonce // is higher than the lane nonce - if sv.Nonce > lane.Nonce { + if sv.Nonce > lane.Nonce() { // Add the delta between the redeemed amount and the voucher // amount to the total - delta := big.Sub(sv.Amount, lane.Redeemed) + delta := big.Sub(sv.Amount, lane.Redeemed()) total = big.Add(total, delta) } } else { diff --git a/paychmgr/paych_test.go b/paychmgr/paych_test.go index 18c6655dadc..434c83e9ccd 100644 --- a/paychmgr/paych_test.go +++ b/paychmgr/paych_test.go @@ -5,31 +5,24 @@ import ( "context" "testing" - "github.com/filecoin-project/lotus/api" - - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/lotus/lib/sigs" - + ds "github.com/ipfs/go-datastore" + ds_sync "github.com/ipfs/go-datastore/sync" "github.com/stretchr/testify/require" - "github.com/filecoin-project/go-state-types/big" - + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/specs-actors/actors/builtin" + v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" tutils "github.com/filecoin-project/specs-actors/support/testing" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - - "github.com/filecoin-project/specs-actors/actors/builtin/account" - - "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + paychmock "github.com/filecoin-project/lotus/chain/actors/builtin/paych/mock" "github.com/filecoin-project/lotus/chain/types" - - ds "github.com/ipfs/go-datastore" - ds_sync "github.com/ipfs/go-datastore/sync" + "github.com/filecoin-project/lotus/lib/sigs" ) func TestCheckVoucherValid(t *testing.T) { @@ -46,8 +39,8 @@ func TestCheckVoucherValid(t *testing.T) { toAcct := tutils.NewActorAddr(t, "toAct") mock := newMockManagerAPI() - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) tcases := []struct { name string @@ -96,10 +89,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherLane: 1, voucherNonce: 2, laneStates: map[uint64]paych.LaneState{ - 1: { - Redeemed: big.NewInt(2), - Nonce: 3, - }, + 1: paychmock.NewMockLaneState(big.NewInt(2), 3), }, }, { name: "passes when nonce higher", @@ -110,10 +100,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherLane: 1, voucherNonce: 3, laneStates: map[uint64]paych.LaneState{ - 1: { - Redeemed: big.NewInt(2), - Nonce: 2, - }, + 1: paychmock.NewMockLaneState(big.NewInt(2), 2), }, }, { name: "passes when nonce for different lane", @@ -124,10 +111,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherLane: 2, voucherNonce: 2, laneStates: map[uint64]paych.LaneState{ - 1: { - Redeemed: big.NewInt(2), - Nonce: 3, - }, + 1: paychmock.NewMockLaneState(big.NewInt(2), 3), }, }, { name: "fails when voucher has higher nonce but lower value than lane state", @@ -139,10 +123,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherLane: 1, voucherNonce: 3, laneStates: map[uint64]paych.LaneState{ - 1: { - Redeemed: big.NewInt(6), - Nonce: 2, - }, + 1: paychmock.NewMockLaneState(big.NewInt(6), 2), }, }, { name: "fails when voucher + ToSend > balance", @@ -168,10 +149,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherNonce: 2, laneStates: map[uint64]paych.LaneState{ // Lane 1 (same as voucher lane 1) - 1: { - Redeemed: big.NewInt(4), - Nonce: 1, - }, + 1: paychmock.NewMockLaneState(big.NewInt(4), 1), }, }, { // required balance = toSend + total redeemed @@ -188,10 +166,7 @@ func TestCheckVoucherValid(t *testing.T) { voucherNonce: 1, laneStates: map[uint64]paych.LaneState{ // Lane 2 (different from voucher lane 1) - 2: { - Redeemed: big.NewInt(4), - Nonce: 1, - }, + 2: paychmock.NewMockLaneState(big.NewInt(4), 1), }, }} @@ -208,18 +183,8 @@ func TestCheckVoucherValid(t *testing.T) { Balance: tcase.actorBalance, } - // Set the state of the channel's lanes - laneStates, err := mock.storeLaneStates(tcase.laneStates) - require.NoError(t, err) - - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: tcase.toSend, - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: laneStates, - }) + mock.setPaychState(ch, act, paychmock.NewMockPayChState( + fromAcct, toAcct, abi.ChainEpoch(0), tcase.toSend, tcase.laneStates)) // Create a manager mgr, err := newManager(store, mock) @@ -255,22 +220,16 @@ func TestCheckVoucherValidCountingAllLanes(t *testing.T) { minDelta := big.NewInt(0) mock := newMockManagerAPI() - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) actorBalance := big.NewInt(10) toSend := big.NewInt(1) laneStates := map[uint64]paych.LaneState{ - 1: { - Nonce: 1, - Redeemed: big.NewInt(3), - }, - 2: { - Nonce: 1, - Redeemed: big.NewInt(4), - }, + 1: paychmock.NewMockLaneState(big.NewInt(3), 1), + 2: paychmock.NewMockLaneState(big.NewInt(4), 1), } act := &types.Actor{ @@ -280,16 +239,7 @@ func TestCheckVoucherValidCountingAllLanes(t *testing.T) { Balance: actorBalance, } - lsCid, err := mock.storeLaneStates(laneStates) - require.NoError(t, err) - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: toSend, - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: lsCid, - }) + mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), toSend, laneStates)) mgr, err := newManager(store, mock) require.NoError(t, err) @@ -389,7 +339,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 voucherLane1Amt := big.NewInt(5) - voucher := paych.SignedVoucher{ + voucher := v0paych.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -404,7 +354,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 again, with a higher amount voucherLane1Amt = big.NewInt(8) - voucher = paych.SignedVoucher{ + voucher = v0paych.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -419,7 +369,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that covers all the remaining funds // in the channel voucherLane2Amt := big.Sub(s.amt, voucherLane1Amt) - voucher = paych.SignedVoucher{ + voucher = v0paych.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -433,7 +383,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that exceeds the remaining funds in the // channel voucherLane2Amt = big.Add(voucherLane2Amt, big.NewInt(1)) - voucher = paych.SignedVoucher{ + voucher = v0paych.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -567,8 +517,8 @@ func TestAllocateLaneWithExistingLaneState(t *testing.T) { toAcct := tutils.NewActorAddr(t, "toAct") mock := newMockManagerAPI() - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) mock.addWalletAddress(to) store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) @@ -584,16 +534,7 @@ func TestAllocateLaneWithExistingLaneState(t *testing.T) { Balance: actorBalance, } - arr, err := adt.MakeEmptyArray(mock.store).Root() - require.NoError(t, err) - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: toSend, - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: arr, - }) + mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), toSend, make(map[uint64]paych.LaneState))) mgr, err := newManager(store, mock) require.NoError(t, err) @@ -681,19 +622,10 @@ func TestAddVoucherInboundWalletKey(t *testing.T) { } mock := newMockManagerAPI() - arr, err := adt.MakeEmptyArray(mock.store).Root() - require.NoError(t, err) - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) - - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: types.NewInt(0), - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: arr, - }) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) + + mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), types.NewInt(0), make(map[uint64]paych.LaneState))) // Create a manager store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) @@ -840,7 +772,7 @@ func TestCheckSpendable(t *testing.T) { // Check that the secret and proof were passed through correctly lastCall := s.mock.getLastCall() - var p paych.UpdateChannelStateParams + var p v0paych.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(lastCall.Params)) require.NoError(t, err) require.Equal(t, otherProof, p.Proof) @@ -854,7 +786,7 @@ func TestCheckSpendable(t *testing.T) { require.True(t, spendable) lastCall = s.mock.getLastCall() - var p2 paych.UpdateChannelStateParams + var p2 v0paych.UpdateChannelStateParams err = p2.UnmarshalCBOR(bytes.NewReader(lastCall.Params)) require.NoError(t, err) require.Equal(t, proof, p2.Proof) @@ -911,7 +843,7 @@ func TestSubmitVoucher(t *testing.T) { // Check that the secret and proof were passed through correctly msg := s.mock.pushedMessages(submitCid) - var p paych.UpdateChannelStateParams + var p v0paych.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, submitProof, p.Proof) @@ -931,7 +863,7 @@ func TestSubmitVoucher(t *testing.T) { require.NoError(t, err) msg = s.mock.pushedMessages(submitCid) - var p2 paych.UpdateChannelStateParams + var p2 v0paych.UpdateChannelStateParams err = p2.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, addVoucherProof2, p2.Proof) @@ -947,7 +879,7 @@ func TestSubmitVoucher(t *testing.T) { require.NoError(t, err) msg = s.mock.pushedMessages(submitCid) - var p3 paych.UpdateChannelStateParams + var p3 v0paych.UpdateChannelStateParams err = p3.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, proof3, p3.Proof) @@ -986,10 +918,8 @@ func testSetupMgrWithChannel(ctx context.Context, t *testing.T) *testScaffold { toAcct := tutils.NewActorAddr(t, "toAct") mock := newMockManagerAPI() - arr, err := adt.MakeEmptyArray(mock.store).Root() - require.NoError(t, err) - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) // Create channel in state balance := big.NewInt(20) @@ -999,14 +929,7 @@ func testSetupMgrWithChannel(ctx context.Context, t *testing.T) *testScaffold { Nonce: 0, Balance: balance, } - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: big.NewInt(0), - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: arr, - }) + mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), big.NewInt(0), make(map[uint64]paych.LaneState))) store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) mgr, err := newManager(store, mock) @@ -1043,8 +966,8 @@ func testGenerateKeyPair(t *testing.T) ([]byte, []byte) { return priv, pub } -func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych.SignedVoucher { - sv := &paych.SignedVoucher{ +func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *v0paych.SignedVoucher { + sv := &v0paych.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, @@ -1059,13 +982,13 @@ func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, non return sv } -func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych.SignedVoucher { - sv := &paych.SignedVoucher{ +func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *v0paych.SignedVoucher { + sv := &v0paych.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, Amount: voucherAmount, - Extra: &paych.ModVerifyParams{ + Extra: &v0paych.ModVerifyParams{ Actor: tutils.NewActorAddr(t, "act"), }, } @@ -1083,13 +1006,13 @@ type mockBestSpendableAPI struct { mgr *Manager } -func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*paych.SignedVoucher, error) { +func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*v0paych.SignedVoucher, error) { vi, err := m.mgr.ListVouchers(ctx, ch) if err != nil { return nil, err } - out := make([]*paych.SignedVoucher, len(vi)) + out := make([]*v0paych.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -1097,7 +1020,7 @@ func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address. return out, nil } -func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { return m.mgr.CheckVoucherSpendable(ctx, ch, voucher, secret, proof) } diff --git a/paychmgr/paychget_test.go b/paychmgr/paychget_test.go index 1f3e4c3969b..93233c54fe3 100644 --- a/paychmgr/paychget_test.go +++ b/paychmgr/paychget_test.go @@ -6,29 +6,22 @@ import ( "testing" "time" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/util/adt" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - cborrpc "github.com/filecoin-project/go-cbor-util" - - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - - "github.com/filecoin-project/specs-actors/actors/builtin" - - "github.com/filecoin-project/lotus/chain/types" + "github.com/ipfs/go-cid" + ds "github.com/ipfs/go-datastore" + ds_sync "github.com/ipfs/go-datastore/sync" + "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" - + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/specs-actors/actors/builtin" + init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" tutils "github.com/filecoin-project/specs-actors/support/testing" - "github.com/ipfs/go-cid" - ds "github.com/ipfs/go-datastore" - ds_sync "github.com/ipfs/go-datastore/sync" - "github.com/stretchr/testify/require" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + paychmock "github.com/filecoin-project/lotus/chain/actors/builtin/paych/mock" + "github.com/filecoin-project/lotus/chain/types" ) func testChannelResponse(t *testing.T, ch address.Address) types.MessageReceipt { @@ -976,25 +969,15 @@ func TestPaychAvailableFunds(t *testing.T) { require.EqualValues(t, 0, av.VoucherReedeemedAmt.Int64()) // Create channel in state - arr, err := adt.MakeEmptyArray(mock.store).Root() - require.NoError(t, err) - mock.setAccountState(fromAcct, account.State{Address: from}) - mock.setAccountState(toAcct, account.State{Address: to}) + mock.setAccountAddress(fromAcct, from) + mock.setAccountAddress(toAcct, to) act := &types.Actor{ Code: builtin.AccountActorCodeID, Head: cid.Cid{}, Nonce: 0, Balance: createAmt, } - mock.setPaychState(ch, act, paych.State{ - From: fromAcct, - To: toAcct, - ToSend: big.NewInt(0), - SettlingAt: abi.ChainEpoch(0), - MinSettleHeight: abi.ChainEpoch(0), - LaneStates: arr, - }) - + mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), big.NewInt(0), make(map[uint64]paych.LaneState))) // Send create channel response response := testChannelResponse(t, ch) mock.receiveMsgResponse(createMsgCid, response) diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 4cf579a4778..2f6dc0593dd 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -6,20 +6,17 @@ import ( "fmt" "sync" - "github.com/filecoin-project/lotus/api" - + "github.com/ipfs/go-cid" "golang.org/x/sync/errgroup" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/ipfs/go-cid" - "golang.org/x/xerrors" - - "github.com/filecoin-project/go-address" + v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" @@ -320,7 +317,7 @@ func (ca *channelAccessor) currentAvailableFunds(channelID string, queuedAmt typ } for _, ls := range laneStates { - totalRedeemed = types.BigAdd(totalRedeemed, ls.Redeemed) + totalRedeemed = types.BigAdd(totalRedeemed, ls.Redeemed()) } } @@ -385,7 +382,7 @@ func (ca *channelAccessor) processTask(ctx context.Context, amt types.BigInt) *p // createPaych sends a message to create the channel and returns the message cid func (ca *channelAccessor) createPaych(ctx context.Context, amt types.BigInt) (cid.Cid, error) { - params, aerr := actors.SerializeParams(&paych.ConstructorParams{From: ca.from, To: ca.to}) + params, aerr := actors.SerializeParams(&v0paych.ConstructorParams{From: ca.from, To: ca.to}) if aerr != nil { return cid.Undef, aerr } diff --git a/paychmgr/state.go b/paychmgr/state.go index 00fe2adce44..2571ef73e83 100644 --- a/paychmgr/state.go +++ b/paychmgr/state.go @@ -3,13 +3,9 @@ package paychmgr import ( "context" - "github.com/filecoin-project/specs-actors/actors/util/adt" - - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" ) @@ -17,14 +13,8 @@ type stateAccessor struct { sm stateManagerAPI } -func (ca *stateAccessor) loadPaychActorState(ctx context.Context, ch address.Address) (*types.Actor, *paych.State, error) { - var pcast paych.State - act, err := ca.sm.LoadActorState(ctx, ch, &pcast, nil) - if err != nil { - return nil, nil, err - } - - return act, &pcast, nil +func (ca *stateAccessor) loadPaychActorState(ctx context.Context, ch address.Address) (*types.Actor, paych.State, error) { + return ca.sm.GetPaychState(ctx, ch, nil) } func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Address, dir uint64) (*ChannelInfo, error) { @@ -33,17 +23,15 @@ func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Ad return nil, err } - var account account.State - _, err = ca.sm.LoadActorState(ctx, st.From, &account, nil) + // Load channel "From" account actor state + from, err := ca.sm.ResolveToKeyAddress(ctx, st.From(), nil) if err != nil { return nil, err } - from := account.Address - _, err = ca.sm.LoadActorState(ctx, st.To, &account, nil) + to, err := ca.sm.ResolveToKeyAddress(ctx, st.To(), nil) if err != nil { return nil, err } - to := account.Address nextLane, err := ca.nextLaneFromState(ctx, st) if err != nil { @@ -67,25 +55,24 @@ func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Ad return ci, nil } -func (ca *stateAccessor) nextLaneFromState(ctx context.Context, st *paych.State) (uint64, error) { - store := ca.sm.AdtStore(ctx) - laneStates, err := adt.AsArray(store, st.LaneStates) +func (ca *stateAccessor) nextLaneFromState(ctx context.Context, st paych.State) (uint64, error) { + laneCount, err := st.LaneCount() if err != nil { return 0, err } - if laneStates.Length() == 0 { + if laneCount == 0 { return 0, nil } - maxID := int64(0) - if err := laneStates.ForEach(nil, func(i int64) error { - if i > maxID { - maxID = i + maxID := uint64(0) + if err := st.ForEachLaneState(func(idx uint64, _ paych.LaneState) error { + if idx > maxID { + maxID = idx } return nil }); err != nil { return 0, err } - return uint64(maxID + 1), nil + return maxID + 1, nil } From b4ee51928233bcc6cacedbc185498e45630cb192 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 01:00:00 -0400 Subject: [PATCH 025/104] Partial progress towards switching to miner and power interfaces --- build/params_2k.go | 4 +- build/params_testnet.go | 4 +- chain/actors/builtin/power/power.go | 1 + chain/actors/builtin/power/v0.go | 28 ++++++++++++-- chain/gen/gen_test.go | 4 +- chain/gen/genesis/miners.go | 16 ++++---- chain/gen/genesis/t04_power.go | 4 +- chain/gen/genesis/util.go | 1 + chain/stmgr/forks_test.go | 8 ++-- chain/stmgr/stmgr.go | 2 +- chain/stmgr/utils.go | 59 +---------------------------- chain/store/store_test.go | 4 +- chain/store/weight.go | 17 ++++++--- chain/sync.go | 19 +++++----- chain/sync_test.go | 4 +- chain/vectors/gen/main.go | 4 +- chain/vm/invoker.go | 4 +- cli/paych_test.go | 4 +- 18 files changed, 81 insertions(+), 106 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index 0ef1d9b3407..313ccfa9d96 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" ) @@ -20,7 +20,7 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ } func init() { - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } diff --git a/build/params_testnet.go b/build/params_testnet.go index 932ad7a7d17..4cfd8a9b62c 100644 --- a/build/params_testnet.go +++ b/build/params_testnet.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" ) var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ @@ -23,7 +23,7 @@ const BreezeGasTampingDuration = 120 const UpgradeSmokeHeight = 51000 func init() { - power.ConsensusMinerMinPower = big.NewInt(10 << 40) + v0power.ConsensusMinerMinPower = big.NewInt(10 << 40) miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg32GiBV1: {}, abi.RegisteredSealProof_StackedDrg64GiBV1: {}, diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 07399e1bf83..65148f0a58b 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -37,6 +37,7 @@ type State interface { MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) + ListAllMiners() ([]address.Address, error) } type Claim struct { diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 45dd570f616..5cf6920c8d0 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -4,12 +4,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" ) type v0State struct { - power.State + v0power.State store adt.Store } @@ -29,7 +29,7 @@ func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { if err != nil { return Claim{}, false, err } - var claim power.Claim + var claim v0power.Claim ok, err := claims.Get(abi.AddrKey(addr), &claim) if err != nil { return Claim{}, false, err @@ -47,3 +47,25 @@ func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (boo func (s *v0State) TotalPowerSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochQAPowerSmoothed, nil } + +func (s *v0State) ListAllMiners() ([]address.Address, error) { + claims, err := adt.AsMap(s.store, s.Claims) + if err != nil { + return nil, err + } + + var miners []address.Address + err = claims.ForEach(nil, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + miners = append(miners, a) + return nil + }) + if err != nil { + return nil, err + } + + return miners, nil +} diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index ebc28a990d6..fd6bceb9533 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" _ "github.com/filecoin-project/lotus/lib/sigs/bls" @@ -17,7 +17,7 @@ func init() { miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) verifreg.MinVerifiedDealSize = big.NewInt(256) } diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 3bed1c1a913..88fe571897a 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -19,7 +19,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -99,7 +99,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } { - constructorParams := &power.CreateMinerParams{ + constructorParams := &v0power.CreateMinerParams{ Owner: m.Worker, Worker: m.Worker, Peer: []byte(m.PeerId), @@ -112,7 +112,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) } - var ma power.CreateMinerReturn + var ma v0power.CreateMinerReturn if err := ma.UnmarshalCBOR(bytes.NewReader(rval)); err != nil { return cid.Undef, xerrors.Errorf("unmarshaling CreateMinerReturn: %w", err) } @@ -207,7 +207,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } } - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { st.TotalQualityAdjPower = qaPow st.TotalRawBytePower = rawPow @@ -249,7 +249,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid sectorWeight := miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) // we've added fake power for this sector above, remove it now - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) //nolint:scopelint st.TotalRawBytePower = types.BigSub(st.TotalRawBytePower, types.NewInt(uint64(m.SectorSize))) return nil @@ -301,7 +301,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } // Sanity-check total network power - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { if !st.TotalRawBytePower.Equals(rawPow) { return xerrors.Errorf("st.TotalRawBytePower doesn't match previously calculated rawPow") } @@ -340,12 +340,12 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry return out, nil } -func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power.CurrentTotalPowerReturn, error) { +func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*v0power.CurrentTotalPowerReturn, error) { pwret, err := doExecValue(ctx, vm, builtin.StoragePowerActorAddr, maddr, big.Zero(), builtin.MethodsPower.CurrentTotalPower, nil) if err != nil { return nil, err } - var pwr power.CurrentTotalPowerReturn + var pwr v0power.CurrentTotalPowerReturn if err := pwr.UnmarshalCBOR(bytes.NewReader(pwret)); err != nil { return nil, err } diff --git a/chain/gen/genesis/t04_power.go b/chain/gen/genesis/t04_power.go index 86ba684e007..40ea68079bc 100644 --- a/chain/gen/genesis/t04_power.go +++ b/chain/gen/genesis/t04_power.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/lotus/chain/types" @@ -30,7 +30,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) { return nil, err } - sms := power.ConstructState(emptyMap, emptyMultiMap) + sms := v0power.ConstructState(emptyMap, emptyMultiMap) stcid, err := store.Put(store.Context(), sms) if err != nil { diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index d8750020675..bcafb007e01 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -2,6 +2,7 @@ package genesis import ( "context" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/build" diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 2fc11b3d74c..d9d0af74594 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime" "golang.org/x/xerrors" @@ -36,7 +36,7 @@ func init() { miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) verifreg.MinVerifiedDealSize = big.NewInt(256) } @@ -148,8 +148,8 @@ func TestForkHeightTriggers(t *testing.T) { } inv.Register(builtin.PaymentChannelActorCodeID, &testActor{}, &testActorState{}) - sm.SetVMConstructor(func(vmopt *vm.VMOpts) (*vm.VM, error) { - nvm, err := vm.NewVM(vmopt) + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { + nvm, err := vm.NewVM(ctx, vmopt) if err != nil { return nil, err } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index f71b788c8f2..827f239205d 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -197,7 +197,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp for i := parentEpoch; i < epoch; i++ { // handle state forks - // XXX: The state tre + // XXX: The state tree err = sm.handleStateForks(ctx, vmi.StateTree(), i, ts) if err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 1bbc9ccc423..e295725f85f 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -13,7 +13,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/runtime/proof" cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -42,7 +41,6 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" - "github.com/filecoin-project/lotus/lib/blockstore" "github.com/filecoin-project/lotus/node/modules/dtypes" ) @@ -326,65 +324,12 @@ func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([ return nil, xerrors.Errorf("failed to load power actor: %w", err) } - state, err := power.Load(sm.cs.Store(ctx), act) + powState, err := power.Load(sm.cs.Store(ctx), act) if err != nil { return nil, xerrors.Errorf("failed to load power actor state: %w", err) } - m, err := adt.AsMap(sm.cs.Store(ctx), state.Claims) - if err != nil { - return nil, err - } - - var miners []address.Address - err = m.ForEach(nil, func(k string) error { - a, err := address.NewFromBytes([]byte(k)) - if err != nil { - return err - } - miners = append(miners, a) - return nil - }) - if err != nil { - return nil, err - } - - return miners, nil -} - -func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid, filter *bitfield.BitField, filterOut bool) ([]*miner.ChainSectorInfo, error) { - a, err := adt.AsArray(store.ActorStore(ctx, bs), ssc) - if err != nil { - return nil, err - } - - var sset []*miner.ChainSectorInfo - var v cbg.Deferred - if err := a.ForEach(&v, func(i int64) error { - if filter != nil { - set, err := filter.IsSet(uint64(i)) - if err != nil { - return xerrors.Errorf("filter check error: %w", err) - } - if set == filterOut { - return nil - } - } - - var oci miner.SectorOnChainInfo - if err := cbor.DecodeInto(v.Raw, &oci); err != nil { - return err - } - sset = append(sset, &miner.ChainSectorInfo{ - Info: oci, - ID: abi.SectorNumber(i), - }) - return nil - }); err != nil { - return nil, err - } - - return sset, nil + return powState.ListAllMiners() } func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, msgs []*types.Message, ts *types.TipSet) (cid.Cid, []*api.InvocResult, error) { diff --git a/chain/store/store_test.go b/chain/store/store_test.go index e56bab4c9f4..8662f10ef78 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -11,7 +11,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/gen" @@ -25,7 +25,7 @@ func init() { miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) verifreg.MinVerifiedDealSize = big.NewInt(256) } diff --git a/chain/store/weight.go b/chain/store/weight.go index 5249df0112b..2d83738c541 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -4,12 +4,13 @@ import ( "context" "math/big" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" + big2 "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" ) @@ -39,11 +40,17 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn return types.NewInt(0), xerrors.Errorf("get power actor: %w", err) } - var st power.State - if err := cst.Get(ctx, act.Head, &st); err != nil { - return types.NewInt(0), xerrors.Errorf("get power actor head (%s, height=%d): %w", act.Head, ts.Height(), err) + powState, err := power.Load(cs.Store(ctx), act) + if err != nil { + return types.NewInt(0), xerrors.Errorf("failed to load power actor state: %w", err) + } + + claim, err := powState.TotalPower() + if err != nil { + return types.NewInt(0), xerrors.Errorf("failed to get total power: %w", err) } - tpow = st.TotalQualityAdjPower // TODO: REVIEW: Is this correct? + + tpow = claim.QualityAdjPower // TODO: REVIEW: Is this correct? } log2P := int64(0) diff --git a/chain/sync.go b/chain/sync.go index bb3e50bdbb4..c1682188962 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -34,12 +34,12 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" blst "github.com/supranational/blst/bindings/go" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/exchange" "github.com/filecoin-project/lotus/chain/gen" @@ -635,26 +635,25 @@ func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet) } func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, baseTs *types.TipSet) error { - var spast power.State - - _, err := syncer.sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &spast, baseTs) + act, err := syncer.sm.LoadActor(ctx, builtin.StoragePowerActorAddr, baseTs) if err != nil { - return err + return xerrors.Errorf("failed to load power actor: %w", err) } - cm, err := adt.AsMap(syncer.store.Store(ctx), spast.Claims) + powState, err := power.Load(syncer.store.Store(ctx), act) if err != nil { - return err + return xerrors.Errorf("failed to load power actor state: %w", err) } - var claim power.Claim - exist, err := cm.Get(abi.AddrKey(maddr), &claim) + _, exist, err := powState.MinerPower(maddr) if err != nil { - return err + return xerrors.Errorf("failed to look up miner's claim: %w", err) } + if !exist { return xerrors.New("miner isn't valid") } + return nil } diff --git a/chain/sync_test.go b/chain/sync_test.go index 0b0d1ed0098..5f972ecc6da 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -21,7 +21,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" @@ -46,7 +46,7 @@ func init() { miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) verifreg.MinVerifiedDealSize = big.NewInt(256) } diff --git a/chain/vectors/gen/main.go b/chain/vectors/gen/main.go index ecc2498b98e..4bf2c420e60 100644 --- a/chain/vectors/gen/main.go +++ b/chain/vectors/gen/main.go @@ -6,7 +6,7 @@ import ( "math/rand" "os" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/go-address" "golang.org/x/xerrors" @@ -27,7 +27,7 @@ import ( func init() { verifreg.MinVerifiedDealSize = big.NewInt(2048) - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) } func MakeHeaderVectors() []vectors.HeaderVector { diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 9f5f8e2d9c7..56e3bea84c1 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -23,7 +23,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/system" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -50,7 +50,7 @@ func NewInvoker() *Invoker { inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{}) inv.Register(builtin.RewardActorCodeID, reward.Actor{}, reward.State{}) inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{}) - inv.Register(builtin.StoragePowerActorCodeID, power.Actor{}, power.State{}) + inv.Register(builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{}) inv.Register(builtin.StorageMinerActorCodeID, miner.Actor{}, miner.State{}) inv.Register(builtin.MultisigActorCodeID, multisig.Actor{}, multisig.State{}) diff --git a/cli/paych_test.go b/cli/paych_test.go index cccc80ff420..0e5bc009643 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -16,7 +16,7 @@ import ( "github.com/filecoin-project/go-state-types/big" saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/multiformats/go-multiaddr" @@ -39,7 +39,7 @@ import ( ) func init() { - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } From 90853e24cfd9e3ef749855fbdf319a821f4403aa Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 01:47:24 -0400 Subject: [PATCH 026/104] Add a boolean HasMinPower to return of GetPower --- api/api_full.go | 5 +++-- chain/stmgr/utils.go | 32 ++++++++++++++++---------------- chain/sync.go | 2 +- cmd/lotus-shed/balances.go | 3 +-- node/impl/full/state.go | 3 ++- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 88496d669ac..fbbf92d8b5b 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -600,8 +600,9 @@ type VoucherCreateResult struct { } type MinerPower struct { - MinerPower power.Claim - TotalPower power.Claim + MinerPower power.Claim + TotalPower power.Claim + HasMinPower bool } type QueryOffer struct { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index e295725f85f..e58d69156c9 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -79,37 +79,42 @@ func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr return vm.ResolveToKeyAddr(state, sm.cs.Store(ctx), 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, bool, error) { return GetPowerRaw(ctx, sm, ts.ParentState(), maddr) } -func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, error) { +func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, bool, error) { act, err := sm.LoadActorRaw(ctx, builtin.StoragePowerActorAddr, st) if err != nil { - return power.Claim{}, power.Claim{}, xerrors.Errorf("(get sset) failed to load power actor state: %w", err) + return power.Claim{}, power.Claim{}, false, xerrors.Errorf("(get sset) failed to load power actor state: %w", err) } - mas, err := power.Load(sm.cs.Store(ctx), act) + pas, err := power.Load(sm.cs.Store(ctx), act) if err != nil { - return power.Claim{}, power.Claim{}, err + return power.Claim{}, power.Claim{}, false, err } - tpow, err := mas.TotalPower() + tpow, err := pas.TotalPower() if err != nil { - return power.Claim{}, power.Claim{}, err + return power.Claim{}, power.Claim{}, false, err } var mpow power.Claim if maddr != address.Undef { var found bool - mpow, found, err = mas.MinerPower(maddr) + mpow, found, err = pas.MinerPower(maddr) if err != nil || !found { // TODO: return an error when not found? - return power.Claim{}, power.Claim{}, err + return power.Claim{}, power.Claim{}, false, err } } - return mpow, tpow, nil + minpow, err := pas.MinerNominalPowerMeetsConsensusMinimum(maddr) + if err != nil { + return power.Claim{}, power.Claim{}, false, err + } + + return mpow, tpow, minpow, nil } func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorPreCommitOnChainInfo, error) { @@ -470,7 +475,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, nil } - mpow, tpow, err := GetPowerRaw(ctx, sm, lbst, maddr) + mpow, tpow, hmp, err := GetPowerRaw(ctx, sm, lbst, maddr) if err != nil { return nil, xerrors.Errorf("failed to get power: %w", err) } @@ -485,11 +490,6 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, xerrors.Errorf("resolving worker address: %w", err) } - hmp, err := MinerHasMinPower(ctx, sm, maddr, lbts) - if err != nil { - return nil, xerrors.Errorf("determining if miner has min power failed: %w", err) - } - return &api.MiningBaseInfo{ MinerPower: mpow.QualityAdjPower, NetworkPower: tpow.QualityAdjPower, diff --git a/chain/sync.go b/chain/sync.go index c1682188962..1d4e1f02b8b 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -853,7 +853,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er return xerrors.Errorf("received block was from slashed or invalid miner") } - mpow, tpow, err := stmgr.GetPowerRaw(ctx, syncer.sm, lbst, h.Miner) + mpow, tpow, _, err := stmgr.GetPowerRaw(ctx, syncer.sm, lbst, h.Miner) if err != nil { return xerrors.Errorf("failed getting power: %w", err) } diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index 7dbfe2eb7a9..248f3b26e4d 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -12,7 +12,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -193,7 +192,7 @@ var chainBalanceStateCmd = &cli.Command{ } if act.Code == builtin.StorageMinerActorCodeID && minerInfo { - pow, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr) + pow, _, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr) if err != nil { return xerrors.Errorf("failed to get power: %w", err) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index d69ba0a419a..a19edb1ca47 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -253,7 +253,7 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, ts return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - m, net, err := stmgr.GetPower(ctx, a.StateManager, ts, addr) + m, net, hmp, err := stmgr.GetPower(ctx, a.StateManager, ts, addr) if err != nil { return nil, err } @@ -261,6 +261,7 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, ts return &api.MinerPower{ MinerPower: m, TotalPower: net, + HasMinPower: hmp, }, nil } From 72d19f369bf5ed9430c2ee374e1a15fb65ba88a8 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 01:49:33 -0400 Subject: [PATCH 027/104] Incremental progress towards using new power state interface --- cmd/lotus-storage-miner/info.go | 3 +- cmd/lotus-storage-miner/init.go | 6 ++-- node/node_test.go | 4 +-- tools/stats/metrics.go | 50 +++++---------------------------- 4 files changed, 13 insertions(+), 50 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index c47a22b0e66..3a7720c52ac 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -17,7 +17,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" @@ -129,7 +128,7 @@ func infoCmdAct(cctx *cli.Context) error { faultyPercentage) } - if pow.MinerPower.RawBytePower.LessThan(power.ConsensusMinerMinPower) { + if !pow.HasMinPower { fmt.Print("Below minimum power threshold, no blocks will be won") } else { expWinChance := float64(types.BigMul(qpercI, types.NewInt(build.BlocksPerEpoch)).Int64()) / 1000000 diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index e2a2419f3eb..8325aae8bb2 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -34,7 +34,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -633,7 +633,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, return address.Undef, err } - params, err := actors.SerializeParams(&power.CreateMinerParams{ + params, err := actors.SerializeParams(&v0power.CreateMinerParams{ Owner: owner, Worker: worker, SealProofType: spt, @@ -681,7 +681,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, return address.Undef, xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode) } - var retval power.CreateMinerReturn + var retval v0power.CreateMinerReturn if err := retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)); err != nil { return address.Undef, err } diff --git a/node/node_test.go b/node/node_test.go index 8cc51f62988..0611bca60be 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -11,7 +11,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/lib/lotuslog" saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" logging "github.com/ipfs/go-log/v2" @@ -21,7 +21,7 @@ import ( func init() { _ = logging.SetLogLevel("*", "INFO") - power.ConsensusMinerMinPower = big.NewInt(2048) + v0power.ConsensusMinerMinPower = big.NewInt(2048) saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index ae79d927362..4f11d24767d 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -10,14 +10,11 @@ import ( "strings" "time" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/util/adt" "golang.org/x/xerrors" "github.com/ipfs/go-cid" @@ -255,55 +252,22 @@ func RecordTipsetStatePoints(ctx context.Context, api api.FullNode, pl *PointLis p := NewPoint("network.balance", netBalFilFloat) pl.AddPoint(p) - totalPower, err := api.StateMinerPower(ctx, address.Address{}, tipset.Key()) + miners, err := api.StateListMiners(ctx, tipset.Key()) if err != nil { return err } - p = NewPoint("chain.power", totalPower.TotalPower.QualityAdjPower.Int64()) - pl.AddPoint(p) - - powerActor, err := api.StateGetActor(ctx, builtin.StoragePowerActorAddr, tipset.Key()) - if err != nil { - return err - } - - powerRaw, err := api.ChainReadObj(ctx, powerActor.Head) - if err != nil { - return err - } - - var powerActorState power.State - - if err := powerActorState.UnmarshalCBOR(bytes.NewReader(powerRaw)); err != nil { - return fmt.Errorf("failed to unmarshal power actor state: %w", err) - } - - s := &apiIpldStore{ctx, api} - mp, err := adt.AsMap(s, powerActorState.Claims) - if err != nil { - return err - } - - var claim power.Claim - err = mp.ForEach(&claim, func(key string) error { - addr, err := address.NewFromBytes([]byte(key)) + for _, addr := range miners { + mp, err := api.StateMinerPower(ctx, addr, tipset.Key()) if err != nil { return err } - if claim.QualityAdjPower.Int64() == 0 { - return nil + if !mp.MinerPower.QualityAdjPower.IsZero() { + p = NewPoint("chain.miner_power", mp.MinerPower.QualityAdjPower.Int64()) + p.AddTag("miner", addr.String()) + pl.AddPoint(p) } - - p = NewPoint("chain.miner_power", claim.QualityAdjPower.Int64()) - p.AddTag("miner", addr.String()) - pl.AddPoint(p) - - return nil - }) - if err != nil { - return err } return nil From b530f25f0933b3cb2a311e401456b00c36dfc206 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 17:20:25 -0400 Subject: [PATCH 028/104] Migrate miner actor --- api/test/window_post.go | 36 +++++++++++++++++++++-------- chain/actors/builtin/miner/miner.go | 1 + chain/actors/builtin/miner/v0.go | 27 ++++++++++++---------- chain/stmgr/forks_test.go | 4 ++-- node/impl/full/state.go | 1 - 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 3f15c754b43..bdc39073041 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -4,6 +4,13 @@ import ( "context" "fmt" + "github.com/filecoin-project/lotus/api/apibstore" + "github.com/filecoin-project/lotus/chain/actors/adt" + lotusminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + cbor "github.com/ipfs/go-ipld-cbor" + + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "os" "strings" "testing" @@ -15,7 +22,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/extern/sector-storage/mock" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" - miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -159,7 +165,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(miner2.WPoStProvingPeriod)+2 { + if head.Height() > di.PeriodStart+(v0miner.WPoStProvingPeriod)+2 { break } @@ -178,6 +184,14 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*uint64(nSectors+GenesisPreseals))) + store := cbor.NewCborStore(apibstore.NewAPIBlockstore(client)) + + mact, err := client.StateGetActor(ctx, maddr, types.EmptyTSK) + require.NoError(t, err) + + minState, err := lotusminer.Load(adt.WrapStore(ctx, store), mact) + require.NoError(t, err) + fmt.Printf("Drop some sectors\n") // Drop 2 sectors from deadline 2 partition 0 (full partition / deadline) @@ -186,12 +200,14 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.NoError(t, err) require.Greater(t, len(parts), 0) - n, err := parts[0].Sectors.Count() + secs, err := parts[0].AllSectors() + require.NoError(t, err) + n, err := secs.Count() require.NoError(t, err) require.Equal(t, uint64(2), n) // Drop the partition - err = parts[0].Sectors.ForEach(func(sid uint64) error { + err = secs.ForEach(func(sid uint64) error { return miner.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).MarkCorrupted(abi.SectorID{ Miner: abi.ActorID(mid), Number: abi.SectorNumber(sid), @@ -208,15 +224,17 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.NoError(t, err) require.Greater(t, len(parts), 0) - n, err := parts[0].Sectors.Count() + secs, err := parts[0].AllSectors() + require.NoError(t, err) + n, err := secs.Count() require.NoError(t, err) require.Equal(t, uint64(2), n) // Drop the sector - sn, err := parts[0].Sectors.First() + sn, err := secs.First() require.NoError(t, err) - all, err := parts[0].Sectors.All(2) + all, err := secs.All(2) require.NoError(t, err) fmt.Println("the sectors", all) @@ -238,7 +256,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(miner2.WPoStProvingPeriod)+2 { + if head.Height() > di.PeriodStart+(minState.WpostProvingPeriod())+2 { break } @@ -268,7 +286,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(miner2.WPoStProvingPeriod)+2 { + if head.Height() > di.PeriodStart+(minState.WpostProvingPeriod())+2 { break } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 5ad8db39ebb..e436fdc69bd 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -46,6 +46,7 @@ type State interface { Info() (MinerInfo, error) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info + WpostProvingPeriod() abi.ChainEpoch } type Deadline interface { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index e1ef9c51f24..446c828f1fd 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -14,21 +14,21 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) type v0State struct { - miner.State + v0miner.State store adt.Store } type v0Deadline struct { - miner.Deadline + v0miner.Deadline store adt.Store } type v0Partition struct { - miner.Partition + v0miner.Partition store adt.Store } @@ -69,13 +69,13 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati // 2. If it's faulty, it will expire early within the first 14 entries // of the expiration queue. stopErr := errors.New("stop") - err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner.Deadline) error { + err = dls.ForEach(s.store, func(dlIdx uint64, dl *v0miner.Deadline) error { partitions, err := dl.PartitionsArray(s.store) if err != nil { return err } quant := s.State.QuantSpecForDeadline(dlIdx) - var part miner.Partition + var part v0miner.Partition return partitions.ForEach(&part, func(partIdx int64) error { if found, err := part.Sectors.IsSet(uint64(num)); err != nil { return err @@ -89,11 +89,11 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati return stopErr } - q, err := miner.LoadExpirationQueue(s.store, part.EarlyTerminated, quant) + q, err := v0miner.LoadExpirationQueue(s.store, part.EarlyTerminated, quant) if err != nil { return err } - var exp miner.ExpirationSet + var exp v0miner.ExpirationSet return q.ForEach(&exp, func(epoch int64) error { if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { return err @@ -151,7 +151,7 @@ func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) } } - var oci miner.SectorOnChainInfo + var oci v0miner.SectorOnChainInfo if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { return err } @@ -184,13 +184,13 @@ func (s *v0State) ForEachDeadline(cb func(uint64, Deadline) error) error { if err != nil { return err } - return dls.ForEach(s.store, func(i uint64, dl *miner.Deadline) error { + return dls.ForEach(s.store, func(i uint64, dl *v0miner.Deadline) error { return cb(i, &v0Deadline{*dl, s.store}) }) } func (s *v0State) NumDeadlines() (uint64, error) { - return miner.WPoStPeriodDeadlines, nil + return v0miner.WPoStPeriodDeadlines, nil } func (s *v0State) Info() (MinerInfo, error) { @@ -230,6 +230,9 @@ func (s *v0State) Info() (MinerInfo, error) { func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { return s.State.DeadlineInfo(epoch) } +func (s *v0State) WpostProvingPeriod() abi.ChainEpoch { + return v0miner.WPoStProvingPeriod +} func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) @@ -244,7 +247,7 @@ func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { if err != nil { return err } - var part miner.Partition + var part v0miner.Partition return ps.ForEach(&part, func(i int64) error { return cb(uint64(i), &v0Partition{part, d.store}) }) diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index d9d0af74594..2db11e83215 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -11,7 +11,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -33,7 +33,7 @@ import ( ) func init() { - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index a19edb1ca47..766f924bde0 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -27,7 +27,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/builtin/power" From 7115485b0acd78a79b90eb0b335c63b63e9256fe Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 21:56:02 -0400 Subject: [PATCH 029/104] Add a getter for network version --- api/api_full.go | 4 ++++ api/apistruct/struct.go | 7 +++++++ node/impl/full/state.go | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/api/api_full.go b/api/api_full.go index fbbf92d8b5b..b472febe018 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "github.com/filecoin-project/go-state-types/network" + "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" @@ -388,6 +390,8 @@ type FullNode interface { // StateCirculatingSupply returns the circulating supply of Filecoin at the given tipset StateCirculatingSupply(context.Context, types.TipSetKey) (CirculatingSupply, error) + // StateNetworkVersion returns the network version at the given tipset + StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error) // MethodGroup: Msig // The Msig methods are used to interact with multisig wallets on the diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 1fcd5e0f347..26f7a8708d7 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -5,6 +5,8 @@ import ( "io" "time" + stnetwork "github.com/filecoin-project/go-state-types/network" + "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -198,6 +200,7 @@ type FullNodeStruct struct { StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` + StateNetworkVersion func(context.Context, types.TipSetKey) (stnetwork.Version, error) `perm:"read"` MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` MsigGetVested func(context.Context, address.Address, types.TipSetKey, types.TipSetKey) (types.BigInt, error) `perm:"read"` @@ -873,6 +876,10 @@ func (c *FullNodeStruct) StateCirculatingSupply(ctx context.Context, tsk types.T return c.Internal.StateCirculatingSupply(ctx, tsk) } +func (c *FullNodeStruct) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (stnetwork.Version, error) { + return c.Internal.StateNetworkVersion(ctx, tsk) +} + func (c *FullNodeStruct) MsigGetAvailableBalance(ctx context.Context, a address.Address, tsk types.TipSetKey) (types.BigInt, error) { return c.Internal.MsigGetAvailableBalance(ctx, a, tsk) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 766f924bde0..1b29a93a915 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "github.com/filecoin-project/go-state-types/network" "strconv" "github.com/filecoin-project/go-state-types/dline" @@ -1120,3 +1121,12 @@ func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetK } return a.StateManager.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree) } + +func (a *StateAPI) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) { + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return -1, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + + return a.StateManager.GetNtwkVersion(ctx, ts.Height()), nil +} From 80b6994fe2cfede39053c452a335fb6dd19c9122 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Wed, 16 Sep 2020 19:13:12 -0700 Subject: [PATCH 030/104] feat(market): update state diffing for market actor Update to abstract actor for markets state diffing. Also move the diff adt functions inside the abstract actors --- .../{events/state => actors/adt}/diff_adt.go | 7 +- .../state => actors/adt}/diff_adt_test.go | 19 +- chain/actors/builtin/market/market.go | 52 +++++ chain/actors/builtin/market/v0.go | 201 +++++++++++++++- chain/events/state/predicates.go | 221 +++++------------- chain/events/state/predicates_test.go | 81 ++++--- cmd/lotus-chainwatch/processor/market.go | 7 +- 7 files changed, 373 insertions(+), 215 deletions(-) rename chain/{events/state => actors/adt}/diff_adt.go (94%) rename chain/{events/state => actors/adt}/diff_adt_test.go (96%) diff --git a/chain/events/state/diff_adt.go b/chain/actors/adt/diff_adt.go similarity index 94% rename from chain/events/state/diff_adt.go rename to chain/actors/adt/diff_adt.go index 519c61c2df7..0784b77a2f1 100644 --- a/chain/events/state/diff_adt.go +++ b/chain/actors/adt/diff_adt.go @@ -1,10 +1,9 @@ -package state +package adt import ( "bytes" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/util/adt" typegen "github.com/whyrusleeping/cbor-gen" ) @@ -27,7 +26,7 @@ type AdtArrayDiff interface { // - All values that exist in curArr nnd not in prevArr are passed to adtArrayDiff.Add() // - All values that exist in preArr and in curArr are passed to AdtArrayDiff.Modify() // - It is the responsibility of AdtArrayDiff.Modify() to determine if the values it was passed have been modified. -func DiffAdtArray(preArr, curArr *adt.Array, out AdtArrayDiff) error { +func DiffAdtArray(preArr, curArr Array, out AdtArrayDiff) error { prevVal := new(typegen.Deferred) if err := preArr.ForEach(prevVal, func(i int64) error { curVal := new(typegen.Deferred) @@ -76,7 +75,7 @@ type AdtMapDiff interface { Remove(key string, val *typegen.Deferred) error } -func DiffAdtMap(preMap, curMap *adt.Map, out AdtMapDiff) error { +func DiffAdtMap(preMap, curMap Map, out AdtMapDiff) error { prevVal := new(typegen.Deferred) if err := preMap.ForEach(prevVal, func(key string) error { curVal := new(typegen.Deferred) diff --git a/chain/events/state/diff_adt_test.go b/chain/actors/adt/diff_adt_test.go similarity index 96% rename from chain/events/state/diff_adt_test.go rename to chain/actors/adt/diff_adt_test.go index 55926afb9ad..436e28bbf52 100644 --- a/chain/events/state/diff_adt_test.go +++ b/chain/actors/adt/diff_adt_test.go @@ -1,4 +1,4 @@ -package state +package adt import ( "bytes" @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/util/adt" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" bstore "github.com/filecoin-project/lotus/lib/blockstore" ) @@ -22,8 +22,8 @@ func TestDiffAdtArray(t *testing.T) { ctxstoreA := newContextStore() ctxstoreB := newContextStore() - arrA := adt.MakeEmptyArray(ctxstoreA) - arrB := adt.MakeEmptyArray(ctxstoreB) + arrA := v0adt.MakeEmptyArray(ctxstoreA) + arrB := v0adt.MakeEmptyArray(ctxstoreB) require.NoError(t, arrA.Set(0, runtime.CBORBytes([]byte{0}))) // delete @@ -76,8 +76,8 @@ func TestDiffAdtMap(t *testing.T) { ctxstoreA := newContextStore() ctxstoreB := newContextStore() - mapA := adt.MakeEmptyMap(ctxstoreA) - mapB := adt.MakeEmptyMap(ctxstoreB) + mapA := v0adt.MakeEmptyMap(ctxstoreA) + mapB := v0adt.MakeEmptyMap(ctxstoreB) require.NoError(t, mapA.Put(abi.UIntKey(0), runtime.CBORBytes([]byte{0}))) // delete @@ -292,12 +292,9 @@ func (t *TestDiffArray) Remove(key uint64, val *typegen.Deferred) error { return nil } -func newContextStore() *contextStore { +func newContextStore() Store { ctx := context.Background() bs := bstore.NewTemporarySync() store := cbornode.NewCborStore(bs) - return &contextStore{ - ctx: ctx, - cst: store, - } + return WrapStore(ctx, store) } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 99cca98797b..051c46dbeb4 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -29,9 +29,14 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler + BalancesChanged(State) bool EscrowTable() (BalanceTable, error) LockedTable() (BalanceTable, error) TotalLocked() (abi.TokenAmount, error) + StatesChanged(State) bool + States() (DealStates, error) + ProposalsChanged(State) bool + Proposals() (DealProposals, error) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, ) (weight, verifiedWeight abi.DealWeight, err error) @@ -40,3 +45,50 @@ type State interface { type BalanceTable interface { Get(key address.Address) (abi.TokenAmount, error) } + +type DealStates interface { + GetDeal(key abi.DealID) (DealState, error) + Diff(DealStates) (*DealStateChanges, error) +} + +type DealProposals interface { + Diff(DealProposals) (*DealProposalChanges, error) +} + +type DealState interface { + SectorStartEpoch() abi.ChainEpoch + SlashEpoch() abi.ChainEpoch + LastUpdatedEpoch() abi.ChainEpoch + Equals(DealState) bool +} + +type DealProposal interface { +} + +type DealStateChanges struct { + Added []DealIDState + Modified []DealStateChange + Removed []DealIDState +} + +type DealIDState struct { + ID abi.DealID + Deal DealState +} + +// DealStateChange is a change in deal state from -> to +type DealStateChange struct { + ID abi.DealID + From DealState + To DealState +} + +type DealProposalChanges struct { + Added []ProposalIDState + Removed []ProposalIDState +} + +type ProposalIDState struct { + ID abi.DealID + Proposal DealProposal +} diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index fb67902da21..8f0aa05946d 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -1,11 +1,17 @@ package market import ( + "bytes" + "errors" + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/util/adt" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + typegen "github.com/whyrusleeping/cbor-gen" ) type v0State struct { @@ -19,12 +25,58 @@ func (s *v0State) TotalLocked() (abi.TokenAmount, error) { return fml, nil } +func (s *v0State) BalancesChanged(otherState State) bool { + v0otherState, ok := otherState.(*v0State) + if !ok { + // there's no way to compare differnt versions of the state, so let's + // just say that means the state of balances has changed + return true + } + return !s.State.EscrowTable.Equals(v0otherState.State.EscrowTable) || !s.State.LockedTable.Equals(v0otherState.State.LockedTable) +} + +func (s *v0State) StatesChanged(otherState State) bool { + v0otherState, ok := otherState.(*v0State) + if !ok { + // there's no way to compare differnt versions of the state, so let's + // just say that means the state of balances has changed + return true + } + return !s.State.States.Equals(v0otherState.State.States) +} + +func (s *v0State) States() (DealStates, error) { + stateArray, err := v0adt.AsArray(s.store, s.State.States) + if err != nil { + return nil, err + } + return &v0DealStates{stateArray}, nil +} + +func (s *v0State) ProposalsChanged(otherState State) bool { + v0otherState, ok := otherState.(*v0State) + if !ok { + // there's no way to compare differnt versions of the state, so let's + // just say that means the state of balances has changed + return true + } + return !s.State.Proposals.Equals(v0otherState.State.Proposals) +} + +func (s *v0State) Proposals() (DealProposals, error) { + proposalArray, err := v0adt.AsArray(s.store, s.State.Proposals) + if err != nil { + return nil, err + } + return &v0DealProposals{proposalArray}, nil +} + func (s *v0State) EscrowTable() (BalanceTable, error) { - return adt.AsBalanceTable(s.store, s.State.EscrowTable) + return v0adt.AsBalanceTable(s.store, s.State.EscrowTable) } func (s *v0State) LockedTable() (BalanceTable, error) { - return adt.AsBalanceTable(s.store, s.State.LockedTable) + return v0adt.AsBalanceTable(s.store, s.State.LockedTable) } func (s *v0State) VerifyDealsForActivation( @@ -32,3 +84,146 @@ func (s *v0State) VerifyDealsForActivation( ) (weight, verifiedWeight abi.DealWeight, err error) { return market.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) } + +type v0DealStates struct { + adt.Array +} + +func (s *v0DealStates) GetDeal(dealID abi.DealID) (DealState, error) { + var deal market.DealState + found, err := s.Array.Get(uint64(dealID), &deal) + if err != nil { + return nil, err + } + if !found { + return nil, nil + } + return &v0DealState{deal}, nil +} + +func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) { + v0other, ok := other.(*v0DealStates) + if !ok { + // TODO handle this if possible on a case by case basis but for now, just fail + return nil, errors.New("cannot compare deal states across versions") + } + results := new(DealStateChanges) + if err := adt.DiffAdtArray(s, v0other, &v0MarketStatesDiffer{results}); err != nil { + return nil, fmt.Errorf("diffing deal states: %w", err) + } + + return results, nil +} + +type v0MarketStatesDiffer struct { + Results *DealStateChanges +} + +func (d *v0MarketStatesDiffer) Add(key uint64, val *typegen.Deferred) error { + ds := new(v0DealState) + err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return err + } + d.Results.Added = append(d.Results.Added, DealIDState{abi.DealID(key), ds}) + return nil +} + +func (d *v0MarketStatesDiffer) Modify(key uint64, from, to *typegen.Deferred) error { + dsFrom := new(v0DealState) + if err := dsFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)); err != nil { + return err + } + + dsTo := new(v0DealState) + if err := dsTo.UnmarshalCBOR(bytes.NewReader(to.Raw)); err != nil { + return err + } + + if *dsFrom != *dsTo { + d.Results.Modified = append(d.Results.Modified, DealStateChange{abi.DealID(key), dsFrom, dsTo}) + } + return nil +} + +func (d *v0MarketStatesDiffer) Remove(key uint64, val *typegen.Deferred) error { + ds := new(v0DealState) + err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return err + } + d.Results.Removed = append(d.Results.Removed, DealIDState{abi.DealID(key), ds}) + return nil +} + +type v0DealState struct { + market.DealState +} + +func (ds *v0DealState) SectorStartEpoch() abi.ChainEpoch { + return ds.DealState.SectorStartEpoch +} + +func (ds *v0DealState) SlashEpoch() abi.ChainEpoch { + return ds.DealState.SlashEpoch +} + +func (ds *v0DealState) LastUpdatedEpoch() abi.ChainEpoch { + return ds.DealState.LastUpdatedEpoch +} + +func (ds *v0DealState) Equals(other DealState) bool { + v0other, ok := other.(*v0DealState) + return ok && *ds == *v0other +} + +type v0DealProposals struct { + adt.Array +} + +func (s *v0DealProposals) Diff(other DealProposals) (*DealProposalChanges, error) { + v0other, ok := other.(*v0DealProposals) + if !ok { + // TODO handle this if possible on a case by case basis but for now, just fail + return nil, errors.New("cannot compare deal proposals across versions") + } + results := new(DealProposalChanges) + if err := adt.DiffAdtArray(s, v0other, &v0MarketProposalsDiffer{results}); err != nil { + return nil, fmt.Errorf("diffing deal proposals: %w", err) + } + + return results, nil +} + +type v0MarketProposalsDiffer struct { + Results *DealProposalChanges +} + +type v0DealProposal struct { + market.DealProposal +} + +func (d *v0MarketProposalsDiffer) Add(key uint64, val *typegen.Deferred) error { + dp := new(v0DealProposal) + err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return err + } + d.Results.Added = append(d.Results.Added, ProposalIDState{abi.DealID(key), dp}) + return nil +} + +func (d *v0MarketProposalsDiffer) Modify(key uint64, from, to *typegen.Deferred) error { + // short circuit, DealProposals are static + return nil +} + +func (d *v0MarketProposalsDiffer) Remove(key uint64, val *typegen.Deferred) error { + dp := new(v0DealProposal) + err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return err + } + d.Results.Removed = append(d.Results.Removed, ProposalIDState{abi.DealID(key), dp}) + return nil +} diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index e5caa41d243..e1e88e1a1d0 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -7,12 +7,13 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/util/adt" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" typegen "github.com/whyrusleeping/cbor-gen" @@ -69,26 +70,26 @@ func (sp *StatePredicates) OnActorStateChanged(addr address.Address, diffStateFu } } -type DiffStorageMarketStateFunc func(ctx context.Context, oldState *market.State, newState *market.State) (changed bool, user UserData, err error) +type DiffStorageMarketStateFunc func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) // OnStorageMarketActorChanged calls diffStorageMarketState when the state changes for the market actor func (sp *StatePredicates) OnStorageMarketActorChanged(diffStorageMarketState DiffStorageMarketStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(builtin.StorageMarketActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - var oldState market.State - if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { + oldState, err := market.Load(adt.WrapStore(ctx, sp.cst), oldActorState) + if err != nil { return false, nil, err } - var newState market.State - if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { + newState, err := market.Load(adt.WrapStore(ctx, sp.cst), newActorState) + if err != nil { return false, nil, err } - return diffStorageMarketState(ctx, &oldState, &newState) + return diffStorageMarketState(ctx, oldState, newState) }) } type BalanceTables struct { - EscrowTable *adt.BalanceTable - LockedTable *adt.BalanceTable + EscrowTable market.BalanceTable + LockedTable market.BalanceTable } // DiffBalanceTablesFunc compares two balance tables @@ -96,32 +97,27 @@ type DiffBalanceTablesFunc func(ctx context.Context, oldBalanceTable, newBalance // OnBalanceChanged runs when the escrow table for available balances changes func (sp *StatePredicates) OnBalanceChanged(diffBalances DiffBalanceTablesFunc) DiffStorageMarketStateFunc { - return func(ctx context.Context, oldState *market.State, newState *market.State) (changed bool, user UserData, err error) { - if oldState.EscrowTable.Equals(newState.EscrowTable) && oldState.LockedTable.Equals(newState.LockedTable) { + return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { + if !oldState.BalancesChanged(newState) { return false, nil, nil } - ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - - oldEscrowRoot, err := adt.AsBalanceTable(ctxStore, oldState.EscrowTable) + oldEscrowRoot, err := oldState.EscrowTable() if err != nil { return false, nil, err } - oldLockedRoot, err := adt.AsBalanceTable(ctxStore, oldState.LockedTable) + oldLockedRoot, err := oldState.LockedTable() if err != nil { return false, nil, err } - newEscrowRoot, err := adt.AsBalanceTable(ctxStore, newState.EscrowTable) + newEscrowRoot, err := newState.EscrowTable() if err != nil { return false, nil, err } - newLockedRoot, err := adt.AsBalanceTable(ctxStore, newState.LockedTable) + newLockedRoot, err := newState.LockedTable() if err != nil { return false, nil, err } @@ -130,25 +126,22 @@ func (sp *StatePredicates) OnBalanceChanged(diffBalances DiffBalanceTablesFunc) } } -type DiffAdtArraysFunc func(ctx context.Context, oldDealStateRoot, newDealStateRoot *adt.Array) (changed bool, user UserData, err error) +type DiffDealStatesFunc func(ctx context.Context, oldDealStateRoot, newDealStateRoot market.DealStates) (changed bool, user UserData, err error) +type DiffDealProposalsFunc func(ctx context.Context, oldDealStateRoot, newDealStateRoot market.DealProposals) (changed bool, user UserData, err error) +type DiffAdtArraysFunc func(ctx context.Context, oldDealStateRoot, newDealStateRoot adt.Array) (changed bool, user UserData, err error) // OnDealStateChanged calls diffDealStates when the market deal state changes -func (sp *StatePredicates) OnDealStateChanged(diffDealStates DiffAdtArraysFunc) DiffStorageMarketStateFunc { - return func(ctx context.Context, oldState *market.State, newState *market.State) (changed bool, user UserData, err error) { - if oldState.States.Equals(newState.States) { +func (sp *StatePredicates) OnDealStateChanged(diffDealStates DiffDealStatesFunc) DiffStorageMarketStateFunc { + return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { + if !oldState.StatesChanged(newState) { return false, nil, nil } - ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - - oldRoot, err := adt.AsArray(ctxStore, oldState.States) + oldRoot, err := oldState.States() if err != nil { return false, nil, err } - newRoot, err := adt.AsArray(ctxStore, newState.States) + newRoot, err := newState.States() if err != nil { return false, nil, err } @@ -158,22 +151,17 @@ func (sp *StatePredicates) OnDealStateChanged(diffDealStates DiffAdtArraysFunc) } // OnDealProposalChanged calls diffDealProps when the market proposal state changes -func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffAdtArraysFunc) DiffStorageMarketStateFunc { - return func(ctx context.Context, oldState *market.State, newState *market.State) (changed bool, user UserData, err error) { - if oldState.Proposals.Equals(newState.Proposals) { +func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffDealProposalsFunc) DiffStorageMarketStateFunc { + return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { + if !oldState.ProposalsChanged(newState) { return false, nil, nil } - ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - - oldRoot, err := adt.AsArray(ctxStore, oldState.Proposals) + oldRoot, err := oldState.Proposals() if err != nil { return false, nil, err } - newRoot, err := adt.AsArray(ctxStore, newState.Proposals) + newRoot, err := newState.Proposals() if err != nil { return false, nil, err } @@ -182,51 +170,14 @@ func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffAdtArraysFunc } } -var _ AdtArrayDiff = &MarketDealProposalChanges{} - -type MarketDealProposalChanges struct { - Added []ProposalIDState - Removed []ProposalIDState -} - -type ProposalIDState struct { - ID abi.DealID - Proposal market.DealProposal -} - -func (m *MarketDealProposalChanges) Add(key uint64, val *typegen.Deferred) error { - dp := new(market.DealProposal) - err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Added = append(m.Added, ProposalIDState{abi.DealID(key), *dp}) - return nil -} - -func (m *MarketDealProposalChanges) Modify(key uint64, from, to *typegen.Deferred) error { - // short circuit, DealProposals are static - return nil -} - -func (m *MarketDealProposalChanges) Remove(key uint64, val *typegen.Deferred) error { - dp := new(market.DealProposal) - err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Removed = append(m.Removed, ProposalIDState{abi.DealID(key), *dp}) - return nil -} - // OnDealProposalAmtChanged detects changes in the deal proposal AMT for all deal proposals and returns a MarketProposalsChanges structure containing: // - Added Proposals // - Modified Proposals // - Removed Proposals -func (sp *StatePredicates) OnDealProposalAmtChanged() DiffAdtArraysFunc { - return func(ctx context.Context, oldDealProps, newDealProps *adt.Array) (changed bool, user UserData, err error) { - proposalChanges := new(MarketDealProposalChanges) - if err := DiffAdtArray(oldDealProps, newDealProps, proposalChanges); err != nil { +func (sp *StatePredicates) OnDealProposalAmtChanged() DiffDealProposalsFunc { + return func(ctx context.Context, oldDealProps, newDealProps market.DealProposals) (changed bool, user UserData, err error) { + proposalChanges, err := oldDealProps.Diff(newDealProps) + if err != nil { return false, nil, err } @@ -238,64 +189,14 @@ func (sp *StatePredicates) OnDealProposalAmtChanged() DiffAdtArraysFunc { } } -var _ AdtArrayDiff = &MarketDealStateChanges{} - -type MarketDealStateChanges struct { - Added []DealIDState - Modified []DealStateChange - Removed []DealIDState -} - -type DealIDState struct { - ID abi.DealID - Deal market.DealState -} - -func (m *MarketDealStateChanges) Add(key uint64, val *typegen.Deferred) error { - ds := new(market.DealState) - err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Added = append(m.Added, DealIDState{abi.DealID(key), *ds}) - return nil -} - -func (m *MarketDealStateChanges) Modify(key uint64, from, to *typegen.Deferred) error { - dsFrom := new(market.DealState) - if err := dsFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)); err != nil { - return err - } - - dsTo := new(market.DealState) - if err := dsTo.UnmarshalCBOR(bytes.NewReader(to.Raw)); err != nil { - return err - } - - if *dsFrom != *dsTo { - m.Modified = append(m.Modified, DealStateChange{abi.DealID(key), dsFrom, dsTo}) - } - return nil -} - -func (m *MarketDealStateChanges) Remove(key uint64, val *typegen.Deferred) error { - ds := new(market.DealState) - err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Removed = append(m.Removed, DealIDState{abi.DealID(key), *ds}) - return nil -} - // OnDealStateAmtChanged detects changes in the deal state AMT for all deal states and returns a MarketDealStateChanges structure containing: // - Added Deals // - Modified Deals // - Removed Deals -func (sp *StatePredicates) OnDealStateAmtChanged() DiffAdtArraysFunc { - return func(ctx context.Context, oldDealStates, newDealStates *adt.Array) (changed bool, user UserData, err error) { - dealStateChanges := new(MarketDealStateChanges) - if err := DiffAdtArray(oldDealStates, newDealStates, dealStateChanges); err != nil { +func (sp *StatePredicates) OnDealStateAmtChanged() DiffDealStatesFunc { + return func(ctx context.Context, oldDealStates, newDealStates market.DealStates) (changed bool, user UserData, err error) { + dealStateChanges, err := oldDealStates.Diff(newDealStates) + if err != nil { return false, nil, err } @@ -313,37 +214,31 @@ type ChangedDeals map[abi.DealID]DealStateChange // DealStateChange is a change in deal state from -> to type DealStateChange struct { ID abi.DealID - From *market.DealState - To *market.DealState + From market.DealState + To market.DealState } // DealStateChangedForIDs detects changes in the deal state AMT for the given deal IDs -func (sp *StatePredicates) DealStateChangedForIDs(dealIds []abi.DealID) DiffAdtArraysFunc { - return func(ctx context.Context, oldDealStateArray, newDealStateArray *adt.Array) (changed bool, user UserData, err error) { +func (sp *StatePredicates) DealStateChangedForIDs(dealIds []abi.DealID) DiffDealStatesFunc { + return func(ctx context.Context, oldDealStates, newDealStates market.DealStates) (changed bool, user UserData, err error) { changedDeals := make(ChangedDeals) for _, dealID := range dealIds { - var oldDealPtr, newDealPtr *market.DealState - var oldDeal, newDeal market.DealState // If the deal has been removed, we just set it to nil - found, err := oldDealStateArray.Get(uint64(dealID), &oldDeal) + oldDeal, err := oldDealStates.GetDeal(dealID) if err != nil { return false, nil, err } - if found { - oldDealPtr = &oldDeal - } - found, err = newDealStateArray.Get(uint64(dealID), &newDeal) + newDeal, err := newDealStates.GetDeal(dealID) if err != nil { return false, nil, err } - if found { - newDealPtr = &newDeal - } - if oldDeal != newDeal { - changedDeals[dealID] = DealStateChange{dealID, oldDealPtr, newDealPtr} + existenceChanged := (oldDeal == nil) != (newDeal == nil) + valueChanged := (oldDeal != nil && newDeal != nil) && !oldDeal.Equals(newDeal) + if existenceChanged || valueChanged { + changedDeals[dealID] = DealStateChange{dealID, oldDeal, newDeal} } } if len(changedDeals) > 0 { @@ -441,7 +336,7 @@ type MinerSectorChanges struct { Removed []miner.SectorOnChainInfo } -var _ AdtArrayDiff = &MinerSectorChanges{} +var _ adt.AdtArrayDiff = &MinerSectorChanges{} type SectorExtensions struct { From miner.SectorOnChainInfo @@ -508,17 +403,17 @@ func (sp *StatePredicates) OnMinerSectorChange() DiffMinerActorStateFunc { return false, nil, nil } - oldSectors, err := adt.AsArray(ctxStore, oldState.Sectors) + oldSectors, err := v0adt.AsArray(ctxStore, oldState.Sectors) if err != nil { return false, nil, err } - newSectors, err := adt.AsArray(ctxStore, newState.Sectors) + newSectors, err := v0adt.AsArray(ctxStore, newState.Sectors) if err != nil { return false, nil, err } - if err := DiffAdtArray(oldSectors, newSectors, sectorChanges); err != nil { + if err := adt.DiffAdtArray(oldSectors, newSectors, sectorChanges); err != nil { return false, nil, err } @@ -584,17 +479,17 @@ func (sp *StatePredicates) OnMinerPreCommitChange() DiffMinerActorStateFunc { return false, nil, nil } - oldPrecommits, err := adt.AsMap(ctxStore, oldState.PreCommittedSectors) + oldPrecommits, err := v0adt.AsMap(ctxStore, oldState.PreCommittedSectors) if err != nil { return false, nil, err } - newPrecommits, err := adt.AsMap(ctxStore, newState.PreCommittedSectors) + newPrecommits, err := v0adt.AsMap(ctxStore, newState.PreCommittedSectors) if err != nil { return false, nil, err } - if err := DiffAdtMap(oldPrecommits, newPrecommits, precommitChanges); err != nil { + if err := adt.DiffAdtMap(oldPrecommits, newPrecommits, precommitChanges); err != nil { return false, nil, err } @@ -763,17 +658,17 @@ func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return false, nil, nil } - oldAddrs, err := adt.AsMap(ctxStore, oldState.AddressMap) + oldAddrs, err := v0adt.AsMap(ctxStore, oldState.AddressMap) if err != nil { return false, nil, err } - newAddrs, err := adt.AsMap(ctxStore, newState.AddressMap) + newAddrs, err := v0adt.AsMap(ctxStore, newState.AddressMap) if err != nil { return false, nil, err } - if err := DiffAdtMap(oldAddrs, newAddrs, addressChanges); err != nil { + if err := adt.DiffAdtMap(oldAddrs, newAddrs, addressChanges); err != nil { return false, nil, err } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 7117a96cc4a..783c720edbd 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -16,7 +16,10 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/specs-actors/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" tutils "github.com/filecoin-project/specs-actors/support/testing" @@ -69,22 +72,22 @@ func TestMarketPredicates(t *testing.T) { bs := bstore.NewTemporarySync() store := adt.WrapStore(ctx, cbornode.NewCborStore(bs)) - oldDeal1 := &market.DealState{ + oldDeal1 := &v0market.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 2, SlashEpoch: 0, } - oldDeal2 := &market.DealState{ + oldDeal2 := &v0market.DealState{ SectorStartEpoch: 4, LastUpdatedEpoch: 5, SlashEpoch: 0, } - oldDeals := map[abi.DealID]*market.DealState{ + oldDeals := map[abi.DealID]*v0market.DealState{ abi.DealID(1): oldDeal1, abi.DealID(2): oldDeal2, } - oldProp1 := &market.DealProposal{ + oldProp1 := &v0market.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -96,7 +99,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - oldProp2 := &market.DealProposal{ + oldProp2 := &v0market.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -108,7 +111,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - oldProps := map[abi.DealID]*market.DealProposal{ + oldProps := map[abi.DealID]*v0market.DealProposal{ abi.DealID(1): oldProp1, abi.DealID(2): oldProp2, } @@ -122,7 +125,7 @@ func TestMarketPredicates(t *testing.T) { oldStateC := createMarketState(ctx, t, store, oldDeals, oldProps, oldBalances) - newDeal1 := &market.DealState{ + newDeal1 := &v0market.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 3, SlashEpoch: 0, @@ -131,19 +134,19 @@ func TestMarketPredicates(t *testing.T) { // deal 2 removed // added - newDeal3 := &market.DealState{ + newDeal3 := &v0market.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 2, SlashEpoch: 3, } - newDeals := map[abi.DealID]*market.DealState{ + newDeals := map[abi.DealID]*v0market.DealState{ abi.DealID(1): newDeal1, // deal 2 was removed abi.DealID(3): newDeal3, } // added - newProp3 := &market.DealProposal{ + newProp3 := &v0market.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -155,7 +158,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - newProps := map[abi.DealID]*market.DealProposal{ + newProps := map[abi.DealID]*v0market.DealProposal{ abi.DealID(1): oldProp1, // 1 was persisted // prop 2 was removed abi.DealID(3): newProp3, // new @@ -178,8 +181,8 @@ func TestMarketPredicates(t *testing.T) { require.NoError(t, err) api := newMockAPI(bs) - api.setActor(oldState.Key(), &types.Actor{Head: oldStateC}) - api.setActor(newState.Key(), &types.Actor{Head: newStateC}) + api.setActor(oldState.Key(), &types.Actor{Code: v0builtin.StorageMarketActorCodeID, Head: oldStateC}) + api.setActor(newState.Key(), &types.Actor{Code: v0builtin.StorageMarketActorCodeID, Head: newStateC}) t.Run("deal ID predicate", func(t *testing.T) { preds := NewStatePredicates(api) @@ -203,11 +206,11 @@ func TestMarketPredicates(t *testing.T) { require.Contains(t, changedDealIDs, abi.DealID(1)) require.Contains(t, changedDealIDs, abi.DealID(2)) deal1 := changedDealIDs[abi.DealID(1)] - if deal1.From.LastUpdatedEpoch != 2 || deal1.To.LastUpdatedEpoch != 3 { + if deal1.From.LastUpdatedEpoch() != 2 || deal1.To.LastUpdatedEpoch() != 3 { t.Fatal("Unexpected change to LastUpdatedEpoch") } deal2 := changedDealIDs[abi.DealID(2)] - if deal2.From.LastUpdatedEpoch != 5 || deal2.To != nil { + if deal2.From.LastUpdatedEpoch() != 5 || deal2.To != nil { t.Fatal("Expected To to be nil") } @@ -230,11 +233,17 @@ func TestMarketPredicates(t *testing.T) { require.False(t, changed) // Test that OnDealStateChanged does not call the callback if the state has not changed - diffDealStateFn := preds.OnDealStateChanged(func(context.Context, *adt.Array, *adt.Array) (bool, UserData, error) { + diffDealStateFn := preds.OnDealStateChanged(func(context.Context, market.DealStates, market.DealStates) (bool, UserData, error) { t.Fatal("No state change so this should not be called") return false, nil, nil }) - marketState := createEmptyMarketState(t, store) + v0marketState := createEmptyMarketState(t, store) + marketCid, err := store.Put(ctx, v0marketState) + require.NoError(t, err) + marketState, err := market.Load(store, &types.Actor{ + Code: v0builtin.StorageMarketActorCodeID, + Head: marketCid, + }) changed, _, err = diffDealStateFn(ctx, marketState, marketState) require.NoError(t, err) require.False(t, changed) @@ -252,18 +261,18 @@ func TestMarketPredicates(t *testing.T) { require.NoError(t, err) require.True(t, changed) - changedDeals, ok := valArr.(*MarketDealStateChanges) + changedDeals, ok := valArr.(*market.DealStateChanges) require.True(t, ok) require.Len(t, changedDeals.Added, 1) require.Equal(t, abi.DealID(3), changedDeals.Added[0].ID) - require.Equal(t, *newDeal3, changedDeals.Added[0].Deal) + require.True(t, dealEquality(*newDeal3, changedDeals.Added[0].Deal)) require.Len(t, changedDeals.Removed, 1) require.Len(t, changedDeals.Modified, 1) require.Equal(t, abi.DealID(1), changedDeals.Modified[0].ID) - require.Equal(t, newDeal1, changedDeals.Modified[0].To) - require.Equal(t, oldDeal1, changedDeals.Modified[0].From) + require.True(t, dealEquality(*newDeal1, changedDeals.Modified[0].To)) + require.True(t, dealEquality(*oldDeal1, changedDeals.Modified[0].From)) require.Equal(t, abi.DealID(2), changedDeals.Removed[0].ID) }) @@ -279,17 +288,15 @@ func TestMarketPredicates(t *testing.T) { require.NoError(t, err) require.True(t, changed) - changedProps, ok := valArr.(*MarketDealProposalChanges) + changedProps, ok := valArr.(*market.DealProposalChanges) require.True(t, ok) require.Len(t, changedProps.Added, 1) require.Equal(t, abi.DealID(3), changedProps.Added[0].ID) - require.Equal(t, *newProp3, changedProps.Added[0].Proposal) // proposals cannot be modified -- no modified testing require.Len(t, changedProps.Removed, 1) require.Equal(t, abi.DealID(2), changedProps.Removed[0].ID) - require.Equal(t, *oldProp2, changedProps.Removed[0].Proposal) }) t.Run("balances predicate", func(t *testing.T) { @@ -342,7 +349,13 @@ func TestMarketPredicates(t *testing.T) { t.Fatal("No state change so this should not be called") return false, nil, nil }) - marketState := createEmptyMarketState(t, store) + v0marketState := createEmptyMarketState(t, store) + marketCid, err := store.Put(ctx, v0marketState) + require.NoError(t, err) + marketState, err := market.Load(store, &types.Actor{ + Code: v0builtin.StorageMarketActorCodeID, + Head: marketCid, + }) changed, _, err = diffDealBalancesFn(ctx, marketState, marketState) require.NoError(t, err) require.False(t, changed) @@ -450,7 +463,7 @@ type balance struct { locked abi.TokenAmount } -func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*market.DealState, props map[abi.DealID]*market.DealProposal, balances map[address.Address]balance) cid.Cid { +func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*v0market.DealState, props map[abi.DealID]*v0market.DealProposal, balances map[address.Address]balance) cid.Cid { dealRootCid := createDealAMT(ctx, t, store, deals) propRootCid := createProposalAMT(ctx, t, store, props) balancesCids := createBalanceTable(ctx, t, store, balances) @@ -465,15 +478,15 @@ func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals return stateC } -func createEmptyMarketState(t *testing.T, store adt.Store) *market.State { +func createEmptyMarketState(t *testing.T, store adt.Store) *v0market.State { emptyArrayCid, err := adt.MakeEmptyArray(store).Root() require.NoError(t, err) emptyMap, err := adt.MakeEmptyMap(store).Root() require.NoError(t, err) - return market.ConstructState(emptyArrayCid, emptyMap, emptyMap) + return v0market.ConstructState(emptyArrayCid, emptyMap, emptyMap) } -func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*market.DealState) cid.Cid { +func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*v0market.DealState) cid.Cid { root := adt.MakeEmptyArray(store) for dealID, dealState := range deals { err := root.Set(uint64(dealID), dealState) @@ -484,7 +497,7 @@ func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map return rootCid } -func createProposalAMT(ctx context.Context, t *testing.T, store adt.Store, props map[abi.DealID]*market.DealProposal) cid.Cid { +func createProposalAMT(ctx context.Context, t *testing.T, store adt.Store, props map[abi.DealID]*v0market.DealProposal) cid.Cid { root := adt.MakeEmptyArray(store) for dealID, prop := range props { err := root.Set(uint64(dealID), prop) @@ -607,3 +620,9 @@ func newSectorPreCommitInfo(sectorNo abi.SectorNumber, sealed cid.Cid, expiratio Expiration: expiration, } } + +func dealEquality(expected v0market.DealState, actual market.DealState) bool { + return expected.LastUpdatedEpoch == actual.LastUpdatedEpoch() && + expected.SectorStartEpoch == actual.SectorStartEpoch() && + expected.SlashEpoch == actual.SlashEpoch() +} diff --git a/cmd/lotus-chainwatch/processor/market.go b/cmd/lotus-chainwatch/processor/market.go index e50ec3076ec..a4bae4b2026 100644 --- a/cmd/lotus-chainwatch/processor/market.go +++ b/cmd/lotus-chainwatch/processor/market.go @@ -8,6 +8,7 @@ import ( "golang.org/x/sync/errgroup" "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/events/state" ) @@ -293,14 +294,14 @@ func (p *Processor) updateMarketActorDealProposals(ctx context.Context, marketTi if !changed { continue } - changes, ok := val.(*state.MarketDealStateChanges) + changes, ok := val.(*market.DealStateChanges) if !ok { return xerrors.Errorf("Unknown type returned by Deal State AMT predicate: %T", val) } for _, modified := range changes.Modified { - if modified.From.SlashEpoch != modified.To.SlashEpoch { - if _, err := stmt.Exec(modified.To.SlashEpoch, modified.ID); err != nil { + if modified.From.SlashEpoch() != modified.To.SlashEpoch() { + if _, err := stmt.Exec(modified.To.SlashEpoch(), modified.ID); err != nil { return err } } From b5ba7a0fad639952d22ee102037d4dc5ae53b99c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 16 Sep 2020 22:34:13 -0400 Subject: [PATCH 031/104] Miner migration --- build/params_2k.go | 4 +- build/params_shared_funcs.go | 6 +-- build/params_shared_vals.go | 5 +- build/params_testground.go | 4 +- build/params_testnet.go | 4 +- chain/actors/builtin/miner/miner.go | 13 +++++- chain/actors/builtin/miner/v0.go | 33 +++++++------ chain/events/state/predicates.go | 34 ++++---------- chain/events/state/predicates_test.go | 22 +++++---- chain/gen/gen.go | 4 +- chain/gen/gen_test.go | 4 +- chain/gen/genesis/miners.go | 19 ++++---- chain/store/store_test.go | 4 +- chain/sync_test.go | 4 +- chain/vm/invoker.go | 4 +- chain/vm/syscalls.go | 6 +-- cli/paych_test.go | 4 +- cmd/lotus-pcr/main.go | 29 ++++++++++-- extern/storage-sealing/checks.go | 27 +++++++++-- extern/storage-sealing/constants.go | 10 +--- extern/storage-sealing/fsm_events.go | 2 +- extern/storage-sealing/precommit_policy.go | 24 ++++++++-- extern/storage-sealing/sealing.go | 22 ++++++++- extern/storage-sealing/states_failed.go | 3 +- extern/storage-sealing/states_sealing.go | 54 ++++++++++++++++++---- extern/storage-sealing/upgrade_queue.go | 3 +- markets/storageadapter/client.go | 3 +- markets/storageadapter/provider.go | 3 +- node/impl/client/client.go | 4 +- node/node_test.go | 6 +-- node/test/builder.go | 4 +- storage/adapter_storage_miner.go | 32 ++++++------- storage/miner.go | 11 ++++- storage/wdpost_journal.go | 2 +- storage/wdpost_run.go | 37 +++++++++------ 35 files changed, 288 insertions(+), 162 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index 313ccfa9d96..cf34706e5bc 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -5,7 +5,7 @@ package build import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" ) @@ -21,7 +21,7 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ func init() { v0power.ConsensusMinerMinPower = big.NewInt(2048) - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } verifreg.MinVerifiedDealSize = big.NewInt(256) diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index 2c585271a6b..08f16cefd68 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -6,14 +6,14 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/node/modules/dtypes" ) func DefaultSectorSize() abi.SectorSize { - szs := make([]abi.SectorSize, 0, len(miner.SupportedProofTypes)) - for spt := range miner.SupportedProofTypes { + szs := make([]abi.SectorSize, 0, len(v0miner.SupportedProofTypes)) + for spt := range v0miner.SupportedProofTypes { ss, err := spt.SectorSize() if err != nil { panic(err) diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 4a46b7fd114..ac7796ae756 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // ///// @@ -23,6 +23,7 @@ const UnixfsLinksPerLevel = 1024 const AllowableClockDriftSecs = uint64(1) const NewestNetworkVersion = network.Version2 +const ActorUpgradeNetworkVersion = network.Version3 // Epochs const ForkLengthThreshold = Finality @@ -31,7 +32,7 @@ const ForkLengthThreshold = Finality var BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch) // Epochs -const Finality = miner.ChainFinality +const Finality = v0miner.ChainFinality const MessageConfidence = uint64(5) // constants for Weight calculation diff --git a/build/params_testground.go b/build/params_testground.go index 395d2a855e7..77e312ac2de 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) var ( @@ -32,7 +32,7 @@ var ( AllowableClockDriftSecs = uint64(1) - Finality = miner.ChainFinality + Finality = v0miner.ChainFinality ForkLengthThreshold = Finality SlashablePowerDelay = 20 diff --git a/build/params_testnet.go b/build/params_testnet.go index 4cfd8a9b62c..a879d3ba71f 100644 --- a/build/params_testnet.go +++ b/build/params_testnet.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" ) @@ -24,7 +24,7 @@ const UpgradeSmokeHeight = 51000 func init() { v0power.ConsensusMinerMinPower = big.NewInt(10 << 40) - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg32GiBV1: {}, abi.RegisteredSealProof_StackedDrg64GiBV1: {}, } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index e436fdc69bd..90c44eff396 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -38,7 +38,9 @@ type State interface { FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) - LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error) + LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) + LoadPreCommittedSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Map, error) + IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error @@ -65,6 +67,15 @@ type Partition interface { type SectorOnChainInfo = v0miner.SectorOnChainInfo type SectorPreCommitInfo = v0miner.SectorPreCommitInfo type SectorPreCommitOnChainInfo = v0miner.SectorPreCommitOnChainInfo +type PoStPartition = v0miner.PoStPartition +type RecoveryDeclaration = v0miner.RecoveryDeclaration +type FaultDeclaration = v0miner.FaultDeclaration + +// Params +type DeclareFaultsParams = v0miner.DeclareFaultsParams +type DeclareFaultsRecoveredParams = v0miner.DeclareFaultsRecoveredParams +type SubmitWindowedPoStParams = v0miner.SubmitWindowedPoStParams +type ProveCommitSectorParams = v0miner.ProveCommitSectorParams type MinerInfo struct { Owner address.Address // Must be an ID-address. diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 446c828f1fd..b56fb1745af 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -1,7 +1,6 @@ package miner import ( - "bytes" "errors" "github.com/filecoin-project/go-address" @@ -132,13 +131,12 @@ func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitO return info, nil } -func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error) { +func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) { a, err := v0adt.AsArray(s.store, s.State.Sectors) if err != nil { return nil, err } - var sset []*ChainSectorInfo var v cbg.Deferred if err := a.ForEach(&v, func(i int64) error { if filter != nil { @@ -147,24 +145,31 @@ func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) return xerrors.Errorf("filter check error: %w", err) } if set == filterOut { - return nil + err = a.Delete(uint64(i)) + if err != nil { + return xerrors.Errorf("filtering error: %w", err) + } } } - - var oci v0miner.SectorOnChainInfo - if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { - return err - } - sset = append(sset, &ChainSectorInfo{ - Info: oci, - ID: abi.SectorNumber(i), - }) return nil }); err != nil { return nil, err } - return sset, nil + return a, nil +} + +func (s *v0State) LoadPreCommittedSectors() (adt.Map, error) { + return v0adt.AsMap(s.store, s.State.PreCommittedSectors) +} + +func (s *v0State) IsAllocated(num abi.SectorNumber) (bool, error) { + var allocatedSectors bitfield.BitField + if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { + return false, err + } + + return allocatedSectors.IsSet(uint64(num)) } func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index e1e88e1a1d0..5a885504fa2 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -4,6 +4,10 @@ import ( "bytes" "context" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -12,7 +16,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" typegen "github.com/whyrusleeping/cbor-gen" @@ -387,28 +390,18 @@ func (m *MinerSectorChanges) Remove(key uint64, val *typegen.Deferred) error { func (sp *StatePredicates) OnMinerSectorChange() DiffMinerActorStateFunc { return func(ctx context.Context, oldState, newState *miner.State) (changed bool, user UserData, err error) { - ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - sectorChanges := &MinerSectorChanges{ Added: []miner.SectorOnChainInfo{}, Extended: []SectorExtensions{}, Removed: []miner.SectorOnChainInfo{}, } - // no sector changes - if oldState.Sectors.Equals(newState.Sectors) { - return false, nil, nil - } - - oldSectors, err := v0adt.AsArray(ctxStore, oldState.Sectors) + oldSectors, err := oldState.LoadSectorsFromSet(nil, false) if err != nil { return false, nil, err } - newSectors, err := v0adt.AsArray(ctxStore, newState.Sectors) + newSectors, err := newState.LoadSectorsFromSet(nil, false) if err != nil { return false, nil, err } @@ -436,7 +429,7 @@ func (m *MinerPreCommitChanges) AsKey(key string) (abi.Keyer, error) { if err != nil { return nil, err } - return miner.SectorKey(abi.SectorNumber(sector)), nil + return v0miner.SectorKey(abi.SectorNumber(sector)), nil } func (m *MinerPreCommitChanges) Add(key string, val *typegen.Deferred) error { @@ -465,26 +458,17 @@ func (m *MinerPreCommitChanges) Remove(key string, val *typegen.Deferred) error func (sp *StatePredicates) OnMinerPreCommitChange() DiffMinerActorStateFunc { return func(ctx context.Context, oldState, newState *miner.State) (changed bool, user UserData, err error) { - ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - precommitChanges := &MinerPreCommitChanges{ Added: []miner.SectorPreCommitOnChainInfo{}, Removed: []miner.SectorPreCommitOnChainInfo{}, } - if oldState.PreCommittedSectors.Equals(newState.PreCommittedSectors) { - return false, nil, nil - } - - oldPrecommits, err := v0adt.AsMap(ctxStore, oldState.PreCommittedSectors) + oldPrecommits, err := oldState.LoadPreCommittedSectors() if err != nil { return false, nil, err } - newPrecommits, err := v0adt.AsMap(ctxStore, newState.PreCommittedSectors) + newPrecommits, err := newState.LoadPreCommittedSectors() if err != nil { return false, nil, err } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 783c720edbd..25f25334d46 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-bitfield" "github.com/stretchr/testify/require" @@ -20,7 +22,7 @@ import ( v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" tutils "github.com/filecoin-project/specs-actors/support/testing" @@ -375,12 +377,12 @@ func TestMinerSectorChange(t *testing.T) { } owner, worker := nextIDAddrF(), nextIDAddrF() - si0 := newSectorOnChainInfo(0, tutils.MakeCID("0", &miner.SealedCIDPrefix), big.NewInt(0), abi.ChainEpoch(0), abi.ChainEpoch(10)) - si1 := newSectorOnChainInfo(1, tutils.MakeCID("1", &miner.SealedCIDPrefix), big.NewInt(1), abi.ChainEpoch(1), abi.ChainEpoch(11)) - si2 := newSectorOnChainInfo(2, tutils.MakeCID("2", &miner.SealedCIDPrefix), big.NewInt(2), abi.ChainEpoch(2), abi.ChainEpoch(11)) + si0 := newSectorOnChainInfo(0, tutils.MakeCID("0", &v0miner.SealedCIDPrefix), big.NewInt(0), abi.ChainEpoch(0), abi.ChainEpoch(10)) + si1 := newSectorOnChainInfo(1, tutils.MakeCID("1", &v0miner.SealedCIDPrefix), big.NewInt(1), abi.ChainEpoch(1), abi.ChainEpoch(11)) + si2 := newSectorOnChainInfo(2, tutils.MakeCID("2", &v0miner.SealedCIDPrefix), big.NewInt(2), abi.ChainEpoch(2), abi.ChainEpoch(11)) oldMinerC := createMinerState(ctx, t, store, owner, worker, []miner.SectorOnChainInfo{si0, si1, si2}) - si3 := newSectorOnChainInfo(3, tutils.MakeCID("3", &miner.SealedCIDPrefix), big.NewInt(3), abi.ChainEpoch(3), abi.ChainEpoch(12)) + si3 := newSectorOnChainInfo(3, tutils.MakeCID("3", &v0miner.SealedCIDPrefix), big.NewInt(3), abi.ChainEpoch(3), abi.ChainEpoch(12)) // 0 delete // 1 extend // 2 same @@ -545,20 +547,20 @@ func createMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, return stateC } -func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, worker address.Address) *miner.State { +func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, worker address.Address) *v0miner.State { emptyArrayCid, err := adt.MakeEmptyArray(store).Root() require.NoError(t, err) emptyMap, err := adt.MakeEmptyMap(store).Root() require.NoError(t, err) - emptyDeadline, err := store.Put(store.Context(), miner.ConstructDeadline(emptyArrayCid)) + emptyDeadline, err := store.Put(store.Context(), v0miner.ConstructDeadline(emptyArrayCid)) require.NoError(t, err) - emptyVestingFunds := miner.ConstructVestingFunds() + emptyVestingFunds := v0miner.ConstructVestingFunds() emptyVestingFundsCid, err := store.Put(store.Context(), emptyVestingFunds) require.NoError(t, err) - emptyDeadlines := miner.ConstructDeadlines(emptyDeadline) + emptyDeadlines := v0miner.ConstructDeadlines(emptyDeadline) emptyDeadlinesCid, err := store.Put(store.Context(), emptyDeadlines) require.NoError(t, err) @@ -568,7 +570,7 @@ func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, o emptyBitfieldCid, err := store.Put(store.Context(), emptyBitfield) require.NoError(t, err) - state, err := miner.ConstructState(minerInfo, 123, emptyBitfieldCid, emptyArrayCid, emptyMap, emptyDeadlinesCid, emptyVestingFundsCid) + state, err := v0miner.ConstructState(minerInfo, 123, emptyBitfieldCid, emptyArrayCid, emptyMap, emptyDeadlinesCid, emptyVestingFundsCid) require.NoError(t, err) return state diff --git a/chain/gen/gen.go b/chain/gen/gen.go index d661411feee..4cae19082b1 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -14,7 +14,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" block "github.com/ipfs/go-block-format" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" @@ -121,7 +121,7 @@ var DefaultRemainderAccountActor = genesis.Actor{ } func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { - saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index fd6bceb9533..496bb016bcd 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -14,7 +14,7 @@ import ( ) func init() { - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 88fe571897a..f6256ffbc28 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -6,6 +6,8 @@ import ( "fmt" "math/rand" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" cbg "github.com/whyrusleeping/cbor-gen" @@ -18,7 +20,7 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -123,9 +125,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } minerInfos[i].maddr = ma.IDAddress - err = vm.MutateState(ctx, minerInfos[i].maddr, func(cst cbor.IpldStore, st *miner.State) error { - maxPeriods := miner.MaxSectorExpirationExtension / miner.WPoStProvingPeriod - minerInfos[i].presealExp = (maxPeriods-1)*miner.WPoStProvingPeriod + st.ProvingPeriodStart - 1 + // TODO: ActorUpgrade + err = vm.MutateState(ctx, minerInfos[i].maddr, func(cst cbor.IpldStore, st *v0miner.State) error { + maxPeriods := v0miner.MaxSectorExpirationExtension / v0miner.WPoStProvingPeriod + minerInfos[i].presealExp = (maxPeriods-1)*v0miner.WPoStProvingPeriod + st.ProvingPeriodStart - 1 return nil }) @@ -201,7 +204,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := v0miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) qaPow = types.BigAdd(qaPow, sectorWeight) } @@ -246,7 +249,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := v0miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) // we've added fake power for this sector above, remove it now err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { @@ -268,9 +271,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting current total power: %w", err) } - pcd := miner.PreCommitDepositForPower(epochReward.ThisEpochRewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) + pcd := v0miner.PreCommitDepositForPower(epochReward.ThisEpochRewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) - pledge := miner.InitialPledgeForPower( + pledge := v0miner.InitialPledgeForPower( sectorWeight, epochReward.ThisEpochBaselinePower, tpow.PledgeCollateral, diff --git a/chain/store/store_test.go b/chain/store/store_test.go index 8662f10ef78..7da8d219db0 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -22,7 +22,7 @@ import ( ) func init() { - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) diff --git a/chain/sync_test.go b/chain/sync_test.go index 5f972ecc6da..e8df32c5609 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -20,7 +20,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -43,7 +43,7 @@ func init() { if err != nil { panic(err) } - miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 56e3bea84c1..5024164a71e 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -20,7 +20,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/cron" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" @@ -52,7 +52,7 @@ func NewInvoker() *Invoker { inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{}) inv.Register(builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{}) - inv.Register(builtin.StorageMinerActorCodeID, miner.Actor{}, miner.State{}) + inv.Register(builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) inv.Register(builtin.MultisigActorCodeID, multisig.Actor{}, multisig.State{}) inv.Register(builtin.PaymentChannelActorCodeID, paych.Actor{}, paych.State{}) inv.Register(builtin.VerifiedRegistryActorCodeID, verifreg.Actor{}, verifreg.State{}) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 3e221f61f79..aab1812d9ca 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -7,6 +7,8 @@ import ( goruntime "runtime" "sync" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/go-address" @@ -21,9 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" ) @@ -197,7 +197,7 @@ func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error { return err } - info, err := mas.GetInfo(adt.WrapStore(ss.ctx, ss.cst)) + info, err := mas.Info() if err != nil { return err } diff --git a/cli/paych_test.go b/cli/paych_test.go index c1e52899bc8..1cf95ef6c69 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/go-state-types/big" - saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -41,7 +41,7 @@ import ( func init() { v0power.ConsensusMinerMinPower = big.NewInt(2048) - saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } verifreg.MinVerifiedDealSize = big.NewInt(256) diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index dc12693cafe..d265bdd499c 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -12,6 +12,11 @@ import ( "strconv" "time" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -24,7 +29,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" @@ -321,6 +325,7 @@ type refunderNodeApi interface { StateMinerInitialPledgeCollateral(ctx context.Context, addr address.Address, precommitInfo miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) StateSectorPreCommitInfo(ctx context.Context, addr address.Address, sector abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) + StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) WalletBalance(ctx context.Context, addr address.Address) (types.BigInt, error) @@ -389,14 +394,28 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu continue } - var proveCommitSector miner.ProveCommitSectorParams - if err := proveCommitSector.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { - log.Warnw("failed to decode provecommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) + var sn abi.SectorNumber + + nv, err := r.api.StateNetworkVersion(ctx, tipset.Key()) + if err != nil { + log.Warnw("failed to get network version") continue } + if nv < build.ActorUpgradeNetworkVersion { + var proveCommitSector v0miner.ProveCommitSectorParams + if err := proveCommitSector.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { + log.Warnw("failed to decode provecommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) + continue + } + + sn = proveCommitSector.SectorNumber + } else { + // TODO: ActorUpgrade + } + // We use the parent tipset key because precommit information is removed when ProveCommitSector is executed - precommitChainInfo, err := r.api.StateSectorPreCommitInfo(ctx, m.To, proveCommitSector.SectorNumber, tipset.Parents()) + precommitChainInfo, err := r.api.StateSectorPreCommitInfo(ctx, m.To, sn, tipset.Parents()) if err != nil { log.Warnw("failed to get precommit info for sector", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", proveCommitSector.SectorNumber) continue diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index 074c4cfcff9..ae5ce0d3361 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -4,6 +4,9 @@ import ( "bytes" "context" + "github.com/filecoin-project/lotus/build" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" "golang.org/x/xerrors" @@ -13,7 +16,6 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/zerocomm" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // TODO: For now we handle this by halting state execution, when we get jsonrpc reconnecting @@ -93,7 +95,19 @@ func checkPrecommit(ctx context.Context, maddr address.Address, si SectorInfo, t return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %s != %s", commD, si.CommD)} } - if height-(si.TicketEpoch+SealRandomnessLookback) > SealRandomnessLookbackLimit(si.SectorType) { + nv, err := api.StateNetworkVersion(ctx, tok) + if err != nil { + return &ErrApi{xerrors.Errorf("calling StateNetworkVersion: %w", err)} + } + + var msd abi.ChainEpoch + if nv < build.ActorUpgradeNetworkVersion { + msd = v0miner.MaxSealDuration[si.SectorType] + } else { + // TODO: ActorUpgrade + } + + if height-(si.TicketEpoch+SealRandomnessLookback) > msd { return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.TicketEpoch+SealRandomnessLookback, height)} } @@ -139,8 +153,13 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte, return &ErrNoPrecommit{xerrors.Errorf("precommit info not found on-chain")} } - if pci.PreCommitEpoch+miner.PreCommitChallengeDelay != si.SeedEpoch { - return &ErrBadSeed{xerrors.Errorf("seed epoch doesn't match on chain info: %d != %d", pci.PreCommitEpoch+miner.PreCommitChallengeDelay, si.SeedEpoch)} + pccd, err := m.getPreCommitChallengeDelay(ctx, tok) + if err != nil { + return xerrors.Errorf("failed to get precommit challenge delay: %w", err) + } + + if pci.PreCommitEpoch+pccd != si.SeedEpoch { + return &ErrBadSeed{xerrors.Errorf("seed epoch doesn't match on chain info: %d != %d", pci.PreCommitEpoch+pccd, si.SeedEpoch)} } buf := new(bytes.Buffer) diff --git a/extern/storage-sealing/constants.go b/extern/storage-sealing/constants.go index ebb3d334762..06c48fa4cf6 100644 --- a/extern/storage-sealing/constants.go +++ b/extern/storage-sealing/constants.go @@ -1,17 +1,11 @@ package sealing import ( - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // Epochs -const SealRandomnessLookback = miner.ChainFinality - -// Epochs -func SealRandomnessLookbackLimit(spt abi.RegisteredSealProof) abi.ChainEpoch { - return miner.MaxSealDuration[spt] -} +const SealRandomnessLookback = v0miner.ChainFinality // Epochs const InteractivePoRepConfidence = 6 diff --git a/extern/storage-sealing/fsm_events.go b/extern/storage-sealing/fsm_events.go index ee95ab1c7f6..3e597d7613e 100644 --- a/extern/storage-sealing/fsm_events.go +++ b/extern/storage-sealing/fsm_events.go @@ -1,12 +1,12 @@ package sealing import ( + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-storage/storage" ) diff --git a/extern/storage-sealing/precommit_policy.go b/extern/storage-sealing/precommit_policy.go index 93a96353546..e36b8251a8d 100644 --- a/extern/storage-sealing/precommit_policy.go +++ b/extern/storage-sealing/precommit_policy.go @@ -3,8 +3,11 @@ package sealing import ( "context" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) type PreCommitPolicy interface { @@ -13,6 +16,7 @@ type PreCommitPolicy interface { type Chain interface { ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) + StateNetworkVersion(ctx context.Context, tok TipSetToken) (network.Version, error) } // BasicPreCommitPolicy satisfies PreCommitPolicy. It has two modes: @@ -48,9 +52,9 @@ func NewBasicPreCommitPolicy(api Chain, duration abi.ChainEpoch, provingBoundary // Expiration produces the pre-commit sector expiration epoch for an encoded // replica containing the provided enumeration of pieces and deals. func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error) { - _, epoch, err := p.api.ChainHead(ctx) + tok, epoch, err := p.api.ChainHead(ctx) if err != nil { - return 0, nil + return 0, err } var end *abi.ChainEpoch @@ -76,7 +80,19 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi end = &tmp } - *end += miner.WPoStProvingPeriod - (*end % miner.WPoStProvingPeriod) + p.provingBoundary - 1 + nv, err := p.api.StateNetworkVersion(ctx, tok) + if err != nil { + return 0, err + } + + var wpp abi.ChainEpoch + if nv < build.ActorUpgradeNetworkVersion { + wpp = v0miner.WPoStProvingPeriod + } else { + // TODO: ActorUpgrade + } + + *end += wpp - (*end % wpp) + p.provingBoundary - 1 return *end, nil } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 533333860b1..0fe754217a3 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -8,6 +8,10 @@ import ( "sync" "time" + "github.com/filecoin-project/lotus/build" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" @@ -20,10 +24,10 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" statemachine "github.com/filecoin-project/go-statemachine" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) const SectorStorePrefix = "/sectors" @@ -53,6 +57,7 @@ type SealingAPI interface { StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error) + StateNetworkVersion(ctx context.Context, tok TipSetToken) (network.Version, error) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) ChainGetRandomnessFromBeacon(ctx context.Context, tok TipSetToken, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) @@ -417,3 +422,18 @@ func getDealPerSectorLimit(size abi.SectorSize) uint64 { } return 512 } + +func (m *Sealing) getPreCommitChallengeDelay(ctx context.Context, tok TipSetToken) (abi.ChainEpoch, error) { + nv, err := m.api.StateNetworkVersion(ctx, tok) + if err != nil { + return -1, xerrors.Errorf("failed to get network version: %w", err) + } + + if nv < build.ActorUpgradeNetworkVersion { + return v0miner.PreCommitChallengeDelay, nil + } else { + // TODO: ActorUpgrade + return -1, nil + } + +} diff --git a/extern/storage-sealing/states_failed.go b/extern/storage-sealing/states_failed.go index 4dd945a81ee..b026e70f9b9 100644 --- a/extern/storage-sealing/states_failed.go +++ b/extern/storage-sealing/states_failed.go @@ -4,13 +4,14 @@ import ( "bytes" "time" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-statemachine" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/extern/sector-storage/zerocomm" ) diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 5e2b72ee12f..e7a3d745041 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -4,6 +4,10 @@ import ( "bytes" "context" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" @@ -12,7 +16,6 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-statemachine" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-storage/storage" ) @@ -180,7 +183,21 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf // Sectors must last _at least_ MinSectorExpiration + MaxSealDuration. // TODO: The "+10" allows the pre-commit to take 10 blocks to be accepted. - if minExpiration := height + miner.MaxSealDuration[sector.SectorType] + miner.MinSectorExpiration + 10; expiration < minExpiration { + nv, err := m.api.StateNetworkVersion(ctx.Context(), tok) + if err != nil { + return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get network version: %w", err)}) + } + + var msd abi.ChainEpoch + var mse abi.ChainEpoch + if nv < build.ActorUpgradeNetworkVersion { + msd = v0miner.MaxSealDuration[sector.SectorType] + mse = v0miner.MinSectorExpiration + } else { + // TODO: ActorUpgrade + } + + if minExpiration := height + msd + mse + 10; expiration < minExpiration { expiration = minExpiration } // TODO: enforce a reasonable _maximum_ sector lifetime? @@ -253,7 +270,7 @@ func (m *Sealing) handlePreCommitWait(ctx statemachine.Context, sector SectorInf func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) error { tok, _, err := m.api.ChainHead(ctx.Context()) if err != nil { - log.Errorf("handleCommitting: api error, not proceeding: %+v", err) + log.Errorf("handleWaitSeed: api error, not proceeding: %+v", err) return nil } @@ -265,7 +282,17 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er return ctx.Send(SectorChainPreCommitFailed{error: xerrors.Errorf("precommit info not found on chain")}) } - randHeight := pci.PreCommitEpoch + miner.PreCommitChallengeDelay + nv, err := m.api.StateNetworkVersion(ctx.Context(), tok) + if err != nil { + return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("failed to get network version: %w", err)}) + } + + pccd, err := m.getPreCommitChallengeDelay(ctx.Context(), tok) + if err != nil { + return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("failed to get precommit challenge delay: %w", err)}) + } + + randHeight := pci.PreCommitEpoch + pccd err = m.events.ChainAt(func(ectx context.Context, _ TipSetToken, curH abi.ChainEpoch) error { // in case of null blocks the randomness can land after the tipset we @@ -356,14 +383,23 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo return ctx.Send(SectorCommitFailed{xerrors.Errorf("commit check error: %w", err)}) } - params := &miner.ProveCommitSectorParams{ - SectorNumber: sector.SectorNumber, - Proof: sector.Proof, + nv, err := m.api.StateNetworkVersion(ctx.Context(), tok) + if err != nil { + return ctx.Send(SectorCommitFailed{xerrors.Errorf("failed to get network version: %w", err)}) } enc := new(bytes.Buffer) - if err := params.MarshalCBOR(enc); err != nil { - return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)}) + if nv < build.ActorUpgradeNetworkVersion { + params := &v0miner.ProveCommitSectorParams{ + SectorNumber: sector.SectorNumber, + Proof: sector.Proof, + } + + if err := params.MarshalCBOR(enc); err != nil { + return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)}) + } + } else { + // TODO: ActorUpgrade } waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok) diff --git a/extern/storage-sealing/upgrade_queue.go b/extern/storage-sealing/upgrade_queue.go index 650fdc83d10..371a5c8627c 100644 --- a/extern/storage-sealing/upgrade_queue.go +++ b/extern/storage-sealing/upgrade_queue.go @@ -3,11 +3,12 @@ package sealing import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) func (m *Sealing) IsMarkedForUpgrade(id abi.SectorNumber) bool { diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 4168792da31..0c9e66eda78 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -6,6 +6,8 @@ import ( "bytes" "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/big" "golang.org/x/xerrors" @@ -29,7 +31,6 @@ import ( "github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/specs-actors/actors/builtin" samarket "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-cid" ) diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 7af1808c17c..22d6c1e1d0b 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -8,6 +8,8 @@ import ( "io" "time" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" @@ -20,7 +22,6 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 7a107c2fda0..6c60269ab78 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -41,7 +41,7 @@ import ( "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-padreader" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" marketevents "github.com/filecoin-project/lotus/markets/loggers" @@ -87,7 +87,7 @@ func calcDealExpiration(minDuration uint64, md *dline.Info, startEpoch abi.Chain minExp := startEpoch + abi.ChainEpoch(minDuration) // Align on miners ProvingPeriodBoundary - return minExp + miner.WPoStProvingPeriod - (minExp % miner.WPoStProvingPeriod) + (md.PeriodStart % miner.WPoStProvingPeriod) - 1 + return minExp + v0miner.WPoStProvingPeriod - (minExp % v0miner.WPoStProvingPeriod) + (md.PeriodStart % v0miner.WPoStProvingPeriod) - 1 } func (a *API) imgr() *importmgr.Mgr { diff --git a/node/node_test.go b/node/node_test.go index 0611bca60be..92b741f7340 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/lib/lotuslog" - saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" logging "github.com/ipfs/go-log/v2" @@ -22,7 +22,7 @@ func init() { _ = logging.SetLogLevel("*", "INFO") v0power.ConsensusMinerMinPower = big.NewInt(2048) - saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } verifreg.MinVerifiedDealSize = big.NewInt(256) @@ -68,7 +68,7 @@ func TestAPIDealFlowReal(t *testing.T) { logging.SetLogLevel("sub", "ERROR") logging.SetLogLevel("storageminer", "ERROR") - saminer.PreCommitChallengeDelay = 5 + v0miner.PreCommitChallengeDelay = 5 t.Run("basic", func(t *testing.T) { test.TestDealFlow(t, builder.Builder, time.Second, false, false) diff --git a/node/test/builder.go b/node/test/builder.go index de2071e7a85..2b26c13fca8 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -37,7 +37,7 @@ import ( "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/mockstorage" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-datastore" "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" @@ -83,7 +83,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr peerid, err := peer.IDFromPrivateKey(pk) require.NoError(t, err) - enc, err := actors.SerializeParams(&miner.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) + enc, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) require.NoError(t, err) msg := &types.Message{ diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index ef917b758c4..8b64789add2 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -4,7 +4,7 @@ import ( "bytes" "context" - "github.com/filecoin-project/go-bitfield" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -16,7 +16,6 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" @@ -84,7 +83,7 @@ func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr ad return mi.Worker, nil } -func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]*miner.Deadline, error) { +func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]miner.Deadline, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) @@ -185,23 +184,13 @@ func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr a if err != nil { return nil, xerrors.Errorf("handleSealFailed(%d): temp error: loading miner state: %+v", sectorNumber, err) } - stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.delegate)) - precommits, err := adt.AsMap(stor, state.PreCommittedSectors) - if err != nil { - return nil, err - } - var pci miner.SectorPreCommitOnChainInfo - ok, err := precommits.Get(abi.UIntKey(uint64(sectorNumber)), &pci) + pci, err := state.GetPrecommittedSector(sectorNumber) if err != nil { return nil, err } - if !ok { - var allocated bitfield.BitField - if err := stor.Get(ctx, state.AllocatedSectors, &allocated); err != nil { - return nil, xerrors.Errorf("loading allocated sector bitfield: %w", err) - } - set, err := allocated.IsSet(uint64(sectorNumber)) + if pci != nil { + set, err := state.IsAllocated(sectorNumber) if err != nil { return nil, xerrors.Errorf("checking if sector is allocated: %w", err) } @@ -212,7 +201,7 @@ func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr a return nil, nil } - return &pci, nil + return pci, nil } func (s SealingAPIAdapter) StateSectorGetInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok sealing.TipSetToken) (*miner.SectorOnChainInfo, error) { @@ -258,6 +247,15 @@ func (s SealingAPIAdapter) StateMarketStorageDeal(ctx context.Context, dealID ab return deal.Proposal, nil } +func (s SealingAPIAdapter) StateNetworkVersion(ctx context.Context, tok sealing.TipSetToken) (network.Version, error) { + tsk, err := types.TipSetKeyFromBytes(tok) + if err != nil { + return -1, err + } + + return s.delegate.StateNetworkVersion(ctx, tsk) +} + func (s SealingAPIAdapter) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) { msg := types.Message{ To: to, diff --git a/storage/miner.go b/storage/miner.go index 3485dba03c4..693ad7c05ff 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -5,6 +5,10 @@ import ( "errors" "time" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-bitfield" @@ -71,7 +75,8 @@ type storageMinerApi interface { StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]miner.Deadline, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) @@ -83,6 +88,7 @@ type storageMinerApi interface { StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error) + StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error) MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) @@ -139,7 +145,8 @@ func (m *Miner) Run(ctx context.Context) error { evts := events.NewEvents(ctx, m.api) adaptedAPI := NewSealingAPIAdapter(m.api) - pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, miner.MaxSectorExpirationExtension-(miner.WPoStProvingPeriod*2), md.PeriodStart%miner.WPoStProvingPeriod) + // TODO: Maybe we update this policy after actor upgrades? + pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, v0miner.MaxSectorExpirationExtension-(v0miner.WPoStProvingPeriod*2), md.PeriodStart%v0miner.WPoStProvingPeriod) m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingConfigFunc(m.getSealConfig), m.handleSealingNotifications) go m.sealing.Run(ctx) //nolint:errcheck // logged intside the function diff --git a/storage/wdpost_journal.go b/storage/wdpost_journal.go index c1a4d4817ca..48eb2f2b1df 100644 --- a/storage/wdpost_journal.go +++ b/storage/wdpost_journal.go @@ -3,7 +3,7 @@ package storage import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" ) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index aa27064556d..bfc2bc95e7a 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -14,20 +14,18 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-cid" "go.opencensus.io/trace" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - iminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/journal" @@ -155,7 +153,7 @@ func (s *WindowPoStScheduler) checkSectors(ctx context.Context, check bitfield.B return sbf, nil } -func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []iminer.Partition) ([]miner.RecoveryDeclaration, *types.SignedMessage, error) { +func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []miner.Partition) ([]miner.RecoveryDeclaration, *types.SignedMessage, error) { ctx, span := trace.StartSpan(ctx, "storage.checkNextRecoveries") defer span.End() @@ -167,11 +165,11 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin for partIdx, partition := range partitions { faults, err := partition.FaultySectors() if err != nil { - return xerrors.Errorf("getting faults: %w", err) + return nil, nil, xerrors.Errorf("getting faults: %w", err) } recovering, err := partition.RecoveringSectors() if err != nil { - return xerrors.Errorf("getting recovering: %w", err) + return nil, nil, xerrors.Errorf("getting recovering: %w", err) } unrecovered, err := bitfield.SubtractBitField(faults, recovering) if err != nil { @@ -254,7 +252,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin return recoveries, sm, nil } -func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []iminer.Partition) ([]miner.FaultDeclaration, *types.SignedMessage, error) { +func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []miner.Partition) ([]miner.FaultDeclaration, *types.SignedMessage, error) { ctx, span := trace.StartSpan(ctx, "storage.checkNextFaults") defer span.End() @@ -348,7 +346,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("resolving actor: %w", err) } - mas, err := iminer.Load(stor, act) + mas, err := miner.Load(stor, act) if err != nil { return nil, xerrors.Errorf("getting miner state: %w", err) } @@ -365,8 +363,8 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty log.Errorf("loading deadline: %v", err) return } - var partitions []iminer.Partition - err = dl.ForEachPartition(func(_ uint64, part iminer.Partition) error { + var partitions []miner.Partition + err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { partitions = append(partitions, part) return nil }) @@ -435,9 +433,9 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("loading deadline: %w", err) } - var partitions []iminer.Partitions - err = dl.ForEachPartition(func(_ uint64, part iminer.Partition) error { - partitions = apppend(partitions, part) + var partitions []miner.Partition + err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { + partitions = append(partitions, part) return nil }) if err != nil { @@ -465,7 +463,11 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("getting active sectors: %w", err) } - toProve, err = bitfield.MergeBitFields(toProve, partition.Recoveries) + recs, err := partition.RecoveringSectors() + if err != nil { + return nil, xerrors.Errorf("getting recovering sectors: %w", err) + } + toProve, err = bitfield.MergeBitFields(toProve, recs) if err != nil { return nil, xerrors.Errorf("adding recoveries to set of sectors to prove: %w", err) } @@ -492,7 +494,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty skipCount += sc - ssi, err := s.sectorsForProof(ctx, good, partition.Sectors, ts) + partitionSectors, err := partition.AllSectors() + if err != nil { + return nil, xerrors.Errorf("getting partition sectors: %w", err) + } + + ssi, err := s.sectorsForProof(ctx, good, partitionSectors, ts) if err != nil { return nil, xerrors.Errorf("getting sorted sector info: %w", err) } From 9e48dd211ac1e6de6a6be5eef434fea7dd5fc1ef Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 02:34:15 -0400 Subject: [PATCH 032/104] Fixups --- chain/actors/builtin/miner/miner.go | 2 +- chain/events/state/predicates.go | 8 ++--- chain/stmgr/utils.go | 41 +++++++++++++++++++++--- extern/storage-sealing/states_sealing.go | 5 --- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 90c44eff396..4acb41daebb 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -39,7 +39,7 @@ type State interface { GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) - LoadPreCommittedSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Map, error) + LoadPreCommittedSectors() (adt.Map, error) IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 5a885504fa2..3e515e6a486 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -302,7 +302,7 @@ func (sp *StatePredicates) AvailableBalanceChangedForAddresses(getAddrs func() [ } } -type DiffMinerActorStateFunc func(ctx context.Context, oldState *miner.State, newState *miner.State) (changed bool, user UserData, err error) +type DiffMinerActorStateFunc func(ctx context.Context, oldState miner.State, newState miner.State) (changed bool, user UserData, err error) func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(builtin.InitActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { @@ -329,7 +329,7 @@ func (sp *StatePredicates) OnMinerActorChange(minerAddr address.Address, diffMin if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { return false, nil, err } - return diffMinerActorState(ctx, &oldState, &newState) + return diffMinerActorState(ctx, oldState, newState) }) } @@ -389,7 +389,7 @@ func (m *MinerSectorChanges) Remove(key uint64, val *typegen.Deferred) error { } func (sp *StatePredicates) OnMinerSectorChange() DiffMinerActorStateFunc { - return func(ctx context.Context, oldState, newState *miner.State) (changed bool, user UserData, err error) { + return func(ctx context.Context, oldState, newState miner.State) (changed bool, user UserData, err error) { sectorChanges := &MinerSectorChanges{ Added: []miner.SectorOnChainInfo{}, Extended: []SectorExtensions{}, @@ -457,7 +457,7 @@ func (m *MinerPreCommitChanges) Remove(key string, val *typegen.Deferred) error } func (sp *StatePredicates) OnMinerPreCommitChange() DiffMinerActorStateFunc { - return func(ctx context.Context, oldState, newState *miner.State) (changed bool, user UserData, err error) { + return func(ctx context.Context, oldState, newState miner.State) (changed bool, user UserData, err error) { precommitChanges := &MinerPreCommitChanges{ Added: []miner.SectorPreCommitOnChainInfo{}, Removed: []miner.SectorPreCommitOnChainInfo{}, diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index e58d69156c9..16167af755b 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -9,6 +9,8 @@ import ( "runtime" "strings" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + saruntime "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime/proof" @@ -156,7 +158,29 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - return mas.LoadSectorsFromSet(filter, filterOut) + sectors, err := mas.LoadSectorsFromSet(filter, filterOut) + if err != nil { + return nil, xerrors.Errorf("(get sset) failed to load sectors: %w", err) + } + + var sset []*miner.ChainSectorInfo + var v cbg.Deferred + if err := sectors.ForEach(&v, func(i int64) error { + var oci v0miner.SectorOnChainInfo + if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { + return err + } + sset = append(sset, &miner.ChainSectorInfo{ + Info: oci, + ID: abi.SectorNumber(i), + }) + + return nil + }); err != nil { + return nil, err + } + + return sset, nil } func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]proof.SectorInfo, error) { @@ -220,12 +244,21 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S out := make([]proof.SectorInfo, len(ids)) for i, n := range ids { - s := sectors[n] + var sinfo miner.SectorOnChainInfo + found, err := sectors.Get(n, &sinfo) + + if err != nil { + return nil, xerrors.Errorf("loading sector info: %w", err) + } + + if !found { + return nil, xerrors.Errorf("didn't find sector info for sector %d", n) + } out[i] = proof.SectorInfo{ SealProof: spt, - SectorNumber: s.ID, - SealedCID: s.Info.SealedCID, + SectorNumber: sinfo.SectorNumber, + SealedCID: sinfo.SealedCID, } } diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index e7a3d745041..f0ff4025d47 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -282,11 +282,6 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er return ctx.Send(SectorChainPreCommitFailed{error: xerrors.Errorf("precommit info not found on chain")}) } - nv, err := m.api.StateNetworkVersion(ctx.Context(), tok) - if err != nil { - return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("failed to get network version: %w", err)}) - } - pccd, err := m.getPreCommitChallengeDelay(ctx.Context(), tok) if err != nil { return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("failed to get precommit challenge delay: %w", err)}) From b60614982ea91a51e128c175da43d1d4e425a0bb Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 02:42:39 -0400 Subject: [PATCH 033/104] Migrate reward actor --- chain/actors/builtin/reward/reward.go | 2 ++ chain/actors/builtin/reward/v0.go | 5 +++++ chain/gen/genesis/miners.go | 10 ++++----- chain/gen/genesis/t02_reward.go | 4 ++-- chain/stmgr/stmgr.go | 30 +++++++++++++++++---------- chain/stmgr/utils.go | 4 ++-- chain/vm/invoker.go | 4 ++-- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index ba03feceda4..d400258df85 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -1,6 +1,7 @@ package reward import ( + "github.com/filecoin-project/go-state-types/abi" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" @@ -30,4 +31,5 @@ type State interface { cbor.Marshaler RewardSmoothed() (builtin.FilterEstimate, error) + TotalStoragePowerReward() abi.TokenAmount } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index a894fa75261..b0558f0ae50 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -1,6 +1,7 @@ package reward import ( + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -14,3 +15,7 @@ type v0State struct { func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochRewardSmoothed, nil } + +func (s *v0State) TotalStoragePowerReward() abi.TokenAmount { + return s.State.TotalMined +} diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index f6256ffbc28..aff226882fe 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -22,7 +22,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/market" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/lotus/chain/state" @@ -222,8 +222,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("mutating state: %w", err) } - err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward.State) error { - *st = *reward.ConstructState(qaPow) + err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *v0reward.State) error { + *st = *v0reward.ConstructState(qaPow) return nil }) if err != nil { @@ -381,13 +381,13 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [ return dealWeights, nil } -func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*reward.ThisEpochRewardReturn, error) { +func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*v0reward.ThisEpochRewardReturn, error) { rwret, err := doExecValue(ctx, vm, builtin.RewardActorAddr, maddr, big.Zero(), builtin.MethodsReward.ThisEpochReward, nil) if err != nil { return nil, err } - var epochReward reward.ThisEpochRewardReturn + var epochReward v0reward.ThisEpochRewardReturn if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil { return nil, err } diff --git a/chain/gen/genesis/t02_reward.go b/chain/gen/genesis/t02_reward.go index d499b24d085..e29e390f9d5 100644 --- a/chain/gen/genesis/t02_reward.go +++ b/chain/gen/genesis/t02_reward.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/lotus/build" @@ -17,7 +17,7 @@ import ( func SetupRewardActor(bs bstore.Blockstore, qaPower big.Int) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - st := reward.ConstructState(qaPower) + st := v0reward.ConstructState(qaPower) hcid, err := cst.Put(context.TODO(), st) if err != nil { diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 8cb1329d2c1..8a72b4ba463 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,6 +5,8 @@ import ( "fmt" "sync" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" + "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -18,7 +20,7 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" @@ -242,15 +244,21 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp processedMsgs[m.Cid()] = true } - var err error - params, err := actors.SerializeParams(&reward.AwardBlockRewardParams{ - Miner: b.Miner, - Penalty: penalty, - GasReward: gasReward, - WinCount: b.WinCount, - }) - if err != nil { - return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err) + var params []byte + + nv := sm.GetNtwkVersion(ctx, epoch) + if nv < build.ActorUpgradeNetworkVersion { + params, err = actors.SerializeParams(&v0reward.AwardBlockRewardParams{ + Miner: b.Miner, + Penalty: penalty, + GasReward: gasReward, + WinCount: b.WinCount, + }) + if err != nil { + return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err) + } + } else { + // TODO: ActorUpgrade } sysAct, err := vmi.StateTree().GetActor(builtin.SystemActorAddr) @@ -1018,7 +1026,7 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err return big.Zero(), xerrors.Errorf("failed to load reward state: %w", err) } - return rst.TotalMined, nil + return rst.TotalStoragePowerReward(), nil } func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 16167af755b..b000a62e1c5 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -29,7 +29,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/cron" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" @@ -555,7 +555,7 @@ func init() { builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market.Actor{}}, builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, builtin.MultisigActorCodeID: {builtin.MethodsMultisig, multisig.Actor{}}, - builtin.RewardActorCodeID: {builtin.MethodsReward, reward.Actor{}}, + builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}}, builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, verifreg.Actor{}}, } diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 5024164a71e..a86a0f03c81 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -24,7 +24,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" + v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/system" "github.com/filecoin-project/specs-actors/actors/runtime" vmr "github.com/filecoin-project/specs-actors/actors/runtime" @@ -48,7 +48,7 @@ func NewInvoker() *Invoker { // NETUPGRADE: register code IDs for v2, etc. inv.Register(builtin.SystemActorCodeID, system.Actor{}, abi.EmptyValue{}) inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{}) - inv.Register(builtin.RewardActorCodeID, reward.Actor{}, reward.State{}) + inv.Register(builtin.RewardActorCodeID, v0reward.Actor{}, v0reward.State{}) inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{}) inv.Register(builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{}) From e2295c372ab2ed0504bda3bb96a502cc3222b8ab Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 02:50:59 -0400 Subject: [PATCH 034/104] Migrate multisig actor --- chain/actors/builtin/multisig/multisig.go | 3 +++ chain/actors/builtin/multisig/v0.go | 14 +++++++++++++- chain/stmgr/stmgr.go | 23 +++++++++++++---------- chain/stmgr/utils.go | 4 ++-- chain/vm/invoker.go | 4 ++-- cli/multisig.go | 14 +++++++------- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index 676dbe75f42..fc58599a9c2 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -28,4 +28,7 @@ type State interface { cbor.Marshaler LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error) + StartEpoch() abi.ChainEpoch + UnlockDuration() abi.ChainEpoch + InitialBalance() abi.TokenAmount } diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index 3bc7e70b28d..dc464d9afe5 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -12,5 +12,17 @@ type v0State struct { } func (s *v0State) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { - return s.State.AmountLocked(currEpoch - s.StartEpoch), nil + return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil +} + +func (s *v0State) StartEpoch() abi.ChainEpoch { + return s.State.StartEpoch +} + +func (s *v0State) UnlockDuration() abi.ChainEpoch { + return s.State.UnlockDuration +} + +func (s *v0State) InitialBalance() abi.TokenAmount { + return s.State.InitialBalance } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 8a72b4ba463..18c67b5f034 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,6 +5,10 @@ import ( "fmt" "sync" + v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/ipfs/go-cid" @@ -19,7 +23,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -793,7 +796,7 @@ func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) ( } type genesisInfo struct { - genesisMsigs []multisig.State + genesisMsigs []v0msig.State // info about the Accounts in the genesis state genesisActors []genesisActor genesisPledge abi.TokenAmount @@ -856,15 +859,15 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return err } - if s.StartEpoch != 0 { + if s.StartEpoch() != 0 { return xerrors.New("genesis multisig doesn't start vesting at epoch 0!") } - ot, f := totalsByEpoch[s.UnlockDuration] + ot, f := totalsByEpoch[s.UnlockDuration()] if f { - totalsByEpoch[s.UnlockDuration] = big.Add(ot, s.InitialBalance) + totalsByEpoch[s.UnlockDuration()] = big.Add(ot, s.InitialBalance()) } else { - totalsByEpoch[s.UnlockDuration] = s.InitialBalance + totalsByEpoch[s.UnlockDuration()] = s.InitialBalance() } } else if act.Code == builtin.AccountActorCodeID { @@ -894,9 +897,9 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return xerrors.Errorf("error setting up genesis infos: %w", err) } - gi.genesisMsigs = make([]multisig.State, 0, len(totalsByEpoch)) + gi.genesisMsigs = make([]v0msig.State, 0, len(totalsByEpoch)) for k, v := range totalsByEpoch { - ns := multisig.State{ + ns := v0msig.State{ InitialBalance: v, UnlockDuration: k, PendingTxns: cid.Undef, @@ -971,9 +974,9 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error { totalsByEpoch[sixYears] = big.NewInt(100_000_000) totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000)) - gi.genesisMsigs = make([]multisig.State, 0, len(totalsByEpoch)) + gi.genesisMsigs = make([]v0msig.State, 0, len(totalsByEpoch)) for k, v := range totalsByEpoch { - ns := multisig.State{ + ns := v0msig.State{ InitialBalance: v, UnlockDuration: k, PendingTxns: cid.Undef, diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index b000a62e1c5..afd790a7443 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -27,7 +27,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/cron" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -554,7 +554,7 @@ func init() { builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, miner.Actor{}}, builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market.Actor{}}, builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, - builtin.MultisigActorCodeID: {builtin.MethodsMultisig, multisig.Actor{}}, + builtin.MultisigActorCodeID: {builtin.MethodsMultisig, v0msig.Actor{}}, builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}}, builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, verifreg.Actor{}}, } diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index a86a0f03c81..4cda32c44ef 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -21,7 +21,7 @@ import ( init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/builtin/market" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" @@ -53,7 +53,7 @@ func NewInvoker() *Invoker { inv.Register(builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{}) inv.Register(builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) - inv.Register(builtin.MultisigActorCodeID, multisig.Actor{}, multisig.State{}) + inv.Register(builtin.MultisigActorCodeID, v0msig.Actor{}, v0msig.State{}) inv.Register(builtin.PaymentChannelActorCodeID, paych.Actor{}, paych.State{}) inv.Register(builtin.VerifiedRegistryActorCodeID, verifreg.Actor{}, verifreg.State{}) inv.Register(builtin.AccountActorCodeID, account.Actor{}, account.State{}) diff --git a/cli/multisig.go b/cli/multisig.go index 4596628f4fb..ffbbd733b0d 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/go-address" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/urfave/cli/v2" @@ -199,7 +199,7 @@ var msigInspectCmd = &cli.Command{ return err } - var mstate samsig.State + var mstate v0msig.State if err := mstate.UnmarshalCBOR(bytes.NewReader(obj)); err != nil { return err } @@ -251,7 +251,7 @@ var msigInspectCmd = &cli.Command{ }, } -func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*samsig.Transaction, error) { +func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*v0msig.Transaction, error) { bs := apibstore.NewAPIBlockstore(lapi) store := adt.WrapStore(ctx, cbor.NewCborStore(bs)) @@ -260,8 +260,8 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return nil, err } - txs := make(map[int64]*samsig.Transaction) - var tx samsig.Transaction + txs := make(map[int64]*v0msig.Transaction) + var tx v0msig.Transaction err = nd.ForEach(&tx, func(k string) error { txid, _ := binary.Varint([]byte(k)) @@ -276,7 +276,7 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return txs, nil } -func state(tx *samsig.Transaction) string { +func state(tx *v0msig.Transaction) string { /* // TODO(why): I strongly disagree with not having these... but i need to move forward if tx.Complete { return "done" @@ -385,7 +385,7 @@ var msigProposeCmd = &cli.Command{ return fmt.Errorf("proposal returned exit %d", wait.Receipt.ExitCode) } - var retval samsig.ProposeReturn + var retval v0msig.ProposeReturn if err := retval.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return fmt.Errorf("failed to unmarshal propose return value: %w", err) } From 691bd9f442c80bbf0cce178e265706a90c2520ce Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 17 Sep 2020 00:32:10 -0700 Subject: [PATCH 035/104] feat(markets): complete markets conversion complete markets conversion to using chain/actors types, also replacing DealProposal/DealState interfaces with structs --- api/api_full.go | 2 +- api/api_storage.go | 4 +- api/apistruct/struct.go | 8 +- chain/actors/builtin/market/market.go | 40 +++++-- chain/actors/builtin/market/v0.go | 144 +++++++++++++++++--------- chain/events/state/predicates.go | 19 ++-- chain/events/state/predicates_test.go | 14 +-- chain/gen/gen.go | 9 +- chain/stmgr/stmgr.go | 20 ++++ chain/stmgr/utils.go | 22 ++-- cli/client.go | 8 +- extern/storage-sealing/sealing.go | 2 +- go.mod | 2 +- go.sum | 4 + markets/storageadapter/client.go | 23 ---- markets/storageadapter/provider.go | 22 ---- markets/utils/converters.go | 8 -- node/impl/full/gas.go | 10 +- node/impl/full/state.go | 87 +++++++--------- node/impl/storminer.go | 30 +++++- storage/adapter_storage_miner.go | 5 +- 21 files changed, 265 insertions(+), 218 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index b472febe018..f565ad5435c 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -19,8 +19,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime/proof" diff --git a/api/api_storage.go b/api/api_storage.go index 37bef2d6cc2..82477218197 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -71,7 +71,7 @@ type StorageMiner interface { stores.SectorIndex MarketImportDealData(ctx context.Context, propcid cid.Cid, path string) error - MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) + MarketListDeals(ctx context.Context) ([]MarketDeal, error) MarketListRetrievalDeals(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) MarketGetDealUpdates(ctx context.Context) (<-chan storagemarket.MinerDeal, error) MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error) @@ -83,7 +83,7 @@ type StorageMiner interface { MarketDataTransferUpdates(ctx context.Context) (<-chan DataTransferChannel, error) DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error - DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) + DealsList(ctx context.Context) ([]MarketDeal, error) DealsConsiderOnlineStorageDeals(context.Context) (bool, error) DealsSetConsiderOnlineStorageDeals(context.Context, bool) error DealsConsiderOnlineRetrievalDeals(context.Context) (bool, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 26f7a8708d7..8bf8f1997ee 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -251,7 +251,7 @@ type StorageMinerStruct struct { MiningBase func(context.Context) (*types.TipSet, error) `perm:"read"` MarketImportDealData func(context.Context, cid.Cid, string) error `perm:"write"` - MarketListDeals func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"` + MarketListDeals func(ctx context.Context) ([]api.MarketDeal, error) `perm:"read"` MarketListRetrievalDeals func(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) `perm:"read"` MarketGetDealUpdates func(ctx context.Context) (<-chan storagemarket.MinerDeal, error) `perm:"read"` MarketListIncompleteDeals func(ctx context.Context) ([]storagemarket.MinerDeal, error) `perm:"read"` @@ -296,7 +296,7 @@ type StorageMinerStruct struct { StorageTryLock func(ctx context.Context, sector abi.SectorID, read stores.SectorFileType, write stores.SectorFileType) (bool, error) `perm:"admin"` DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"` - DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"` + DealsList func(ctx context.Context) ([]api.MarketDeal, error) `perm:"read"` DealsConsiderOnlineStorageDeals func(context.Context) (bool, error) `perm:"read"` DealsSetConsiderOnlineStorageDeals func(context.Context, bool) error `perm:"admin"` DealsConsiderOnlineRetrievalDeals func(context.Context) (bool, error) `perm:"read"` @@ -1128,7 +1128,7 @@ func (c *StorageMinerStruct) MarketImportDealData(ctx context.Context, propcid c return c.Internal.MarketImportDealData(ctx, propcid, path) } -func (c *StorageMinerStruct) MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) { +func (c *StorageMinerStruct) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) { return c.Internal.MarketListDeals(ctx) } @@ -1172,7 +1172,7 @@ func (c *StorageMinerStruct) DealsImportData(ctx context.Context, dealPropCid ci return c.Internal.DealsImportData(ctx, dealPropCid, file) } -func (c *StorageMinerStruct) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) { +func (c *StorageMinerStruct) DealsList(ctx context.Context) ([]api.MarketDeal, error) { return c.Internal.DealsList(ctx) } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 051c46dbeb4..73c2528d0a5 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -43,26 +44,39 @@ type State interface { } type BalanceTable interface { + ForEach(cb func(address.Address, abi.TokenAmount) error) error Get(key address.Address) (abi.TokenAmount, error) } type DealStates interface { - GetDeal(key abi.DealID) (DealState, error) + Get(id abi.DealID) (*DealState, bool, error) Diff(DealStates) (*DealStateChanges, error) } type DealProposals interface { + ForEach(cb func(id abi.DealID, dp DealProposal) error) error + Get(id abi.DealID) (*DealProposal, bool, error) Diff(DealProposals) (*DealProposalChanges, error) } -type DealState interface { - SectorStartEpoch() abi.ChainEpoch - SlashEpoch() abi.ChainEpoch - LastUpdatedEpoch() abi.ChainEpoch - Equals(DealState) bool +type DealState struct { + SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector + LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated + SlashEpoch abi.ChainEpoch // -1 if deal never slashed } -type DealProposal interface { +type DealProposal struct { + PieceCID cid.Cid + PieceSize abi.PaddedPieceSize + VerifiedDeal bool + Client address.Address + Provider address.Address + Label string + StartEpoch abi.ChainEpoch + EndEpoch abi.ChainEpoch + StoragePricePerEpoch abi.TokenAmount + ProviderCollateral abi.TokenAmount + ClientCollateral abi.TokenAmount } type DealStateChanges struct { @@ -79,8 +93,8 @@ type DealIDState struct { // DealStateChange is a change in deal state from -> to type DealStateChange struct { ID abi.DealID - From DealState - To DealState + From *DealState + To *DealState } type DealProposalChanges struct { @@ -92,3 +106,11 @@ type ProposalIDState struct { ID abi.DealID Proposal DealProposal } + +func EmptyDealState() *DealState { + return &DealState{ + SectorStartEpoch: -1, + SlashEpoch: -1, + LastUpdatedEpoch: -1, + } +} diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 8f0aa05946d..92ebb59bacd 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -72,11 +72,19 @@ func (s *v0State) Proposals() (DealProposals, error) { } func (s *v0State) EscrowTable() (BalanceTable, error) { - return v0adt.AsBalanceTable(s.store, s.State.EscrowTable) + bt, err := v0adt.AsBalanceTable(s.store, s.State.EscrowTable) + if err != nil { + return nil, err + } + return &v0BalanceTable{bt}, nil } func (s *v0State) LockedTable() (BalanceTable, error) { - return v0adt.AsBalanceTable(s.store, s.State.LockedTable) + bt, err := v0adt.AsBalanceTable(s.store, s.State.LockedTable) + if err != nil { + return nil, err + } + return &v0BalanceTable{bt}, nil } func (s *v0State) VerifyDealsForActivation( @@ -85,20 +93,37 @@ func (s *v0State) VerifyDealsForActivation( return market.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) } +type v0BalanceTable struct { + *v0adt.BalanceTable +} + +func (bt *v0BalanceTable) ForEach(cb func(address.Address, abi.TokenAmount) error) error { + asMap := (*v0adt.Map)(bt.BalanceTable) + var ta abi.TokenAmount + return asMap.ForEach(&ta, func(key string) error { + a, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(a, ta) + }) +} + type v0DealStates struct { adt.Array } -func (s *v0DealStates) GetDeal(dealID abi.DealID) (DealState, error) { - var deal market.DealState - found, err := s.Array.Get(uint64(dealID), &deal) +func (s *v0DealStates) Get(dealID abi.DealID) (*DealState, bool, error) { + var v0deal market.DealState + found, err := s.Array.Get(uint64(dealID), &v0deal) if err != nil { - return nil, err + return nil, false, err } if !found { - return nil, nil + return nil, false, nil } - return &v0DealState{deal}, nil + deal := fromV0DealState(v0deal) + return &deal, true, nil } func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) { @@ -108,7 +133,7 @@ func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) { return nil, errors.New("cannot compare deal states across versions") } results := new(DealStateChanges) - if err := adt.DiffAdtArray(s, v0other, &v0MarketStatesDiffer{results}); err != nil { + if err := adt.DiffAdtArray(s.Array, v0other.Array, &v0MarketStatesDiffer{results}); err != nil { return nil, fmt.Errorf("diffing deal states: %w", err) } @@ -120,61 +145,50 @@ type v0MarketStatesDiffer struct { } func (d *v0MarketStatesDiffer) Add(key uint64, val *typegen.Deferred) error { - ds := new(v0DealState) - err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) + v0ds := new(market.DealState) + err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { return err } - d.Results.Added = append(d.Results.Added, DealIDState{abi.DealID(key), ds}) + d.Results.Added = append(d.Results.Added, DealIDState{abi.DealID(key), fromV0DealState(*v0ds)}) return nil } func (d *v0MarketStatesDiffer) Modify(key uint64, from, to *typegen.Deferred) error { - dsFrom := new(v0DealState) - if err := dsFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)); err != nil { + v0dsFrom := new(market.DealState) + if err := v0dsFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)); err != nil { return err } - dsTo := new(v0DealState) - if err := dsTo.UnmarshalCBOR(bytes.NewReader(to.Raw)); err != nil { + v0dsTo := new(market.DealState) + if err := v0dsTo.UnmarshalCBOR(bytes.NewReader(to.Raw)); err != nil { return err } - if *dsFrom != *dsTo { - d.Results.Modified = append(d.Results.Modified, DealStateChange{abi.DealID(key), dsFrom, dsTo}) + if *v0dsFrom != *v0dsTo { + dsFrom := fromV0DealState(*v0dsFrom) + dsTo := fromV0DealState(*v0dsTo) + d.Results.Modified = append(d.Results.Modified, DealStateChange{abi.DealID(key), &dsFrom, &dsTo}) } return nil } func (d *v0MarketStatesDiffer) Remove(key uint64, val *typegen.Deferred) error { - ds := new(v0DealState) - err := ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) + v0ds := new(market.DealState) + err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { return err } - d.Results.Removed = append(d.Results.Removed, DealIDState{abi.DealID(key), ds}) + d.Results.Removed = append(d.Results.Removed, DealIDState{abi.DealID(key), fromV0DealState(*v0ds)}) return nil } -type v0DealState struct { - market.DealState -} - -func (ds *v0DealState) SectorStartEpoch() abi.ChainEpoch { - return ds.DealState.SectorStartEpoch -} - -func (ds *v0DealState) SlashEpoch() abi.ChainEpoch { - return ds.DealState.SlashEpoch -} - -func (ds *v0DealState) LastUpdatedEpoch() abi.ChainEpoch { - return ds.DealState.LastUpdatedEpoch -} - -func (ds *v0DealState) Equals(other DealState) bool { - v0other, ok := other.(*v0DealState) - return ok && *ds == *v0other +func fromV0DealState(v0 market.DealState) DealState { + return DealState{ + SectorStartEpoch: v0.SectorStartEpoch, + SlashEpoch: v0.SlashEpoch, + LastUpdatedEpoch: v0.LastUpdatedEpoch, + } } type v0DealProposals struct { @@ -188,28 +202,60 @@ func (s *v0DealProposals) Diff(other DealProposals) (*DealProposalChanges, error return nil, errors.New("cannot compare deal proposals across versions") } results := new(DealProposalChanges) - if err := adt.DiffAdtArray(s, v0other, &v0MarketProposalsDiffer{results}); err != nil { + if err := adt.DiffAdtArray(s.Array, v0other.Array, &v0MarketProposalsDiffer{results}); err != nil { return nil, fmt.Errorf("diffing deal proposals: %w", err) } return results, nil } +func (s *v0DealProposals) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var v0proposal market.DealProposal + found, err := s.Array.Get(uint64(dealID), &v0proposal) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + proposal := fromV0DealProposal(v0proposal) + return &proposal, true, nil +} + +func (s *v0DealProposals) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var v0dp market.DealProposal + return s.Array.ForEach(&v0dp, func(idx int64) error { + return cb(abi.DealID(idx), fromV0DealProposal(v0dp)) + }) +} + type v0MarketProposalsDiffer struct { Results *DealProposalChanges } -type v0DealProposal struct { - market.DealProposal +func fromV0DealProposal(v0 market.DealProposal) DealProposal { + return DealProposal{ + PieceCID: v0.PieceCID, + PieceSize: v0.PieceSize, + VerifiedDeal: v0.VerifiedDeal, + Client: v0.Client, + Provider: v0.Provider, + Label: v0.Label, + StartEpoch: v0.StartEpoch, + EndEpoch: v0.EndEpoch, + StoragePricePerEpoch: v0.StoragePricePerEpoch, + ProviderCollateral: v0.ProviderCollateral, + ClientCollateral: v0.ClientCollateral, + } } func (d *v0MarketProposalsDiffer) Add(key uint64, val *typegen.Deferred) error { - dp := new(v0DealProposal) - err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + v0dp := new(market.DealProposal) + err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { return err } - d.Results.Added = append(d.Results.Added, ProposalIDState{abi.DealID(key), dp}) + d.Results.Added = append(d.Results.Added, ProposalIDState{abi.DealID(key), fromV0DealProposal(*v0dp)}) return nil } @@ -219,11 +265,11 @@ func (d *v0MarketProposalsDiffer) Modify(key uint64, from, to *typegen.Deferred) } func (d *v0MarketProposalsDiffer) Remove(key uint64, val *typegen.Deferred) error { - dp := new(v0DealProposal) - err := dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + v0dp := new(market.DealProposal) + err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { return err } - d.Results.Removed = append(d.Results.Removed, ProposalIDState{abi.DealID(key), dp}) + d.Results.Removed = append(d.Results.Removed, ProposalIDState{abi.DealID(key), fromV0DealProposal(*v0dp)}) return nil } diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 3e515e6a486..7a76098232c 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -212,14 +212,7 @@ func (sp *StatePredicates) OnDealStateAmtChanged() DiffDealStatesFunc { } // ChangedDeals is a set of changes to deal state -type ChangedDeals map[abi.DealID]DealStateChange - -// DealStateChange is a change in deal state from -> to -type DealStateChange struct { - ID abi.DealID - From market.DealState - To market.DealState -} +type ChangedDeals map[abi.DealID]market.DealStateChange // DealStateChangedForIDs detects changes in the deal state AMT for the given deal IDs func (sp *StatePredicates) DealStateChangedForIDs(dealIds []abi.DealID) DiffDealStatesFunc { @@ -228,20 +221,20 @@ func (sp *StatePredicates) DealStateChangedForIDs(dealIds []abi.DealID) DiffDeal for _, dealID := range dealIds { // If the deal has been removed, we just set it to nil - oldDeal, err := oldDealStates.GetDeal(dealID) + oldDeal, oldFound, err := oldDealStates.Get(dealID) if err != nil { return false, nil, err } - newDeal, err := newDealStates.GetDeal(dealID) + newDeal, newFound, err := newDealStates.Get(dealID) if err != nil { return false, nil, err } - existenceChanged := (oldDeal == nil) != (newDeal == nil) - valueChanged := (oldDeal != nil && newDeal != nil) && !oldDeal.Equals(newDeal) + existenceChanged := oldFound != newFound + valueChanged := (oldFound && newFound) && *oldDeal != *newDeal if existenceChanged || valueChanged { - changedDeals[dealID] = DealStateChange{dealID, oldDeal, newDeal} + changedDeals[dealID] = market.DealStateChange{ID: dealID, From: oldDeal, To: newDeal} } } if len(changedDeals) > 0 { diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 25f25334d46..6541aa3b416 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -208,11 +208,11 @@ func TestMarketPredicates(t *testing.T) { require.Contains(t, changedDealIDs, abi.DealID(1)) require.Contains(t, changedDealIDs, abi.DealID(2)) deal1 := changedDealIDs[abi.DealID(1)] - if deal1.From.LastUpdatedEpoch() != 2 || deal1.To.LastUpdatedEpoch() != 3 { + if deal1.From.LastUpdatedEpoch != 2 || deal1.To.LastUpdatedEpoch != 3 { t.Fatal("Unexpected change to LastUpdatedEpoch") } deal2 := changedDealIDs[abi.DealID(2)] - if deal2.From.LastUpdatedEpoch() != 5 || deal2.To != nil { + if deal2.From.LastUpdatedEpoch != 5 || deal2.To != nil { t.Fatal("Expected To to be nil") } @@ -273,8 +273,8 @@ func TestMarketPredicates(t *testing.T) { require.Len(t, changedDeals.Modified, 1) require.Equal(t, abi.DealID(1), changedDeals.Modified[0].ID) - require.True(t, dealEquality(*newDeal1, changedDeals.Modified[0].To)) - require.True(t, dealEquality(*oldDeal1, changedDeals.Modified[0].From)) + require.True(t, dealEquality(*newDeal1, *changedDeals.Modified[0].To)) + require.True(t, dealEquality(*oldDeal1, *changedDeals.Modified[0].From)) require.Equal(t, abi.DealID(2), changedDeals.Removed[0].ID) }) @@ -624,7 +624,7 @@ func newSectorPreCommitInfo(sectorNo abi.SectorNumber, sealed cid.Cid, expiratio } func dealEquality(expected v0market.DealState, actual market.DealState) bool { - return expected.LastUpdatedEpoch == actual.LastUpdatedEpoch() && - expected.SectorStartEpoch == actual.SectorStartEpoch() && - expected.SlashEpoch == actual.SlashEpoch() + return expected.LastUpdatedEpoch == actual.LastUpdatedEpoch && + expected.SectorStartEpoch == actual.SectorStartEpoch && + expected.SlashEpoch == actual.SlashEpoch } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 4cae19082b1..4163f0b2d0e 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -489,13 +489,16 @@ func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticke // ResyncBankerNonce is used for dealing with messages made when // simulating forks func (cg *ChainGen) ResyncBankerNonce(ts *types.TipSet) error { - var act types.Actor - err := cg.sm.WithParentState(ts, cg.sm.WithActor(cg.banker, stmgr.GetActor(&act))) + st, err := cg.sm.ParentState(ts) + if err != nil { + return err + } + act, err := st.GetActor(cg.banker) if err != nil { return err } - cg.bankerNonce = act.Nonce + return nil } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 18c67b5f034..2a6737e2cca 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -1175,3 +1175,23 @@ func (sm *StateManager) GetPaychState(ctx context.Context, addr address.Address, } return act, actState, nil } + +func (sm *StateManager) GetMarketState(ctx context.Context, ts *types.TipSet) (market.State, error) { + st, err := sm.ParentState(ts) + if err != nil { + return nil, err + } + + // TODO maybe there needs to be code here to differentiate address based on ts height? + addr := builtin.StorageMarketActorAddr + act, err := st.GetActor(addr) + if err != nil { + return nil, err + } + + actState, err := market.Load(sm.cs.Store(ctx), act) + if err != nil { + return nil, err + } + return actState, nil +} diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index afd790a7443..38b66c51290 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -34,7 +34,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/adt" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" @@ -318,40 +317,35 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts return nil, xerrors.Errorf("failed to load market actor state: %w", err) } - store := sm.ChainStore().Store(ctx) - - da, err := adt.AsArray(store, state.Proposals) + proposals, err := state.Proposals() if err != nil { return nil, err } - var dp market.DealProposal - if found, err := da.Get(uint64(dealID), &dp); err != nil { + proposal, found, err := proposals.Get(dealID) + + if err != nil { return nil, err } else if !found { return nil, xerrors.Errorf("deal %d not found", dealID) } - sa, err := market.AsDealStateArray(store, state.States) + states, err := state.States() if err != nil { return nil, err } - st, found, err := sa.Get(dealID) + st, found, err := states.Get(dealID) if err != nil { return nil, err } if !found { - st = &market.DealState{ - SectorStartEpoch: -1, - LastUpdatedEpoch: -1, - SlashEpoch: -1, - } + st = market.EmptyDealState() } return &api.MarketDeal{ - Proposal: dp, + Proposal: *proposal, State: *st, }, nil } diff --git a/cli/client.go b/cli/client.go index e68f98791f8..eda5ffae886 100644 --- a/cli/client.go +++ b/cli/client.go @@ -29,13 +29,13 @@ import ( "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/api" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/tablewriter" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" ) var CidBaseFlag = cli.StringFlag{ @@ -1045,11 +1045,7 @@ func dealFromDealInfo(ctx context.Context, full api.FullNode, head *types.TipSet if v.DealID == 0 { return deal{ LocalDeal: v, - OnChainDealState: market.DealState{ - SectorStartEpoch: -1, - LastUpdatedEpoch: -1, - SlashEpoch: -1, - }, + OnChainDealState: *market.EmptyDealState() } } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 0fe754217a3..e9a98fec9de 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -25,9 +25,9 @@ import ( "github.com/filecoin-project/go-state-types/crypto" statemachine "github.com/filecoin-project/go-statemachine" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - "github.com/filecoin-project/specs-actors/actors/builtin/market" ) const SectorStorePrefix = "/sectors" diff --git a/go.mod b/go.mod index 65c2addb85b..0397ff275c5 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-data-transfer v0.6.3 github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f - github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c + github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9 github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 diff --git a/go.sum b/go.sum index b6b7247676f..3d012da921d 100644 --- a/go.sum +++ b/go.sum @@ -228,6 +228,10 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1 github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c h1:YGoyYmELQ0LHwDj/WcOvY3oYt+3iM0wdrAhqJQUAIy4= github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= +github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917050751-2af52e9606c6 h1:k97Z2JP3WpDVGU/7Bz3RtnqrYtn9X428Ps8OkoFq61I= +github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917050751-2af52e9606c6/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= +github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9 h1:SnCUC9wHDId9TtV8PsQp8q1OOsi+NOLOwitIDnAgUa4= +github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 0c9e66eda78..781715903e5 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -98,29 +98,6 @@ func (c *ClientNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Sign return err == nil, err } -func (c *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) ([]storagemarket.StorageDeal, error) { - tsk, err := types.TipSetKeyFromBytes(encodedTs) - if err != nil { - return nil, err - } - - allDeals, err := c.StateMarketDeals(ctx, tsk) - if err != nil { - return nil, err - } - - var out []storagemarket.StorageDeal - - for _, deal := range allDeals { - storageDeal := utils.FromOnChainDeal(deal.Proposal, deal.State) - if storageDeal.Client == addr { - out = append(out, storageDeal) - } - } - - return out, nil -} - // Adds funds with the StorageMinerActor for a storage participant. Used by both providers and clients. func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error) { // (Provider Node API) diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 22d6c1e1d0b..98935b30a2a 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -142,28 +142,6 @@ func (n *ProviderNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Si return err == nil, err } -func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) ([]storagemarket.StorageDeal, error) { - tsk, err := types.TipSetKeyFromBytes(encodedTs) - if err != nil { - return nil, err - } - allDeals, err := n.StateMarketDeals(ctx, tsk) - if err != nil { - return nil, err - } - - var out []storagemarket.StorageDeal - - for _, deal := range allDeals { - sharedDeal := utils.FromOnChainDeal(deal.Proposal, deal.State) - if sharedDeal.Provider == addr { - out = append(out, sharedDeal) - } - } - - return out, nil -} - func (n *ProviderNodeAdapter) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { diff --git a/markets/utils/converters.go b/markets/utils/converters.go index 05472801d42..4a3d211404b 100644 --- a/markets/utils/converters.go +++ b/markets/utils/converters.go @@ -4,7 +4,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/specs-actors/actors/builtin/market" peer "github.com/libp2p/go-libp2p-core/peer" "github.com/multiformats/go-multiaddr" @@ -31,13 +30,6 @@ func NewStorageProviderInfo(address address.Address, miner address.Address, sect } } -func FromOnChainDeal(prop market.DealProposal, state market.DealState) storagemarket.StorageDeal { - return storagemarket.StorageDeal{ - DealProposal: prop, - DealState: state, - } -} - func ToSharedBalance(bal api.MarketBalance) storagemarket.Balance { return storagemarket.Balance{ Locked: bal.Locked, diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 536bef360c4..b207a1f6d1a 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -166,8 +166,14 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, } // Special case for PaymentChannel collect, which is deleting actor - var act types.Actor - err = a.Stmgr.WithParentState(ts, a.Stmgr.WithActor(msg.To, stmgr.GetActor(&act))) + st, err := a.Stmgr.ParentState(ts) + if err != nil { + _ = err + // somewhat ignore it as it can happen and we just want to detect + // an existing PaymentChannel actor + return res.MsgRct.GasUsed, nil + } + act, err := st.GetActor(msg.To) if err != nil { _ = err // somewhat ignore it as it can happen and we just want to detect diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 1b29a93a915..241561a9fce 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "errors" - "fmt" - "github.com/filecoin-project/go-state-types/network" "strconv" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/dline" cid "github.com/ipfs/go-cid" @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/builtin/power" @@ -42,7 +43,6 @@ import ( "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/lib/bufbstore" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" ) var errBreakForeach = errors.New("break") @@ -259,8 +259,8 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, ts } return &api.MinerPower{ - MinerPower: m, - TotalPower: net, + MinerPower: m, + TotalPower: net, HasMinPower: hmp, }, nil } @@ -489,35 +489,29 @@ func (a *StateAPI) StateMarketBalance(ctx context.Context, addr address.Address, func (a *StateAPI) StateMarketParticipants(ctx context.Context, tsk types.TipSetKey) (map[string]api.MarketBalance, error) { out := map[string]api.MarketBalance{} - var state market.State ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - if _, err := a.StateManager.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts); err != nil { + + state, err := a.StateManager.GetMarketState(ctx, ts) + if err != nil { return nil, err } - store := a.StateManager.ChainStore().Store(ctx) - escrow, err := adt.AsMap(store, state.EscrowTable) + escrow, err := state.EscrowTable() if err != nil { return nil, err } - locked, err := adt.AsMap(store, state.LockedTable) + locked, err := state.LockedTable() if err != nil { return nil, err } - var es, lk abi.TokenAmount - err = escrow.ForEach(&es, func(k string) error { - a, err := address.NewFromBytes([]byte(k)) - if err != nil { - return err - } + err = escrow.ForEach(func(a address.Address, es abi.TokenAmount) error { - if found, err := locked.Get(abi.AddrKey(a), &lk); err != nil { + lk, err := locked.Get(a) + if err != nil { return err - } else if !found { - return fmt.Errorf("locked funds not found") } out[a.String()] = api.MarketBalance{ @@ -535,37 +529,36 @@ func (a *StateAPI) StateMarketParticipants(ctx context.Context, tsk types.TipSet func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]api.MarketDeal, error) { out := map[string]api.MarketDeal{} - var state market.State ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - if _, err := a.StateManager.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts); err != nil { + + state, err := a.StateManager.GetMarketState(ctx, ts) + if err != nil { return nil, err } - store := a.StateManager.ChainStore().Store(ctx) - da, err := adt.AsArray(store, state.Proposals) + da, err := state.Proposals() if err != nil { return nil, err } - sa, err := adt.AsArray(store, state.States) + sa, err := state.States() if err != nil { return nil, err } - var d market.DealProposal - if err := da.ForEach(&d, func(i int64) error { - var s market.DealState - if found, err := sa.Get(uint64(i), &s); err != nil { + if err := da.ForEach(func(dealID abi.DealID, d market.DealProposal) error { + s, found, err := sa.Get(dealID) + if err != nil { return xerrors.Errorf("failed to get state for deal in proposals array: %w", err) } else if !found { - s.SectorStartEpoch = -1 + s = market.EmptyDealState() } - out[strconv.FormatInt(i, 10)] = api.MarketDeal{ + out[strconv.FormatInt(int64(dealID), 10)] = api.MarketDeal{ Proposal: d, - State: s, + State: *s, } return nil }); err != nil { @@ -872,10 +865,10 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr var sectorWeight abi.StoragePower if act, err := state.GetActor(market.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor %s: %w", maddr, err) - } else s, err := market.Load(store, act); err != nil { + } else if s, err := market.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading market actor state %s: %w", maddr, err) } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { - return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) + return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) } else { // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() @@ -887,9 +880,9 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr var powerSmoothed smoothing.FilterEstimate if act, err := state.GetActor(power.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else s, err := power.Load(store, act); err != nil { + } else if s, err := power.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err) - } else p, err := s.TotalPowerSmoothed(); err != nil { + } else if p, err := s.TotalPowerSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total power: %w", err) } else { powerSmoothed = p @@ -898,9 +891,9 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr var rewardSmoothed smoothing.FilterEstimate if act, err := state.GetActor(reward.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else s, err := reward.Load(store, act); err != nil { + } else if s, err := reward.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else r, err := s.RewardSmoothed(); err != nil { + } else if r, err := s.RewardSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) } else { rewardSmoothed = r @@ -934,10 +927,10 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr var sectorWeight abi.StoragePower if act, err := state.GetActor(market.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor %s: %w", maddr, err) - } else s, err := market.Load(store, act); err != nil { + } else if s, err := market.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading market actor state %s: %w", maddr, err) } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { - return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) + return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err) } else { // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() @@ -947,16 +940,16 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr } var ( - powerSmoothed smoothing.FilterEstimate + powerSmoothed smoothing.FilterEstimate pledgeCollerateral abi.TokenAmount ) if act, err := state.GetActor(power.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else s, err := power.Load(store, act); err != nil { + } else if s, err := power.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err) - } else p, err := s.TotalPowerSmoothed(); err != nil { + } else if p, err := s.TotalPowerSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total power: %w", err) - } else c, err := s.TotalLocked(); err != nil { + } else if c, err := s.TotalLocked(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine pledge collateral: %w", err) } else { powerSmoothed = p @@ -965,15 +958,15 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr var ( rewardSmoothed smoothing.FilterEstimate - baselinePower abi.StoragePower + baselinePower abi.StoragePower ) if act, err := state.GetActor(reward.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else s, err := reward.Load(store, act); err != nil { + } else if s, err := reward.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else r, err := s.RewardSmoothed(); err != nil { + } else if r, err := s.RewardSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) - } else p, err := s.BaselinePower(); err != nil { + } else if p, err := s.BaselinePower(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) } else { rewardSmoothed = r diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 6eedc9f544e..89dd7c2c28e 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -305,8 +305,30 @@ func (sm *StorageMinerAPI) MarketImportDealData(ctx context.Context, propCid cid return sm.StorageProvider.ImportDataForDeal(ctx, propCid, fi) } -func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) { - return sm.StorageProvider.ListDeals(ctx) +func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, error) { + ts, err := sm.Full.ChainHead(ctx) + if err != nil { + return nil, err + } + tsk := ts.Key() + allDeals, err := sm.Full.StateMarketDeals(ctx, tsk) + if err != nil { + return nil, err + } + + var out []api.MarketDeal + + for _, deal := range allDeals { + if deal.Proposal.Provider == sm.Miner.Address() { + out = append(out, deal) + } + } + + return out, nil +} + +func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) { + return sm.StorageProvider.listDeals(ctx) } func (sm *StorageMinerAPI) MarketListRetrievalDeals(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) { @@ -395,8 +417,8 @@ func (sm *StorageMinerAPI) MarketDataTransferUpdates(ctx context.Context) (<-cha return channels, nil } -func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) { - return sm.StorageProvider.ListDeals(ctx) +func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]api.MarketDeal, error) { + return sm.listDeals(ctx) } func (sm *StorageMinerAPI) RetrievalDealsList(ctx context.Context) (map[retrievalmarket.ProviderDealIdentifier]retrievalmarket.ProviderDealState, error) { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 8b64789add2..7dced43311a 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -15,12 +15,13 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -136,7 +137,7 @@ func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr return cid.Undef, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) } - ccparams, err := actors.SerializeParams(&market.ComputeDataCommitmentParams{ + ccparams, err := actors.SerializeParams(&v0market.ComputeDataCommitmentParams{ DealIDs: deals, SectorType: sectorType, }) From 7bf165c73a37025307619ea49ae8fc6aaa36b2b9 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 03:07:01 -0400 Subject: [PATCH 036/104] Remove miner-related specs actors types from API --- api/api_full.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index f565ad5435c..e575c5bdd02 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -25,7 +25,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime/proof" - miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" @@ -317,16 +316,16 @@ type FullNode interface { // StateMinerSectors returns info about the given miner's sectors. If the filter bitfield is nil, all sectors are included. // If the filterOut boolean is set to true, any sectors in the filter are excluded. // If false, only those sectors in the filter are included. - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) // StateMinerActiveSectors returns info about sectors that a given miner is actively proving. - StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner2.ChainSectorInfo, error) + StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner.ChainSectorInfo, error) // StateMinerProvingDeadline calculates the deadline at some epoch for a proving period // and returns the deadline-related calculations. StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) // StateMinerPower returns the power of the indicated miner StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) // StateMinerInfo returns info about the indicated miner - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner2.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) // StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) // StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset From 053cfc1cc7f5935d616d19813862c3c38bde6cb8 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 03:48:39 -0400 Subject: [PATCH 037/104] Migrate verifreg actor --- api/api_full.go | 3 +-- api/apistruct/struct.go | 5 ++--- build/params_2k.go | 4 ++-- chain/gen/gen_test.go | 4 ++-- chain/gen/genesis/t06_vreg.go | 4 ++-- chain/stmgr/forks_test.go | 4 ++-- chain/stmgr/utils.go | 4 ++-- chain/store/store_test.go | 4 ++-- chain/sync_test.go | 4 ++-- chain/vectors/gen/main.go | 4 ++-- chain/vm/invoker.go | 4 ++-- cli/paych_test.go | 4 ++-- markets/storageadapter/provider.go | 7 ++++--- node/impl/full/state.go | 33 +++++++++++------------------- node/node_test.go | 4 ++-- 15 files changed, 41 insertions(+), 51 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index e575c5bdd02..d570da7de19 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -22,7 +22,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/lotus/chain/actors/builtin/power" @@ -382,7 +381,7 @@ type FullNode interface { // StateVerifiedClientStatus returns the data cap for the given address. // Returns nil if there is no entry in the data cap table for the // address. - StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*verifreg.DataCap, error) + StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) // StateDealProviderCollateralBounds returns the min and max collateral a storage provider // can issue. It takes the deal size and verified status as parameters. StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (DealCollateralBounds, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 8bf8f1997ee..837400b6566 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -30,7 +30,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/storiface" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" @@ -197,7 +196,7 @@ type FullNodeStruct struct { StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` - StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` + StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (abi.StoragePower, error) `perm:"read"` StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` StateNetworkVersion func(context.Context, types.TipSetKey) (stnetwork.Version, error) `perm:"read"` @@ -864,7 +863,7 @@ func (c *FullNodeStruct) StateCompute(ctx context.Context, height abi.ChainEpoch return c.Internal.StateCompute(ctx, height, msgs, tsk) } -func (c *FullNodeStruct) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*verifreg.DataCap, error) { +func (c *FullNodeStruct) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) { return c.Internal.StateVerifiedClientStatus(ctx, addr, tsk) } diff --git a/build/params_2k.go b/build/params_2k.go index cf34706e5bc..9c8a591d1b1 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/big" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" ) const UpgradeBreezeHeight = -1 @@ -24,7 +24,7 @@ func init() { v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) BuildType |= Build2k } diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index 496bb016bcd..9d1262f7709 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/big" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" _ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/secp" @@ -18,7 +18,7 @@ func init() { abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } func testGeneration(t testing.TB, n int, msgs int, sectors int) { diff --git a/chain/gen/genesis/t06_vreg.go b/chain/gen/genesis/t06_vreg.go index 6636fa05f71..d91cdf7b1cc 100644 --- a/chain/gen/genesis/t06_vreg.go +++ b/chain/gen/genesis/t06_vreg.go @@ -7,7 +7,7 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/chain/types" @@ -34,7 +34,7 @@ func SetupVerifiedRegistryActor(bs bstore.Blockstore) (*types.Actor, error) { return nil, err } - sms := verifreg.ConstructState(h, RootVerifierID) + sms := v0verifreg.ConstructState(h, RootVerifierID) stcid, err := store.Put(store.Context(), sms) if err != nil { diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 2db11e83215..c4fb1b3be27 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -13,7 +13,7 @@ import ( init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime" "golang.org/x/xerrors" @@ -37,7 +37,7 @@ func init() { abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } const testForkHeight = 40 diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 38b66c51290..b7c888a3626 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -30,7 +30,7 @@ import ( v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -550,7 +550,7 @@ func init() { builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, builtin.MultisigActorCodeID: {builtin.MethodsMultisig, v0msig.Actor{}}, builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}}, - builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, verifreg.Actor{}}, + builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, v0verifreg.Actor{}}, } for c, m := range cidToMethods { diff --git a/chain/store/store_test.go b/chain/store/store_test.go index 7da8d219db0..83238a67d05 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/crypto" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/store" @@ -26,7 +26,7 @@ func init() { abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } func BenchmarkGetRandomness(b *testing.B) { diff --git a/chain/sync_test.go b/chain/sync_test.go index e8df32c5609..d98663fb1b7 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -22,7 +22,7 @@ import ( "github.com/filecoin-project/go-state-types/big" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -47,7 +47,7 @@ func init() { abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } v0power.ConsensusMinerMinPower = big.NewInt(2048) - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } const source = 0 diff --git a/chain/vectors/gen/main.go b/chain/vectors/gen/main.go index 4bf2c420e60..36b770f039e 100644 --- a/chain/vectors/gen/main.go +++ b/chain/vectors/gen/main.go @@ -19,14 +19,14 @@ import ( "github.com/filecoin-project/lotus/chain/types/mock" "github.com/filecoin-project/lotus/chain/vectors" "github.com/filecoin-project/lotus/chain/wallet" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" _ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/secp" ) func init() { - verifreg.MinVerifiedDealSize = big.NewInt(2048) + v0verifreg.MinVerifiedDealSize = big.NewInt(2048) v0power.ConsensusMinerMinPower = big.NewInt(2048) } diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 4cda32c44ef..b31b45767b4 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -55,7 +55,7 @@ func NewInvoker() *Invoker { inv.Register(builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) inv.Register(builtin.MultisigActorCodeID, v0msig.Actor{}, v0msig.State{}) inv.Register(builtin.PaymentChannelActorCodeID, paych.Actor{}, paych.State{}) - inv.Register(builtin.VerifiedRegistryActorCodeID, verifreg.Actor{}, verifreg.State{}) + inv.Register(builtin.VerifiedRegistryActorCodeID, v0verifreg.Actor{}, v0verifreg.State{}) inv.Register(builtin.AccountActorCodeID, account.Actor{}, account.State{}) return inv diff --git a/cli/paych_test.go b/cli/paych_test.go index 1cf95ef6c69..598c178eb66 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/go-state-types/big" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/multiformats/go-multiaddr" @@ -44,7 +44,7 @@ func init() { v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } // TestPaymentChannels does a basic test to exercise the payment channel CLI diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 98935b30a2a..fb93a1e7244 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -8,6 +8,8 @@ import ( "io" "time" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" @@ -22,7 +24,6 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -361,10 +362,10 @@ func (n *ProviderNodeAdapter) WaitForMessage(ctx context.Context, mcid cid.Cid, return cb(receipt.Receipt.ExitCode, receipt.Receipt.Return, receipt.Message, nil) } -func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (*verifreg.DataCap, error) { +func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (abi.StoragePower, error) { tsk, err := types.TipSetKeyFromBytes(encodedTs) if err != nil { - return nil, err + return big.Zero(), err } return n.StateVerifiedClientStatus(ctx, addr, tsk) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 241561a9fce..a21f0cf80e8 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -6,9 +6,10 @@ import ( "errors" "strconv" - "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/go-state-types/network" cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" @@ -23,7 +24,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/smoothing" @@ -1018,40 +1018,31 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address } // StateVerifiedClientStatus returns the data cap for the given address. -// Returns nil if there is no entry in the data cap table for the +// Returns zero if there is no entry in the data cap table for the // address. -func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*verifreg.DataCap, error) { +func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) { act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) if err != nil { - return nil, err + return big.Zero(), err } aid, err := a.StateLookupID(ctx, addr, tsk) if err != nil { log.Warnf("lookup failure %v", err) - return nil, err + return big.Zero(), err } - store := a.StateManager.ChainStore().Store(ctx) - - var st verifreg.State - if err := store.Get(ctx, act.Head, &st); err != nil { - return nil, err - } - - vh, err := adt.AsMap(store, st.VerifiedClients) + vrs, err := verifreg.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return nil, err + return big.Zero(), xerrors.Errorf("failed to load verified registry state: %w", err) } - var dcap verifreg.DataCap - if found, err := vh.Get(abi.AddrKey(aid), &dcap); err != nil { - return nil, err - } else if !found { - return nil, nil + _, dcap, err := vrs.VerifiedClientDataCap(aid) + if err != nil { + return big.Zero(), xerrors.Errorf("looking up verified client: %w", err) } - return &dcap, nil + return dcap, nil } var dealProviderCollateralNum = types.NewInt(110) diff --git a/node/node_test.go b/node/node_test.go index 92b741f7340..68ee178fc6e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/lotus/lib/lotuslog" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" logging "github.com/ipfs/go-log/v2" "github.com/filecoin-project/lotus/api/test" @@ -25,7 +25,7 @@ func init() { v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - verifreg.MinVerifiedDealSize = big.NewInt(256) + v0verifreg.MinVerifiedDealSize = big.NewInt(256) } func TestAPI(t *testing.T) { From 31ff5230bbf3506bc69f86c0f30daa53e01c7867 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 17 Sep 2020 04:17:14 -0400 Subject: [PATCH 038/104] Get State API almost working --- api/api_full.go | 2 + api/apistruct/struct.go | 5 + chain/actors/builtin/miner/miner.go | 3 + chain/actors/builtin/miner/v0.go | 8 ++ chain/actors/builtin/reward/reward.go | 4 +- chain/actors/builtin/reward/v0.go | 12 +- chain/actors/builtin/verifreg/v0.go | 37 +++++++ chain/actors/builtin/verifreg/verifreg.go | 34 ++++++ chain/stmgr/read.go | 1 + chain/stmgr/stmgr.go | 2 +- chain/stmgr/utils.go | 12 +- chain/sub/incoming.go | 1 - cli/client.go | 8 +- cmd/lotus-storage-miner/proving.go | 10 +- markets/storageadapter/provider.go | 10 +- node/impl/full/state.go | 128 +++++++++++++--------- node/impl/storminer.go | 2 +- storage/adapter_storage_miner.go | 4 +- storage/addresses.go | 5 +- storage/miner.go | 2 +- storage/wdpost_sched.go | 2 - 21 files changed, 211 insertions(+), 81 deletions(-) create mode 100644 chain/actors/builtin/verifreg/v0.go create mode 100644 chain/actors/builtin/verifreg/verifreg.go diff --git a/api/api_full.go b/api/api_full.go index d570da7de19..1adcc5c19d4 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -325,6 +325,8 @@ type FullNode interface { StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) // StateMinerInfo returns info about the indicated miner StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) + // StateMinerDeadlines returns all the proving deadlines for the given miner + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) // StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) // StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 837400b6566..ab86d78197f 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -167,6 +167,7 @@ type FullNodeStruct struct { StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` + StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) `perm:"read"` StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` @@ -751,6 +752,10 @@ func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Addre return c.Internal.StateMinerInfo(ctx, actor, tsk) } +func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { + return c.Internal.StateMinerDeadlines(ctx, actor, tsk) +} + func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { return c.Internal.StateMinerFaults(ctx, actor, tsk) } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 4acb41daebb..725c5f2ff91 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -34,6 +34,9 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler + AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error) + VestedFunds(abi.ChainEpoch) (abi.TokenAmount, error) + GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index b56fb1745af..cbe42b3dae4 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -31,6 +31,14 @@ type v0Partition struct { store adt.Store } +func (s *v0State) AvailableBalance(bal abi.TokenAmount) (abi.TokenAmount, error) { + return s.GetAvailableBalance(bal), nil +} + +func (s *v0State) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.CheckVestedFunds(s.store, epoch) +} + func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { info, ok, err := s.State.GetSector(s.store, num) if !ok || err != nil { diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index d400258df85..9093b33c605 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -31,5 +31,7 @@ type State interface { cbor.Marshaler RewardSmoothed() (builtin.FilterEstimate, error) - TotalStoragePowerReward() abi.TokenAmount + EffectiveBaselinePower() (abi.StoragePower, error) + ThisEpochBaselinePower() (abi.StoragePower, error) + TotalStoragePowerReward() (abi.TokenAmount, error) } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index b0558f0ae50..16ac2b071f0 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -16,6 +16,14 @@ func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochRewardSmoothed, nil } -func (s *v0State) TotalStoragePowerReward() abi.TokenAmount { - return s.State.TotalMined +func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) { + return s.State.TotalMined, nil +} + +func (s *v0State) EffectiveBaselinePower() (abi.StoragePower, error) { + return s.State.EffectiveBaselinePower, nil +} + +func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil } diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go new file mode 100644 index 00000000000..cbaf4d23660 --- /dev/null +++ b/chain/actors/builtin/verifreg/v0.go @@ -0,0 +1,37 @@ +package verifreg + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" +) + +type v0State struct { + v0verifreg.State + store adt.Store +} + +func (s *v0State) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + if addr.Protocol() != address.ID { + return false, big.Zero(), xerrors.Errorf("can only look up ID addresses") + } + + vh, err := v0adt.AsMap(s.store, s.VerifiedClients) + if err != nil { + return false, big.Zero(), xerrors.Errorf("loading verified clients: %w", err) + } + + var dcap abi.StoragePower + if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil { + return false, big.Zero(), xerrors.Errorf("looking up verified clients: %w", err) + } else if !found { + return false, big.Zero(), nil + } + + return true, dcap, nil +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go new file mode 100644 index 00000000000..4cb5bb55b26 --- /dev/null +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -0,0 +1,34 @@ +package verifreg + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +var Address = v0builtin.VerifiedRegistryActorAddr + +func Load(store adt.Store, act *types.Actor) (State, error) { + switch act.Code { + case v0builtin.VerifiedRegistryActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error) +} diff --git a/chain/stmgr/read.go b/chain/stmgr/read.go index 53eb8d384ed..9a9b8026576 100644 --- a/chain/stmgr/read.go +++ b/chain/stmgr/read.go @@ -2,6 +2,7 @@ package stmgr import ( "context" + "golang.org/x/xerrors" "github.com/ipfs/go-cid" diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 2a6737e2cca..89ad6edd913 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -1029,7 +1029,7 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err return big.Zero(), xerrors.Errorf("failed to load reward state: %w", err) } - return rst.TotalStoragePowerReward(), nil + return rst.TotalStoragePowerReward() } func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index b7c888a3626..4fabefbfffa 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -9,6 +9,10 @@ import ( "runtime" "strings" + v0init "github.com/filecoin-project/specs-actors/actors/builtin/init" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" saruntime "github.com/filecoin-project/specs-actors/actors/runtime" @@ -541,12 +545,12 @@ var MethodsMap = map[cid.Cid]map[abi.MethodNum]MethodMeta{} func init() { cidToMethods := map[cid.Cid][2]interface{}{ // builtin.SystemActorCodeID: {builtin.MethodsSystem, system.Actor{} }- apparently it doesn't have methods - builtin.InitActorCodeID: {builtin.MethodsInit, init_.Actor{}}, + builtin.InitActorCodeID: {builtin.MethodsInit, v0init.Actor{}}, builtin.CronActorCodeID: {builtin.MethodsCron, cron.Actor{}}, builtin.AccountActorCodeID: {builtin.MethodsAccount, account.Actor{}}, - builtin.StoragePowerActorCodeID: {builtin.MethodsPower, power.Actor{}}, - builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, miner.Actor{}}, - builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market.Actor{}}, + builtin.StoragePowerActorCodeID: {builtin.MethodsPower, v0power.Actor{}}, + builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, v0miner.Actor{}}, + builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, v0market.Actor{}}, builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, builtin.MultisigActorCodeID: {builtin.MethodsMultisig, v0msig.Actor{}}, builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}}, diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 1af5d8188af..c6e0c8b803f 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -1,7 +1,6 @@ package sub import ( - "bytes" "context" "errors" "fmt" diff --git a/cli/client.go b/cli/client.go index eda5ffae886..f6d5299431a 100644 --- a/cli/client.go +++ b/cli/client.go @@ -33,9 +33,9 @@ import ( "github.com/filecoin-project/lotus/api" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/tablewriter" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" ) var CidBaseFlag = cli.StringFlag{ @@ -417,7 +417,7 @@ var clientDealCmd = &cli.Command{ return err } - isVerified := dcap != nil + isVerified := dcap != types.EmptyInt // If the user has explicitly set the --verified-deal flag if cctx.IsSet("verified-deal") { @@ -1044,8 +1044,8 @@ var clientListDeals = &cli.Command{ func dealFromDealInfo(ctx context.Context, full api.FullNode, head *types.TipSet, v api.DealInfo) deal { if v.DealID == 0 { return deal{ - LocalDeal: v, - OnChainDealState: *market.EmptyDealState() + LocalDeal: v, + OnChainDealState: *market.EmptyDealState(), } } diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index d9bf813763c..d3e2137524b 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -74,7 +74,7 @@ var provingFaultsCmd = &cli.Command{ _, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors") err = mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { - faults, err := part.Faults() + faults, err := part.FaultySectors() if err != nil { return err } @@ -158,7 +158,7 @@ var provingInfoCmd = &cli.Command{ } } - if bf, err := part.Faults(); err != nil { + if bf, err := part.FaultySectors(); err != nil { return err } else if count, err := bf.Count(); err != nil { return err @@ -166,7 +166,7 @@ var provingInfoCmd = &cli.Command{ faults += count } - if bf, err := part.Recovering(); err != nil { + if bf, err := part.RecoveringSectors(); err != nil { return err } else if count, err := bf.Count(); err != nil { return err @@ -286,14 +286,14 @@ var provingDeadlinesCmd = &cli.Command{ faults := uint64(0) for _, partition := range partitions { - sc, err := partition.Sectors.Count() + sc, err := partition.AllSectors.Count() if err != nil { return err } sectors += sc - fc, err := partition.Faults.Count() + fc, err := partition.FaultySectors.Count() if err != nil { return err } diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index fb93a1e7244..90bf28b4150 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -8,8 +8,6 @@ import ( "io" "time" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" @@ -362,12 +360,14 @@ func (n *ProviderNodeAdapter) WaitForMessage(ctx context.Context, mcid cid.Cid, return cb(receipt.Receipt.ExitCode, receipt.Receipt.Return, receipt.Message, nil) } -func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (abi.StoragePower, error) { +func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (*abi.StoragePower, error) { tsk, err := types.TipSetKeyFromBytes(encodedTs) if err != nil { - return big.Zero(), err + return nil, err } - return n.StateVerifiedClientStatus(ctx, addr, tsk) + + sp, err := n.StateVerifiedClientStatus(ctx, addr, tsk) + return &sp, err } func (n *ProviderNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID abi.DealID, onDealExpired storagemarket.DealExpiredCallback, onDealSlashed storagemarket.DealSlashedCallback) error { diff --git a/node/impl/full/state.go b/node/impl/full/state.go index a21f0cf80e8..48f9d503c81 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -6,6 +6,8 @@ import ( "errors" "strconv" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" "github.com/filecoin-project/go-state-types/dline" @@ -73,6 +75,11 @@ func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, } func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { // TODO: only used in cli + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -88,7 +95,7 @@ func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Ad return nil, xerrors.Errorf("merge partition active sets: %w", err) } - return mas.LoadSectorsFromSet(&activeSectors, false) + return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, maddr, &activeSectors, false) } func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { @@ -105,7 +112,7 @@ func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, ts return mas.Info() } -func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]miner.Deadline, error) { +func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { act, err := a.StateManager.LoadActorTsk(ctx, m, tsk) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -121,9 +128,9 @@ func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, t return nil, xerrors.Errorf("getting deadline count: %w", err) } - out := make([]miner.Deadline, deadlines) + out := make([]*miner.Deadline, deadlines) if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error { - out[i] = dl + out[i] = &dl return nil }); err != nil { return nil, err @@ -671,12 +678,18 @@ func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Addre return api.MinerSectors{Live: liveCount, Active: activeCount, Faulty: faultyCount}, nil } -func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorPreCommitOnChainInfo, error) { +func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { - return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - return stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts) + + pci, err := stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts) + if err != nil { + return miner.SectorPreCommitOnChainInfo{}, err + } + + return *pci, err } func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) { @@ -873,7 +886,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() - // TODO: handle changes to this function across actor upgrades. + // TODO: ActorUpgrade sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw) } @@ -899,8 +912,8 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr rewardSmoothed = r } - // TODO: abstract over network upgrades. - deposit := v0miner.PreCommitDepositForPower(rewardSmoothed, powerSmoothed, sectorWeight) + // TODO: ActorUpgrade + deposit := v0miner.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight) return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil } @@ -940,8 +953,8 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr } var ( - powerSmoothed smoothing.FilterEstimate - pledgeCollerateral abi.TokenAmount + powerSmoothed smoothing.FilterEstimate + pledgeCollateral abi.TokenAmount ) if act, err := state.GetActor(power.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) @@ -966,26 +979,26 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) } else if r, err := s.RewardSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) - } else if p, err := s.BaselinePower(); err != nil { + } else if p, err := s.ThisEpochBaselinePower(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) } else { rewardSmoothed = r baselinePower = p } - // TODO: abstract over network upgrades. - circSupply, err := a.StateCirculatingSupply(ctx, ts.Key()) if err != nil { return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err) } - initialPledge := miner.InitialPledgeForPower( + // TODO: ActorUpgrade + + initialPledge := v0miner.InitialPledgeForPower( sectorWeight, baselinePower, pledgeCollateral, - rewardSmoothed, - powerSmoothed, + &rewardSmoothed, + &powerSmoothed, circSupply.FilCirculating, ) @@ -998,23 +1011,27 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var act *types.Actor - var mas miner.State + act, err := a.StateManager.LoadActor(ctx, maddr, ts) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to load miner actor: %w", err) + } - if err := a.StateManager.WithParentState(ts, a.StateManager.WithActor(maddr, func(actor *types.Actor) error { - act = actor - return a.StateManager.WithActorState(ctx, &mas)(actor) - })); err != nil { - return types.BigInt{}, xerrors.Errorf("getting miner state: %w", err) + mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act) + if err != nil { + return types.EmptyInt, xerrors.Errorf("failed to load miner actor state: %w", err) } - as := store.ActorStore(ctx, a.Chain.Blockstore()) - vested, err := mas.CheckVestedFunds(as, ts.Height()) + vested, err := mas.VestedFunds(ts.Height()) if err != nil { return types.EmptyInt, err } - return types.BigAdd(mas.GetAvailableBalance(act.Balance), vested), nil + abal, err := mas.AvailableBalance(act.Balance) + if err != nil { + return types.EmptyInt, err + } + + return types.BigAdd(abal, vested), nil } // StateVerifiedClientStatus returns the data cap for the given address. @@ -1023,23 +1040,23 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) { act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) if err != nil { - return big.Zero(), err + return types.EmptyInt, err } aid, err := a.StateLookupID(ctx, addr, tsk) if err != nil { log.Warnf("lookup failure %v", err) - return big.Zero(), err + return types.EmptyInt, err } vrs, err := verifreg.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return big.Zero(), xerrors.Errorf("failed to load verified registry state: %w", err) + return types.EmptyInt, xerrors.Errorf("failed to load verified registry state: %w", err) } _, dcap, err := vrs.VerifiedClientDataCap(aid) if err != nil { - return big.Zero(), xerrors.Errorf("looking up verified client: %w", err) + return types.EmptyInt, xerrors.Errorf("looking up verified client: %w", err) } return dcap, nil @@ -1056,23 +1073,24 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - var powerState power.State - var rewardState reward.State - - err = a.StateManager.WithParentStateTsk(ts.Key(), func(state *state.StateTree) error { - if err := a.StateManager.WithActor(builtin.StoragePowerActorAddr, a.StateManager.WithActorState(ctx, &powerState))(state); err != nil { - return xerrors.Errorf("getting power state: %w", err) - } + pact, err := a.StateGetActor(ctx, builtin.StoragePowerActorAddr, tsk) + if err != nil { + return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor: %w", err) + } - if err := a.StateManager.WithActor(builtin.RewardActorAddr, a.StateManager.WithActorState(ctx, &rewardState))(state); err != nil { - return xerrors.Errorf("getting reward state: %w", err) - } + ract, err := a.StateGetActor(ctx, builtin.RewardActorAddr, tsk) + if err != nil { + return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor: %w", err) + } - return nil - }) + pst, err := power.Load(a.StateManager.ChainStore().Store(ctx), pact) + if err != nil { + return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor state: %w", err) + } + rst, err := reward.Load(a.StateManager.ChainStore().Store(ctx), ract) if err != nil { - return api.DealCollateralBounds{}, xerrors.Errorf("getting power and reward actor states: %w", err) + return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor state: %w", err) } circ, err := a.StateCirculatingSupply(ctx, ts.Key()) @@ -1080,11 +1098,21 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w", err) } - min, max := market.DealProviderCollateralBounds(size, + powClaim, err := pst.TotalPower() + if err != nil { + return api.DealCollateralBounds{}, xerrors.Errorf("getting total power: %w", err) + } + + rewPow, err := rst.ThisEpochBaselinePower() + if err != nil { + return api.DealCollateralBounds{}, xerrors.Errorf("getting reward baseline power: %w", err) + } + + min, max := v0market.DealProviderCollateralBounds(size, verified, - powerState.TotalRawBytePower, - powerState.ThisEpochQualityAdjPower, - rewardState.ThisEpochBaselinePower, + powClaim.RawBytePower, + powClaim.QualityAdjPower, + rewPow, circ.FilCirculating, a.StateManager.GetNtwkVersion(ctx, ts.Height())) return api.DealCollateralBounds{ @@ -1109,7 +1137,7 @@ func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetK func (a *StateAPI) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { - return -1, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return network.VersionMax, xerrors.Errorf("loading tipset %s: %w", tsk, err) } return a.StateManager.GetNtwkVersion(ctx, ts.Height()), nil diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 89dd7c2c28e..5634c140b16 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -328,7 +328,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err } func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) { - return sm.StorageProvider.listDeals(ctx) + return sm.listDeals(ctx) } func (sm *StorageMinerAPI) MarketListRetrievalDeals(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 7dced43311a..8db977d2c81 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -84,7 +84,7 @@ func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr ad return mi.Worker, nil } -func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]miner.Deadline, error) { +func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]*miner.Deadline, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) @@ -251,7 +251,7 @@ func (s SealingAPIAdapter) StateMarketStorageDeal(ctx context.Context, dealID ab func (s SealingAPIAdapter) StateNetworkVersion(ctx context.Context, tok sealing.TipSetToken) (network.Version, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { - return -1, err + return network.VersionMax, err } return s.delegate.StateNetworkVersion(ctx, tsk) diff --git a/storage/addresses.go b/storage/addresses.go index bef84536733..639e996e343 100644 --- a/storage/addresses.go +++ b/storage/addresses.go @@ -3,12 +3,13 @@ package storage import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" ) @@ -27,7 +28,7 @@ type addrSelectApi interface { StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error) } -func AddressFor(ctx context.Context, a addrSelectApi, mi api.MinerInfo, use AddrUse, minFunds abi.TokenAmount) (address.Address, error) { +func AddressFor(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, use AddrUse, minFunds abi.TokenAmount) (address.Address, error) { switch use { case PreCommitAddr, CommitAddr: // always use worker, at least for now diff --git a/storage/miner.go b/storage/miner.go index 693ad7c05ff..227c51961dc 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -76,7 +76,7 @@ type storageMinerApi interface { StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) - StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]miner.Deadline, error) + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index c927a154764..112210bafb3 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -4,8 +4,6 @@ import ( "context" "time" - "github.com/filecoin-project/go-state-types/dline" - "golang.org/x/xerrors" "github.com/filecoin-project/go-address" From e6326438013bfe0c30cc1f86c04f398b3c681dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 17 Sep 2020 12:22:56 +0200 Subject: [PATCH 039/104] api: Test return types --- api/api_full.go | 2 +- api/api_test.go | 69 +++++++++++++++++++ api/apistruct/struct.go | 4 +- cli/wallet.go | 6 +- .../sector-storage/ffiwrapper/sealer_test.go | 12 ++++ node/impl/full/wallet.go | 4 +- 6 files changed, 91 insertions(+), 6 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 1adcc5c19d4..778b458a8f9 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -230,7 +230,7 @@ type FullNode interface { WalletSignMessage(context.Context, address.Address, *types.Message) (*types.SignedMessage, error) // WalletVerify takes an address, a signature, and some bytes, and indicates whether the signature is valid. // The address does not have to be in the wallet. - WalletVerify(context.Context, address.Address, []byte, *crypto.Signature) bool + WalletVerify(context.Context, address.Address, []byte, *crypto.Signature) (bool, error) // WalletDefaultAddress returns the address marked as default in the wallet. WalletDefaultAddress(context.Context) (address.Address, error) // WalletSetDefault marks the given address as as the default one. diff --git a/api/api_test.go b/api/api_test.go index 1b438258acc..06514142685 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -1,12 +1,16 @@ package api import ( + "encoding/json" "os" "os/exec" "path/filepath" + "reflect" "runtime" "strings" "testing" + + "github.com/stretchr/testify/require" ) func goCmd() string { @@ -32,3 +36,68 @@ func TestDoesntDependOnFFI(t *testing.T) { } } } + +func TestReturnTypes(t *testing.T) { + errType := reflect.TypeOf(new(error)).Elem() + bareIface := reflect.TypeOf(new(interface{})).Elem() + jmarsh := reflect.TypeOf(new(json.Marshaler)).Elem() + + tst := func(api interface{}) func(t *testing.T) { + return func(t *testing.T) { + ra := reflect.TypeOf(api).Elem() + for i := 0; i < ra.NumMethod(); i++ { + m := ra.Method(i) + switch m.Type.NumOut() { + case 1: // if 1 return value, it must be an error + require.Equal(t, errType, m.Type.Out(0), m.Name) + + case 2: // if 2 return values, first cant be an interface/function, second must be an error + seen := map[reflect.Type]struct{}{} + todo := []reflect.Type{m.Type.Out(0)} + for len(todo) > 0 { + typ := todo[len(todo) - 1] + todo = todo[:len(todo)-1] + + if _, ok := seen[typ]; ok { + continue + } + seen[typ] = struct{}{} + + if typ.Kind() == reflect.Interface && typ != bareIface && !typ.Implements(jmarsh) { + t.Error("methods can't return interfaces", m.Name) + } + + switch typ.Kind() { + case reflect.Ptr: + fallthrough + case reflect.Array: + fallthrough + case reflect.Slice: + fallthrough + case reflect.Chan: + todo = append(todo, typ.Elem()) + case reflect.Map: + todo = append(todo, typ.Elem()) + todo = append(todo, typ.Key()) + case reflect.Struct: + for i := 0; i < typ.NumField(); i++ { + todo = append(todo, typ.Field(i).Type) + } + } + } + + require.NotEqual(t, reflect.Func.String(), m.Type.Out(0).Kind().String(), m.Name) + require.Equal(t, errType, m.Type.Out(1), m.Name) + + default: + t.Error("methods can only have 1 or 2 return values", m.Name) + } + } + } + } + + t.Run("common", tst(new(Common))) + t.Run("full", tst(new(FullNode))) + t.Run("miner", tst(new(StorageMiner))) + t.Run("worker", tst(new(WorkerAPI))) +} diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ab86d78197f..c8a2b91ac00 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -134,7 +134,7 @@ type FullNodeStruct struct { WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"` WalletSign func(context.Context, address.Address, []byte) (*crypto.Signature, error) `perm:"sign"` WalletSignMessage func(context.Context, address.Address, *types.Message) (*types.SignedMessage, error) `perm:"sign"` - WalletVerify func(context.Context, address.Address, []byte, *crypto.Signature) bool `perm:"read"` + WalletVerify func(context.Context, address.Address, []byte, *crypto.Signature) (bool, error) `perm:"read"` WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"` WalletSetDefault func(context.Context, address.Address) error `perm:"admin"` WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` @@ -604,7 +604,7 @@ func (c *FullNodeStruct) WalletSignMessage(ctx context.Context, k address.Addres return c.Internal.WalletSignMessage(ctx, k, msg) } -func (c *FullNodeStruct) WalletVerify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) bool { +func (c *FullNodeStruct) WalletVerify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) (bool, error) { return c.Internal.WalletVerify(ctx, k, msg, sig) } diff --git a/cli/wallet.go b/cli/wallet.go index 4339a1fb6a4..27993a1ba3c 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -382,7 +382,11 @@ var walletVerify = &cli.Command{ return err } - if api.WalletVerify(ctx, addr, msg, &sig) { + ok, err := api.WalletVerify(ctx, addr, msg, &sig) + if err != nil { + return err + } + if ok { fmt.Println("valid") return nil } diff --git a/extern/sector-storage/ffiwrapper/sealer_test.go b/extern/sector-storage/ffiwrapper/sealer_test.go index d59de2cabc7..bb26adb77be 100644 --- a/extern/sector-storage/ffiwrapper/sealer_test.go +++ b/extern/sector-storage/ffiwrapper/sealer_test.go @@ -245,6 +245,10 @@ func TestDownloadParams(t *testing.T) { } func TestSealAndVerify(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + defer requireFDsClosed(t, openFDs(t)) if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware @@ -314,6 +318,10 @@ func TestSealAndVerify(t *testing.T) { } func TestSealPoStNoCommit(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + defer requireFDsClosed(t, openFDs(t)) if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware @@ -375,6 +383,10 @@ func TestSealPoStNoCommit(t *testing.T) { } func TestSealAndVerify3(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + defer requireFDsClosed(t, openFDs(t)) if runtime.NumCPU() < 10 && os.Getenv("CI") == "" { // don't bother on slow hardware diff --git a/node/impl/full/wallet.go b/node/impl/full/wallet.go index bda8824e70c..64231b74eb6 100644 --- a/node/impl/full/wallet.go +++ b/node/impl/full/wallet.go @@ -67,8 +67,8 @@ func (a *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, ms }, nil } -func (a *WalletAPI) WalletVerify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) bool { - return sigs.Verify(sig, k, msg) == nil +func (a *WalletAPI) WalletVerify(ctx context.Context, k address.Address, msg []byte, sig *crypto.Signature) (bool, error) { + return sigs.Verify(sig, k, msg) == nil, nil } func (a *WalletAPI) WalletDefaultAddress(ctx context.Context) (address.Address, error) { From 6eda53565f62f804b72522594b82396cb7aa2038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 17 Sep 2020 17:30:15 +0200 Subject: [PATCH 040/104] Most tests passing --- api/api_full.go | 18 ++++- api/api_test.go | 2 +- api/apistruct/struct.go | 13 ++-- api/test/window_post.go | 4 +- chain/actors/builtin/builtin.go | 2 +- chain/actors/builtin/miner/miner.go | 1 + chain/actors/builtin/miner/v0.go | 4 ++ chain/actors/builtin/reward/reward.go | 2 +- chain/events/state/predicates.go | 26 +++---- chain/messagepool/selection_test.go | 3 + chain/state/statetree_test.go | 21 +++--- chain/stmgr/stmgr.go | 6 +- chain/stmgr/utils.go | 12 +++- cli/client.go | 2 +- cmd/lotus-chainwatch/processor/market.go | 4 +- cmd/lotus-pcr/main.go | 8 +-- cmd/lotus-storage-miner/proving.go | 23 ++----- conformance/driver.go | 2 +- .../storage-sealing/precommit_policy_test.go | 6 ++ extern/storage-sealing/sealing.go | 2 +- markets/storageadapter/provider.go | 6 +- node/impl/full/state.go | 68 +++++++++++++++---- storage/adapter_storage_miner.go | 4 +- storage/miner.go | 2 +- 24 files changed, 158 insertions(+), 83 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 778b458a8f9..6454966a4b4 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -326,7 +326,9 @@ type FullNode interface { // StateMinerInfo returns info about the indicated miner StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) // StateMinerDeadlines returns all the proving deadlines for the given miner - StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]Deadline, error) + // StateMinerPartitions returns all partitions in the specified deadline + StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]Partition, error) // StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) // StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset @@ -383,7 +385,7 @@ type FullNode interface { // StateVerifiedClientStatus returns the data cap for the given address. // Returns nil if there is no entry in the data cap table for the // address. - StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) + StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) // StateDealProviderCollateralBounds returns the min and max collateral a storage provider // can issue. It takes the deal size and verified status as parameters. StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (DealCollateralBounds, error) @@ -816,6 +818,18 @@ const ( MsigCancel ) +type Deadline struct { + PostSubmissions bitfield.BitField +} + +type Partition struct { + AllSectors bitfield.BitField + FaultySectors bitfield.BitField + RecoveringSectors bitfield.BitField + LiveSectors bitfield.BitField + ActiveSectors bitfield.BitField +} + type Fault struct { Miner address.Address Epoch abi.ChainEpoch diff --git a/api/api_test.go b/api/api_test.go index 06514142685..34c47f432c5 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -55,7 +55,7 @@ func TestReturnTypes(t *testing.T) { seen := map[reflect.Type]struct{}{} todo := []reflect.Type{m.Type.Out(0)} for len(todo) > 0 { - typ := todo[len(todo) - 1] + typ := todo[len(todo)-1] todo = todo[:len(todo)-1] if _, ok := seen[typ]; ok { diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index c8a2b91ac00..397a0d60a98 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -167,7 +167,8 @@ type FullNodeStruct struct { StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` - StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) `perm:"read"` + StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) `perm:"read"` + StateMinerPartitions func(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]api.Partition, error) `perm:"read"` StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"` StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"` @@ -197,7 +198,7 @@ type FullNodeStruct struct { StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"` StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` - StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (abi.StoragePower, error) `perm:"read"` + StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*abi.StoragePower, error) `perm:"read"` StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` StateNetworkVersion func(context.Context, types.TipSetKey) (stnetwork.Version, error) `perm:"read"` @@ -752,10 +753,14 @@ func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Addre return c.Internal.StateMinerInfo(ctx, actor, tsk) } -func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { +func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]api.Deadline, error) { return c.Internal.StateMinerDeadlines(ctx, actor, tsk) } +func (c *FullNodeStruct) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]api.Partition, error) { + return c.Internal.StateMinerPartitions(ctx, m, dlIdx, tsk) +} + func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { return c.Internal.StateMinerFaults(ctx, actor, tsk) } @@ -868,7 +873,7 @@ func (c *FullNodeStruct) StateCompute(ctx context.Context, height abi.ChainEpoch return c.Internal.StateCompute(ctx, height, msgs, tsk) } -func (c *FullNodeStruct) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) { +func (c *FullNodeStruct) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) { return c.Internal.StateVerifiedClientStatus(ctx, addr, tsk) } diff --git a/api/test/window_post.go b/api/test/window_post.go index bdc39073041..e2bf5f36e92 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -200,7 +200,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.NoError(t, err) require.Greater(t, len(parts), 0) - secs, err := parts[0].AllSectors() + secs := parts[0].AllSectors require.NoError(t, err) n, err := secs.Count() require.NoError(t, err) @@ -224,7 +224,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.NoError(t, err) require.Greater(t, len(parts), 0) - secs, err := parts[0].AllSectors() + secs := parts[0].AllSectors require.NoError(t, err) n, err := secs.Count() require.NoError(t, err) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 517f0d70c44..bee8e59d6d9 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -17,7 +17,7 @@ const ( // Converts a network version into a specs-actors version. func VersionForNetwork(version network.Version) Version { switch version { - case network.Version0, network.Version1: + case network.Version0, network.Version1, network.Version2: return Version0 default: panic(fmt.Sprintf("unsupported network version %d", version)) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 725c5f2ff91..d754d0b7460 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -57,6 +57,7 @@ type State interface { type Deadline interface { LoadPartition(idx uint64) (Partition, error) ForEachPartition(cb func(idx uint64, part Partition) error) error + PostSubmissions() (bitfield.BitField, error) } type Partition interface { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index cbe42b3dae4..b3fe594d158 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -266,6 +266,10 @@ func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { }) } +func (d *v0Deadline) PostSubmissions() (bitfield.BitField, error) { + return d.Deadline.PostSubmissions, nil +} + func (p *v0Partition) AllSectors() (bitfield.BitField, error) { return p.Partition.Sectors, nil } diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 9093b33c605..52a26ab157a 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -28,7 +28,7 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { } type State interface { - cbor.Marshaler + cbor.Er RewardSmoothed() (builtin.FilterEstimate, error) EffectiveBaselinePower() (abi.StoragePower, error) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 7a76098232c..f27b5dc8f7d 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -12,11 +12,10 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors/adt" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/specs-actors/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" typegen "github.com/whyrusleeping/cbor-gen" @@ -299,12 +298,12 @@ type DiffMinerActorStateFunc func(ctx context.Context, oldState miner.State, new func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(builtin.InitActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - var oldState init_.State - if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { + oldState, err := init_.Load(adt.WrapStore(ctx, sp.cst), oldActorState) + if err != nil { return false, nil, err } - var newState init_.State - if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { + newState, err := init_.Load(adt.WrapStore(ctx, sp.cst), newActorState) + if err != nil { return false, nil, err } return diffInitActorState(ctx, &oldState, &newState) @@ -314,12 +313,12 @@ func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorSta func (sp *StatePredicates) OnMinerActorChange(minerAddr address.Address, diffMinerActorState DiffMinerActorStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(minerAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - var oldState miner.State - if err := sp.cst.Get(ctx, oldActorState.Head, &oldState); err != nil { + oldState, err := miner.Load(adt.WrapStore(ctx, sp.cst), oldActorState) + if err != nil { return false, nil, err } - var newState miner.State - if err := sp.cst.Get(ctx, newActorState.Head, &newState); err != nil { + newState, err := miner.Load(adt.WrapStore(ctx, sp.cst), newActorState) + if err != nil { return false, nil, err } return diffMinerActorState(ctx, oldState, newState) @@ -620,7 +619,7 @@ func (i *InitActorAddressChanges) Remove(key string, val *typegen.Deferred) erro func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return func(ctx context.Context, oldState, newState *init_.State) (changed bool, user UserData, err error) { - ctxStore := &contextStore{ + /*ctxStore := &contextStore{ ctx: ctx, cst: sp.cst, } @@ -653,6 +652,9 @@ func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return false, nil, nil } - return true, addressChanges, nil + return true, addressChanges, nil*/ + + panic("TODO") + return false, nil, nil } } diff --git a/chain/messagepool/selection_test.go b/chain/messagepool/selection_test.go index 5e372fc85cd..ea19dad9c0c 100644 --- a/chain/messagepool/selection_test.go +++ b/chain/messagepool/selection_test.go @@ -1216,6 +1216,9 @@ func makeZipfPremiumDistribution(rng *rand.Rand) func() uint64 { } func TestCompetitiveMessageSelectionExp(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } var capacityBoost, rewardBoost, tqReward float64 seeds := []int64{1947, 1976, 2020, 2100, 10000, 143324, 432432, 131, 32, 45} for _, seed := range seeds { diff --git a/chain/state/statetree_test.go b/chain/state/statetree_test.go index e45090d1ab1..79ab2060618 100644 --- a/chain/state/statetree_test.go +++ b/chain/state/statetree_test.go @@ -5,17 +5,20 @@ import ( "fmt" "testing" - "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" address "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/build" + builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" ) func BenchmarkStateTreeSet(b *testing.B) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { b.Fatal(err) } @@ -42,7 +45,7 @@ func BenchmarkStateTreeSet(b *testing.B) { func BenchmarkStateTreeSetFlush(b *testing.B) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { b.Fatal(err) } @@ -72,7 +75,7 @@ func BenchmarkStateTreeSetFlush(b *testing.B) { func BenchmarkStateTree10kGetActor(b *testing.B) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { b.Fatal(err) } @@ -114,7 +117,7 @@ func BenchmarkStateTree10kGetActor(b *testing.B) { func TestSetCache(t *testing.T) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { t.Fatal(err) } @@ -151,7 +154,7 @@ func TestSetCache(t *testing.T) { func TestSnapshots(t *testing.T) { ctx := context.Background() cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { t.Fatal(err) } @@ -234,7 +237,7 @@ func assertNotHas(t *testing.T, st *StateTree, addr address.Address) { func TestStateTreeConsistency(t *testing.T) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst) + st, err := NewStateTree(cst, builtin2.VersionForNetwork(build.NewestNetworkVersion)) if err != nil { t.Fatal(err) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 89ad6edd913..90154868e59 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -1024,9 +1024,9 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err return big.Zero(), xerrors.Errorf("failed to load reward actor state: %w", err) } - var rst reward.State - if err := st.Store.Get(ctx, ractor.Head, &rst); err != nil { - return big.Zero(), xerrors.Errorf("failed to load reward state: %w", err) + rst, err := reward.Load(adt.WrapStore(ctx, st.Store), ractor) + if err != nil { + return big.Zero(), err } return rst.TotalStoragePowerReward() diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 4fabefbfffa..8f39216c662 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -247,8 +247,18 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S out := make([]proof.SectorInfo, len(ids)) for i, n := range ids { + sb, err := provingSectors.Slice(n, 1) + if err != nil { + return nil, err + } + + sid, err := sb.First() + if err != nil { + return nil, err + } + var sinfo miner.SectorOnChainInfo - found, err := sectors.Get(n, &sinfo) + found, err := sectors.Get(sid, &sinfo) if err != nil { return nil, xerrors.Errorf("loading sector info: %w", err) diff --git a/cli/client.go b/cli/client.go index f6d5299431a..3339387904f 100644 --- a/cli/client.go +++ b/cli/client.go @@ -417,7 +417,7 @@ var clientDealCmd = &cli.Command{ return err } - isVerified := dcap != types.EmptyInt + isVerified := dcap != nil // If the user has explicitly set the --verified-deal flag if cctx.IsSet("verified-deal") { diff --git a/cmd/lotus-chainwatch/processor/market.go b/cmd/lotus-chainwatch/processor/market.go index a4bae4b2026..17aa1c37b4f 100644 --- a/cmd/lotus-chainwatch/processor/market.go +++ b/cmd/lotus-chainwatch/processor/market.go @@ -300,8 +300,8 @@ func (p *Processor) updateMarketActorDealProposals(ctx context.Context, marketTi } for _, modified := range changes.Modified { - if modified.From.SlashEpoch() != modified.To.SlashEpoch() { - if _, err := stmt.Exec(modified.To.SlashEpoch(), modified.ID); err != nil { + if modified.From.SlashEpoch != modified.To.SlashEpoch { + if _, err := stmt.Exec(modified.To.SlashEpoch, modified.ID); err != nil { return err } } diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index d265bdd499c..aa467e38a6e 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -417,24 +417,24 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu // We use the parent tipset key because precommit information is removed when ProveCommitSector is executed precommitChainInfo, err := r.api.StateSectorPreCommitInfo(ctx, m.To, sn, tipset.Parents()) if err != nil { - log.Warnw("failed to get precommit info for sector", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", proveCommitSector.SectorNumber) + log.Warnw("failed to get precommit info for sector", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", sn) continue } precommitTipset, err := r.api.ChainGetTipSetByHeight(ctx, precommitChainInfo.PreCommitEpoch, tipset.Key()) if err != nil { - log.Warnf("failed to lookup precommit epoch", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", proveCommitSector.SectorNumber) + log.Warnf("failed to lookup precommit epoch", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", sn) continue } collateral, err := r.api.StateMinerInitialPledgeCollateral(ctx, m.To, precommitChainInfo.Info, precommitTipset.Key()) if err != nil { - log.Warnw("failed to get initial pledge collateral", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", proveCommitSector.SectorNumber) + log.Warnw("failed to get initial pledge collateral", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", sn) } collateral = big.Sub(collateral, precommitChainInfo.PreCommitDeposit) if collateral.LessThan(big.Zero()) { - log.Debugw("skipping zero pledge collateral difference", "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", proveCommitSector.SectorNumber) + log.Debugw("skipping zero pledge collateral difference", "method", messageMethod, "cid", msg.Cid, "miner", m.To, "sector_number", sn) continue } diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index d3e2137524b..ffc0946e36a 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "fmt" "os" "text/tabwriter" @@ -73,12 +72,12 @@ var provingFaultsCmd = &cli.Command{ tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) _, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors") err = mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { - dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { faults, err := part.FaultySectors() if err != nil { return err } - faults.ForEach(func(num uint64) error { + return faults.ForEach(func(num uint64) error { _, _ = fmt.Fprintf(tw, "%d\t%d\t%d\n", dlIdx, partIdx, num) return nil }) @@ -173,6 +172,8 @@ var provingInfoCmd = &cli.Command{ } else { recovering += count } + + return nil }) }); err != nil { return xerrors.Errorf("walking miner deadlines and partitions: %w", err) @@ -250,22 +251,6 @@ var provingDeadlinesCmd = &cli.Command{ return xerrors.Errorf("getting deadlines: %w", err) } - var mas miner.State - { - mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) - if err != nil { - return err - } - miner.Load - rmas, err := api.ChainReadObj(ctx, mact.Head) - if err != nil { - return err - } - if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { - return err - } - } - fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) diff --git a/conformance/driver.go b/conformance/driver.go index a3363783713..66b6d0f8a71 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -132,7 +132,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, preroot cid.Cid, epoch BaseFee: BaseFee, } - lvm, err := vm.NewVM(vmOpts) + lvm, err := vm.NewVM(context.TODO(), vmOpts) if err != nil { return nil, cid.Undef, err } diff --git a/extern/storage-sealing/precommit_policy_test.go b/extern/storage-sealing/precommit_policy_test.go index b9c3ec49bb1..30b538a8807 100644 --- a/extern/storage-sealing/precommit_policy_test.go +++ b/extern/storage-sealing/precommit_policy_test.go @@ -2,6 +2,8 @@ package sealing_test import ( "context" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/build" "testing" "github.com/ipfs/go-cid" @@ -18,6 +20,10 @@ type fakeChain struct { h abi.ChainEpoch } +func (f *fakeChain) StateNetworkVersion(ctx context.Context, tok sealing.TipSetToken) (network.Version, error) { + return build.NewestNetworkVersion, nil +} + func (f *fakeChain) ChainHead(ctx context.Context) (sealing.TipSetToken, abi.ChainEpoch, error) { return []byte{1, 2, 3}, f.h, nil } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index e9a98fec9de..6d60e7a6e27 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -24,8 +24,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" statemachine "github.com/filecoin-project/go-statemachine" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" ) diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 90bf28b4150..04c1055df5a 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -108,7 +108,9 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema curTime := time.Now() for time.Since(curTime) < addPieceRetryTimeout { if !xerrors.Is(err, sealing.ErrTooManySectorsSealing) { - log.Errorf("failed to addPiece for deal %d, err: %w", deal.DealID, err) + if err != nil { + log.Errorf("failed to addPiece for deal %d, err: %w", deal.DealID, err) + } break } select { @@ -367,7 +369,7 @@ func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Addre } sp, err := n.StateVerifiedClientStatus(ctx, addr, tsk) - return &sp, err + return sp, err } func (n *ProviderNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID abi.DealID, onDealExpired storagemarket.DealExpiredCallback, onDealSlashed storagemarket.DealSlashedCallback) error { diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 48f9d503c81..04055043a9d 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -112,7 +112,7 @@ func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, ts return mas.Info() } -func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) { +func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]api.Deadline, error) { act, err := a.StateManager.LoadActorTsk(ctx, m, tsk) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -128,9 +128,16 @@ func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, t return nil, xerrors.Errorf("getting deadline count: %w", err) } - out := make([]*miner.Deadline, deadlines) + out := make([]api.Deadline, deadlines) if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error { - out[i] = &dl + ps, err := dl.PostSubmissions() + if err != nil { + return err + } + + out[i] = api.Deadline{ + PostSubmissions: ps, + } return nil }); err != nil { return nil, err @@ -138,7 +145,7 @@ func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, t return out, nil } -func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]*miner.Partition, error) { +func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]api.Partition, error) { act, err := a.StateManager.LoadActorTsk(ctx, m, tsk) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -154,10 +161,40 @@ func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, return nil, xerrors.Errorf("failed to load the deadline: %w", err) } - var out []*miner.Partition + var out []api.Partition err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { - p := part - out = append(out, &p) + allSectors, err := part.AllSectors() + if err != nil { + return xerrors.Errorf("getting AllSectors: %w", err) + } + + faultySectors, err := part.FaultySectors() + if err != nil { + return xerrors.Errorf("getting FaultySectors: %w", err) + } + + recoveringSectors, err := part.RecoveringSectors() + if err != nil { + return xerrors.Errorf("getting RecoveringSectors: %w", err) + } + + liveSectors, err := part.LiveSectors() + if err != nil { + return xerrors.Errorf("getting LiveSectors: %w", err) + } + + activeSectors, err := part.ActiveSectors() + if err != nil { + return xerrors.Errorf("getting ActiveSectors: %w", err) + } + + out = append(out, api.Partition{ + AllSectors: allSectors, + FaultySectors: faultySectors, + RecoveringSectors: recoveringSectors, + LiveSectors: liveSectors, + ActiveSectors: activeSectors, + }) return nil }) @@ -1037,29 +1074,32 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address // StateVerifiedClientStatus returns the data cap for the given address. // Returns zero if there is no entry in the data cap table for the // address. -func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) { +func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) { act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) if err != nil { - return types.EmptyInt, err + return nil, err } aid, err := a.StateLookupID(ctx, addr, tsk) if err != nil { log.Warnf("lookup failure %v", err) - return types.EmptyInt, err + return nil, err } vrs, err := verifreg.Load(a.StateManager.ChainStore().Store(ctx), act) if err != nil { - return types.EmptyInt, xerrors.Errorf("failed to load verified registry state: %w", err) + return nil, xerrors.Errorf("failed to load verified registry state: %w", err) } - _, dcap, err := vrs.VerifiedClientDataCap(aid) + verified, dcap, err := vrs.VerifiedClientDataCap(aid) if err != nil { - return types.EmptyInt, xerrors.Errorf("looking up verified client: %w", err) + return nil, xerrors.Errorf("looking up verified client: %w", err) + } + if !verified { + return nil, nil } - return dcap, nil + return &dcap, nil } var dealProviderCollateralNum = types.NewInt(110) diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 8db977d2c81..efbd9581792 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -84,7 +84,7 @@ func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr ad return mi.Worker, nil } -func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]*miner.Deadline, error) { +func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]api.Deadline, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) @@ -190,7 +190,7 @@ func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr a if err != nil { return nil, err } - if pci != nil { + if pci == nil { set, err := state.IsAllocated(sectorNumber) if err != nil { return nil, xerrors.Errorf("checking if sector is allocated: %w", err) diff --git a/storage/miner.go b/storage/miner.go index 227c51961dc..d7780898d57 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -76,7 +76,7 @@ type storageMinerApi interface { StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) - StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) + StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) From 68e884ee441f2ea3b02103536c0947788630612c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 17 Sep 2020 17:31:09 +0200 Subject: [PATCH 041/104] docsgen --- api/docgen/docgen.go | 1 + documentation/en/api-methods.md | 35 ++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index d00643a02d1..ced536cc3cb 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -114,6 +114,7 @@ func init() { addExample(retrievalmarket.ClientEventDealAccepted) addExample(retrievalmarket.DealStatusNew) addExample(network.ReachabilityPublic) + addExample(build.NewestNetworkVersion) addExample(&types.ExecutionTrace{ Msg: exampleValue(reflect.TypeOf(&types.Message{}), nil).(*types.Message), MsgRct: exampleValue(reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt), diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 27875eca1af..364a0f1be22 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -149,6 +149,7 @@ * [StateMinerSectorCount](#StateMinerSectorCount) * [StateMinerSectors](#StateMinerSectors) * [StateNetworkName](#StateNetworkName) + * [StateNetworkVersion](#StateNetworkVersion) * [StateReadState](#StateReadState) * [StateReplay](#StateReplay) * [StateSearchMsg](#StateSearchMsg) @@ -211,7 +212,7 @@ Response: ```json { "Version": "string value", - "APIVersion": 3584, + "APIVersion": 3840, "BlockDelay": 42 } ``` @@ -3509,7 +3510,7 @@ Inputs: Response: `"0"` ### StateMinerPartitions -StateMinerPartitions loads miner partitions for the specified miner/deadline +StateMinerPartitions returns all partitions in the specified deadline Perms: read @@ -3563,7 +3564,8 @@ Response: "TotalPower": { "RawBytePower": "0", "QualityAdjPower": "0" - } + }, + "HasMinPower": true } ``` @@ -3697,8 +3699,9 @@ Inputs: Response: ```json { - "Sectors": 42, - "Active": 42 + "Live": 42, + "Active": 42, + "Faulty": 42 } ``` @@ -3741,6 +3744,28 @@ Inputs: `null` Response: `"lotus"` +### StateNetworkVersion +StateNetworkVersion returns the network version at the given tipset + + +Perms: read + +Inputs: +```json +[ + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: `2` + ### StateReadState StateReadState returns the indicated actor's state. From 82b95e34b790d300c273ce765fdd4f3704f610cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 17 Sep 2020 17:37:16 +0200 Subject: [PATCH 042/104] cbor gen --- chain/exchange/cbor_gen.go | 12 +-- chain/types/cbor_gen.go | 128 +++++++++++++++++++++++++ lotuspond/front/src/chain/methods.json | 3 +- 3 files changed, 136 insertions(+), 7 deletions(-) diff --git a/chain/exchange/cbor_gen.go b/chain/exchange/cbor_gen.go index dc91babe3c7..29b2580813a 100644 --- a/chain/exchange/cbor_gen.go +++ b/chain/exchange/cbor_gen.go @@ -146,7 +146,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error { scratch := make([]byte, 9) - // t.Status (blocksync.status) (uint64) + // t.Status (exchange.status) (uint64) if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { return err @@ -164,7 +164,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error { return err } - // t.Chain ([]*blocksync.BSTipSet) (slice) + // t.Chain ([]*exchange.BSTipSet) (slice) if len(t.Chain) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Chain was too long") } @@ -198,7 +198,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input had wrong number of fields") } - // t.Status (blocksync.status) (uint64) + // t.Status (exchange.status) (uint64) { @@ -222,7 +222,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { t.ErrorMessage = string(sval) } - // t.Chain ([]*blocksync.BSTipSet) (slice) + // t.Chain ([]*exchange.BSTipSet) (slice) maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { @@ -567,7 +567,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { } } - // t.Messages (blocksync.CompactedMessages) (struct) + // t.Messages (exchange.CompactedMessages) (struct) if err := t.Messages.MarshalCBOR(w); err != nil { return err } @@ -621,7 +621,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { t.Blocks[i] = &v } - // t.Messages (blocksync.CompactedMessages) (struct) + // t.Messages (exchange.CompactedMessages) (struct) { diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index 676ae7054c0..f95df33bced 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -1634,3 +1634,131 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { } return nil } + +var lengthBufStateRoot = []byte{131} + +func (t *StateRoot) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufStateRoot); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.Version (uint64) (uint64) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Version)); err != nil { + return err + } + + // t.Actors (cid.Cid) (struct) + + if err := cbg.WriteCidBuf(scratch, w, t.Actors); err != nil { + return xerrors.Errorf("failed to write cid field t.Actors: %w", err) + } + + // t.Info (cid.Cid) (struct) + + if err := cbg.WriteCidBuf(scratch, w, t.Info); err != nil { + return xerrors.Errorf("failed to write cid field t.Info: %w", err) + } + + return nil +} + +func (t *StateRoot) UnmarshalCBOR(r io.Reader) error { + *t = StateRoot{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 3 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.Version (uint64) (uint64) + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Version = uint64(extra) + + } + // t.Actors (cid.Cid) (struct) + + { + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.Actors: %w", err) + } + + t.Actors = c + + } + // t.Info (cid.Cid) (struct) + + { + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.Info: %w", err) + } + + t.Info = c + + } + return nil +} + +var lengthBufStateInfo = []byte{128} + +func (t *StateInfo) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufStateInfo); err != nil { + return err + } + + return nil +} + +func (t *StateInfo) UnmarshalCBOR(r io.Reader) error { + *t = StateInfo{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 0 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + return nil +} diff --git a/lotuspond/front/src/chain/methods.json b/lotuspond/front/src/chain/methods.json index ad1076c8498..ce4919cc489 100644 --- a/lotuspond/front/src/chain/methods.json +++ b/lotuspond/front/src/chain/methods.json @@ -23,7 +23,8 @@ "AddSigner", "RemoveSigner", "SwapSigner", - "ChangeNumApprovalsThreshold" + "ChangeNumApprovalsThreshold", + "LockBalance" ], "fil/1/paymentchannel": [ "Send", From c40c1361f0307f888d3812d78aff70883aa550c4 Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Thu, 17 Sep 2020 18:14:07 +0200 Subject: [PATCH 043/104] fix: paych To() --- chain/actors/builtin/paych/v0.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go index 16a65bc9bf1..7d63b891315 100644 --- a/chain/actors/builtin/paych/v0.go +++ b/chain/actors/builtin/paych/v0.go @@ -22,7 +22,7 @@ func (s *v0State) From() address.Address { // Recipient of payouts from channel func (s *v0State) To() address.Address { - return s.State.From + return s.State.To } // Height at which the channel can be `Collected` From 18bc59b93befe07fa4fe9f76652616f743c71fa2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 13:52:16 -0700 Subject: [PATCH 044/104] uncruft --- api/types.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/types.go b/api/types.go index 53c0fe203d1..a69aa28d99e 100644 --- a/api/types.go +++ b/api/types.go @@ -107,5 +107,3 @@ func NewDataTransferChannel(hostID peer.ID, channelState datatransfer.ChannelSta } return channel } - -// type TODO (stebalien): this was here, why was this here? From 708aa368e1d6867647c2424fc4b1290ce3226d81 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 13:53:18 -0700 Subject: [PATCH 045/104] remove dep on v0 miner --- api/test/window_post.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index e2bf5f36e92..6b41ba6c63f 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -9,8 +9,6 @@ import ( lotusminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" cbor "github.com/ipfs/go-ipld-cbor" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "os" "strings" "testing" @@ -165,7 +163,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(v0miner.WPoStProvingPeriod)+2 { + if head.Height() > di.PeriodStart+(di.WPoStProvingPeriod)+2 { break } From ae38970526b3ea65713333a74ae89f0697ef7e90 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 14:53:57 -0700 Subject: [PATCH 046/104] remove WpostProvignPeriod function --- api/test/window_post.go | 17 ++--------------- chain/actors/builtin/miner/miner.go | 1 - chain/actors/builtin/miner/v0.go | 3 --- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 6b41ba6c63f..683489a9158 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -4,11 +4,6 @@ import ( "context" "fmt" - "github.com/filecoin-project/lotus/api/apibstore" - "github.com/filecoin-project/lotus/chain/actors/adt" - lotusminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - cbor "github.com/ipfs/go-ipld-cbor" - "os" "strings" "testing" @@ -182,14 +177,6 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*uint64(nSectors+GenesisPreseals))) - store := cbor.NewCborStore(apibstore.NewAPIBlockstore(client)) - - mact, err := client.StateGetActor(ctx, maddr, types.EmptyTSK) - require.NoError(t, err) - - minState, err := lotusminer.Load(adt.WrapStore(ctx, store), mact) - require.NoError(t, err) - fmt.Printf("Drop some sectors\n") // Drop 2 sectors from deadline 2 partition 0 (full partition / deadline) @@ -254,7 +241,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(minState.WpostProvingPeriod())+2 { + if head.Height() > di.PeriodStart+(di.WPoStProvingPeriod)+2 { break } @@ -284,7 +271,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(minState.WpostProvingPeriod())+2 { + if head.Height() > di.PeriodStart+di.WPoStProvingPeriod+2 { break } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index d754d0b7460..cb34dd55716 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -51,7 +51,6 @@ type State interface { Info() (MinerInfo, error) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info - WpostProvingPeriod() abi.ChainEpoch } type Deadline interface { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index b3fe594d158..74812e85a09 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -243,9 +243,6 @@ func (s *v0State) Info() (MinerInfo, error) { func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { return s.State.DeadlineInfo(epoch) } -func (s *v0State) WpostProvingPeriod() abi.ChainEpoch { - return v0miner.WPoStProvingPeriod -} func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) From dc58f71604b6dbf63c21da966a2d4e146b36abeb Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 14:59:10 -0700 Subject: [PATCH 047/104] remove unnecessary code Go does have some nice features, once in a while. --- chain/actors/builtin/market/v0.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 92ebb59bacd..d2e77fa9260 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -184,11 +184,7 @@ func (d *v0MarketStatesDiffer) Remove(key uint64, val *typegen.Deferred) error { } func fromV0DealState(v0 market.DealState) DealState { - return DealState{ - SectorStartEpoch: v0.SectorStartEpoch, - SlashEpoch: v0.SlashEpoch, - LastUpdatedEpoch: v0.LastUpdatedEpoch, - } + return (DealState)(v0) } type v0DealProposals struct { @@ -234,19 +230,7 @@ type v0MarketProposalsDiffer struct { } func fromV0DealProposal(v0 market.DealProposal) DealProposal { - return DealProposal{ - PieceCID: v0.PieceCID, - PieceSize: v0.PieceSize, - VerifiedDeal: v0.VerifiedDeal, - Client: v0.Client, - Provider: v0.Provider, - Label: v0.Label, - StartEpoch: v0.StartEpoch, - EndEpoch: v0.EndEpoch, - StoragePricePerEpoch: v0.StoragePricePerEpoch, - ProviderCollateral: v0.ProviderCollateral, - ClientCollateral: v0.ClientCollateral, - } + return (DealProposal)(v0) } func (d *v0MarketProposalsDiffer) Add(key uint64, val *typegen.Deferred) error { From 5bcfee00425c28988db1ef95c5633788bde7dea1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 16:08:54 -0700 Subject: [PATCH 048/104] make market diffs work across version upgrades --- chain/actors/builtin/market/market.go | 7 ++ chain/actors/builtin/market/util.go | 91 +++++++++++++++++++++ chain/actors/builtin/market/v0.go | 110 +++++--------------------- 3 files changed, 119 insertions(+), 89 deletions(-) create mode 100644 chain/actors/builtin/market/util.go diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 73c2528d0a5..1c11c027e74 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -51,12 +52,18 @@ type BalanceTable interface { type DealStates interface { Get(id abi.DealID) (*DealState, bool, error) Diff(DealStates) (*DealStateChanges, error) + + array() adt.Array + decode(*cbg.Deferred) (*DealState, error) } type DealProposals interface { ForEach(cb func(id abi.DealID, dp DealProposal) error) error Get(id abi.DealID) (*DealProposal, bool, error) Diff(DealProposals) (*DealProposalChanges, error) + + array() adt.Array + decode(*cbg.Deferred) (*DealProposal, error) } type DealState struct { diff --git a/chain/actors/builtin/market/util.go b/chain/actors/builtin/market/util.go new file mode 100644 index 00000000000..92fdd682301 --- /dev/null +++ b/chain/actors/builtin/market/util.go @@ -0,0 +1,91 @@ +package market + +import ( + "fmt" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/adt" + cbg "github.com/whyrusleeping/cbor-gen" +) + +func diffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) { + results := new(DealProposalChanges) + if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketProposalsDiffer{results, pre, cur}); err != nil { + return nil, fmt.Errorf("diffing deal states: %w", err) + } + return results, nil +} + +type marketProposalsDiffer struct { + Results *DealProposalChanges + pre, cur DealProposals +} + +func (d *marketProposalsDiffer) Add(key uint64, val *cbg.Deferred) error { + dp, err := d.cur.decode(val) + if err != nil { + return err + } + d.Results.Added = append(d.Results.Added, ProposalIDState{abi.DealID(key), *dp}) + return nil +} + +func (d *marketProposalsDiffer) Modify(key uint64, from, to *cbg.Deferred) error { + // short circuit, DealProposals are static + return nil +} + +func (d *marketProposalsDiffer) Remove(key uint64, val *cbg.Deferred) error { + dp, err := d.pre.decode(val) + if err != nil { + return err + } + d.Results.Removed = append(d.Results.Removed, ProposalIDState{abi.DealID(key), *dp}) + return nil +} + +func diffDealStates(pre, cur DealStates) (*DealStateChanges, error) { + results := new(DealStateChanges) + if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketStatesDiffer{results, pre, cur}); err != nil { + return nil, fmt.Errorf("diffing deal states: %w", err) + } + return results, nil +} + +type marketStatesDiffer struct { + Results *DealStateChanges + pre, cur DealStates +} + +func (d *marketStatesDiffer) Add(key uint64, val *cbg.Deferred) error { + ds, err := d.cur.decode(val) + if err != nil { + return err + } + d.Results.Added = append(d.Results.Added, DealIDState{abi.DealID(key), *ds}) + return nil +} + +func (d *marketStatesDiffer) Modify(key uint64, from, to *cbg.Deferred) error { + dsFrom, err := d.pre.decode(from) + if err != nil { + return err + } + dsTo, err := d.cur.decode(to) + if err != nil { + return err + } + if *dsFrom != *dsTo { + d.Results.Modified = append(d.Results.Modified, DealStateChange{abi.DealID(key), dsFrom, dsTo}) + } + return nil +} + +func (d *marketStatesDiffer) Remove(key uint64, val *cbg.Deferred) error { + ds, err := d.pre.decode(val) + if err != nil { + return err + } + d.Results.Removed = append(d.Results.Removed, DealIDState{abi.DealID(key), *ds}) + return nil +} diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index d2e77fa9260..58744674971 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -2,8 +2,6 @@ package market import ( "bytes" - "errors" - "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -11,7 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/market" v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" - typegen "github.com/whyrusleeping/cbor-gen" + cbg "github.com/whyrusleeping/cbor-gen" ) type v0State struct { @@ -127,60 +125,20 @@ func (s *v0DealStates) Get(dealID abi.DealID) (*DealState, bool, error) { } func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) { - v0other, ok := other.(*v0DealStates) - if !ok { - // TODO handle this if possible on a case by case basis but for now, just fail - return nil, errors.New("cannot compare deal states across versions") - } - results := new(DealStateChanges) - if err := adt.DiffAdtArray(s.Array, v0other.Array, &v0MarketStatesDiffer{results}); err != nil { - return nil, fmt.Errorf("diffing deal states: %w", err) - } - - return results, nil + return diffDealStates(s, other) } -type v0MarketStatesDiffer struct { - Results *DealStateChanges -} - -func (d *v0MarketStatesDiffer) Add(key uint64, val *typegen.Deferred) error { - v0ds := new(market.DealState) - err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - d.Results.Added = append(d.Results.Added, DealIDState{abi.DealID(key), fromV0DealState(*v0ds)}) - return nil -} - -func (d *v0MarketStatesDiffer) Modify(key uint64, from, to *typegen.Deferred) error { - v0dsFrom := new(market.DealState) - if err := v0dsFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)); err != nil { - return err - } - - v0dsTo := new(market.DealState) - if err := v0dsTo.UnmarshalCBOR(bytes.NewReader(to.Raw)); err != nil { - return err - } - - if *v0dsFrom != *v0dsTo { - dsFrom := fromV0DealState(*v0dsFrom) - dsTo := fromV0DealState(*v0dsTo) - d.Results.Modified = append(d.Results.Modified, DealStateChange{abi.DealID(key), &dsFrom, &dsTo}) +func (s *v0DealStates) decode(val *cbg.Deferred) (*DealState, error) { + var v0ds market.DealState + if err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err } - return nil + ds := fromV0DealState(v0ds) + return &ds, nil } -func (d *v0MarketStatesDiffer) Remove(key uint64, val *typegen.Deferred) error { - v0ds := new(market.DealState) - err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - d.Results.Removed = append(d.Results.Removed, DealIDState{abi.DealID(key), fromV0DealState(*v0ds)}) - return nil +func (s *v0DealStates) array() adt.Array { + return s.Array } func fromV0DealState(v0 market.DealState) DealState { @@ -192,17 +150,7 @@ type v0DealProposals struct { } func (s *v0DealProposals) Diff(other DealProposals) (*DealProposalChanges, error) { - v0other, ok := other.(*v0DealProposals) - if !ok { - // TODO handle this if possible on a case by case basis but for now, just fail - return nil, errors.New("cannot compare deal proposals across versions") - } - results := new(DealProposalChanges) - if err := adt.DiffAdtArray(s.Array, v0other.Array, &v0MarketProposalsDiffer{results}); err != nil { - return nil, fmt.Errorf("diffing deal proposals: %w", err) - } - - return results, nil + return diffDealProposals(s, other) } func (s *v0DealProposals) Get(dealID abi.DealID) (*DealProposal, bool, error) { @@ -225,35 +173,19 @@ func (s *v0DealProposals) ForEach(cb func(dealID abi.DealID, dp DealProposal) er }) } -type v0MarketProposalsDiffer struct { - Results *DealProposalChanges -} - -func fromV0DealProposal(v0 market.DealProposal) DealProposal { - return (DealProposal)(v0) -} - -func (d *v0MarketProposalsDiffer) Add(key uint64, val *typegen.Deferred) error { - v0dp := new(market.DealProposal) - err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err +func (s *v0DealProposals) decode(val *cbg.Deferred) (*DealProposal, error) { + var v0dp market.DealProposal + if err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err } - d.Results.Added = append(d.Results.Added, ProposalIDState{abi.DealID(key), fromV0DealProposal(*v0dp)}) - return nil + dp := fromV0DealProposal(v0dp) + return &dp, nil } -func (d *v0MarketProposalsDiffer) Modify(key uint64, from, to *typegen.Deferred) error { - // short circuit, DealProposals are static - return nil +func (s *v0DealProposals) array() adt.Array { + return s.Array } -func (d *v0MarketProposalsDiffer) Remove(key uint64, val *typegen.Deferred) error { - v0dp := new(market.DealProposal) - err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - d.Results.Removed = append(d.Results.Removed, ProposalIDState{abi.DealID(key), fromV0DealProposal(*v0dp)}) - return nil +func fromV0DealProposal(v0 market.DealProposal) DealProposal { + return (DealProposal)(v0) } From b2ee59024f935721f6f277f8ae381afb05a70d91 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 21:39:34 -0700 Subject: [PATCH 049/104] improve diff logic * Make diffing work across versions. * Start porting more chainwatch logic. --- chain/actors/builtin/miner/diff.go | 127 ++++++++++ chain/actors/builtin/miner/miner.go | 28 ++- chain/actors/builtin/miner/v0.go | 41 +++ chain/events/state/predicates.go | 128 +--------- chain/events/state/predicates_test.go | 4 +- cmd/lotus-chainwatch/processor/miner.go | 317 ++++++++++++------------ 6 files changed, 361 insertions(+), 284 deletions(-) create mode 100644 chain/actors/builtin/miner/diff.go diff --git a/chain/actors/builtin/miner/diff.go b/chain/actors/builtin/miner/diff.go new file mode 100644 index 00000000000..dde4db89002 --- /dev/null +++ b/chain/actors/builtin/miner/diff.go @@ -0,0 +1,127 @@ +package miner + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/adt" + cbg "github.com/whyrusleeping/cbor-gen" +) + +func DiffPreCommits(pre, cur State) (*PreCommitChanges, error) { + results := new(PreCommitChanges) + + prep, err := pre.precommits() + if err != nil { + return nil, err + } + + curp, err := cur.precommits() + if err != nil { + return nil, err + } + + err = adt.DiffAdtMap(prep, curp, &preCommitDiffer{results, pre, cur}) + if err != nil { + return nil, err + } + + return results, nil +} + +type preCommitDiffer struct { + Results *PreCommitChanges + pre, after State +} + +func (m *preCommitDiffer) AsKey(key string) (abi.Keyer, error) { + sector, err := abi.ParseUIntKey(key) + if err != nil { + return nil, err + } + return abi.UIntKey(sector), nil +} + +func (m *preCommitDiffer) Add(key string, val *cbg.Deferred) error { + sp, err := m.after.decodeSectorPreCommitOnChainInfo(val) + if err != nil { + return err + } + m.Results.Added = append(m.Results.Added, sp) + return nil +} + +func (m *preCommitDiffer) Modify(key string, from, to *cbg.Deferred) error { + return nil +} + +func (m *preCommitDiffer) Remove(key string, val *cbg.Deferred) error { + sp, err := m.pre.decodeSectorPreCommitOnChainInfo(val) + if err != nil { + return err + } + m.Results.Removed = append(m.Results.Removed, sp) + return nil +} + +func DiffSectors(pre, cur State) (*SectorChanges, error) { + results := new(SectorChanges) + + pres, err := pre.sectors() + if err != nil { + return nil, err + } + + curs, err := cur.sectors() + if err != nil { + return nil, err + } + + err = adt.DiffAdtArray(pres, curs, §orDiffer{results, pre, cur}) + if err != nil { + return nil, err + } + + return results, nil +} + +type sectorDiffer struct { + Results *SectorChanges + pre, after State +} + +func (m *sectorDiffer) Add(key uint64, val *cbg.Deferred) error { + si, err := m.after.decodeSectorOnChainInfo(val) + if err != nil { + return err + } + m.Results.Added = append(m.Results.Added, si) + return nil +} + +func (m *sectorDiffer) Modify(key uint64, from, to *cbg.Deferred) error { + siFrom, err := m.pre.decodeSectorOnChainInfo(from) + if err != nil { + return err + } + + siTo, err := m.after.decodeSectorOnChainInfo(to) + if err != nil { + return err + } + + if siFrom.Expiration != siTo.Expiration { + m.Results.Extended = append(m.Results.Extended, SectorExtensions{ + From: siFrom, + To: siTo, + }) + } + return nil +} + +func (m *sectorDiffer) Remove(key uint64, val *cbg.Deferred) error { + si, err := m.pre.decodeSectorOnChainInfo(val) + if err != nil { + return err + } + m.Results.Removed = append(m.Results.Removed, si) + return nil +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index cb34dd55716..793c4badcf7 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -3,6 +3,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/dline" "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -42,21 +43,30 @@ type State interface { GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) - LoadPreCommittedSectors() (adt.Map, error) IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) + DeadlinesChanged(State) bool + Info() (MinerInfo, error) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info + + // Diff helpers. Used by Diff* functions internally. + sectors() (adt.Array, error) + decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) + precommits() (adt.Map, error) + decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) } type Deadline interface { LoadPartition(idx uint64) (Partition, error) ForEachPartition(cb func(idx uint64, part Partition) error) error PostSubmissions() (bitfield.BitField, error) + + PartitionsChanged(Deadline) bool } type Partition interface { @@ -110,3 +120,19 @@ type SectorLocation struct { Deadline uint64 Partition uint64 } + +type SectorChanges struct { + Added []SectorOnChainInfo + Extended []SectorExtensions + Removed []SectorOnChainInfo +} + +type SectorExtensions struct { + From SectorOnChainInfo + To SectorOnChainInfo +} + +type PreCommitChanges struct { + Added []SectorPreCommitOnChainInfo + Removed []SectorPreCommitOnChainInfo +} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 74812e85a09..9f4cea6ce3b 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -1,6 +1,7 @@ package miner import ( + "bytes" "errors" "github.com/filecoin-project/go-address" @@ -206,6 +207,16 @@ func (s *v0State) NumDeadlines() (uint64, error) { return v0miner.WPoStPeriodDeadlines, nil } +func (s *v0State) DeadlinesChanged(other State) bool { + v0other, ok := other.(*v0State) + if !ok { + // treat an upgrade as a change, always + return true + } + + return s.State.Deadlines.Equals(v0other.Deadlines) +} + func (s *v0State) Info() (MinerInfo, error) { info, err := s.State.GetInfo(s.store) if err != nil { @@ -244,6 +255,26 @@ func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { return s.State.DeadlineInfo(epoch) } +func (s *v0State) sectors() (adt.Array, error) { + return v0adt.AsArray(s.store, s.Sectors) +} + +func (s *v0State) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si v0miner.SectorOnChainInfo + err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) + return si, err +} + +func (s *v0State) precommits() (adt.Map, error) { + return v0adt.AsMap(s.store, s.PreCommittedSectors) +} + +func (s *v0State) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { + var sp v0miner.SectorPreCommitOnChainInfo + err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + return sp, err +} + func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -263,6 +294,16 @@ func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { }) } +func (s *v0Deadline) PartitionsChanged(other Deadline) bool { + v0other, ok := other.(*v0Deadline) + if !ok { + // treat an upgrade as a change, always + return true + } + + return s.Deadline.Partitions.Equals(v0other.Deadline.Partitions) +} + func (d *v0Deadline) PostSubmissions() (bitfield.BitField, error) { return d.Deadline.PostSubmissions, nil } diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index f27b5dc8f7d..721de9dd2d9 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -4,8 +4,6 @@ import ( "bytes" "context" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/go-address" @@ -325,83 +323,12 @@ func (sp *StatePredicates) OnMinerActorChange(minerAddr address.Address, diffMin }) } -type MinerSectorChanges struct { - Added []miner.SectorOnChainInfo - Extended []SectorExtensions - Removed []miner.SectorOnChainInfo -} - -var _ adt.AdtArrayDiff = &MinerSectorChanges{} - -type SectorExtensions struct { - From miner.SectorOnChainInfo - To miner.SectorOnChainInfo -} - -func (m *MinerSectorChanges) Add(key uint64, val *typegen.Deferred) error { - si := new(miner.SectorOnChainInfo) - err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Added = append(m.Added, *si) - return nil -} - -func (m *MinerSectorChanges) Modify(key uint64, from, to *typegen.Deferred) error { - siFrom := new(miner.SectorOnChainInfo) - err := siFrom.UnmarshalCBOR(bytes.NewReader(from.Raw)) - if err != nil { - return err - } - - siTo := new(miner.SectorOnChainInfo) - err = siTo.UnmarshalCBOR(bytes.NewReader(to.Raw)) - if err != nil { - return err - } - - if siFrom.Expiration != siTo.Expiration { - m.Extended = append(m.Extended, SectorExtensions{ - From: *siFrom, - To: *siTo, - }) - } - return nil -} - -func (m *MinerSectorChanges) Remove(key uint64, val *typegen.Deferred) error { - si := new(miner.SectorOnChainInfo) - err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Removed = append(m.Removed, *si) - return nil -} - func (sp *StatePredicates) OnMinerSectorChange() DiffMinerActorStateFunc { return func(ctx context.Context, oldState, newState miner.State) (changed bool, user UserData, err error) { - sectorChanges := &MinerSectorChanges{ - Added: []miner.SectorOnChainInfo{}, - Extended: []SectorExtensions{}, - Removed: []miner.SectorOnChainInfo{}, - } - - oldSectors, err := oldState.LoadSectorsFromSet(nil, false) - if err != nil { - return false, nil, err - } - - newSectors, err := newState.LoadSectorsFromSet(nil, false) + sectorChanges, err := miner.DiffSectors(oldState, newState) if err != nil { return false, nil, err } - - if err := adt.DiffAdtArray(oldSectors, newSectors, sectorChanges); err != nil { - return false, nil, err - } - // nothing changed if len(sectorChanges.Added)+len(sectorChanges.Extended)+len(sectorChanges.Removed) == 0 { return false, nil, nil @@ -411,64 +338,13 @@ func (sp *StatePredicates) OnMinerSectorChange() DiffMinerActorStateFunc { } } -type MinerPreCommitChanges struct { - Added []miner.SectorPreCommitOnChainInfo - Removed []miner.SectorPreCommitOnChainInfo -} - -func (m *MinerPreCommitChanges) AsKey(key string) (abi.Keyer, error) { - sector, err := abi.ParseUIntKey(key) - if err != nil { - return nil, err - } - return v0miner.SectorKey(abi.SectorNumber(sector)), nil -} - -func (m *MinerPreCommitChanges) Add(key string, val *typegen.Deferred) error { - sp := new(miner.SectorPreCommitOnChainInfo) - err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Added = append(m.Added, *sp) - return nil -} - -func (m *MinerPreCommitChanges) Modify(key string, from, to *typegen.Deferred) error { - return nil -} - -func (m *MinerPreCommitChanges) Remove(key string, val *typegen.Deferred) error { - sp := new(miner.SectorPreCommitOnChainInfo) - err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - if err != nil { - return err - } - m.Removed = append(m.Removed, *sp) - return nil -} - func (sp *StatePredicates) OnMinerPreCommitChange() DiffMinerActorStateFunc { return func(ctx context.Context, oldState, newState miner.State) (changed bool, user UserData, err error) { - precommitChanges := &MinerPreCommitChanges{ - Added: []miner.SectorPreCommitOnChainInfo{}, - Removed: []miner.SectorPreCommitOnChainInfo{}, - } - - oldPrecommits, err := oldState.LoadPreCommittedSectors() - if err != nil { - return false, nil, err - } - - newPrecommits, err := newState.LoadPreCommittedSectors() + precommitChanges, err := miner.DiffPreCommits(oldState, newState) if err != nil { return false, nil, err } - if err := adt.DiffAdtMap(oldPrecommits, newPrecommits, precommitChanges); err != nil { - return false, nil, err - } - if len(precommitChanges.Added)+len(precommitChanges.Removed) == 0 { return false, nil, nil } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 6541aa3b416..243d8814e32 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -409,7 +409,7 @@ func TestMinerSectorChange(t *testing.T) { require.True(t, change) require.NotNil(t, val) - sectorChanges, ok := val.(*MinerSectorChanges) + sectorChanges, ok := val.(*miner.SectorChanges) require.True(t, ok) require.Equal(t, len(sectorChanges.Added), 1) @@ -433,7 +433,7 @@ func TestMinerSectorChange(t *testing.T) { require.True(t, change) require.NotNil(t, val) - sectorChanges, ok = val.(*MinerSectorChanges) + sectorChanges, ok = val.(*miner.SectorChanges) require.True(t, ok) require.Equal(t, 1, len(sectorChanges.Added)) diff --git a/cmd/lotus-chainwatch/processor/miner.go b/cmd/lotus-chainwatch/processor/miner.go index 71d88192753..1fd2a119f45 100644 --- a/cmd/lotus-chainwatch/processor/miner.go +++ b/cmd/lotus-chainwatch/processor/miner.go @@ -16,12 +16,14 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/apibstore" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events/state" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util" ) @@ -204,6 +206,8 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe log.Debugw("Processed Miners", "duration", time.Since(start).String()) }() + stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(p.node)) + var out []minerActorInfo // TODO add parallel calls if this becomes slow for tipset, miners := range minerTips { @@ -230,15 +234,13 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe mi.rawPower = claim.RawBytePower } - // Get the miner state info - astb, err := p.node.ChainReadObj(ctx, act.act.Head) + // Get the miner state + mas, err := miner.Load(stor, &act.act) if err != nil { log.Warnw("failed to find miner actor state", "address", act.addr, "error", err) continue } - if err := mi.state.UnmarshalCBOR(bytes.NewReader(astb)); err != nil { - return nil, err - } + mi.state = mas out = append(out, mi) } } @@ -322,11 +324,6 @@ func (p *Processor) storeMinerPreCommitInfo(ctx context.Context, miners []minerA for _, m := range miners { m := m grp.Go(func() error { - minerSectors, err := adt.AsArray(p.ctxStore, m.state.Sectors) - if err != nil { - return err - } - changes, err := p.getMinerPreCommitChanges(ctx, m) if err != nil { if strings.Contains(err.Error(), types.ErrActorNotFound.Error()) { @@ -399,10 +396,12 @@ func (p *Processor) storeMinerPreCommitInfo(ctx context.Context, miners []minerA } var preCommitExpired []uint64 for _, removed := range changes.Removed { - var sector miner.SectorOnChainInfo - if found, err := minerSectors.Get(uint64(removed.Info.SectorNumber), §or); err != nil { + // TODO: we can optimize this to not load the AMT every time, if necessary. + si, err := m.state.GetSector(removed.Info.SectorNumber) + if err != nil { return err - } else if !found { + } + if si == nil { preCommitExpired = append(preCommitExpired, uint64(removed.Info.SectorNumber)) } } @@ -653,21 +652,12 @@ func (p *Processor) storeMinerSectorEvents(ctx context.Context, sectorEvents, pr func (p *Processor) getMinerStateAt(ctx context.Context, maddr address.Address, tskey types.TipSetKey) (miner.State, error) { prevActor, err := p.node.StateGetActor(ctx, maddr, tskey) if err != nil { - return miner.State{}, err - } - var out miner.State - // Get the miner state info - astb, err := p.node.ChainReadObj(ctx, prevActor.Head) - if err != nil { - return miner.State{}, err - } - if err := out.UnmarshalCBOR(bytes.NewReader(astb)); err != nil { - return miner.State{}, err + return nil, err } - return out, nil + return miner.Load(store.ActorStore(ctx, apibstore.NewAPIBlockstore(p.node)), prevActor) } -func (p *Processor) getMinerPreCommitChanges(ctx context.Context, m minerActorInfo) (*state.MinerPreCommitChanges, error) { +func (p *Processor) getMinerPreCommitChanges(ctx context.Context, m minerActorInfo) (*miner.PreCommitChanges, error) { pred := state.NewStatePredicates(p.node) changed, val, err := pred.OnMinerActorChange(m.common.addr, pred.OnMinerPreCommitChange())(ctx, m.common.parentTsKey, m.common.tsKey) if err != nil { @@ -676,11 +666,11 @@ func (p *Processor) getMinerPreCommitChanges(ctx context.Context, m minerActorIn if !changed { return nil, nil } - out := val.(*state.MinerPreCommitChanges) + out := val.(*miner.PreCommitChanges) return out, nil } -func (p *Processor) getMinerSectorChanges(ctx context.Context, m minerActorInfo) (*state.MinerSectorChanges, error) { +func (p *Processor) getMinerSectorChanges(ctx context.Context, m minerActorInfo) (*miner.SectorChanges, error) { pred := state.NewStatePredicates(p.node) changed, val, err := pred.OnMinerActorChange(m.common.addr, pred.OnMinerSectorChange())(ctx, m.common.parentTsKey, m.common.tsKey) if err != nil { @@ -689,7 +679,7 @@ func (p *Processor) getMinerSectorChanges(ctx context.Context, m minerActorInfo) if !changed { return nil, nil } - out := val.(*state.MinerSectorChanges) + out := val.(*miner.SectorChanges) return out, nil } @@ -698,179 +688,196 @@ func (p *Processor) diffMinerPartitions(ctx context.Context, m minerActorInfo, e if err != nil { return err } - dlIdx := prevMiner.CurrentDeadline curMiner := m.state - - // load the old deadline - prevDls, err := prevMiner.LoadDeadlines(p.ctxStore) - if err != nil { - return err - } - var prevDl miner.Deadline - if err := p.ctxStore.Get(ctx, prevDls.Due[dlIdx], &prevDl); err != nil { - return err + if !prevMiner.DeadlinesChanged(curMiner) { + return nil } + panic("TODO") - prevPartitions, err := prevDl.PartitionsArray(p.ctxStore) - if err != nil { - return err - } + // FIXME: This code doesn't work. + // 1. We need to diff all deadlines, not just the "current" deadline. + // 2. We need to handle the case where we _add_ a partition. (i.e., + // where len(newPartitions) != len(oldPartitions). + /* - // load the new deadline - curDls, err := curMiner.LoadDeadlines(p.ctxStore) - if err != nil { - return err - } + // NOTE: If we change the number of deadlines in an upgrade, this will + // break. - var curDl miner.Deadline - if err := p.ctxStore.Get(ctx, curDls.Due[dlIdx], &curDl); err != nil { - return err - } + // load the old deadline + prevDls, err := prevMiner.LoadDeadlines(p.ctxStore) + if err != nil { + return err + } + var prevDl miner.Deadline + if err := p.ctxStore.Get(ctx, prevDls.Due[dlIdx], &prevDl); err != nil { + return err + } - curPartitions, err := curDl.PartitionsArray(p.ctxStore) - if err != nil { - return err - } + prevPartitions, err := prevDl.PartitionsArray(p.ctxStore) + if err != nil { + return err + } - // TODO this can be optimized by inspecting the miner state for partitions that have changed and only inspecting those. - var prevPart miner.Partition - if err := prevPartitions.ForEach(&prevPart, func(i int64) error { - var curPart miner.Partition - if found, err := curPartitions.Get(uint64(i), &curPart); err != nil { - return err - } else if !found { - log.Fatal("I don't know what this means, are partitions ever removed?") - } - partitionDiff, err := p.diffPartition(prevPart, curPart) - if err != nil { - return err - } + // load the new deadline + curDls, err := curMiner.LoadDeadlines(p.ctxStore) + if err != nil { + return err + } - recovered, err := partitionDiff.Recovered.All(miner.SectorsMax) - if err != nil { - return err - } - events <- &MinerSectorsEvent{ - MinerID: m.common.addr, - StateRoot: m.common.stateroot, - SectorIDs: recovered, - Event: SectorRecovered, - } - inRecovery, err := partitionDiff.InRecovery.All(miner.SectorsMax) - if err != nil { - return err - } - events <- &MinerSectorsEvent{ - MinerID: m.common.addr, - StateRoot: m.common.stateroot, - SectorIDs: inRecovery, - Event: SectorRecovering, - } - faulted, err := partitionDiff.Faulted.All(miner.SectorsMax) - if err != nil { - return err - } - events <- &MinerSectorsEvent{ - MinerID: m.common.addr, - StateRoot: m.common.stateroot, - SectorIDs: faulted, - Event: SectorFaulted, - } - terminated, err := partitionDiff.Terminated.All(miner.SectorsMax) - if err != nil { - return err - } - events <- &MinerSectorsEvent{ - MinerID: m.common.addr, - StateRoot: m.common.stateroot, - SectorIDs: terminated, - Event: SectorTerminated, - } - expired, err := partitionDiff.Expired.All(miner.SectorsMax) - if err != nil { - return err - } - events <- &MinerSectorsEvent{ - MinerID: m.common.addr, - StateRoot: m.common.stateroot, - SectorIDs: expired, - Event: SectorExpired, - } + var curDl miner.Deadline + if err := p.ctxStore.Get(ctx, curDls.Due[dlIdx], &curDl); err != nil { + return err + } - return nil - }); err != nil { - return err - } + curPartitions, err := curDl.PartitionsArray(p.ctxStore) + if err != nil { + return err + } - return nil + // TODO this can be optimized by inspecting the miner state for partitions that have changed and only inspecting those. + var prevPart miner.Partition + if err := prevPartitions.ForEach(&prevPart, func(i int64) error { + var curPart miner.Partition + if found, err := curPartitions.Get(uint64(i), &curPart); err != nil { + return err + } else if !found { + log.Fatal("I don't know what this means, are partitions ever removed?") + } + partitionDiff, err := p.diffPartition(prevPart, curPart) + if err != nil { + return err + } + + recovered, err := partitionDiff.Recovered.All(miner.SectorsMax) + if err != nil { + return err + } + events <- &MinerSectorsEvent{ + MinerID: m.common.addr, + StateRoot: m.common.stateroot, + SectorIDs: recovered, + Event: SectorRecovered, + } + inRecovery, err := partitionDiff.InRecovery.All(miner.SectorsMax) + if err != nil { + return err + } + events <- &MinerSectorsEvent{ + MinerID: m.common.addr, + StateRoot: m.common.stateroot, + SectorIDs: inRecovery, + Event: SectorRecovering, + } + faulted, err := partitionDiff.Faulted.All(miner.SectorsMax) + if err != nil { + return err + } + events <- &MinerSectorsEvent{ + MinerID: m.common.addr, + StateRoot: m.common.stateroot, + SectorIDs: faulted, + Event: SectorFaulted, + } + terminated, err := partitionDiff.Terminated.All(miner.SectorsMax) + if err != nil { + return err + } + events <- &MinerSectorsEvent{ + MinerID: m.common.addr, + StateRoot: m.common.stateroot, + SectorIDs: terminated, + Event: SectorTerminated, + } + expired, err := partitionDiff.Expired.All(miner.SectorsMax) + if err != nil { + return err + } + events <- &MinerSectorsEvent{ + MinerID: m.common.addr, + StateRoot: m.common.stateroot, + SectorIDs: expired, + Event: SectorExpired, + } + + return nil + }); err != nil { + return err + } + + return nil + */ } func (p *Processor) diffPartition(prevPart, curPart miner.Partition) (*PartitionStatus, error) { - // all the sectors that were in previous but not in current - allRemovedSectors, err := bitfield.SubtractBitField(prevPart.Sectors, curPart.Sectors) + prevLiveSectors, err := prevPart.LiveSectors() + if err != nil { + return nil, err + } + curLiveSectors, err := curPart.LiveSectors() if err != nil { return nil, err } - // list of sectors that were terminated before their expiration. - terminatedEarlyArr, err := adt.AsArray(p.ctxStore, curPart.EarlyTerminated) + removedSectors, err := bitfield.SubtractBitField(prevLiveSectors, curLiveSectors) if err != nil { return nil, err } - expired := bitfield.New() - var bf bitfield.BitField - if err := terminatedEarlyArr.ForEach(&bf, func(i int64) error { - // expired = all removals - termination - expirations, err := bitfield.SubtractBitField(allRemovedSectors, bf) - if err != nil { - return err - } - // merge with expired sectors from other epochs - expired, err = bitfield.MergeBitFields(expirations, expired) - if err != nil { - return nil - } - return nil - }); err != nil { + prevRecoveries, err := prevPart.RecoveringSectors() + if err != nil { + return nil, err + } + + curRecoveries, err := curPart.RecoveringSectors() + if err != nil { + return nil, err + } + + newRecoveries, err := bitfield.SubtractBitField(curRecoveries, prevRecoveries) + if err != nil { return nil, err } - // terminated = all removals - expired - terminated, err := bitfield.SubtractBitField(allRemovedSectors, expired) + prevFaults, err := prevPart.FaultySectors() if err != nil { return nil, err } - // faults in current but not previous - faults, err := bitfield.SubtractBitField(curPart.Recoveries, prevPart.Recoveries) + curFaults, err := curPart.FaultySectors() if err != nil { return nil, err } - // recoveries in current but not previous - inRecovery, err := bitfield.SubtractBitField(curPart.Recoveries, prevPart.Recoveries) + newFaults, err := bitfield.SubtractBitField(curFaults, prevFaults) if err != nil { return nil, err } // all current good sectors - newActiveSectors, err := curPart.ActiveSectors() + curActiveSectors, err := curPart.ActiveSectors() if err != nil { return nil, err } // sectors that were previously fault and are now currently active are considered recovered. - recovered, err := bitfield.IntersectBitField(prevPart.Faults, newActiveSectors) + recovered, err := bitfield.IntersectBitField(prevFaults, curActiveSectors) if err != nil { return nil, err } + // TODO: distinguish between "terminated" and "expired" sectors. The + // previous code here never had a chance of working in the first place, + // so I'm not going to try to replicate it right now. + // + // How? If the sector expires before it should (according to sector + // info) and it wasn't replaced by a pre-commit deleted in this change + // set, it was "early terminated". + return &PartitionStatus{ - Terminated: terminated, - Expired: expired, - Faulted: faults, - InRecovery: inRecovery, + Terminated: bitfield.New(), + Expired: removedSectors, + Faulted: newFaults, + InRecovery: newRecoveries, Recovered: recovered, }, nil } From f2a0779bb9a6c4e5f9768c3d6ef3da30027c24cb Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 21:41:36 -0700 Subject: [PATCH 050/104] remove specs-actors import --- chain/events/state/predicates.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 721de9dd2d9..e0e97777294 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -9,15 +9,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/lotus/chain/actors/adt" - init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin" cbor "github.com/ipfs/go-ipld-cbor" typegen "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lotus/api/apibstore" + "github.com/filecoin-project/lotus/chain/actors/adt" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" ) @@ -74,7 +73,7 @@ type DiffStorageMarketStateFunc func(ctx context.Context, oldState market.State, // OnStorageMarketActorChanged calls diffStorageMarketState when the state changes for the market actor func (sp *StatePredicates) OnStorageMarketActorChanged(diffStorageMarketState DiffStorageMarketStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(builtin.StorageMarketActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { + return sp.OnActorStateChanged(market.Address, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { oldState, err := market.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err @@ -295,7 +294,7 @@ func (sp *StatePredicates) AvailableBalanceChangedForAddresses(getAddrs func() [ type DiffMinerActorStateFunc func(ctx context.Context, oldState miner.State, newState miner.State) (changed bool, user UserData, err error) func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorStateFunc) DiffTipSetKeyFunc { - return sp.OnActorStateChanged(builtin.InitActorAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { + return sp.OnActorStateChanged(init_.Address, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { oldState, err := init_.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err From 8bd6791e58d8420ce4434e8a92ff87768895e274 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 21:44:10 -0700 Subject: [PATCH 051/104] more fixups --- tools/stats/metrics.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index 4f11d24767d..86dbe678057 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -12,13 +12,13 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin" - "golang.org/x/xerrors" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" + "golang.org/x/xerrors" cbg "github.com/whyrusleeping/cbor-gen" @@ -242,7 +242,7 @@ func RecordTipsetStatePoints(ctx context.Context, api api.FullNode, pl *PointLis //p := NewPoint("chain.pledge_collateral", pcFilFloat) //pl.AddPoint(p) - netBal, err := api.WalletBalance(ctx, builtin.RewardActorAddr) + netBal, err := api.WalletBalance(ctx, reward.Address) if err != nil { return err } From daa441b989514f549a1ea5d5bc28bf51e9d3c901 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 17 Sep 2020 21:48:50 -0700 Subject: [PATCH 052/104] simplify market diff --- chain/actors/builtin/market/{util.go => diff.go} | 4 ++-- chain/actors/builtin/market/market.go | 2 -- chain/actors/builtin/market/v0.go | 8 -------- chain/events/state/predicates.go | 4 ++-- 4 files changed, 4 insertions(+), 14 deletions(-) rename chain/actors/builtin/market/{util.go => diff.go} (94%) diff --git a/chain/actors/builtin/market/util.go b/chain/actors/builtin/market/diff.go similarity index 94% rename from chain/actors/builtin/market/util.go rename to chain/actors/builtin/market/diff.go index 92fdd682301..d0b4a2fd3f6 100644 --- a/chain/actors/builtin/market/util.go +++ b/chain/actors/builtin/market/diff.go @@ -8,7 +8,7 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" ) -func diffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) { +func DiffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) { results := new(DealProposalChanges) if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketProposalsDiffer{results, pre, cur}); err != nil { return nil, fmt.Errorf("diffing deal states: %w", err) @@ -44,7 +44,7 @@ func (d *marketProposalsDiffer) Remove(key uint64, val *cbg.Deferred) error { return nil } -func diffDealStates(pre, cur DealStates) (*DealStateChanges, error) { +func DiffDealStates(pre, cur DealStates) (*DealStateChanges, error) { results := new(DealStateChanges) if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketStatesDiffer{results, pre, cur}); err != nil { return nil, fmt.Errorf("diffing deal states: %w", err) diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 1c11c027e74..c65fa093d2e 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -51,7 +51,6 @@ type BalanceTable interface { type DealStates interface { Get(id abi.DealID) (*DealState, bool, error) - Diff(DealStates) (*DealStateChanges, error) array() adt.Array decode(*cbg.Deferred) (*DealState, error) @@ -60,7 +59,6 @@ type DealStates interface { type DealProposals interface { ForEach(cb func(id abi.DealID, dp DealProposal) error) error Get(id abi.DealID) (*DealProposal, bool, error) - Diff(DealProposals) (*DealProposalChanges, error) array() adt.Array decode(*cbg.Deferred) (*DealProposal, error) diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 58744674971..671907ad46a 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -124,10 +124,6 @@ func (s *v0DealStates) Get(dealID abi.DealID) (*DealState, bool, error) { return &deal, true, nil } -func (s *v0DealStates) Diff(other DealStates) (*DealStateChanges, error) { - return diffDealStates(s, other) -} - func (s *v0DealStates) decode(val *cbg.Deferred) (*DealState, error) { var v0ds market.DealState if err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -149,10 +145,6 @@ type v0DealProposals struct { adt.Array } -func (s *v0DealProposals) Diff(other DealProposals) (*DealProposalChanges, error) { - return diffDealProposals(s, other) -} - func (s *v0DealProposals) Get(dealID abi.DealID) (*DealProposal, bool, error) { var v0proposal market.DealProposal found, err := s.Array.Get(uint64(dealID), &v0proposal) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index e0e97777294..4e821633ec0 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -175,7 +175,7 @@ func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffDealProposals // - Removed Proposals func (sp *StatePredicates) OnDealProposalAmtChanged() DiffDealProposalsFunc { return func(ctx context.Context, oldDealProps, newDealProps market.DealProposals) (changed bool, user UserData, err error) { - proposalChanges, err := oldDealProps.Diff(newDealProps) + proposalChanges, err := market.DiffDealProposals(oldDealProps, newDealProps) if err != nil { return false, nil, err } @@ -194,7 +194,7 @@ func (sp *StatePredicates) OnDealProposalAmtChanged() DiffDealProposalsFunc { // - Removed Deals func (sp *StatePredicates) OnDealStateAmtChanged() DiffDealStatesFunc { return func(ctx context.Context, oldDealStates, newDealStates market.DealStates) (changed bool, user UserData, err error) { - dealStateChanges, err := oldDealStates.Diff(newDealStates) + dealStateChanges, err := market.DiffDealStates(oldDealStates, newDealStates) if err != nil { return false, nil, err } From 37de154a7cefe4eac620273464fb53b12dc0d190 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 18 Sep 2020 01:12:45 -0400 Subject: [PATCH 053/104] Fixup tests --- api/test/ccupgrade.go | 1 + chain/actors/builtin/miner/v0.go | 11 ++++++----- chain/events/state/predicates_test.go | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/test/ccupgrade.go b/api/test/ccupgrade.go index 130b55cb863..b281f30a027 100644 --- a/api/test/ccupgrade.go +++ b/api/test/ccupgrade.go @@ -85,6 +85,7 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { { exp, err := client.StateSectorExpiration(ctx, maddr, CC, types.EmptyTSK) require.NoError(t, err) + require.NotNil(t, exp) require.Greater(t, 50000, int(exp.OnTime)) } { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 9f4cea6ce3b..e0ae2594a83 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -65,7 +65,7 @@ func (s *v0State) FindSector(num abi.SectorNumber) (*SectorLocation, error) { // If the sector isn't found or has already been terminated, this method returns // nil and no error. If the sector does not expire early, the Early expiration // field is 0. -func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpiration, err error) { +func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { return nil, err @@ -77,6 +77,7 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati // 2. If it's faulty, it will expire early within the first 14 entries // of the expiration queue. stopErr := errors.New("stop") + out := SectorExpiration{} err = dls.ForEach(s.store, func(dlIdx uint64, dl *v0miner.Deadline) error { partitions, err := dl.PartitionsArray(s.store) if err != nil { @@ -97,7 +98,7 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati return stopErr } - q, err := v0miner.LoadExpirationQueue(s.store, part.EarlyTerminated, quant) + q, err := v0miner.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant) if err != nil { return err } @@ -128,7 +129,7 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpirati if out.Early == 0 && out.OnTime == 0 { return nil, nil } - return out, nil + return &out, nil } func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { @@ -294,14 +295,14 @@ func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { }) } -func (s *v0Deadline) PartitionsChanged(other Deadline) bool { +func (d *v0Deadline) PartitionsChanged(other Deadline) bool { v0other, ok := other.(*v0Deadline) if !ok { // treat an upgrade as a change, always return true } - return s.Deadline.Partitions.Equals(v0other.Deadline.Partitions) + return d.Deadline.Partitions.Equals(v0other.Deadline.Partitions) } func (d *v0Deadline) PostSubmissions() (bitfield.BitField, error) { diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 243d8814e32..0412c642182 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -398,8 +398,8 @@ func TestMinerSectorChange(t *testing.T) { require.NoError(t, err) api := newMockAPI(bs) - api.setActor(oldState.Key(), &types.Actor{Head: oldMinerC}) - api.setActor(newState.Key(), &types.Actor{Head: newMinerC}) + api.setActor(oldState.Key(), &types.Actor{Head: oldMinerC, Code: v0builtin.StorageMinerActorCodeID}) + api.setActor(newState.Key(), &types.Actor{Head: newMinerC, Code: v0builtin.StorageMinerActorCodeID}) preds := NewStatePredicates(api) From fce423c7431d2d48cea876ffdbe95a5747f320dd Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 18 Sep 2020 02:14:18 -0400 Subject: [PATCH 054/104] Appease the linter and get everything building --- build/params_testground.go | 3 ++- extern/storage-sealing/checks.go | 1 + extern/storage-sealing/precommit_policy.go | 1 + extern/storage-sealing/precommit_policy_test.go | 3 ++- extern/storage-sealing/sealing.go | 5 ++--- extern/storage-sealing/states_sealing.go | 3 +++ go.sum | 4 ---- node/impl/full/state.go | 3 --- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/build/params_testground.go b/build/params_testground.go index 77e312ac2de..1b30ae2e93a 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -80,5 +80,6 @@ var ( 0: DrandMainnet, } - NewestNetworkVersion = network.Version2 + NewestNetworkVersion = network.Version2 + ActorUpgradeNetworkVersion = network.Version3 ) diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index ae5ce0d3361..677cef1e91b 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -105,6 +105,7 @@ func checkPrecommit(ctx context.Context, maddr address.Address, si SectorInfo, t msd = v0miner.MaxSealDuration[si.SectorType] } else { // TODO: ActorUpgrade + msd = 0 } if height-(si.TicketEpoch+SealRandomnessLookback) > msd { diff --git a/extern/storage-sealing/precommit_policy.go b/extern/storage-sealing/precommit_policy.go index e36b8251a8d..76d8671443b 100644 --- a/extern/storage-sealing/precommit_policy.go +++ b/extern/storage-sealing/precommit_policy.go @@ -90,6 +90,7 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi wpp = v0miner.WPoStProvingPeriod } else { // TODO: ActorUpgrade + wpp = 0 } *end += wpp - (*end % wpp) + p.provingBoundary - 1 diff --git a/extern/storage-sealing/precommit_policy_test.go b/extern/storage-sealing/precommit_policy_test.go index 30b538a8807..52814167a57 100644 --- a/extern/storage-sealing/precommit_policy_test.go +++ b/extern/storage-sealing/precommit_policy_test.go @@ -2,9 +2,10 @@ package sealing_test import ( "context" + "testing" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/build" - "testing" "github.com/ipfs/go-cid" "github.com/stretchr/testify/assert" diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 6d60e7a6e27..01551e6d7f4 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -431,9 +431,8 @@ func (m *Sealing) getPreCommitChallengeDelay(ctx context.Context, tok TipSetToke if nv < build.ActorUpgradeNetworkVersion { return v0miner.PreCommitChallengeDelay, nil - } else { - // TODO: ActorUpgrade - return -1, nil } + // TODO: ActorUpgrade + return -1, nil } diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index f0ff4025d47..6ae42a91f25 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -195,6 +195,8 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf mse = v0miner.MinSectorExpiration } else { // TODO: ActorUpgrade + msd = 0 + mse = 0 } if minExpiration := height + msd + mse + 10; expiration < minExpiration { @@ -395,6 +397,7 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo } } else { // TODO: ActorUpgrade + enc = nil } waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok) diff --git a/go.sum b/go.sum index 3d012da921d..5ebec6cbf11 100644 --- a/go.sum +++ b/go.sum @@ -226,10 +226,6 @@ github.com/filecoin-project/go-data-transfer v0.6.3 h1:7TLwm8nuodHYD/uiwJjKc/PGR github.com/filecoin-project/go-data-transfer v0.6.3/go.mod h1:PmBKVXkhh67/tnEdJXQwDHl5mT+7Tbcwe1NPninqhnM= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1:GxJzR3oRIMTPtpZ0b7QF8FKPK6/iPAc7trhlL5k/g+s= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= -github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c h1:YGoyYmELQ0LHwDj/WcOvY3oYt+3iM0wdrAhqJQUAIy4= -github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= -github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917050751-2af52e9606c6 h1:k97Z2JP3WpDVGU/7Bz3RtnqrYtn9X428Ps8OkoFq61I= -github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917050751-2af52e9606c6/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9 h1:SnCUC9wHDId9TtV8PsQp8q1OOsi+NOLOwitIDnAgUa4= github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A= github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 04055043a9d..729baef2c3f 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -3,7 +3,6 @@ package full import ( "bytes" "context" - "errors" "strconv" v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" @@ -47,8 +46,6 @@ import ( "github.com/filecoin-project/lotus/node/modules/dtypes" ) -var errBreakForeach = errors.New("break") - type StateAPI struct { fx.In From 694463ffbe63f2f48985c391bdf98f388155fabc Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 18 Sep 2020 03:06:28 -0400 Subject: [PATCH 055/104] More lint fixes --- chain/events/state/predicates.go | 1 - chain/events/state/predicates_test.go | 2 ++ chain/stmgr/stmgr.go | 1 + cmd/lotus-pcr/main.go | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 4e821633ec0..21e1720e6e2 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -530,6 +530,5 @@ func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return true, addressChanges, nil*/ panic("TODO") - return false, nil, nil } } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 0412c642182..604eec75d90 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -246,6 +246,7 @@ func TestMarketPredicates(t *testing.T) { Code: v0builtin.StorageMarketActorCodeID, Head: marketCid, }) + require.NoError(t, err) changed, _, err = diffDealStateFn(ctx, marketState, marketState) require.NoError(t, err) require.False(t, changed) @@ -358,6 +359,7 @@ func TestMarketPredicates(t *testing.T) { Code: v0builtin.StorageMarketActorCodeID, Head: marketCid, }) + require.NoError(t, err) changed, _, err = diffDealBalancesFn(ctx, marketState, marketState) require.NoError(t, err) require.False(t, changed) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 90154868e59..d1adbbc622d 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -262,6 +262,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp } } else { // TODO: ActorUpgrade + params = nil } sysAct, err := vmi.StateTree().GetActor(builtin.SystemActorAddr) diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index aa467e38a6e..3dedb24fc59 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -412,6 +412,7 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu sn = proveCommitSector.SectorNumber } else { // TODO: ActorUpgrade + sn = -1 } // We use the parent tipset key because precommit information is removed when ProveCommitSector is executed From ccd0a67b01c31da932c2a3b052269ba4d703df17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 18 Sep 2020 20:34:23 +0200 Subject: [PATCH 056/104] wip fixing wdpost tests --- storage/wdpost_run_test.go | 61 ++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index af529a75e05..1a930b41a04 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -7,8 +7,6 @@ import ( "github.com/filecoin-project/go-state-types/dline" - "golang.org/x/xerrors" - "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" @@ -17,17 +15,20 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/specs-actors/actors/builtin" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" tutils "github.com/filecoin-project/specs-actors/support/testing" + + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" ) type mockStorageMinerAPI struct { - partitions []*miner.Partition + partitions []api.Partition pushedMessages chan *types.Message } @@ -37,6 +38,14 @@ func newMockStorageMinerAPI() *mockStorageMinerAPI { } } +func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Address, key types.TipSetKey) (miner.MinerInfo, error) { + panic("implement me") +} + +func (m *mockStorageMinerAPI) StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error) { + panic("implement me") +} + func (m *mockStorageMinerAPI) ChainGetRandomnessFromTickets(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) { return abi.Randomness("ticket rand"), nil } @@ -45,18 +54,18 @@ func (m *mockStorageMinerAPI) ChainGetRandomnessFromBeacon(ctx context.Context, return abi.Randomness("beacon rand"), nil } -func (m *mockStorageMinerAPI) setPartitions(ps []*miner.Partition) { +func (m *mockStorageMinerAPI) setPartitions(ps []api.Partition) { m.partitions = append(m.partitions, ps...) } -func (m *mockStorageMinerAPI) StateMinerPartitions(ctx context.Context, address address.Address, u uint64, key types.TipSetKey) ([]*miner.Partition, error) { +func (m *mockStorageMinerAPI) StateMinerPartitions(ctx context.Context, a address.Address, dlIdx uint64, tsk types.TipSetKey) ([]api.Partition, error) { return m.partitions, nil } -func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, field *bitfield.BitField, b bool, key types.TipSetKey) ([]*api.ChainSectorInfo, error) { - var sis []*api.ChainSectorInfo +func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, field *bitfield.BitField, b bool, key types.TipSetKey) ([]*miner.ChainSectorInfo, error) { + var sis []*miner.ChainSectorInfo _ = field.ForEach(func(i uint64) error { - sis = append(sis, &api.ChainSectorInfo{ + sis = append(sis, &miner.ChainSectorInfo{ Info: miner.SectorOnChainInfo{ SectorNumber: abi.SectorNumber(i), }, @@ -67,10 +76,6 @@ func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address add return sis, nil } -func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, address address.Address, key types.TipSetKey) (api.MinerInfo, error) { - return api.MinerInfo{}, xerrors.Errorf("err") -} - func (m *mockStorageMinerAPI) MpoolPushMessage(ctx context.Context, message *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { m.pushedMessages <- message return &types.SignedMessage{ @@ -127,21 +132,27 @@ func TestWDPostDoPost(t *testing.T) { require.NoError(t, err) // Work out the number of partitions that can be included in a message // without exceeding the message sector limit - partitionsPerMsg := int(miner.AddressedSectorsMax / sectorsPerPartition) + + require.NoError(t, err) + partitionsPerMsg := int(v0miner.AddressedSectorsMax / sectorsPerPartition) // Enough partitions to fill expectedMsgCount-1 messages partitionCount := (expectedMsgCount - 1) * partitionsPerMsg // Add an extra partition that should be included in the last message partitionCount++ - var partitions []*miner.Partition + var partitions []api.Partition for p := 0; p < partitionCount; p++ { sectors := bitfield.New() for s := uint64(0); s < sectorsPerPartition; s++ { sectors.Set(s) } - partitions = append(partitions, &miner.Partition{ - Sectors: sectors, + partitions = append(partitions, api.Partition{ + AllSectors: sectors, + FaultySectors: bitfield.New(), + RecoveringSectors: bitfield.New(), + LiveSectors: sectors, + ActiveSectors: sectors, }) } mockStgMinerAPI.setPartitions(partitions) @@ -204,7 +215,7 @@ func (m *mockStorageMinerAPI) StateCall(ctx context.Context, message *types.Mess panic("implement me") } -func (m *mockStorageMinerAPI) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok types.TipSetKey) ([]*miner.Deadline, error) { +func (m *mockStorageMinerAPI) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok types.TipSetKey) ([]api.Deadline, error) { panic("implement me") } @@ -216,7 +227,7 @@ func (m *mockStorageMinerAPI) StateSectorGetInfo(ctx context.Context, address ad panic("implement me") } -func (m *mockStorageMinerAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*api.SectorLocation, error) { +func (m *mockStorageMinerAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) { panic("implement me") } @@ -237,7 +248,9 @@ func (m *mockStorageMinerAPI) StateSearchMsg(ctx context.Context, cid cid.Cid) ( } func (m *mockStorageMinerAPI) StateGetActor(ctx context.Context, actor address.Address, ts types.TipSetKey) (*types.Actor, error) { - panic("implement me") + return &types.Actor{ + Code: v0builtin.StorageMinerActorCodeID, + }, nil } func (m *mockStorageMinerAPI) StateGetReceipt(ctx context.Context, cid cid.Cid, key types.TipSetKey) (*types.MessageReceipt, error) { @@ -303,3 +316,5 @@ func (m *mockStorageMinerAPI) WalletBalance(ctx context.Context, address address func (m *mockStorageMinerAPI) WalletHas(ctx context.Context, address address.Address) (bool, error) { panic("implement me") } + +var _ storageMinerApi = &mockStorageMinerAPI{} From c3046f487cf01a0a4d06c42510f04c33ddd3965a Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 18 Sep 2020 14:41:03 -0400 Subject: [PATCH 057/104] Don't use -1 as default sector number --- cmd/lotus-pcr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 3dedb24fc59..53c8223ed56 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -412,7 +412,7 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu sn = proveCommitSector.SectorNumber } else { // TODO: ActorUpgrade - sn = -1 + sn = 0 } // We use the parent tipset key because precommit information is removed when ProveCommitSector is executed From fb2b25c2975b9f996646d71e9fd0b3410d7572b0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 13:43:14 -0700 Subject: [PATCH 058/104] finish upgrading chainwatch --- chain/actors/builtin/init/init.go | 3 + chain/actors/builtin/init/v0.go | 19 ++++ chain/actors/builtin/power/power.go | 4 + chain/actors/builtin/power/v0.go | 12 +++ chain/actors/builtin/reward/reward.go | 11 ++- chain/actors/builtin/reward/v0.go | 22 ++++- .../processor/common_actors.go | 29 ++---- cmd/lotus-chainwatch/processor/miner.go | 29 ++---- cmd/lotus-chainwatch/processor/power.go | 76 +++++++------- cmd/lotus-chainwatch/processor/reward.go | 99 ++++++++++++------- node/impl/full/state.go | 4 +- 11 files changed, 185 insertions(+), 123 deletions(-) diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 3b1a49564b2..7485c599ff3 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -4,6 +4,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" @@ -33,4 +34,6 @@ type State interface { ResolveAddress(address address.Address) (address.Address, bool, error) MapAddressToNewID(address address.Address) (address.Address, error) NetworkName() (dtypes.NetworkName, error) + + ForEachActor(func(id abi.ActorID, address address.Address) error) error } diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index 711b702e25f..e286e1ef2b6 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -2,11 +2,15 @@ package init import ( "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + cbg "github.com/whyrusleeping/cbor-gen" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" + + v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" ) type v0State struct { @@ -22,6 +26,21 @@ func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, e return s.State.MapAddressToNewID(s.store, address) } +func (s *v0State) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := v0adt.AsMap(s.store, s.State.AddressMap) + if err != nil { + return err + } + var actorID cbg.CborInt + return addrs.ForEach(&actorID, func(key string) error { + addr, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(abi.ActorID(actorID), addr) + }) +} + func (s *v0State) NetworkName() (dtypes.NetworkName, error) { return dtypes.NetworkName(s.State.NetworkName), nil } diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 65148f0a58b..7170526bf91 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -33,8 +33,12 @@ type State interface { TotalLocked() (abi.TokenAmount, error) TotalPower() (Claim, error) + TotalCommitted() (Claim, error) TotalPowerSmoothed() (builtin.FilterEstimate, error) + // MinerCounts returns the number of miners. Participating is the number + // with power above the minimum miner threshold. + MinerCounts() (participating, total uint64, err error) MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) ListAllMiners() ([]address.Address, error) diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 5cf6920c8d0..9730be893c5 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -24,6 +24,14 @@ func (s *v0State) TotalPower() (Claim, error) { }, nil } +// Committed power to the network. Includes miners below the minimum threshold. +func (s *v0State) TotalCommitted() (Claim, error) { + return Claim{ + RawBytePower: s.TotalBytesCommitted, + QualityAdjPower: s.TotalQABytesCommitted, + }, nil +} + func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { claims, err := adt.AsMap(s.store, s.Claims) if err != nil { @@ -48,6 +56,10 @@ func (s *v0State) TotalPowerSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochQAPowerSmoothed, nil } +func (s *v0State) MinerCounts() (uint64, uint64, error) { + return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil +} + func (s *v0State) ListAllMiners() ([]address.Address, error) { claims, err := adt.AsMap(s.store, s.Claims) if err != nil { diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 52a26ab157a..66df887fcbd 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -30,8 +30,15 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Er - RewardSmoothed() (builtin.FilterEstimate, error) - EffectiveBaselinePower() (abi.StoragePower, error) ThisEpochBaselinePower() (abi.StoragePower, error) + ThisEpochReward() (abi.StoragePower, error) + ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) + + EffectiveBaselinePower() (abi.StoragePower, error) + EffectiveNetworkTime() (abi.ChainEpoch, error) + TotalStoragePowerReward() (abi.TokenAmount, error) + + CumsumBaseline() (abi.StoragePower, error) + CumsumRealized() (abi.StoragePower, error) } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 16ac2b071f0..d12eccf5941 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -12,10 +12,18 @@ type v0State struct { store adt.Store } -func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) { +func (s *v0State) ThisEpochReward() (abi.StoragePower, error) { + return s.State.ThisEpochReward, nil +} + +func (s *v0State) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochRewardSmoothed, nil } +func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil +} + func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) { return s.State.TotalMined, nil } @@ -24,6 +32,14 @@ func (s *v0State) EffectiveBaselinePower() (abi.StoragePower, error) { return s.State.EffectiveBaselinePower, nil } -func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) { - return s.State.ThisEpochBaselinePower, nil +func (s *v0State) EffectiveNetworkTime() (abi.ChainEpoch, error) { + return s.State.EffectiveNetworkTime, nil +} + +func (s *v0State) CumsumBaseline() (abi.StoragePower, error) { + return s.State.CumsumBaseline, nil +} + +func (s *v0State) CumsumRealized() (abi.StoragePower, error) { + return s.State.CumsumBaseline, nil } diff --git a/cmd/lotus-chainwatch/processor/common_actors.go b/cmd/lotus-chainwatch/processor/common_actors.go index d6aec7f90c7..56520880c7d 100644 --- a/cmd/lotus-chainwatch/processor/common_actors.go +++ b/cmd/lotus-chainwatch/processor/common_actors.go @@ -1,7 +1,6 @@ package processor import ( - "bytes" "context" "time" @@ -9,14 +8,13 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + _init "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/types" cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util" "github.com/filecoin-project/specs-actors/actors/builtin" - _init "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/ipfs/go-cid" - typegen "github.com/whyrusleeping/cbor-gen" ) func (p *Processor) setupCommonActors() error { @@ -150,32 +148,17 @@ func (p Processor) storeActorAddresses(ctx context.Context, actors map[cid.Cid]A return err } - initActorRaw, err := p.node.ChainReadObj(ctx, initActor.Head) - if err != nil { - return err - } - - var initActorState _init.State - if err := initActorState.UnmarshalCBOR(bytes.NewReader(initActorRaw)); err != nil { - return err - } - ctxStore := cw_util.NewAPIIpldStore(ctx, p.node) - addrMap, err := adt.AsMap(ctxStore, initActorState.AddressMap) + initActorState, err := _init.Load(cw_util.NewAPIIpldStore(ctx, p.node), initActor) if err != nil { return err } // gross.. - var actorID typegen.CborInt - if err := addrMap.ForEach(&actorID, func(key string) error { - longAddr, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - shortAddr, err := address.NewIDAddress(uint64(actorID)) + if err := initActorState.ForEachActor(func(id abi.ActorID, addr address.Address) error { + idAddr, err := address.NewIDAddress(uint64(id)) if err != nil { return err } - addressToID[longAddr] = shortAddr + addressToID[addr] = idAddr return nil }); err != nil { return err diff --git a/cmd/lotus-chainwatch/processor/miner.go b/cmd/lotus-chainwatch/processor/miner.go index 1fd2a119f45..17eef3afab0 100644 --- a/cmd/lotus-chainwatch/processor/miner.go +++ b/cmd/lotus-chainwatch/processor/miner.go @@ -1,9 +1,7 @@ package processor import ( - "bytes" "context" - "fmt" "strings" "time" @@ -15,13 +13,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -212,7 +208,7 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe // TODO add parallel calls if this becomes slow for tipset, miners := range minerTips { // get the power actors claims map - minersClaims, err := getPowerActorClaimsMap(ctx, p.node, tipset) + powerState, err := getPowerActorState(ctx, p.node, tipset) if err != nil { return nil, err } @@ -222,10 +218,9 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe var mi minerActorInfo mi.common = act - var claim power.Claim // get miner claim from power actors claim map and store if found, else the miner had no claim at // this tipset - found, err := minersClaims.Get(abi.AddrKey(act.addr), &claim) + claim, found, err := powerState.MinerPower(act.addr) if err != nil { return nil, err } @@ -1027,22 +1022,10 @@ func (p *Processor) storeMinersPower(miners []minerActorInfo) error { } // load the power actor state clam as an adt.Map at the tipset `ts`. -func getPowerActorClaimsMap(ctx context.Context, api api.FullNode, ts types.TipSetKey) (*adt.Map, error) { - powerActor, err := api.StateGetActor(ctx, builtin.StoragePowerActorAddr, ts) +func getPowerActorState(ctx context.Context, api api.FullNode, ts types.TipSetKey) (power.State, error) { + powerActor, err := api.StateGetActor(ctx, power.Address, ts) if err != nil { return nil, err } - - powerRaw, err := api.ChainReadObj(ctx, powerActor.Head) - if err != nil { - return nil, err - } - - var powerActorState power.State - if err := powerActorState.UnmarshalCBOR(bytes.NewReader(powerRaw)); err != nil { - return nil, fmt.Errorf("failed to unmarshal power actor state: %w", err) - } - - s := cw_util.NewAPIIpldStore(ctx, api) - return adt.AsMap(s, powerActorState.Claims) + return power.Load(cw_util.NewAPIIpldStore(ctx, api), powerActor) } diff --git a/cmd/lotus-chainwatch/processor/power.go b/cmd/lotus-chainwatch/processor/power.go index dfd7eddd72d..403580e3ba5 100644 --- a/cmd/lotus-chainwatch/processor/power.go +++ b/cmd/lotus-chainwatch/processor/power.go @@ -1,16 +1,14 @@ package processor import ( - "bytes" "context" "time" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/util/smoothing" + + "github.com/filecoin-project/lotus/chain/actors/builtin" ) type powerActorInfo struct { @@ -22,10 +20,7 @@ type powerActorInfo struct { totalQualityAdjustedBytesCommitted big.Int totalPledgeCollateral big.Int - newRawBytes big.Int - newQualityAdjustedBytes big.Int - newPledgeCollateral big.Int - newQAPowerSmoothed *smoothing.FilterEstimate + qaPowerSmoothed builtin.FilterEstimate minerCount int64 minerCountAboveMinimumPower int64 @@ -44,10 +39,6 @@ create table if not exists chain_power constraint power_smoothing_estimates_pk primary key, - new_raw_bytes_power text not null, - new_qa_bytes_power text not null, - new_pledge_collateral text not null, - total_raw_bytes_power text not null, total_raw_bytes_committed text not null, total_qa_bytes_power text not null, @@ -92,35 +83,49 @@ func (p *Processor) processPowerActors(ctx context.Context, powerTips ActorTips) var pw powerActorInfo pw.common = act - powerActor, err := p.node.StateGetActor(ctx, builtin.StoragePowerActorAddr, tipset) + powerActorState, err := getPowerActorState(ctx, p.node, tipset) if err != nil { return nil, xerrors.Errorf("get power state (@ %s): %w", pw.common.stateroot.String(), err) } - powerStateRaw, err := p.node.ChainReadObj(ctx, powerActor.Head) - if err != nil { - return nil, xerrors.Errorf("read state obj (@ %s): %w", pw.common.stateroot.String(), err) + if totalPower, err := powerActorState.TotalPower(); err != nil { + return nil, xerrors.Errorf("failed to compute total power: %w", err) + } else { + pw.totalRawBytes = totalPower.RawBytePower + pw.totalQualityAdjustedBytes = totalPower.QualityAdjPower } - var powerActorState power.State - if err := powerActorState.UnmarshalCBOR(bytes.NewReader(powerStateRaw)); err != nil { - return nil, xerrors.Errorf("unmarshal state (@ %s): %w", pw.common.stateroot.String(), err) + if totalCommitted, err := powerActorState.TotalCommitted(); err != nil { + return nil, xerrors.Errorf("failed to compute total committed: %w", err) + } else { + pw.totalRawBytesCommitted = totalCommitted.RawBytePower + pw.totalQualityAdjustedBytesCommitted = totalCommitted.QualityAdjPower } - pw.totalRawBytes = powerActorState.TotalRawBytePower - pw.totalRawBytesCommitted = powerActorState.TotalBytesCommitted - pw.totalQualityAdjustedBytes = powerActorState.TotalQualityAdjPower - pw.totalQualityAdjustedBytesCommitted = powerActorState.TotalQABytesCommitted - pw.totalPledgeCollateral = powerActorState.TotalPledgeCollateral + if totalLocked, err := powerActorState.TotalLocked(); err != nil { + return nil, xerrors.Errorf("failed to compute total locked: %w", err) + } else { + pw.totalPledgeCollateral = totalLocked + } - pw.newRawBytes = powerActorState.ThisEpochRawBytePower - pw.newQualityAdjustedBytes = powerActorState.ThisEpochQualityAdjPower - pw.newPledgeCollateral = powerActorState.ThisEpochPledgeCollateral - pw.newQAPowerSmoothed = powerActorState.ThisEpochQAPowerSmoothed + if powerSmoothed, err := powerActorState.TotalPowerSmoothed(); err != nil { + return nil, xerrors.Errorf("failed to determine smoothed power: %w", err) + } else { + pw.qaPowerSmoothed = powerSmoothed + } - pw.minerCount = powerActorState.MinerCount - pw.minerCountAboveMinimumPower = powerActorState.MinerAboveMinPowerCount - out = append(out, pw) + // NOTE: this doesn't set new* fields. Previously, we + // filled these using ThisEpoch* fields from the actor + // state, but these fields are effectively internal + // state and don't represent "new" power, as was + // assumed. + + if participating, total, err := powerActorState.MinerCounts(); err != nil { + return nil, xerrors.Errorf("failed to count miners: %w", err) + } else { + pw.minerCountAboveMinimumPower = int64(participating) + pw.minerCount = int64(total) + } } } @@ -142,7 +147,7 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e return xerrors.Errorf("prep chain_power: %w", err) } - stmt, err := tx.Prepare(`copy cp (state_root, new_raw_bytes_power, new_qa_bytes_power, new_pledge_collateral, total_raw_bytes_power, total_raw_bytes_committed, total_qa_bytes_power, total_qa_bytes_committed, total_pledge_collateral, qa_smoothed_position_estimate, qa_smoothed_velocity_estimate, miner_count, minimum_consensus_miner_count) from stdin;`) + stmt, err := tx.Prepare(`copy cp (state_root, total_raw_bytes_power, total_raw_bytes_committed, total_qa_bytes_power, total_qa_bytes_committed, total_pledge_collateral, qa_smoothed_position_estimate, qa_smoothed_velocity_estimate, miner_count, minimum_consensus_miner_count) from stdin;`) if err != nil { return xerrors.Errorf("prepare tmp chain_power: %w", err) } @@ -150,9 +155,6 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e for _, ps := range powerStates { if _, err := stmt.Exec( ps.common.stateroot.String(), - ps.newRawBytes.String(), - ps.newQualityAdjustedBytes.String(), - ps.newPledgeCollateral.String(), ps.totalRawBytes.String(), ps.totalRawBytesCommitted.String(), @@ -160,8 +162,8 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e ps.totalQualityAdjustedBytesCommitted.String(), ps.totalPledgeCollateral.String(), - ps.newQAPowerSmoothed.PositionEstimate.String(), - ps.newQAPowerSmoothed.VelocityEstimate.String(), + ps.qaPowerSmoothed.PositionEstimate.String(), + ps.qaPowerSmoothed.VelocityEstimate.String(), ps.minerCount, ps.minerCountAboveMinimumPower, diff --git a/cmd/lotus-chainwatch/processor/reward.go b/cmd/lotus-chainwatch/processor/reward.go index 5bdb478dfc8..35d4bbf01f3 100644 --- a/cmd/lotus-chainwatch/processor/reward.go +++ b/cmd/lotus-chainwatch/processor/reward.go @@ -1,18 +1,18 @@ package processor import ( - "bytes" "context" "time" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/actors/util/smoothing" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/types" + + cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util" ) type rewardActorInfo struct { @@ -24,13 +24,66 @@ type rewardActorInfo struct { effectiveNetworkTime int64 effectiveBaselinePower big.Int + // NOTE: These variables are wrong. Talk to @ZX about fixing. These _do + // not_ represent "new" anything. newBaselinePower big.Int newBaseReward big.Int - newSmoothingEstimate *smoothing.FilterEstimate + newSmoothingEstimate builtin.FilterEstimate totalMinedReward big.Int } +func (rw *rewardActorInfo) set(s reward.State) error { + if p, err := s.CumsumBaseline(); err != nil { + return xerrors.Errorf("getting cumsum baseline power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.cumSumBaselinePower = p + } + + if p, err := s.CumsumRealized(); err != nil { + return xerrors.Errorf("getting cumsum realized power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.cumSumRealizedPower = p + } + + if t, err := s.EffectiveNetworkTime(); err != nil { + return xerrors.Errorf("getting effective network time (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.effectiveNetworkTime = int64(t) + } + + if p, err := s.EffectiveBaselinePower(); err != nil { + return xerrors.Errorf("getting effective baseline power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.effectiveBaselinePower = p + } + + if t, err := s.TotalStoragePowerReward(); err != nil { + return xerrors.Errorf("getting total mined (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.totalMinedReward = t + } + + if p, err := s.ThisEpochBaselinePower(); err != nil { + return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.newBaselinePower = p + } + + if t, err := s.ThisEpochReward(); err != nil { + return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.newBaseReward = t + } + + if e, err := s.ThisEpochRewardSmoothed(); err != nil { + return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) + } else { + rw.newSmoothingEstimate = e + } + return nil +} + func (p *Processor) setupRewards() error { tx, err := p.db.Begin() if err != nil { @@ -89,29 +142,19 @@ func (p *Processor) processRewardActors(ctx context.Context, rewardTips ActorTip rw.common = act // get reward actor states at each tipset once for all updates - rewardActor, err := p.node.StateGetActor(ctx, builtin.RewardActorAddr, tipset) + rewardActor, err := p.node.StateGetActor(ctx, reward.Address, tipset) if err != nil { return nil, xerrors.Errorf("get reward state (@ %s): %w", rw.common.stateroot.String(), err) } - rewardStateRaw, err := p.node.ChainReadObj(ctx, rewardActor.Head) + rewardActorState, err := reward.Load(cw_util.NewAPIIpldStore(ctx, p.node), rewardActor) if err != nil { return nil, xerrors.Errorf("read state obj (@ %s): %w", rw.common.stateroot.String(), err) } - - var rewardActorState reward.State - if err := rewardActorState.UnmarshalCBOR(bytes.NewReader(rewardStateRaw)); err != nil { - return nil, xerrors.Errorf("unmarshal state (@ %s): %w", rw.common.stateroot.String(), err) + if err := rw.set(rewardActorState); err != nil { + return nil, err } - rw.cumSumBaselinePower = rewardActorState.CumsumBaseline - rw.cumSumRealizedPower = rewardActorState.CumsumRealized - rw.effectiveNetworkTime = int64(rewardActorState.EffectiveNetworkTime) - rw.effectiveBaselinePower = rewardActorState.EffectiveBaselinePower - rw.newBaselinePower = rewardActorState.ThisEpochBaselinePower - rw.newBaseReward = rewardActorState.ThisEpochReward - rw.newSmoothingEstimate = rewardActorState.ThisEpochRewardSmoothed - rw.totalMinedReward = rewardActorState.TotalMined out = append(out, rw) } } @@ -126,29 +169,19 @@ func (p *Processor) processRewardActors(ctx context.Context, rewardTips ActorTip rw.common.stateroot = tipset.ParentState() rw.common.parentTsKey = tipset.Parents() // get reward actor states at each tipset once for all updates - rewardActor, err := p.node.StateGetActor(ctx, builtin.RewardActorAddr, tsKey) + rewardActor, err := p.node.StateGetActor(ctx, reward.Address, tsKey) if err != nil { return nil, err } - rewardStateRaw, err := p.node.ChainReadObj(ctx, rewardActor.Head) + rewardActorState, err := reward.Load(cw_util.NewAPIIpldStore(ctx, p.node), rewardActor) if err != nil { - return nil, err + return nil, xerrors.Errorf("read state obj (@ %s): %w", rw.common.stateroot.String(), err) } - var rewardActorState reward.State - if err := rewardActorState.UnmarshalCBOR(bytes.NewReader(rewardStateRaw)); err != nil { + if err := rw.set(rewardActorState); err != nil { return nil, err } - - rw.cumSumBaselinePower = rewardActorState.CumsumBaseline - rw.cumSumRealizedPower = rewardActorState.CumsumRealized - rw.effectiveNetworkTime = int64(rewardActorState.EffectiveNetworkTime) - rw.effectiveBaselinePower = rewardActorState.EffectiveBaselinePower - rw.newBaselinePower = rewardActorState.ThisEpochBaselinePower - rw.newBaseReward = rewardActorState.ThisEpochReward - rw.newSmoothingEstimate = rewardActorState.ThisEpochRewardSmoothed - rw.totalMinedReward = rewardActorState.TotalMined out = append(out, rw) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 05fcc51714d..3bed0dfbb8e 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -940,7 +940,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) } else if s, err := reward.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else if r, err := s.RewardSmoothed(); err != nil { + } else if r, err := s.ThisEpochRewardSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) } else { rewardSmoothed = r @@ -1011,7 +1011,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) } else if s, err := reward.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else if r, err := s.RewardSmoothed(); err != nil { + } else if r, err := s.ThisEpochRewardSmoothed(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) } else if p, err := s.ThisEpochBaselinePower(); err != nil { return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) From 298efa221cf8908e7aefb2476b997420e18c554a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 13:52:07 -0700 Subject: [PATCH 059/104] fix lint errors --- cmd/lotus-chainwatch/processor/power.go | 37 ++++++++++--------- cmd/lotus-chainwatch/processor/reward.go | 47 ++++++++++-------------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/cmd/lotus-chainwatch/processor/power.go b/cmd/lotus-chainwatch/processor/power.go index 403580e3ba5..726a46706d0 100644 --- a/cmd/lotus-chainwatch/processor/power.go +++ b/cmd/lotus-chainwatch/processor/power.go @@ -88,30 +88,24 @@ func (p *Processor) processPowerActors(ctx context.Context, powerTips ActorTips) return nil, xerrors.Errorf("get power state (@ %s): %w", pw.common.stateroot.String(), err) } - if totalPower, err := powerActorState.TotalPower(); err != nil { + totalPower, err := powerActorState.TotalPower() + if err != nil { return nil, xerrors.Errorf("failed to compute total power: %w", err) - } else { - pw.totalRawBytes = totalPower.RawBytePower - pw.totalQualityAdjustedBytes = totalPower.QualityAdjPower } - if totalCommitted, err := powerActorState.TotalCommitted(); err != nil { + totalCommitted, err := powerActorState.TotalCommitted() + if err != nil { return nil, xerrors.Errorf("failed to compute total committed: %w", err) - } else { - pw.totalRawBytesCommitted = totalCommitted.RawBytePower - pw.totalQualityAdjustedBytesCommitted = totalCommitted.QualityAdjPower } - if totalLocked, err := powerActorState.TotalLocked(); err != nil { + totalLocked, err := powerActorState.TotalLocked() + if err != nil { return nil, xerrors.Errorf("failed to compute total locked: %w", err) - } else { - pw.totalPledgeCollateral = totalLocked } - if powerSmoothed, err := powerActorState.TotalPowerSmoothed(); err != nil { + powerSmoothed, err := powerActorState.TotalPowerSmoothed() + if err != nil { return nil, xerrors.Errorf("failed to determine smoothed power: %w", err) - } else { - pw.qaPowerSmoothed = powerSmoothed } // NOTE: this doesn't set new* fields. Previously, we @@ -120,12 +114,19 @@ func (p *Processor) processPowerActors(ctx context.Context, powerTips ActorTips) // state and don't represent "new" power, as was // assumed. - if participating, total, err := powerActorState.MinerCounts(); err != nil { + participatingMiners, totalMiners, err := powerActorState.MinerCounts() + if err != nil { return nil, xerrors.Errorf("failed to count miners: %w", err) - } else { - pw.minerCountAboveMinimumPower = int64(participating) - pw.minerCount = int64(total) } + + pw.totalRawBytes = totalPower.RawBytePower + pw.totalQualityAdjustedBytes = totalPower.QualityAdjPower + pw.totalRawBytesCommitted = totalCommitted.RawBytePower + pw.totalQualityAdjustedBytesCommitted = totalCommitted.QualityAdjPower + pw.totalPledgeCollateral = totalLocked + pw.qaPowerSmoothed = powerSmoothed + pw.minerCountAboveMinimumPower = int64(participatingMiners) + pw.minerCount = int64(totalMiners) } } diff --git a/cmd/lotus-chainwatch/processor/reward.go b/cmd/lotus-chainwatch/processor/reward.go index 35d4bbf01f3..72a329c87a0 100644 --- a/cmd/lotus-chainwatch/processor/reward.go +++ b/cmd/lotus-chainwatch/processor/reward.go @@ -6,6 +6,7 @@ import ( "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -21,7 +22,7 @@ type rewardActorInfo struct { cumSumBaselinePower big.Int cumSumRealizedPower big.Int - effectiveNetworkTime int64 + effectiveNetworkTime abi.ChainEpoch effectiveBaselinePower big.Int // NOTE: These variables are wrong. Talk to @ZX about fixing. These _do @@ -33,53 +34,45 @@ type rewardActorInfo struct { totalMinedReward big.Int } -func (rw *rewardActorInfo) set(s reward.State) error { - if p, err := s.CumsumBaseline(); err != nil { +func (rw *rewardActorInfo) set(s reward.State) (err error) { + rw.cumSumBaselinePower, err = s.CumsumBaseline() + if err != nil { return xerrors.Errorf("getting cumsum baseline power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.cumSumBaselinePower = p } - if p, err := s.CumsumRealized(); err != nil { + rw.cumSumRealizedPower, err = s.CumsumRealized() + if err != nil { return xerrors.Errorf("getting cumsum realized power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.cumSumRealizedPower = p } - if t, err := s.EffectiveNetworkTime(); err != nil { + rw.effectiveNetworkTime, err = s.EffectiveNetworkTime() + if err != nil { return xerrors.Errorf("getting effective network time (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.effectiveNetworkTime = int64(t) } - if p, err := s.EffectiveBaselinePower(); err != nil { + rw.effectiveBaselinePower, err = s.EffectiveBaselinePower() + if err != nil { return xerrors.Errorf("getting effective baseline power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.effectiveBaselinePower = p } - if t, err := s.TotalStoragePowerReward(); err != nil { + rw.totalMinedReward, err = s.TotalStoragePowerReward() + if err != nil { return xerrors.Errorf("getting total mined (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.totalMinedReward = t } - if p, err := s.ThisEpochBaselinePower(); err != nil { + rw.newBaselinePower, err = s.ThisEpochBaselinePower() + if err != nil { return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.newBaselinePower = p } - if t, err := s.ThisEpochReward(); err != nil { + rw.newBaseReward, err = s.ThisEpochReward() + if err != nil { return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.newBaseReward = t } - if e, err := s.ThisEpochRewardSmoothed(); err != nil { + rw.newSmoothingEstimate, err = s.ThisEpochRewardSmoothed() + if err != nil { return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err) - } else { - rw.newSmoothingEstimate = e } return nil } @@ -213,7 +206,7 @@ func (p *Processor) persistRewardActors(ctx context.Context, rewards []rewardAct rewardState.common.stateroot.String(), rewardState.cumSumBaselinePower.String(), rewardState.cumSumRealizedPower.String(), - rewardState.effectiveNetworkTime, + uint64(rewardState.effectiveNetworkTime), rewardState.effectiveBaselinePower.String(), rewardState.newBaselinePower.String(), rewardState.newBaseReward.String(), From 8747c6083e6ecc1c60620c8dcf67bb07a304d8d4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:20:53 -0700 Subject: [PATCH 060/104] abstract over account actor --- chain/actors/builtin/account/account.go | 31 +++++++++++++++++++++++++ chain/actors/builtin/account/v0.go | 16 +++++++++++++ chain/vm/vm.go | 13 ++++------- 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 chain/actors/builtin/account/account.go create mode 100644 chain/actors/builtin/account/v0.go diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go new file mode 100644 index 00000000000..d4cbe4177cf --- /dev/null +++ b/chain/actors/builtin/account/account.go @@ -0,0 +1,31 @@ +package account + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/cbor" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" +) + +func Load(store adt.Store, act *types.Actor) (State, error) { + switch act.Code { + case v0builtin.AccountActorCodeID: + out := v0State{store: store} + err := store.Get(store.Context(), act.Head, &out) + if err != nil { + return nil, err + } + return &out, nil + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +type State interface { + cbor.Marshaler + + PubkeyAddress() (address.Address, error) +} diff --git a/chain/actors/builtin/account/v0.go b/chain/actors/builtin/account/v0.go new file mode 100644 index 00000000000..6001dd7bff1 --- /dev/null +++ b/chain/actors/builtin/account/v0.go @@ -0,0 +1,16 @@ +package account + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/specs-actors/actors/builtin/account" +) + +type v0State struct { + account.State + store adt.Store +} + +func (s *v0State) PubkeyAddress() (address.Address, error) { + return s.Address, nil +} diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 542dfee695b..25c937ca3e5 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -23,10 +23,11 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/aerrors" + "github.com/filecoin-project/lotus/chain/actors/builtin/account" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/blockstore" @@ -49,16 +50,12 @@ func ResolveToKeyAddr(state types.StateTree, cst cbor.IpldStore, addr address.Ad return address.Undef, xerrors.Errorf("failed to find actor: %s", addr) } - if act.Code != builtin.AccountActorCodeID { - return address.Undef, xerrors.Errorf("address %s was not for an account actor", addr) - } - - var aast account.State - if err := cst.Get(context.TODO(), act.Head, &aast); err != nil { + aast, err := account.Load(adt.WrapStore(context.TODO(), cst), act) + if err != nil { return address.Undef, xerrors.Errorf("failed to get account actor state for %s: %w", addr, err) } - return aast.Address, nil + return aast.PubkeyAddress() } var _ cbor.IpldBlockstore = (*gasChargingBlocks)(nil) From 24df873498f0af9ec38672a7c6c9024ec6546b5f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:21:05 -0700 Subject: [PATCH 061/104] rename imports --- chain/vm/invoker.go | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index b31b45767b4..501b933e26e 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -6,28 +6,28 @@ import ( "fmt" "reflect" - "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/aerrors" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - "github.com/filecoin-project/specs-actors/actors/builtin/market" + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0account "github.com/filecoin-project/specs-actors/actors/builtin/account" + v0cron "github.com/filecoin-project/specs-actors/actors/builtin/cron" + v0init "github.com/filecoin-project/specs-actors/actors/builtin/init" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/actors/builtin/system" - "github.com/filecoin-project/specs-actors/actors/runtime" + v0system "github.com/filecoin-project/specs-actors/actors/builtin/system" + v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" vmr "github.com/filecoin-project/specs-actors/actors/runtime" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/exitcode" + + "github.com/filecoin-project/lotus/chain/actors/aerrors" ) type Invoker struct { @@ -35,7 +35,7 @@ type Invoker struct { builtInState map[cid.Cid]reflect.Type } -type invokeFunc func(rt runtime.Runtime, params []byte) ([]byte, aerrors.ActorError) +type invokeFunc func(rt vmr.Runtime, params []byte) ([]byte, aerrors.ActorError) type nativeCode []invokeFunc func NewInvoker() *Invoker { @@ -46,22 +46,22 @@ func NewInvoker() *Invoker { // add builtInCode using: register(cid, singleton) // NETUPGRADE: register code IDs for v2, etc. - inv.Register(builtin.SystemActorCodeID, system.Actor{}, abi.EmptyValue{}) - inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{}) - inv.Register(builtin.RewardActorCodeID, v0reward.Actor{}, v0reward.State{}) - inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{}) - inv.Register(builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) - inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{}) - inv.Register(builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) - inv.Register(builtin.MultisigActorCodeID, v0msig.Actor{}, v0msig.State{}) - inv.Register(builtin.PaymentChannelActorCodeID, paych.Actor{}, paych.State{}) - inv.Register(builtin.VerifiedRegistryActorCodeID, v0verifreg.Actor{}, v0verifreg.State{}) - inv.Register(builtin.AccountActorCodeID, account.Actor{}, account.State{}) + inv.Register(v0builtin.SystemActorCodeID, v0system.Actor{}, abi.EmptyValue{}) + inv.Register(v0builtin.InitActorCodeID, v0init.Actor{}, v0init.State{}) + inv.Register(v0builtin.RewardActorCodeID, v0reward.Actor{}, v0reward.State{}) + inv.Register(v0builtin.CronActorCodeID, v0cron.Actor{}, v0cron.State{}) + inv.Register(v0builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) + inv.Register(v0builtin.StorageMarketActorCodeID, v0market.Actor{}, v0market.State{}) + inv.Register(v0builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) + inv.Register(v0builtin.MultisigActorCodeID, v0msig.Actor{}, v0msig.State{}) + inv.Register(v0builtin.PaymentChannelActorCodeID, v0paych.Actor{}, v0paych.State{}) + inv.Register(v0builtin.VerifiedRegistryActorCodeID, v0verifreg.Actor{}, v0verifreg.State{}) + inv.Register(v0builtin.AccountActorCodeID, v0account.Actor{}, v0account.State{}) return inv } -func (inv *Invoker) Invoke(codeCid cid.Cid, rt runtime.Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { +func (inv *Invoker) Invoke(codeCid cid.Cid, rt vmr.Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { code, ok := inv.builtInCode[codeCid] if !ok { @@ -177,7 +177,7 @@ func DecodeParams(b []byte, out interface{}) error { } func DumpActorState(code cid.Cid, b []byte) (interface{}, error) { - if code == builtin.AccountActorCodeID { // Account code special case + if code == v0builtin.AccountActorCodeID { // Account code special case return nil, nil } From e60027c00af38a2dee6b3de14c4f28a582b21069 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:22:38 -0700 Subject: [PATCH 062/104] remove todo --- chain/stmgr/stmgr.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index fee76369a0e..d183b7ce253 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -1183,9 +1183,7 @@ func (sm *StateManager) GetMarketState(ctx context.Context, ts *types.TipSet) (m return nil, err } - // TODO maybe there needs to be code here to differentiate address based on ts height? - addr := builtin.StorageMarketActorAddr - act, err := st.GetActor(addr) + act, err := st.GetActor(market.Address) if err != nil { return nil, err } From 8285eda8e507358f5a64080e3894573f6b5b131c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:46:42 -0700 Subject: [PATCH 063/104] migrate storage miner info --- chain/actors/builtin/miner/miner.go | 10 +++++++ chain/actors/builtin/miner/v0.go | 16 +++++++++++ cmd/lotus-storage-miner/info.go | 44 +++++++++++++---------------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 82dc002ca31..c67e773bf25 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -35,8 +35,12 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler + // Total available balance to spend. AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error) + // Funds that will vest by the given epoch. VestedFunds(abi.ChainEpoch) (abi.TokenAmount, error) + // Funds locked for various reasons. + LockedFunds() (LockedFunds, error) GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) FindSector(abi.SectorNumber) (*SectorLocation, error) @@ -138,3 +142,9 @@ type PreCommitChanges struct { Added []SectorPreCommitOnChainInfo Removed []SectorPreCommitOnChainInfo } + +type LockedFunds struct { + VestingFunds abi.TokenAmount + InitialPledgeRequirement abi.TokenAmount + PreCommitDeposits abi.TokenAmount +} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index d333dff7683..0f27d7d7fea 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -40,6 +40,22 @@ func (s *v0State) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.CheckVestedFunds(s.store, epoch) } +func (s *v0State) LockedFunds() (LockedFunds, error) { + return LockedFunds{ + VestingFunds: s.State.LockedFunds, + InitialPledgeRequirement: s.State.InitialPledgeRequirement, + PreCommitDeposits: s.State.PreCommitDeposits, + }, nil +} + +func (s *v0State) InitialPledge() (abi.TokenAmount, error) { + return s.State.InitialPledgeRequirement, nil +} + +func (s *v0State) PreCommitDeposits() (abi.TokenAmount, error) { + return s.State.PreCommitDeposits, nil +} + func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { info, ok, err := s.State.GetSector(s.store, num) if !ok || err != nil { diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 3a7720c52ac..3ccfd67da48 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "context" "fmt" "sort" @@ -16,12 +15,12 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-state-types/abi" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/blockstore" @@ -54,11 +53,6 @@ func infoCmdAct(cctx *cli.Context) error { ctx := lcli.ReqContext(cctx) - head, err := api.ChainHead(ctx) - if err != nil { - return xerrors.Errorf("getting chain head: %w", err) - } - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) if err != nil { return err @@ -68,15 +62,11 @@ func infoCmdAct(cctx *cli.Context) error { if err != nil { return err } - var mas miner.State - { - rmas, err := api.ChainReadObj(ctx, mact.Head) - if err != nil { - return err - } - if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil { - return err - } + + tbs := bufbstore.NewTieredBstore(apibstore.NewAPIBlockstore(api), blockstore.NewTemporary()) + mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) + if err != nil { + return err } fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) @@ -172,17 +162,21 @@ func infoCmdAct(cctx *cli.Context) error { fmt.Printf("\tActive: %d, %s (Verified: %d, %s)\n", nactiveDeals, types.SizeStr(types.NewInt(uint64(activeDealBytes))), nVerifDeals, types.SizeStr(types.NewInt(uint64(activeVerifDealBytes)))) fmt.Println() - tbs := bufbstore.NewTieredBstore(apibstore.NewAPIBlockstore(api), blockstore.NewTemporary()) - _, err = mas.UnlockVestedFunds(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), head.Height()) + // NOTE: there's no need to unlock anything here. Funds only + // vest on deadline boundaries, and they're unlocked by cron. + lockedFunds, err := mas.LockedFunds() if err != nil { - return xerrors.Errorf("calculating vested funds: %w", err) + return xerrors.Errorf("getting locked funds: %w", err) + } + availBalance, err := mas.AvailableBalance(mact.Balance) + if err != nil { + return xerrors.Errorf("getting available balance: %w", err) } - fmt.Printf("Miner Balance: %s\n", color.YellowString("%s", types.FIL(mact.Balance))) - fmt.Printf("\tPreCommit: %s\n", types.FIL(mas.PreCommitDeposits)) - fmt.Printf("\tPledge: %s\n", types.FIL(mas.InitialPledgeRequirement)) - fmt.Printf("\tLocked: %s\n", types.FIL(mas.LockedFunds)) - color.Green("\tAvailable: %s", types.FIL(mas.GetAvailableBalance(mact.Balance))) + fmt.Printf("\tPreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits)) + fmt.Printf("\tPledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement)) + fmt.Printf("\tVesting: %s\n", types.FIL(lockedFunds.VestingFunds)) + color.Green("\tAvailable: %s", types.FIL(availBalance)) wb, err := api.WalletBalance(ctx, mi.Worker) if err != nil { return xerrors.Errorf("getting worker balance: %w", err) From 4a7055c32874a08f13ec850e63480dd30a30e66c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:46:55 -0700 Subject: [PATCH 064/104] fix state loading in vm --- chain/vm/syscalls.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index aab1812d9ca..a7f5dab0c85 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -7,8 +7,6 @@ import ( goruntime "runtime" "sync" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/go-address" @@ -20,6 +18,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" @@ -192,8 +192,8 @@ func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error { } // use that to get the miner state - var mas miner.State - if err = ss.cst.Get(ss.ctx, act.Head, &mas); err != nil { + mas, err := miner.Load(adt.WrapStore(ss.ctx, ss.cst), act) + if err != nil { return err } From f741ce6e3090fefe18d8d480a507b435b54d9fb5 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:51:18 -0700 Subject: [PATCH 065/104] fixup some more imports --- cmd/lotus-storage-miner/actor.go | 11 ++++++----- cmd/lotus-storage-miner/init.go | 17 +++++++++-------- cmd/lotus-storage-miner/sectors.go | 3 +-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index c84e006d7fb..2493c5a1e18 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -14,8 +14,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" @@ -87,7 +88,7 @@ var actorSetAddrsCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) + params, err := actors.SerializeParams(&v0miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) if err != nil { return err } @@ -152,7 +153,7 @@ var actorSetPeeridCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&miner.ChangePeerIDParams{NewID: abi.PeerID(pid)}) + params, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(pid)}) if err != nil { return err } @@ -225,7 +226,7 @@ var actorWithdrawCmd = &cli.Command{ } } - params, err := actors.SerializeParams(&miner.WithdrawBalanceParams{ + params, err := actors.SerializeParams(&v0miner.WithdrawBalanceParams{ AmountRequested: amount, // Default to attempting to withdraw all the extra funds in the miner actor }) if err != nil { @@ -450,7 +451,7 @@ var actorControlSet = &cli.Command{ return nil } - cwp := &miner.ChangeWorkerAddressParams{ + cwp := &v0miner.ChangeWorkerAddressParams{ NewWorker: mi.Worker, NewControlAddrs: toSet, } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 8325aae8bb2..715daead849 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -31,9 +31,10 @@ import ( sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/stores" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" - miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" lapi "github.com/filecoin-project/lotus/api" @@ -372,7 +373,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string, return mds.Put(datastore.NewKey(modules.StorageCounterDSPrefix), buf[:size]) } -func findMarketDealID(ctx context.Context, api lapi.FullNode, deal market.DealProposal) (abi.DealID, error) { +func findMarketDealID(ctx context.Context, api lapi.FullNode, deal v0market.DealProposal) (abi.DealID, error) { // TODO: find a better way // (this is only used by genesis miners) @@ -566,7 +567,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. return xerrors.Errorf("getWorkerAddr returned bad address: %w", err) } - enc, err := actors.SerializeParams(&miner2.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) + enc, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) if err != nil { return err } @@ -574,7 +575,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. msg := &types.Message{ To: addr, From: mi.Worker, - Method: builtin.MethodsMiner.ChangePeerID, + Method: v0builtin.MethodsMiner.ChangePeerID, Params: enc, Value: types.NewInt(0), GasPremium: gasPrice, @@ -653,11 +654,11 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, } createStorageMinerMsg := &types.Message{ - To: builtin.StoragePowerActorAddr, + To: v0builtin.StoragePowerActorAddr, From: sender, Value: big.Zero(), - Method: builtin.MethodsPower.CreateMiner, + Method: v0builtin.MethodsPower.CreateMiner, Params: params, GasLimit: 0, diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 06f09fe2078..032a68ac243 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -8,14 +8,13 @@ import ( "text/tabwriter" "time" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/urfave/cli/v2" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) From c130806c374905ec8afa1c25d0201bd1c2c9fe48 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:59:14 -0700 Subject: [PATCH 066/104] compile fix --- cmd/lotus-storage-miner/sectors.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 032a68ac243..5659bed79a2 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -13,6 +13,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" + v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" @@ -378,7 +380,7 @@ var sectorsCapacityCollateralCmd = &cli.Command{ Expiration: abi.ChainEpoch(cctx.Uint64("expiration")), } if pci.Expiration == 0 { - pci.Expiration = miner.MaxSectorExpirationExtension + pci.Expiration = v0miner.MaxSectorExpirationExtension } pc, err := nApi.StateMinerInitialPledgeCollateral(ctx, maddr, pci, types.EmptyTSK) if err != nil { From 1bf3b4989dae6ddde14ed8ae5d81b15057901c0f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 14:59:27 -0700 Subject: [PATCH 067/104] rename imports to match actors code `sed -i 's/\bv0\(\w\)\(\w*\)/\L\1\E\20/g' **/*.go` --- build/params_2k.go | 12 +-- build/params_shared_funcs.go | 6 +- build/params_shared_vals.go | 4 +- build/params_testground.go | 4 +- build/params_testnet.go | 8 +- chain/actors/adt/adt.go | 8 +- chain/actors/adt/diff_adt_test.go | 10 +- chain/actors/builtin/account/account.go | 6 +- chain/actors/builtin/account/v0.go | 4 +- chain/actors/builtin/builtin.go | 4 +- chain/actors/builtin/init/init.go | 8 +- chain/actors/builtin/init/v0.go | 14 +-- chain/actors/builtin/market/market.go | 8 +- chain/actors/builtin/market/v0.go | 106 +++++++++--------- chain/actors/builtin/miner/miner.go | 30 +++--- chain/actors/builtin/miner/v0.go | 120 ++++++++++----------- chain/actors/builtin/multisig/multisig.go | 6 +- chain/actors/builtin/multisig/v0.go | 10 +- chain/actors/builtin/paych/paych.go | 6 +- chain/actors/builtin/paych/v0.go | 30 +++--- chain/actors/builtin/power/power.go | 8 +- chain/actors/builtin/power/v0.go | 24 ++--- chain/actors/builtin/reward/reward.go | 8 +- chain/actors/builtin/reward/v0.go | 18 ++-- chain/actors/builtin/verifreg/v0.go | 12 +-- chain/actors/builtin/verifreg/verifreg.go | 8 +- chain/events/state/predicates.go | 4 +- chain/events/state/predicates_test.go | 78 +++++++------- chain/gen/gen.go | 4 +- chain/gen/gen_test.go | 12 +-- chain/gen/genesis/genesis.go | 60 +++++------ chain/gen/genesis/miners.go | 42 ++++---- chain/gen/genesis/t02_reward.go | 4 +- chain/gen/genesis/t04_power.go | 4 +- chain/gen/genesis/t06_vreg.go | 4 +- chain/stmgr/forks.go | 14 +-- chain/stmgr/forks_test.go | 12 +-- chain/stmgr/stmgr.go | 16 +-- chain/stmgr/utils.go | 30 +++--- chain/store/store_test.go | 12 +-- chain/sync_test.go | 12 +-- chain/vectors/gen/main.go | 8 +- chain/vm/invoker.go | 48 ++++----- cli/multisig.go | 14 +-- cli/paych_test.go | 12 +-- cmd/lotus-pcr/main.go | 4 +- cmd/lotus-storage-miner/actor.go | 10 +- cmd/lotus-storage-miner/init.go | 22 ++-- cmd/lotus-storage-miner/sectors.go | 4 +- extern/storage-sealing/checks.go | 8 +- extern/storage-sealing/constants.go | 4 +- extern/storage-sealing/precommit_policy.go | 4 +- extern/storage-sealing/sealing.go | 4 +- extern/storage-sealing/states_sealing.go | 8 +- node/impl/client/client.go | 4 +- node/impl/full/state.go | 14 +-- node/node_test.go | 14 +-- node/test/builder.go | 4 +- paychmgr/manager.go | 14 +-- paychmgr/paych.go | 22 ++-- paychmgr/paych_test.go | 36 +++---- paychmgr/simple.go | 4 +- storage/adapter_storage_miner.go | 4 +- storage/miner.go | 4 +- storage/wdpost_run_test.go | 8 +- 65 files changed, 534 insertions(+), 534 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index 61c5fd71dea..4a49da22ba4 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -5,9 +5,9 @@ package build import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" ) const UpgradeBreezeHeight = -1 @@ -20,11 +20,11 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ } func init() { - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + power0.ConsensusMinerMinPower = big.NewInt(2048) + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + verifreg0.MinVerifiedDealSize = big.NewInt(256) BuildType |= Build2k } diff --git a/build/params_shared_funcs.go b/build/params_shared_funcs.go index 08f16cefd68..0e9739914b1 100644 --- a/build/params_shared_funcs.go +++ b/build/params_shared_funcs.go @@ -6,14 +6,14 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" "github.com/filecoin-project/go-state-types/abi" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/node/modules/dtypes" ) func DefaultSectorSize() abi.SectorSize { - szs := make([]abi.SectorSize, 0, len(v0miner.SupportedProofTypes)) - for spt := range v0miner.SupportedProofTypes { + szs := make([]abi.SectorSize, 0, len(miner0.SupportedProofTypes)) + for spt := range miner0.SupportedProofTypes { ss, err := spt.SectorSize() if err != nil { panic(err) diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index ac7796ae756..3ee9f52ec7a 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // ///// @@ -32,7 +32,7 @@ const ForkLengthThreshold = Finality var BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch) // Epochs -const Finality = v0miner.ChainFinality +const Finality = miner0.ChainFinality const MessageConfidence = uint64(5) // constants for Weight calculation diff --git a/build/params_testground.go b/build/params_testground.go index 1b30ae2e93a..954b5ccfd67 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) var ( @@ -32,7 +32,7 @@ var ( AllowableClockDriftSecs = uint64(1) - Finality = v0miner.ChainFinality + Finality = miner0.ChainFinality ForkLengthThreshold = Finality SlashablePowerDelay = 20 diff --git a/build/params_testnet.go b/build/params_testnet.go index a879d3ba71f..108aba20c1a 100644 --- a/build/params_testnet.go +++ b/build/params_testnet.go @@ -8,8 +8,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" ) var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ @@ -23,8 +23,8 @@ const BreezeGasTampingDuration = 120 const UpgradeSmokeHeight = 51000 func init() { - v0power.ConsensusMinerMinPower = big.NewInt(10 << 40) - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + power0.ConsensusMinerMinPower = big.NewInt(10 << 40) + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg32GiBV1: {}, abi.RegisteredSealProof_StackedDrg64GiBV1: {}, } diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index ebf32c3c4bf..fd5ee3f875c 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/actors/builtin" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) type Map interface { @@ -24,7 +24,7 @@ type Map interface { func AsMap(store Store, root cid.Cid, version builtin.Version) (Map, error) { switch version { case builtin.Version0: - return v0adt.AsMap(store, root) + return adt0.AsMap(store, root) } return nil, xerrors.Errorf("unknown network version: %d", version) } @@ -32,7 +32,7 @@ func AsMap(store Store, root cid.Cid, version builtin.Version) (Map, error) { func NewMap(store Store, version builtin.Version) (Map, error) { switch version { case builtin.Version0: - return v0adt.MakeEmptyMap(store), nil + return adt0.MakeEmptyMap(store), nil } return nil, xerrors.Errorf("unknown network version: %d", version) } @@ -51,7 +51,7 @@ type Array interface { func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) { switch builtin.VersionForNetwork(version) { case builtin.Version0: - return v0adt.AsArray(store, root) + return adt0.AsArray(store, root) } return nil, xerrors.Errorf("unknown network version: %d", version) } diff --git a/chain/actors/adt/diff_adt_test.go b/chain/actors/adt/diff_adt_test.go index 436e28bbf52..1c0726003db 100644 --- a/chain/actors/adt/diff_adt_test.go +++ b/chain/actors/adt/diff_adt_test.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/runtime" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" bstore "github.com/filecoin-project/lotus/lib/blockstore" ) @@ -22,8 +22,8 @@ func TestDiffAdtArray(t *testing.T) { ctxstoreA := newContextStore() ctxstoreB := newContextStore() - arrA := v0adt.MakeEmptyArray(ctxstoreA) - arrB := v0adt.MakeEmptyArray(ctxstoreB) + arrA := adt0.MakeEmptyArray(ctxstoreA) + arrB := adt0.MakeEmptyArray(ctxstoreB) require.NoError(t, arrA.Set(0, runtime.CBORBytes([]byte{0}))) // delete @@ -76,8 +76,8 @@ func TestDiffAdtMap(t *testing.T) { ctxstoreA := newContextStore() ctxstoreB := newContextStore() - mapA := v0adt.MakeEmptyMap(ctxstoreA) - mapB := v0adt.MakeEmptyMap(ctxstoreB) + mapA := adt0.MakeEmptyMap(ctxstoreA) + mapB := adt0.MakeEmptyMap(ctxstoreB) require.NoError(t, mapA.Put(abi.UIntKey(0), runtime.CBORBytes([]byte{0}))) // delete diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index d4cbe4177cf..5b90580ece5 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -13,8 +13,8 @@ import ( func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { - case v0builtin.AccountActorCodeID: - out := v0State{store: store} + case builtin0.AccountActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/account/v0.go b/chain/actors/builtin/account/v0.go index 6001dd7bff1..535255d0e1b 100644 --- a/chain/actors/builtin/account/v0.go +++ b/chain/actors/builtin/account/v0.go @@ -6,11 +6,11 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/account" ) -type v0State struct { +type state0 struct { account.State store adt.Store } -func (s *v0State) PubkeyAddress() (address.Address, error) { +func (s *state0) PubkeyAddress() (address.Address, error) { return s.Address, nil } diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index bee8e59d6d9..4ce77804c0c 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-state-types/network" - v0smoothing "github.com/filecoin-project/specs-actors/actors/util/smoothing" + smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" ) type Version int @@ -25,4 +25,4 @@ func VersionForNetwork(version network.Version) Version { } // TODO: find some way to abstract over this. -type FilterEstimate = v0smoothing.FilterEstimate +type FilterEstimate = smoothing0.FilterEstimate diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 7485c599ff3..1164891f8b3 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -6,19 +6,19 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" ) -var Address = v0builtin.InitActorAddr +var Address = builtin0.InitActorAddr func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { - case v0builtin.InitActorCodeID: - out := v0State{store: store} + case builtin0.InitActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index e286e1ef2b6..0e8395a08fd 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -10,24 +10,24 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) -type v0State struct { +type state0 struct { init_.State store adt.Store } -func (s *v0State) ResolveAddress(address address.Address) (address.Address, bool, error) { +func (s *state0) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } -func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, error) { +func (s *state0) MapAddressToNewID(address address.Address) (address.Address, error) { return s.State.MapAddressToNewID(s.store, address) } -func (s *v0State) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { - addrs, err := v0adt.AsMap(s.store, s.State.AddressMap) +func (s *state0) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := adt0.AsMap(s.store, s.State.AddressMap) if err != nil { return err } @@ -41,6 +41,6 @@ func (s *v0State) ForEachActor(cb func(id abi.ActorID, address address.Address) }) } -func (s *v0State) NetworkName() (dtypes.NetworkName, error) { +func (s *state0) NetworkName() (dtypes.NetworkName, error) { return dtypes.NetworkName(s.State.NetworkName), nil } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index c65fa093d2e..fa5f027b329 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -14,12 +14,12 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -var Address = v0builtin.StorageMarketActorAddr +var Address = builtin0.StorageMarketActorAddr func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.StorageMarketActorCodeID: - out := v0State{store: store} + case builtin0.StorageMarketActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 671907ad46a..27eee4c5062 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -8,95 +8,95 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" cbg "github.com/whyrusleeping/cbor-gen" ) -type v0State struct { +type state0 struct { market.State store adt.Store } -func (s *v0State) TotalLocked() (abi.TokenAmount, error) { +func (s *state0) TotalLocked() (abi.TokenAmount, error) { fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) fml = types.BigAdd(fml, s.TotalClientStorageFee) return fml, nil } -func (s *v0State) BalancesChanged(otherState State) bool { - v0otherState, ok := otherState.(*v0State) +func (s *state0) BalancesChanged(otherState State) bool { + otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare differnt versions of the state, so let's // just say that means the state of balances has changed return true } - return !s.State.EscrowTable.Equals(v0otherState.State.EscrowTable) || !s.State.LockedTable.Equals(v0otherState.State.LockedTable) + return !s.State.EscrowTable.Equals(otherState0.State.EscrowTable) || !s.State.LockedTable.Equals(otherState0.State.LockedTable) } -func (s *v0State) StatesChanged(otherState State) bool { - v0otherState, ok := otherState.(*v0State) +func (s *state0) StatesChanged(otherState State) bool { + otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare differnt versions of the state, so let's // just say that means the state of balances has changed return true } - return !s.State.States.Equals(v0otherState.State.States) + return !s.State.States.Equals(otherState0.State.States) } -func (s *v0State) States() (DealStates, error) { - stateArray, err := v0adt.AsArray(s.store, s.State.States) +func (s *state0) States() (DealStates, error) { + stateArray, err := adt0.AsArray(s.store, s.State.States) if err != nil { return nil, err } - return &v0DealStates{stateArray}, nil + return &dealStates0{stateArray}, nil } -func (s *v0State) ProposalsChanged(otherState State) bool { - v0otherState, ok := otherState.(*v0State) +func (s *state0) ProposalsChanged(otherState State) bool { + otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare differnt versions of the state, so let's // just say that means the state of balances has changed return true } - return !s.State.Proposals.Equals(v0otherState.State.Proposals) + return !s.State.Proposals.Equals(otherState0.State.Proposals) } -func (s *v0State) Proposals() (DealProposals, error) { - proposalArray, err := v0adt.AsArray(s.store, s.State.Proposals) +func (s *state0) Proposals() (DealProposals, error) { + proposalArray, err := adt0.AsArray(s.store, s.State.Proposals) if err != nil { return nil, err } - return &v0DealProposals{proposalArray}, nil + return &dealProposals0{proposalArray}, nil } -func (s *v0State) EscrowTable() (BalanceTable, error) { - bt, err := v0adt.AsBalanceTable(s.store, s.State.EscrowTable) +func (s *state0) EscrowTable() (BalanceTable, error) { + bt, err := adt0.AsBalanceTable(s.store, s.State.EscrowTable) if err != nil { return nil, err } - return &v0BalanceTable{bt}, nil + return &balanceTable0{bt}, nil } -func (s *v0State) LockedTable() (BalanceTable, error) { - bt, err := v0adt.AsBalanceTable(s.store, s.State.LockedTable) +func (s *state0) LockedTable() (BalanceTable, error) { + bt, err := adt0.AsBalanceTable(s.store, s.State.LockedTable) if err != nil { return nil, err } - return &v0BalanceTable{bt}, nil + return &balanceTable0{bt}, nil } -func (s *v0State) VerifyDealsForActivation( +func (s *state0) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, ) (weight, verifiedWeight abi.DealWeight, err error) { return market.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) } -type v0BalanceTable struct { - *v0adt.BalanceTable +type balanceTable0 struct { + *adt0.BalanceTable } -func (bt *v0BalanceTable) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*v0adt.Map)(bt.BalanceTable) +func (bt *balanceTable0) ForEach(cb func(address.Address, abi.TokenAmount) error) error { + asMap := (*adt0.Map)(bt.BalanceTable) var ta abi.TokenAmount return asMap.ForEach(&ta, func(key string) error { a, err := address.NewFromBytes([]byte(key)) @@ -107,33 +107,33 @@ func (bt *v0BalanceTable) ForEach(cb func(address.Address, abi.TokenAmount) erro }) } -type v0DealStates struct { +type dealStates0 struct { adt.Array } -func (s *v0DealStates) Get(dealID abi.DealID) (*DealState, bool, error) { - var v0deal market.DealState - found, err := s.Array.Get(uint64(dealID), &v0deal) +func (s *dealStates0) Get(dealID abi.DealID) (*DealState, bool, error) { + var deal0 market.DealState + found, err := s.Array.Get(uint64(dealID), &deal0) if err != nil { return nil, false, err } if !found { return nil, false, nil } - deal := fromV0DealState(v0deal) + deal := fromV0DealState(deal0) return &deal, true, nil } -func (s *v0DealStates) decode(val *cbg.Deferred) (*DealState, error) { - var v0ds market.DealState - if err := v0ds.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { +func (s *dealStates0) decode(val *cbg.Deferred) (*DealState, error) { + var ds0 market.DealState + if err := ds0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - ds := fromV0DealState(v0ds) + ds := fromV0DealState(ds0) return &ds, nil } -func (s *v0DealStates) array() adt.Array { +func (s *dealStates0) array() adt.Array { return s.Array } @@ -141,40 +141,40 @@ func fromV0DealState(v0 market.DealState) DealState { return (DealState)(v0) } -type v0DealProposals struct { +type dealProposals0 struct { adt.Array } -func (s *v0DealProposals) Get(dealID abi.DealID) (*DealProposal, bool, error) { - var v0proposal market.DealProposal - found, err := s.Array.Get(uint64(dealID), &v0proposal) +func (s *dealProposals0) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var proposal0 market.DealProposal + found, err := s.Array.Get(uint64(dealID), &proposal0) if err != nil { return nil, false, err } if !found { return nil, false, nil } - proposal := fromV0DealProposal(v0proposal) + proposal := fromV0DealProposal(proposal0) return &proposal, true, nil } -func (s *v0DealProposals) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { - var v0dp market.DealProposal - return s.Array.ForEach(&v0dp, func(idx int64) error { - return cb(abi.DealID(idx), fromV0DealProposal(v0dp)) +func (s *dealProposals0) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var dp0 market.DealProposal + return s.Array.ForEach(&dp0, func(idx int64) error { + return cb(abi.DealID(idx), fromV0DealProposal(dp0)) }) } -func (s *v0DealProposals) decode(val *cbg.Deferred) (*DealProposal, error) { - var v0dp market.DealProposal - if err := v0dp.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { +func (s *dealProposals0) decode(val *cbg.Deferred) (*DealProposal, error) { + var dp0 market.DealProposal + if err := dp0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV0DealProposal(v0dp) + dp := fromV0DealProposal(dp0) return &dp, nil } -func (s *v0DealProposals) array() adt.Array { +func (s *dealProposals0) array() adt.Array { return s.Array } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index c67e773bf25..b9cff99daa3 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -10,19 +10,19 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" ) -var Address = v0builtin.InitActorAddr +var Address = builtin0.InitActorAddr func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.StorageMinerActorCodeID: - out := v0State{store: store} + case builtin0.StorageMinerActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err @@ -83,18 +83,18 @@ type Partition interface { ActiveSectors() (bitfield.BitField, error) } -type SectorOnChainInfo = v0miner.SectorOnChainInfo -type SectorPreCommitInfo = v0miner.SectorPreCommitInfo -type SectorPreCommitOnChainInfo = v0miner.SectorPreCommitOnChainInfo -type PoStPartition = v0miner.PoStPartition -type RecoveryDeclaration = v0miner.RecoveryDeclaration -type FaultDeclaration = v0miner.FaultDeclaration +type SectorOnChainInfo = miner0.SectorOnChainInfo +type SectorPreCommitInfo = miner0.SectorPreCommitInfo +type SectorPreCommitOnChainInfo = miner0.SectorPreCommitOnChainInfo +type PoStPartition = miner0.PoStPartition +type RecoveryDeclaration = miner0.RecoveryDeclaration +type FaultDeclaration = miner0.FaultDeclaration // Params -type DeclareFaultsParams = v0miner.DeclareFaultsParams -type DeclareFaultsRecoveredParams = v0miner.DeclareFaultsRecoveredParams -type SubmitWindowedPoStParams = v0miner.SubmitWindowedPoStParams -type ProveCommitSectorParams = v0miner.ProveCommitSectorParams +type DeclareFaultsParams = miner0.DeclareFaultsParams +type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams +type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams +type ProveCommitSectorParams = miner0.ProveCommitSectorParams type MinerInfo struct { Owner address.Address // Must be an ID-address. diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 0f27d7d7fea..26a91edd14b 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -9,38 +9,38 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/chain/actors/adt" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) -type v0State struct { - v0miner.State +type state0 struct { + miner0.State store adt.Store } -type v0Deadline struct { - v0miner.Deadline +type deadline0 struct { + miner0.Deadline store adt.Store } -type v0Partition struct { - v0miner.Partition +type partition0 struct { + miner0.Partition store adt.Store } -func (s *v0State) AvailableBalance(bal abi.TokenAmount) (abi.TokenAmount, error) { +func (s *state0) AvailableBalance(bal abi.TokenAmount) (abi.TokenAmount, error) { return s.GetAvailableBalance(bal), nil } -func (s *v0State) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { +func (s *state0) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.CheckVestedFunds(s.store, epoch) } -func (s *v0State) LockedFunds() (LockedFunds, error) { +func (s *state0) LockedFunds() (LockedFunds, error) { return LockedFunds{ VestingFunds: s.State.LockedFunds, InitialPledgeRequirement: s.State.InitialPledgeRequirement, @@ -48,15 +48,15 @@ func (s *v0State) LockedFunds() (LockedFunds, error) { }, nil } -func (s *v0State) InitialPledge() (abi.TokenAmount, error) { +func (s *state0) InitialPledge() (abi.TokenAmount, error) { return s.State.InitialPledgeRequirement, nil } -func (s *v0State) PreCommitDeposits() (abi.TokenAmount, error) { +func (s *state0) PreCommitDeposits() (abi.TokenAmount, error) { return s.State.PreCommitDeposits, nil } -func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { +func (s *state0) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { info, ok, err := s.State.GetSector(s.store, num) if !ok || err != nil { return nil, err @@ -65,7 +65,7 @@ func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { return info, nil } -func (s *v0State) FindSector(num abi.SectorNumber) (*SectorLocation, error) { +func (s *state0) FindSector(num abi.SectorNumber) (*SectorLocation, error) { dlIdx, partIdx, err := s.State.FindSector(s.store, num) if err != nil { return nil, err @@ -81,7 +81,7 @@ func (s *v0State) FindSector(num abi.SectorNumber) (*SectorLocation, error) { // If the sector isn't found or has already been terminated, this method returns // nil and no error. If the sector does not expire early, the Early expiration // field is 0. -func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { +func (s *state0) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { return nil, err @@ -94,13 +94,13 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, // of the expiration queue. stopErr := errors.New("stop") out := SectorExpiration{} - err = dls.ForEach(s.store, func(dlIdx uint64, dl *v0miner.Deadline) error { + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner0.Deadline) error { partitions, err := dl.PartitionsArray(s.store) if err != nil { return err } quant := s.State.QuantSpecForDeadline(dlIdx) - var part v0miner.Partition + var part miner0.Partition return partitions.ForEach(&part, func(partIdx int64) error { if found, err := part.Sectors.IsSet(uint64(num)); err != nil { return err @@ -114,11 +114,11 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, return stopErr } - q, err := v0miner.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant) + q, err := miner0.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant) if err != nil { return err } - var exp v0miner.ExpirationSet + var exp miner0.ExpirationSet return q.ForEach(&exp, func(epoch int64) error { if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { return err @@ -148,7 +148,7 @@ func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, return &out, nil } -func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -157,8 +157,8 @@ func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitO return info, nil } -func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) { - a, err := v0adt.AsArray(s.store, s.State.Sectors) +func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) { + a, err := adt0.AsArray(s.store, s.State.Sectors) if err != nil { return nil, err } @@ -185,11 +185,11 @@ func (s *v0State) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) return a, nil } -func (s *v0State) LoadPreCommittedSectors() (adt.Map, error) { - return v0adt.AsMap(s.store, s.State.PreCommittedSectors) +func (s *state0) LoadPreCommittedSectors() (adt.Map, error) { + return adt0.AsMap(s.store, s.State.PreCommittedSectors) } -func (s *v0State) IsAllocated(num abi.SectorNumber) (bool, error) { +func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) { var allocatedSectors bitfield.BitField if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { return false, err @@ -198,7 +198,7 @@ func (s *v0State) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } -func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { +func (s *state0) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { return nil, err @@ -207,39 +207,39 @@ func (s *v0State) LoadDeadline(idx uint64) (Deadline, error) { if err != nil { return nil, err } - return &v0Deadline{*dl, s.store}, nil + return &deadline0{*dl, s.store}, nil } -func (s *v0State) ForEachDeadline(cb func(uint64, Deadline) error) error { +func (s *state0) ForEachDeadline(cb func(uint64, Deadline) error) error { dls, err := s.State.LoadDeadlines(s.store) if err != nil { return err } - return dls.ForEach(s.store, func(i uint64, dl *v0miner.Deadline) error { - return cb(i, &v0Deadline{*dl, s.store}) + return dls.ForEach(s.store, func(i uint64, dl *miner0.Deadline) error { + return cb(i, &deadline0{*dl, s.store}) }) } -func (s *v0State) NumDeadlines() (uint64, error) { - return v0miner.WPoStPeriodDeadlines, nil +func (s *state0) NumDeadlines() (uint64, error) { + return miner0.WPoStPeriodDeadlines, nil } // Max sectors per PoSt -func (s *v0State) MaxAddressedSectors() (uint64, error) { - return v0miner.AddressedSectorsMax, nil +func (s *state0) MaxAddressedSectors() (uint64, error) { + return miner0.AddressedSectorsMax, nil } -func (s *v0State) DeadlinesChanged(other State) bool { - v0other, ok := other.(*v0State) +func (s *state0) DeadlinesChanged(other State) bool { + other0, ok := other.(*state0) if !ok { // treat an upgrade as a change, always return true } - return s.State.Deadlines.Equals(v0other.Deadlines) + return s.State.Deadlines.Equals(other0.Deadlines) } -func (s *v0State) Info() (MinerInfo, error) { +func (s *state0) Info() (MinerInfo, error) { info, err := s.State.GetInfo(s.store) if err != nil { return MinerInfo{}, err @@ -273,71 +273,71 @@ func (s *v0State) Info() (MinerInfo, error) { return mi, nil } -func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { +func (s *state0) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { return s.State.DeadlineInfo(epoch) } -func (s *v0State) sectors() (adt.Array, error) { - return v0adt.AsArray(s.store, s.Sectors) +func (s *state0) sectors() (adt.Array, error) { + return adt0.AsArray(s.store, s.Sectors) } -func (s *v0State) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { - var si v0miner.SectorOnChainInfo +func (s *state0) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si miner0.SectorOnChainInfo err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) return si, err } -func (s *v0State) precommits() (adt.Map, error) { - return v0adt.AsMap(s.store, s.PreCommittedSectors) +func (s *state0) precommits() (adt.Map, error) { + return adt0.AsMap(s.store, s.PreCommittedSectors) } -func (s *v0State) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { - var sp v0miner.SectorPreCommitOnChainInfo +func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { + var sp miner0.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) return sp, err } -func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) { +func (d *deadline0) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { return nil, err } - return &v0Partition{*p, d.store}, nil + return &partition0{*p, d.store}, nil } -func (d *v0Deadline) ForEachPartition(cb func(uint64, Partition) error) error { +func (d *deadline0) ForEachPartition(cb func(uint64, Partition) error) error { ps, err := d.Deadline.PartitionsArray(d.store) if err != nil { return err } - var part v0miner.Partition + var part miner0.Partition return ps.ForEach(&part, func(i int64) error { - return cb(uint64(i), &v0Partition{part, d.store}) + return cb(uint64(i), &partition0{part, d.store}) }) } -func (d *v0Deadline) PartitionsChanged(other Deadline) bool { - v0other, ok := other.(*v0Deadline) +func (d *deadline0) PartitionsChanged(other Deadline) bool { + other0, ok := other.(*deadline0) if !ok { // treat an upgrade as a change, always return true } - return d.Deadline.Partitions.Equals(v0other.Deadline.Partitions) + return d.Deadline.Partitions.Equals(other0.Deadline.Partitions) } -func (d *v0Deadline) PostSubmissions() (bitfield.BitField, error) { +func (d *deadline0) PostSubmissions() (bitfield.BitField, error) { return d.Deadline.PostSubmissions, nil } -func (p *v0Partition) AllSectors() (bitfield.BitField, error) { +func (p *partition0) AllSectors() (bitfield.BitField, error) { return p.Partition.Sectors, nil } -func (p *v0Partition) FaultySectors() (bitfield.BitField, error) { +func (p *partition0) FaultySectors() (bitfield.BitField, error) { return p.Partition.Faults, nil } -func (p *v0Partition) RecoveringSectors() (bitfield.BitField, error) { +func (p *partition0) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index fc58599a9c2..86a68c178ce 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -13,8 +13,8 @@ import ( func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { - case v0builtin.MultisigActorCodeID: - out := v0State{store: store} + case builtin0.MultisigActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index dc464d9afe5..ded834d5f06 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -6,23 +6,23 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/multisig" ) -type v0State struct { +type state0 struct { multisig.State store adt.Store } -func (s *v0State) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { +func (s *state0) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } -func (s *v0State) StartEpoch() abi.ChainEpoch { +func (s *state0) StartEpoch() abi.ChainEpoch { return s.State.StartEpoch } -func (s *v0State) UnlockDuration() abi.ChainEpoch { +func (s *state0) UnlockDuration() abi.ChainEpoch { return s.State.UnlockDuration } -func (s *v0State) InitialBalance() abi.TokenAmount { +func (s *state0) InitialBalance() abi.TokenAmount { return s.State.InitialBalance } diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go index 974d64fde11..5eec5f08b5e 100644 --- a/chain/actors/builtin/paych/paych.go +++ b/chain/actors/builtin/paych/paych.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -16,8 +16,8 @@ import ( // Load returns an abstract copy of payment channel state, irregardless of actor version func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { - case v0builtin.PaymentChannelActorCodeID: - out := v0State{store: store} + case builtin0.PaymentChannelActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go index 7d63b891315..0c4b2f218ab 100644 --- a/chain/actors/builtin/paych/v0.go +++ b/chain/actors/builtin/paych/v0.go @@ -6,42 +6,42 @@ import ( big "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) -type v0State struct { +type state0 struct { paych.State store adt.Store - lsAmt *v0adt.Array + lsAmt *adt0.Array } // Channel owner, who has funded the actor -func (s *v0State) From() address.Address { +func (s *state0) From() address.Address { return s.State.From } // Recipient of payouts from channel -func (s *v0State) To() address.Address { +func (s *state0) To() address.Address { return s.State.To } // Height at which the channel can be `Collected` -func (s *v0State) SettlingAt() abi.ChainEpoch { +func (s *state0) SettlingAt() abi.ChainEpoch { return s.State.SettlingAt } // Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *v0State) ToSend() abi.TokenAmount { +func (s *state0) ToSend() abi.TokenAmount { return s.State.ToSend } -func (s *v0State) getOrLoadLsAmt() (*v0adt.Array, error) { +func (s *state0) getOrLoadLsAmt() (*adt0.Array, error) { if s.lsAmt != nil { return s.lsAmt, nil } // Get the lane state from the chain - lsamt, err := v0adt.AsArray(s.store, s.State.LaneStates) + lsamt, err := adt0.AsArray(s.store, s.State.LaneStates) if err != nil { return nil, err } @@ -51,7 +51,7 @@ func (s *v0State) getOrLoadLsAmt() (*v0adt.Array, error) { } // Get total number of lanes -func (s *v0State) LaneCount() (uint64, error) { +func (s *state0) LaneCount() (uint64, error) { lsamt, err := s.getOrLoadLsAmt() if err != nil { return 0, err @@ -60,7 +60,7 @@ func (s *v0State) LaneCount() (uint64, error) { } // Iterate lane states -func (s *v0State) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { +func (s *state0) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain lsamt, err := s.getOrLoadLsAmt() if err != nil { @@ -72,18 +72,18 @@ func (s *v0State) ForEachLaneState(cb func(idx uint64, dl LaneState) error) erro // very large index. var ls paych.LaneState return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &v0LaneState{ls}) + return cb(uint64(i), &laneState0{ls}) }) } -type v0LaneState struct { +type laneState0 struct { paych.LaneState } -func (ls *v0LaneState) Redeemed() big.Int { +func (ls *laneState0) Redeemed() big.Int { return ls.LaneState.Redeemed } -func (ls *v0LaneState) Nonce() uint64 { +func (ls *laneState0) Nonce() uint64 { return ls.LaneState.Nonce } diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 7170526bf91..e4bb52d440e 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -6,19 +6,19 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -var Address = v0builtin.StoragePowerActorAddr +var Address = builtin0.StoragePowerActorAddr func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.StoragePowerActorCodeID: - out := v0State{store: store} + case builtin0.StoragePowerActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 9730be893c5..1d5a93d2b06 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -4,20 +4,20 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/builtin" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" ) -type v0State struct { - v0power.State +type state0 struct { + power0.State store adt.Store } -func (s *v0State) TotalLocked() (abi.TokenAmount, error) { +func (s *state0) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } -func (s *v0State) TotalPower() (Claim, error) { +func (s *state0) TotalPower() (Claim, error) { return Claim{ RawBytePower: s.TotalRawBytePower, QualityAdjPower: s.TotalQualityAdjPower, @@ -25,19 +25,19 @@ func (s *v0State) TotalPower() (Claim, error) { } // Committed power to the network. Includes miners below the minimum threshold. -func (s *v0State) TotalCommitted() (Claim, error) { +func (s *state0) TotalCommitted() (Claim, error) { return Claim{ RawBytePower: s.TotalBytesCommitted, QualityAdjPower: s.TotalQABytesCommitted, }, nil } -func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { +func (s *state0) MinerPower(addr address.Address) (Claim, bool, error) { claims, err := adt.AsMap(s.store, s.Claims) if err != nil { return Claim{}, false, err } - var claim v0power.Claim + var claim power0.Claim ok, err := claims.Get(abi.AddrKey(addr), &claim) if err != nil { return Claim{}, false, err @@ -48,19 +48,19 @@ func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { }, ok, nil } -func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { +func (s *state0) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) } -func (s *v0State) TotalPowerSmoothed() (builtin.FilterEstimate, error) { +func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochQAPowerSmoothed, nil } -func (s *v0State) MinerCounts() (uint64, uint64, error) { +func (s *state0) MinerCounts() (uint64, uint64, error) { return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil } -func (s *v0State) ListAllMiners() ([]address.Address, error) { +func (s *state0) ListAllMiners() ([]address.Address, error) { claims, err := adt.AsMap(s.store, s.Claims) if err != nil { return nil, err diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 66df887fcbd..b56292fff0f 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -5,19 +5,19 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -var Address = v0builtin.RewardActorAddr +var Address = builtin0.RewardActorAddr func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { - case v0builtin.RewardActorCodeID: - out := v0State{store: store} + case builtin0.RewardActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index d12eccf5941..50ad4997118 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -7,39 +7,39 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/adt" ) -type v0State struct { +type state0 struct { reward.State store adt.Store } -func (s *v0State) ThisEpochReward() (abi.StoragePower, error) { +func (s *state0) ThisEpochReward() (abi.StoragePower, error) { return s.State.ThisEpochReward, nil } -func (s *v0State) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { +func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { return *s.State.ThisEpochRewardSmoothed, nil } -func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) { +func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) { return s.State.ThisEpochBaselinePower, nil } -func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) { +func (s *state0) TotalStoragePowerReward() (abi.TokenAmount, error) { return s.State.TotalMined, nil } -func (s *v0State) EffectiveBaselinePower() (abi.StoragePower, error) { +func (s *state0) EffectiveBaselinePower() (abi.StoragePower, error) { return s.State.EffectiveBaselinePower, nil } -func (s *v0State) EffectiveNetworkTime() (abi.ChainEpoch, error) { +func (s *state0) EffectiveNetworkTime() (abi.ChainEpoch, error) { return s.State.EffectiveNetworkTime, nil } -func (s *v0State) CumsumBaseline() (abi.StoragePower, error) { +func (s *state0) CumsumBaseline() (abi.StoragePower, error) { return s.State.CumsumBaseline, nil } -func (s *v0State) CumsumRealized() (abi.StoragePower, error) { +func (s *state0) CumsumRealized() (abi.StoragePower, error) { return s.State.CumsumBaseline, nil } diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index cbaf4d23660..c397d6679f9 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -4,24 +4,24 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/chain/actors/adt" ) -type v0State struct { - v0verifreg.State +type state0 struct { + verifreg0.State store adt.Store } -func (s *v0State) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { +func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { if addr.Protocol() != address.ID { return false, big.Zero(), xerrors.Errorf("can only look up ID addresses") } - vh, err := v0adt.AsMap(s.store, s.VerifiedClients) + vh, err := adt0.AsMap(s.store, s.VerifiedClients) if err != nil { return false, big.Zero(), xerrors.Errorf("loading verified clients: %w", err) } diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 4cb5bb55b26..000a9434950 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -6,18 +6,18 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" ) -var Address = v0builtin.VerifiedRegistryActorAddr +var Address = builtin0.VerifiedRegistryActorAddr func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { - case v0builtin.VerifiedRegistryActorCodeID: - out := v0State{store: store} + case builtin0.VerifiedRegistryActorCodeID: + out := state0{store: store} err := store.Get(store.Context(), act.Head, &out) if err != nil { return nil, err diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 21e1720e6e2..56dfb981d37 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -509,12 +509,12 @@ func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return false, nil, nil } - oldAddrs, err := v0adt.AsMap(ctxStore, oldState.AddressMap) + oldAddrs, err := adt0.AsMap(ctxStore, oldState.AddressMap) if err != nil { return false, nil, err } - newAddrs, err := v0adt.AsMap(ctxStore, newState.AddressMap) + newAddrs, err := adt0.AsMap(ctxStore, newState.AddressMap) if err != nil { return false, nil, err } diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 604eec75d90..832f6a0a767 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -19,10 +19,10 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/chain/actors/builtin/market" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" tutils "github.com/filecoin-project/specs-actors/support/testing" @@ -74,22 +74,22 @@ func TestMarketPredicates(t *testing.T) { bs := bstore.NewTemporarySync() store := adt.WrapStore(ctx, cbornode.NewCborStore(bs)) - oldDeal1 := &v0market.DealState{ + oldDeal1 := &market0.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 2, SlashEpoch: 0, } - oldDeal2 := &v0market.DealState{ + oldDeal2 := &market0.DealState{ SectorStartEpoch: 4, LastUpdatedEpoch: 5, SlashEpoch: 0, } - oldDeals := map[abi.DealID]*v0market.DealState{ + oldDeals := map[abi.DealID]*market0.DealState{ abi.DealID(1): oldDeal1, abi.DealID(2): oldDeal2, } - oldProp1 := &v0market.DealProposal{ + oldProp1 := &market0.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -101,7 +101,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - oldProp2 := &v0market.DealProposal{ + oldProp2 := &market0.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -113,7 +113,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - oldProps := map[abi.DealID]*v0market.DealProposal{ + oldProps := map[abi.DealID]*market0.DealProposal{ abi.DealID(1): oldProp1, abi.DealID(2): oldProp2, } @@ -127,7 +127,7 @@ func TestMarketPredicates(t *testing.T) { oldStateC := createMarketState(ctx, t, store, oldDeals, oldProps, oldBalances) - newDeal1 := &v0market.DealState{ + newDeal1 := &market0.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 3, SlashEpoch: 0, @@ -136,19 +136,19 @@ func TestMarketPredicates(t *testing.T) { // deal 2 removed // added - newDeal3 := &v0market.DealState{ + newDeal3 := &market0.DealState{ SectorStartEpoch: 1, LastUpdatedEpoch: 2, SlashEpoch: 3, } - newDeals := map[abi.DealID]*v0market.DealState{ + newDeals := map[abi.DealID]*market0.DealState{ abi.DealID(1): newDeal1, // deal 2 was removed abi.DealID(3): newDeal3, } // added - newProp3 := &v0market.DealProposal{ + newProp3 := &market0.DealProposal{ PieceCID: dummyCid, PieceSize: 0, VerifiedDeal: false, @@ -160,7 +160,7 @@ func TestMarketPredicates(t *testing.T) { ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } - newProps := map[abi.DealID]*v0market.DealProposal{ + newProps := map[abi.DealID]*market0.DealProposal{ abi.DealID(1): oldProp1, // 1 was persisted // prop 2 was removed abi.DealID(3): newProp3, // new @@ -183,8 +183,8 @@ func TestMarketPredicates(t *testing.T) { require.NoError(t, err) api := newMockAPI(bs) - api.setActor(oldState.Key(), &types.Actor{Code: v0builtin.StorageMarketActorCodeID, Head: oldStateC}) - api.setActor(newState.Key(), &types.Actor{Code: v0builtin.StorageMarketActorCodeID, Head: newStateC}) + api.setActor(oldState.Key(), &types.Actor{Code: builtin0.StorageMarketActorCodeID, Head: oldStateC}) + api.setActor(newState.Key(), &types.Actor{Code: builtin0.StorageMarketActorCodeID, Head: newStateC}) t.Run("deal ID predicate", func(t *testing.T) { preds := NewStatePredicates(api) @@ -239,11 +239,11 @@ func TestMarketPredicates(t *testing.T) { t.Fatal("No state change so this should not be called") return false, nil, nil }) - v0marketState := createEmptyMarketState(t, store) - marketCid, err := store.Put(ctx, v0marketState) + marketState0 := createEmptyMarketState(t, store) + marketCid, err := store.Put(ctx, marketState0) require.NoError(t, err) marketState, err := market.Load(store, &types.Actor{ - Code: v0builtin.StorageMarketActorCodeID, + Code: builtin0.StorageMarketActorCodeID, Head: marketCid, }) require.NoError(t, err) @@ -352,11 +352,11 @@ func TestMarketPredicates(t *testing.T) { t.Fatal("No state change so this should not be called") return false, nil, nil }) - v0marketState := createEmptyMarketState(t, store) - marketCid, err := store.Put(ctx, v0marketState) + marketState0 := createEmptyMarketState(t, store) + marketCid, err := store.Put(ctx, marketState0) require.NoError(t, err) marketState, err := market.Load(store, &types.Actor{ - Code: v0builtin.StorageMarketActorCodeID, + Code: builtin0.StorageMarketActorCodeID, Head: marketCid, }) require.NoError(t, err) @@ -379,12 +379,12 @@ func TestMinerSectorChange(t *testing.T) { } owner, worker := nextIDAddrF(), nextIDAddrF() - si0 := newSectorOnChainInfo(0, tutils.MakeCID("0", &v0miner.SealedCIDPrefix), big.NewInt(0), abi.ChainEpoch(0), abi.ChainEpoch(10)) - si1 := newSectorOnChainInfo(1, tutils.MakeCID("1", &v0miner.SealedCIDPrefix), big.NewInt(1), abi.ChainEpoch(1), abi.ChainEpoch(11)) - si2 := newSectorOnChainInfo(2, tutils.MakeCID("2", &v0miner.SealedCIDPrefix), big.NewInt(2), abi.ChainEpoch(2), abi.ChainEpoch(11)) + si0 := newSectorOnChainInfo(0, tutils.MakeCID("0", &miner0.SealedCIDPrefix), big.NewInt(0), abi.ChainEpoch(0), abi.ChainEpoch(10)) + si1 := newSectorOnChainInfo(1, tutils.MakeCID("1", &miner0.SealedCIDPrefix), big.NewInt(1), abi.ChainEpoch(1), abi.ChainEpoch(11)) + si2 := newSectorOnChainInfo(2, tutils.MakeCID("2", &miner0.SealedCIDPrefix), big.NewInt(2), abi.ChainEpoch(2), abi.ChainEpoch(11)) oldMinerC := createMinerState(ctx, t, store, owner, worker, []miner.SectorOnChainInfo{si0, si1, si2}) - si3 := newSectorOnChainInfo(3, tutils.MakeCID("3", &v0miner.SealedCIDPrefix), big.NewInt(3), abi.ChainEpoch(3), abi.ChainEpoch(12)) + si3 := newSectorOnChainInfo(3, tutils.MakeCID("3", &miner0.SealedCIDPrefix), big.NewInt(3), abi.ChainEpoch(3), abi.ChainEpoch(12)) // 0 delete // 1 extend // 2 same @@ -400,8 +400,8 @@ func TestMinerSectorChange(t *testing.T) { require.NoError(t, err) api := newMockAPI(bs) - api.setActor(oldState.Key(), &types.Actor{Head: oldMinerC, Code: v0builtin.StorageMinerActorCodeID}) - api.setActor(newState.Key(), &types.Actor{Head: newMinerC, Code: v0builtin.StorageMinerActorCodeID}) + api.setActor(oldState.Key(), &types.Actor{Head: oldMinerC, Code: builtin0.StorageMinerActorCodeID}) + api.setActor(newState.Key(), &types.Actor{Head: newMinerC, Code: builtin0.StorageMinerActorCodeID}) preds := NewStatePredicates(api) @@ -467,7 +467,7 @@ type balance struct { locked abi.TokenAmount } -func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*v0market.DealState, props map[abi.DealID]*v0market.DealProposal, balances map[address.Address]balance) cid.Cid { +func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*market0.DealState, props map[abi.DealID]*market0.DealProposal, balances map[address.Address]balance) cid.Cid { dealRootCid := createDealAMT(ctx, t, store, deals) propRootCid := createProposalAMT(ctx, t, store, props) balancesCids := createBalanceTable(ctx, t, store, balances) @@ -482,15 +482,15 @@ func createMarketState(ctx context.Context, t *testing.T, store adt.Store, deals return stateC } -func createEmptyMarketState(t *testing.T, store adt.Store) *v0market.State { +func createEmptyMarketState(t *testing.T, store adt.Store) *market0.State { emptyArrayCid, err := adt.MakeEmptyArray(store).Root() require.NoError(t, err) emptyMap, err := adt.MakeEmptyMap(store).Root() require.NoError(t, err) - return v0market.ConstructState(emptyArrayCid, emptyMap, emptyMap) + return market0.ConstructState(emptyArrayCid, emptyMap, emptyMap) } -func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*v0market.DealState) cid.Cid { +func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map[abi.DealID]*market0.DealState) cid.Cid { root := adt.MakeEmptyArray(store) for dealID, dealState := range deals { err := root.Set(uint64(dealID), dealState) @@ -501,7 +501,7 @@ func createDealAMT(ctx context.Context, t *testing.T, store adt.Store, deals map return rootCid } -func createProposalAMT(ctx context.Context, t *testing.T, store adt.Store, props map[abi.DealID]*v0market.DealProposal) cid.Cid { +func createProposalAMT(ctx context.Context, t *testing.T, store adt.Store, props map[abi.DealID]*market0.DealProposal) cid.Cid { root := adt.MakeEmptyArray(store) for dealID, prop := range props { err := root.Set(uint64(dealID), prop) @@ -549,20 +549,20 @@ func createMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, return stateC } -func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, worker address.Address) *v0miner.State { +func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, owner, worker address.Address) *miner0.State { emptyArrayCid, err := adt.MakeEmptyArray(store).Root() require.NoError(t, err) emptyMap, err := adt.MakeEmptyMap(store).Root() require.NoError(t, err) - emptyDeadline, err := store.Put(store.Context(), v0miner.ConstructDeadline(emptyArrayCid)) + emptyDeadline, err := store.Put(store.Context(), miner0.ConstructDeadline(emptyArrayCid)) require.NoError(t, err) - emptyVestingFunds := v0miner.ConstructVestingFunds() + emptyVestingFunds := miner0.ConstructVestingFunds() emptyVestingFundsCid, err := store.Put(store.Context(), emptyVestingFunds) require.NoError(t, err) - emptyDeadlines := v0miner.ConstructDeadlines(emptyDeadline) + emptyDeadlines := miner0.ConstructDeadlines(emptyDeadline) emptyDeadlinesCid, err := store.Put(store.Context(), emptyDeadlines) require.NoError(t, err) @@ -572,7 +572,7 @@ func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, o emptyBitfieldCid, err := store.Put(store.Context(), emptyBitfield) require.NoError(t, err) - state, err := v0miner.ConstructState(minerInfo, 123, emptyBitfieldCid, emptyArrayCid, emptyMap, emptyDeadlinesCid, emptyVestingFundsCid) + state, err := miner0.ConstructState(minerInfo, 123, emptyBitfieldCid, emptyArrayCid, emptyMap, emptyDeadlinesCid, emptyVestingFundsCid) require.NoError(t, err) return state @@ -625,7 +625,7 @@ func newSectorPreCommitInfo(sectorNo abi.SectorNumber, sealed cid.Cid, expiratio } } -func dealEquality(expected v0market.DealState, actual market.DealState) bool { +func dealEquality(expected market0.DealState, actual market.DealState) bool { return expected.LastUpdatedEpoch == actual.LastUpdatedEpoch && expected.SectorStartEpoch == actual.SectorStartEpoch && expected.SlashEpoch == actual.SlashEpoch diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 4163f0b2d0e..c4ecf1d41d5 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -14,7 +14,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" block "github.com/ipfs/go-block-format" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" @@ -121,7 +121,7 @@ var DefaultRemainderAccountActor = genesis.Actor{ } func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index 9d1262f7709..be913f5f2f3 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -5,20 +5,20 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" _ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/secp" ) func init() { - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + power0.ConsensusMinerMinPower = big.NewInt(2048) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } func testGeneration(t testing.TB, n int, msgs int, sectors int) { diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index be2ed70aaf3..039e284cd16 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -17,11 +17,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0account "github.com/filecoin-project/specs-actors/actors/builtin/account" - v0multisig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - v0adt "github.com/filecoin-project/specs-actors/actors/util/adt" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" + multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -126,7 +126,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - if err := state.SetActor(v0builtin.SystemActorAddr, sysact); err != nil { + if err := state.SetActor(builtin0.SystemActorAddr, sysact); err != nil { return nil, nil, xerrors.Errorf("set init actor: %w", err) } @@ -136,7 +136,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - if err := state.SetActor(v0builtin.InitActorAddr, initact); err != nil { + if err := state.SetActor(builtin0.InitActorAddr, initact); err != nil { return nil, nil, xerrors.Errorf("set init actor: %w", err) } @@ -147,7 +147,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - err = state.SetActor(v0builtin.RewardActorAddr, rewact) + err = state.SetActor(builtin0.RewardActorAddr, rewact) if err != nil { return nil, nil, xerrors.Errorf("set network account actor: %w", err) } @@ -157,7 +157,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup cron actor: %w", err) } - if err := state.SetActor(v0builtin.CronActorAddr, cronact); err != nil { + if err := state.SetActor(builtin0.CronActorAddr, cronact); err != nil { return nil, nil, xerrors.Errorf("set cron actor: %w", err) } @@ -166,7 +166,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(v0builtin.StoragePowerActorAddr, spact); err != nil { + if err := state.SetActor(builtin0.StoragePowerActorAddr, spact); err != nil { return nil, nil, xerrors.Errorf("set storage market actor: %w", err) } @@ -175,7 +175,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(v0builtin.StorageMarketActorAddr, marketact); err != nil { + if err := state.SetActor(builtin0.StorageMarketActorAddr, marketact); err != nil { return nil, nil, xerrors.Errorf("set market actor: %w", err) } @@ -184,20 +184,20 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(v0builtin.VerifiedRegistryActorAddr, verifact); err != nil { + if err := state.SetActor(builtin0.VerifiedRegistryActorAddr, verifact); err != nil { return nil, nil, xerrors.Errorf("set market actor: %w", err) } - burntRoot, err := cst.Put(ctx, &v0account.State{ - Address: v0builtin.BurntFundsActorAddr, + burntRoot, err := cst.Put(ctx, &account0.State{ + Address: builtin0.BurntFundsActorAddr, }) if err != nil { return nil, nil, xerrors.Errorf("failed to setup burnt funds actor state: %w", err) } // Setup burnt-funds - err = state.SetActor(v0builtin.BurntFundsActorAddr, &types.Actor{ - Code: v0builtin.AccountActorCodeID, + err = state.SetActor(builtin0.BurntFundsActorAddr, &types.Actor{ + Code: builtin0.AccountActorCodeID, Balance: types.NewInt(0), Head: burntRoot, }) @@ -262,13 +262,13 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, err } - verifierState, err := cst.Put(ctx, &v0account.State{Address: verifierAd}) + verifierState, err := cst.Put(ctx, &account0.State{Address: verifierAd}) if err != nil { return nil, nil, err } err = state.SetActor(verifierId, &types.Actor{ - Code: v0builtin.AccountActorCodeID, + Code: builtin0.AccountActorCodeID, Balance: types.NewInt(0), Head: verifierState, }) @@ -315,7 +315,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - st, err := cst.Put(ctx, &v0account.State{Address: ainfo.Owner}) + st, err := cst.Put(ctx, &account0.State{Address: ainfo.Owner}) if err != nil { return err } @@ -326,7 +326,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St } err = state.SetActor(ida, &types.Actor{ - Code: v0builtin.AccountActorCodeID, + Code: builtin0.AccountActorCodeID, Balance: info.Balance, Head: st, }) @@ -344,7 +344,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - pending, err := v0adt.MakeEmptyMap(v0adt.WrapStore(ctx, cst)).Root() + pending, err := adt0.MakeEmptyMap(adt0.WrapStore(ctx, cst)).Root() if err != nil { return xerrors.Errorf("failed to create empty map: %v", err) } @@ -364,12 +364,12 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I continue } - st, err := cst.Put(ctx, &v0account.State{Address: e}) + st, err := cst.Put(ctx, &account0.State{Address: e}) if err != nil { return err } err = state.SetActor(idAddress, &types.Actor{ - Code: v0builtin.AccountActorCodeID, + Code: builtin0.AccountActorCodeID, Balance: types.NewInt(0), Head: st, }) @@ -379,7 +379,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I signers = append(signers, idAddress) } - st, err := cst.Put(ctx, &v0multisig.State{ + st, err := cst.Put(ctx, &multisig0.State{ Signers: signers, NumApprovalsThreshold: uint64(ainfo.Threshold), StartEpoch: abi.ChainEpoch(ainfo.VestingStart), @@ -391,7 +391,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I return err } err = state.SetActor(ida, &types.Actor{ - Code: v0builtin.MultisigActorCodeID, + Code: builtin0.MultisigActorCodeID, Balance: info.Balance, Head: st, }) @@ -442,7 +442,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci return cid.Undef, err } - _, err = doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&v0verifreg.AddVerifierParams{ + _, err = doExecValue(ctx, vm, builtin0.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg0.AddVerifierParams{ Address: verifier, Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough @@ -453,7 +453,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci } for c, amt := range verifNeeds { - _, err := doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&v0verifreg.AddVerifiedClientParams{ + _, err := doExecValue(ctx, vm, builtin0.VerifiedRegistryActorAddr, verifier, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&verifreg0.AddVerifiedClientParams{ Address: c, Allowance: abi.NewStoragePower(int64(amt)), })) @@ -495,8 +495,8 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB return nil, xerrors.Errorf("setup miners failed: %w", err) } - store := v0adt.WrapStore(ctx, cbor.NewCborStore(bs)) - emptyroot, err := v0adt.MakeEmptyArray(store).Root() + store := adt0.WrapStore(ctx, cbor.NewCborStore(bs)) + emptyroot, err := adt0.MakeEmptyArray(store).Root() if err != nil { return nil, xerrors.Errorf("amt build failed: %w", err) } @@ -544,7 +544,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB } b := &types.BlockHeader{ - Miner: v0builtin.SystemActorAddr, + Miner: builtin0.SystemActorAddr, Ticket: genesisticket, Parents: []cid.Cid{filecoinGenesisCid}, Height: 0, diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index aff226882fe..853c9c4a0ac 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -20,9 +20,9 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/lotus/chain/state" @@ -101,7 +101,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } { - constructorParams := &v0power.CreateMinerParams{ + constructorParams := &power0.CreateMinerParams{ Owner: m.Worker, Worker: m.Worker, Peer: []byte(m.PeerId), @@ -114,7 +114,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) } - var ma v0power.CreateMinerReturn + var ma power0.CreateMinerReturn if err := ma.UnmarshalCBOR(bytes.NewReader(rval)); err != nil { return cid.Undef, xerrors.Errorf("unmarshaling CreateMinerReturn: %w", err) } @@ -126,9 +126,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid minerInfos[i].maddr = ma.IDAddress // TODO: ActorUpgrade - err = vm.MutateState(ctx, minerInfos[i].maddr, func(cst cbor.IpldStore, st *v0miner.State) error { - maxPeriods := v0miner.MaxSectorExpirationExtension / v0miner.WPoStProvingPeriod - minerInfos[i].presealExp = (maxPeriods-1)*v0miner.WPoStProvingPeriod + st.ProvingPeriodStart - 1 + err = vm.MutateState(ctx, minerInfos[i].maddr, func(cst cbor.IpldStore, st *miner0.State) error { + maxPeriods := miner0.MaxSectorExpirationExtension / miner0.WPoStProvingPeriod + minerInfos[i].presealExp = (maxPeriods-1)*miner0.WPoStProvingPeriod + st.ProvingPeriodStart - 1 return nil }) @@ -204,13 +204,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := v0miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := miner0.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) qaPow = types.BigAdd(qaPow, sectorWeight) } } - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { st.TotalQualityAdjPower = qaPow st.TotalRawBytePower = rawPow @@ -222,8 +222,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("mutating state: %w", err) } - err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *v0reward.State) error { - *st = *v0reward.ConstructState(qaPow) + err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward0.State) error { + *st = *reward0.ConstructState(qaPow) return nil }) if err != nil { @@ -249,10 +249,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := v0miner.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := miner0.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) // we've added fake power for this sector above, remove it now - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) //nolint:scopelint st.TotalRawBytePower = types.BigSub(st.TotalRawBytePower, types.NewInt(uint64(m.SectorSize))) return nil @@ -271,9 +271,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting current total power: %w", err) } - pcd := v0miner.PreCommitDepositForPower(epochReward.ThisEpochRewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) + pcd := miner0.PreCommitDepositForPower(epochReward.ThisEpochRewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) - pledge := v0miner.InitialPledgeForPower( + pledge := miner0.InitialPledgeForPower( sectorWeight, epochReward.ThisEpochBaselinePower, tpow.PledgeCollateral, @@ -304,7 +304,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } // Sanity-check total network power - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *v0power.State) error { + err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { if !st.TotalRawBytePower.Equals(rawPow) { return xerrors.Errorf("st.TotalRawBytePower doesn't match previously calculated rawPow") } @@ -343,12 +343,12 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry return out, nil } -func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*v0power.CurrentTotalPowerReturn, error) { +func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { pwret, err := doExecValue(ctx, vm, builtin.StoragePowerActorAddr, maddr, big.Zero(), builtin.MethodsPower.CurrentTotalPower, nil) if err != nil { return nil, err } - var pwr v0power.CurrentTotalPowerReturn + var pwr power0.CurrentTotalPowerReturn if err := pwr.UnmarshalCBOR(bytes.NewReader(pwret)); err != nil { return nil, err } @@ -381,13 +381,13 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [ return dealWeights, nil } -func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*v0reward.ThisEpochRewardReturn, error) { +func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*reward0.ThisEpochRewardReturn, error) { rwret, err := doExecValue(ctx, vm, builtin.RewardActorAddr, maddr, big.Zero(), builtin.MethodsReward.ThisEpochReward, nil) if err != nil { return nil, err } - var epochReward v0reward.ThisEpochRewardReturn + var epochReward reward0.ThisEpochRewardReturn if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil { return nil, err } diff --git a/chain/gen/genesis/t02_reward.go b/chain/gen/genesis/t02_reward.go index e29e390f9d5..92531051b14 100644 --- a/chain/gen/genesis/t02_reward.go +++ b/chain/gen/genesis/t02_reward.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/lotus/build" @@ -17,7 +17,7 @@ import ( func SetupRewardActor(bs bstore.Blockstore, qaPower big.Int) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - st := v0reward.ConstructState(qaPower) + st := reward0.ConstructState(qaPower) hcid, err := cst.Put(context.TODO(), st) if err != nil { diff --git a/chain/gen/genesis/t04_power.go b/chain/gen/genesis/t04_power.go index 40ea68079bc..2f1303ba46c 100644 --- a/chain/gen/genesis/t04_power.go +++ b/chain/gen/genesis/t04_power.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/lotus/chain/types" @@ -30,7 +30,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) { return nil, err } - sms := v0power.ConstructState(emptyMap, emptyMultiMap) + sms := power0.ConstructState(emptyMap, emptyMultiMap) stcid, err := store.Put(store.Context(), sms) if err != nil { diff --git a/chain/gen/genesis/t06_vreg.go b/chain/gen/genesis/t06_vreg.go index d91cdf7b1cc..1709b205f1f 100644 --- a/chain/gen/genesis/t06_vreg.go +++ b/chain/gen/genesis/t06_vreg.go @@ -7,7 +7,7 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/specs-actors/actors/builtin" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/chain/types" @@ -34,7 +34,7 @@ func SetupVerifiedRegistryActor(bs bstore.Blockstore) (*types.Actor, error) { return nil, err } - sms := v0verifreg.ConstructState(h, RootVerifierID) + sms := verifreg0.ConstructState(h, RootVerifierID) stcid, err := store.Put(store.Context(), sms) if err != nil { diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 6505367183b..bb496849b92 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -9,8 +9,8 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -135,7 +135,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types }) } case builtin.StorageMinerActorCodeID: - var st v0miner.State + var st miner0.State if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } @@ -172,7 +172,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types } // pull up power table to give miners back some funds proportional to their power - var ps v0power.State + var ps power0.State powAct, err := tree.GetActor(builtin.StoragePowerActorAddr) if err != nil { return xerrors.Errorf("failed to load power actor: %w", err) @@ -211,12 +211,12 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types }) } case builtin.StorageMinerActorCodeID: - var st v0miner.State + var st miner0.State if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } - var minfo v0miner.MinerInfo + var minfo miner0.MinerInfo if err := cst.Get(ctx, st.Info, &minfo); err != nil { return xerrors.Errorf("failed to get miner info: %w", err) } @@ -240,7 +240,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types // Now make sure to give each miner who had power at the lookback some FIL lbact, err := lbtree.GetActor(addr) if err == nil { - var lbst v0miner.State + var lbst miner0.State if err := sm.ChainStore().Store(ctx).Get(ctx, lbact.Head, &lbst); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) } diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index c4fb1b3be27..87d328ce199 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -11,9 +11,9 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/runtime" "golang.org/x/xerrors" @@ -33,11 +33,11 @@ import ( ) func init() { - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + power0.ConsensusMinerMinPower = big.NewInt(2048) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } const testForkHeight = 40 diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index d183b7ce253..e6e55793088 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" @@ -23,7 +23,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" @@ -251,7 +251,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp nv := sm.GetNtwkVersion(ctx, epoch) if nv < build.ActorUpgradeNetworkVersion { - params, err = actors.SerializeParams(&v0reward.AwardBlockRewardParams{ + params, err = actors.SerializeParams(&reward0.AwardBlockRewardParams{ Miner: b.Miner, Penalty: penalty, GasReward: gasReward, @@ -797,7 +797,7 @@ func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) ( } type genesisInfo struct { - genesisMsigs []v0msig.State + genesisMsigs []msig0.State // info about the Accounts in the genesis state genesisActors []genesisActor genesisPledge abi.TokenAmount @@ -898,9 +898,9 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return xerrors.Errorf("error setting up genesis infos: %w", err) } - gi.genesisMsigs = make([]v0msig.State, 0, len(totalsByEpoch)) + gi.genesisMsigs = make([]msig0.State, 0, len(totalsByEpoch)) for k, v := range totalsByEpoch { - ns := v0msig.State{ + ns := msig0.State{ InitialBalance: v, UnlockDuration: k, PendingTxns: cid.Undef, @@ -975,9 +975,9 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error { totalsByEpoch[sixYears] = big.NewInt(100_000_000) totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000)) - gi.genesisMsigs = make([]v0msig.State, 0, len(totalsByEpoch)) + gi.genesisMsigs = make([]msig0.State, 0, len(totalsByEpoch)) for k, v := range totalsByEpoch { - ns := v0msig.State{ + ns := msig0.State{ InitialBalance: v, UnlockDuration: k, PendingTxns: cid.Undef, diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 8c55fc1f2d2..3684b9e77ac 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -9,11 +9,11 @@ import ( "runtime" "strings" - v0init "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" saruntime "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime/proof" @@ -31,10 +31,10 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" "github.com/filecoin-project/specs-actors/actors/builtin/cron" - v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -169,7 +169,7 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, var sset []*miner.ChainSectorInfo var v cbg.Deferred if err := sectors.ForEach(&v, func(i int64) error { - var oci v0miner.SectorOnChainInfo + var oci miner0.SectorOnChainInfo if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { return err } @@ -555,16 +555,16 @@ var MethodsMap = map[cid.Cid]map[abi.MethodNum]MethodMeta{} func init() { cidToMethods := map[cid.Cid][2]interface{}{ // builtin.SystemActorCodeID: {builtin.MethodsSystem, system.Actor{} }- apparently it doesn't have methods - builtin.InitActorCodeID: {builtin.MethodsInit, v0init.Actor{}}, + builtin.InitActorCodeID: {builtin.MethodsInit, init0.Actor{}}, builtin.CronActorCodeID: {builtin.MethodsCron, cron.Actor{}}, builtin.AccountActorCodeID: {builtin.MethodsAccount, account.Actor{}}, - builtin.StoragePowerActorCodeID: {builtin.MethodsPower, v0power.Actor{}}, - builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, v0miner.Actor{}}, - builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, v0market.Actor{}}, + builtin.StoragePowerActorCodeID: {builtin.MethodsPower, power0.Actor{}}, + builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, miner0.Actor{}}, + builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market0.Actor{}}, builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, - builtin.MultisigActorCodeID: {builtin.MethodsMultisig, v0msig.Actor{}}, - builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}}, - builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, v0verifreg.Actor{}}, + builtin.MultisigActorCodeID: {builtin.MethodsMultisig, msig0.Actor{}}, + builtin.RewardActorCodeID: {builtin.MethodsReward, reward0.Actor{}}, + builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, verifreg0.Actor{}}, } for c, m := range cidToMethods { diff --git a/chain/store/store_test.go b/chain/store/store_test.go index 83238a67d05..d5e09255900 100644 --- a/chain/store/store_test.go +++ b/chain/store/store_test.go @@ -10,9 +10,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/store" @@ -22,11 +22,11 @@ import ( ) func init() { - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + power0.ConsensusMinerMinPower = big.NewInt(2048) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } func BenchmarkGetRandomness(b *testing.B) { diff --git a/chain/sync_test.go b/chain/sync_test.go index 2baa5d8a460..53001caf824 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -20,9 +20,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -43,11 +43,11 @@ func init() { if err != nil { panic(err) } - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + power0.ConsensusMinerMinPower = big.NewInt(2048) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } const source = 0 diff --git a/chain/vectors/gen/main.go b/chain/vectors/gen/main.go index 36b770f039e..2b1c6f34010 100644 --- a/chain/vectors/gen/main.go +++ b/chain/vectors/gen/main.go @@ -6,7 +6,7 @@ import ( "math/rand" "os" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/go-address" "golang.org/x/xerrors" @@ -19,15 +19,15 @@ import ( "github.com/filecoin-project/lotus/chain/types/mock" "github.com/filecoin-project/lotus/chain/vectors" "github.com/filecoin-project/lotus/chain/wallet" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" _ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/secp" ) func init() { - v0verifreg.MinVerifiedDealSize = big.NewInt(2048) - v0power.ConsensusMinerMinPower = big.NewInt(2048) + verifreg0.MinVerifiedDealSize = big.NewInt(2048) + power0.ConsensusMinerMinPower = big.NewInt(2048) } func MakeHeaderVectors() []vectors.HeaderVector { diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 501b933e26e..0a83e273d04 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -10,18 +10,18 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0account "github.com/filecoin-project/specs-actors/actors/builtin/account" - v0cron "github.com/filecoin-project/specs-actors/actors/builtin/cron" - v0init "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0reward "github.com/filecoin-project/specs-actors/actors/builtin/reward" - v0system "github.com/filecoin-project/specs-actors/actors/builtin/system" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" + cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" + system0 "github.com/filecoin-project/specs-actors/actors/builtin/system" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" vmr "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/go-state-types/abi" @@ -46,17 +46,17 @@ func NewInvoker() *Invoker { // add builtInCode using: register(cid, singleton) // NETUPGRADE: register code IDs for v2, etc. - inv.Register(v0builtin.SystemActorCodeID, v0system.Actor{}, abi.EmptyValue{}) - inv.Register(v0builtin.InitActorCodeID, v0init.Actor{}, v0init.State{}) - inv.Register(v0builtin.RewardActorCodeID, v0reward.Actor{}, v0reward.State{}) - inv.Register(v0builtin.CronActorCodeID, v0cron.Actor{}, v0cron.State{}) - inv.Register(v0builtin.StoragePowerActorCodeID, v0power.Actor{}, v0power.State{}) - inv.Register(v0builtin.StorageMarketActorCodeID, v0market.Actor{}, v0market.State{}) - inv.Register(v0builtin.StorageMinerActorCodeID, v0miner.Actor{}, v0miner.State{}) - inv.Register(v0builtin.MultisigActorCodeID, v0msig.Actor{}, v0msig.State{}) - inv.Register(v0builtin.PaymentChannelActorCodeID, v0paych.Actor{}, v0paych.State{}) - inv.Register(v0builtin.VerifiedRegistryActorCodeID, v0verifreg.Actor{}, v0verifreg.State{}) - inv.Register(v0builtin.AccountActorCodeID, v0account.Actor{}, v0account.State{}) + inv.Register(builtin0.SystemActorCodeID, system0.Actor{}, abi.EmptyValue{}) + inv.Register(builtin0.InitActorCodeID, init0.Actor{}, init0.State{}) + inv.Register(builtin0.RewardActorCodeID, reward0.Actor{}, reward0.State{}) + inv.Register(builtin0.CronActorCodeID, cron0.Actor{}, cron0.State{}) + inv.Register(builtin0.StoragePowerActorCodeID, power0.Actor{}, power0.State{}) + inv.Register(builtin0.StorageMarketActorCodeID, market0.Actor{}, market0.State{}) + inv.Register(builtin0.StorageMinerActorCodeID, miner0.Actor{}, miner0.State{}) + inv.Register(builtin0.MultisigActorCodeID, msig0.Actor{}, msig0.State{}) + inv.Register(builtin0.PaymentChannelActorCodeID, paych0.Actor{}, paych0.State{}) + inv.Register(builtin0.VerifiedRegistryActorCodeID, verifreg0.Actor{}, verifreg0.State{}) + inv.Register(builtin0.AccountActorCodeID, account0.Actor{}, account0.State{}) return inv } @@ -177,7 +177,7 @@ func DecodeParams(b []byte, out interface{}) error { } func DumpActorState(code cid.Cid, b []byte) (interface{}, error) { - if code == v0builtin.AccountActorCodeID { // Account code special case + if code == builtin0.AccountActorCodeID { // Account code special case return nil, nil } diff --git a/cli/multisig.go b/cli/multisig.go index ffbbd733b0d..23095bf061c 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/go-address" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0msig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/urfave/cli/v2" @@ -199,7 +199,7 @@ var msigInspectCmd = &cli.Command{ return err } - var mstate v0msig.State + var mstate msig0.State if err := mstate.UnmarshalCBOR(bytes.NewReader(obj)); err != nil { return err } @@ -251,7 +251,7 @@ var msigInspectCmd = &cli.Command{ }, } -func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*v0msig.Transaction, error) { +func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*msig0.Transaction, error) { bs := apibstore.NewAPIBlockstore(lapi) store := adt.WrapStore(ctx, cbor.NewCborStore(bs)) @@ -260,8 +260,8 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return nil, err } - txs := make(map[int64]*v0msig.Transaction) - var tx v0msig.Transaction + txs := make(map[int64]*msig0.Transaction) + var tx msig0.Transaction err = nd.ForEach(&tx, func(k string) error { txid, _ := binary.Varint([]byte(k)) @@ -276,7 +276,7 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return txs, nil } -func state(tx *v0msig.Transaction) string { +func state(tx *msig0.Transaction) string { /* // TODO(why): I strongly disagree with not having these... but i need to move forward if tx.Complete { return "done" @@ -385,7 +385,7 @@ var msigProposeCmd = &cli.Command{ return fmt.Errorf("proposal returned exit %d", wait.Receipt.ExitCode) } - var retval v0msig.ProposeReturn + var retval msig0.ProposeReturn if err := retval.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return fmt.Errorf("failed to unmarshal propose return value: %w", err) } diff --git a/cli/paych_test.go b/cli/paych_test.go index 598c178eb66..49631f1fcb0 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -15,9 +15,9 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/go-state-types/big" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/multiformats/go-multiaddr" @@ -40,11 +40,11 @@ import ( ) func init() { - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + power0.ConsensusMinerMinPower = big.NewInt(2048) + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } // TestPaymentChannels does a basic test to exercise the payment channel CLI diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 53c8223ed56..c8179d9b659 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -12,7 +12,7 @@ import ( "strconv" "time" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" @@ -403,7 +403,7 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu } if nv < build.ActorUpgradeNetworkVersion { - var proveCommitSector v0miner.ProveCommitSectorParams + var proveCommitSector miner0.ProveCommitSectorParams if err := proveCommitSector.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { log.Warnw("failed to decode provecommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) continue diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index 2493c5a1e18..ea21aa90d59 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -16,7 +16,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" @@ -88,7 +88,7 @@ var actorSetAddrsCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&v0miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) + params, err := actors.SerializeParams(&miner0.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) if err != nil { return err } @@ -153,7 +153,7 @@ var actorSetPeeridCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(pid)}) + params, err := actors.SerializeParams(&miner0.ChangePeerIDParams{NewID: abi.PeerID(pid)}) if err != nil { return err } @@ -226,7 +226,7 @@ var actorWithdrawCmd = &cli.Command{ } } - params, err := actors.SerializeParams(&v0miner.WithdrawBalanceParams{ + params, err := actors.SerializeParams(&miner0.WithdrawBalanceParams{ AmountRequested: amount, // Default to attempting to withdraw all the extra funds in the miner actor }) if err != nil { @@ -451,7 +451,7 @@ var actorControlSet = &cli.Command{ return nil } - cwp := &v0miner.ChangeWorkerAddressParams{ + cwp := &miner0.ChangeWorkerAddressParams{ NewWorker: mi.Worker, NewControlAddrs: toSet, } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 715daead849..4faf6a25b22 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -32,10 +32,10 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/stores" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -373,7 +373,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string, return mds.Put(datastore.NewKey(modules.StorageCounterDSPrefix), buf[:size]) } -func findMarketDealID(ctx context.Context, api lapi.FullNode, deal v0market.DealProposal) (abi.DealID, error) { +func findMarketDealID(ctx context.Context, api lapi.FullNode, deal market0.DealProposal) (abi.DealID, error) { // TODO: find a better way // (this is only used by genesis miners) @@ -567,7 +567,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. return xerrors.Errorf("getWorkerAddr returned bad address: %w", err) } - enc, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) + enc, err := actors.SerializeParams(&miner0.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) if err != nil { return err } @@ -575,7 +575,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. msg := &types.Message{ To: addr, From: mi.Worker, - Method: v0builtin.MethodsMiner.ChangePeerID, + Method: builtin0.MethodsMiner.ChangePeerID, Params: enc, Value: types.NewInt(0), GasPremium: gasPrice, @@ -634,7 +634,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, return address.Undef, err } - params, err := actors.SerializeParams(&v0power.CreateMinerParams{ + params, err := actors.SerializeParams(&power0.CreateMinerParams{ Owner: owner, Worker: worker, SealProofType: spt, @@ -654,11 +654,11 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, } createStorageMinerMsg := &types.Message{ - To: v0builtin.StoragePowerActorAddr, + To: builtin0.StoragePowerActorAddr, From: sender, Value: big.Zero(), - Method: v0builtin.MethodsPower.CreateMiner, + Method: builtin0.MethodsPower.CreateMiner, Params: params, GasLimit: 0, @@ -682,7 +682,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, return address.Undef, xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode) } - var retval v0power.CreateMinerReturn + var retval power0.CreateMinerReturn if err := retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)); err != nil { return address.Undef, err } diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 5659bed79a2..83550dbda48 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" @@ -380,7 +380,7 @@ var sectorsCapacityCollateralCmd = &cli.Command{ Expiration: abi.ChainEpoch(cctx.Uint64("expiration")), } if pci.Expiration == 0 { - pci.Expiration = v0miner.MaxSectorExpirationExtension + pci.Expiration = miner0.MaxSectorExpirationExtension } pc, err := nApi.StateMinerInitialPledgeCollateral(ctx, maddr, pci, types.EmptyTSK) if err != nil { diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index 677cef1e91b..27b62f49a71 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -5,9 +5,9 @@ import ( "context" "github.com/filecoin-project/lotus/build" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" "golang.org/x/xerrors" @@ -102,7 +102,7 @@ func checkPrecommit(ctx context.Context, maddr address.Address, si SectorInfo, t var msd abi.ChainEpoch if nv < build.ActorUpgradeNetworkVersion { - msd = v0miner.MaxSealDuration[si.SectorType] + msd = miner0.MaxSealDuration[si.SectorType] } else { // TODO: ActorUpgrade msd = 0 @@ -190,7 +190,7 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte, log.Warn("on-chain sealed CID doesn't match!") } - ok, err := m.verif.VerifySeal(v0proof.SealVerifyInfo{ + ok, err := m.verif.VerifySeal(proof0.SealVerifyInfo{ SectorID: m.minerSector(si.SectorNumber), SealedCID: pci.Info.SealedCID, SealProof: spt, diff --git a/extern/storage-sealing/constants.go b/extern/storage-sealing/constants.go index 06c48fa4cf6..8c7fa5abc8c 100644 --- a/extern/storage-sealing/constants.go +++ b/extern/storage-sealing/constants.go @@ -1,11 +1,11 @@ package sealing import ( - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // Epochs -const SealRandomnessLookback = v0miner.ChainFinality +const SealRandomnessLookback = miner0.ChainFinality // Epochs const InteractivePoRepConfidence = 6 diff --git a/extern/storage-sealing/precommit_policy.go b/extern/storage-sealing/precommit_policy.go index 76d8671443b..2ee6c1afc2e 100644 --- a/extern/storage-sealing/precommit_policy.go +++ b/extern/storage-sealing/precommit_policy.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/go-state-types/abi" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) type PreCommitPolicy interface { @@ -87,7 +87,7 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi var wpp abi.ChainEpoch if nv < build.ActorUpgradeNetworkVersion { - wpp = v0miner.WPoStProvingPeriod + wpp = miner0.WPoStProvingPeriod } else { // TODO: ActorUpgrade wpp = 0 diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 01551e6d7f4..d5772e1d618 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -9,7 +9,7 @@ import ( "time" "github.com/filecoin-project/lotus/build" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" @@ -430,7 +430,7 @@ func (m *Sealing) getPreCommitChallengeDelay(ctx context.Context, tok TipSetToke } if nv < build.ActorUpgradeNetworkVersion { - return v0miner.PreCommitChallengeDelay, nil + return miner0.PreCommitChallengeDelay, nil } // TODO: ActorUpgrade diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 6ae42a91f25..0109326fb1c 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "golang.org/x/xerrors" @@ -191,8 +191,8 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf var msd abi.ChainEpoch var mse abi.ChainEpoch if nv < build.ActorUpgradeNetworkVersion { - msd = v0miner.MaxSealDuration[sector.SectorType] - mse = v0miner.MinSectorExpiration + msd = miner0.MaxSealDuration[sector.SectorType] + mse = miner0.MinSectorExpiration } else { // TODO: ActorUpgrade msd = 0 @@ -387,7 +387,7 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo enc := new(bytes.Buffer) if nv < build.ActorUpgradeNetworkVersion { - params := &v0miner.ProveCommitSectorParams{ + params := &miner0.ProveCommitSectorParams{ SectorNumber: sector.SectorNumber, Proof: sector.Proof, } diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 6c60269ab78..8b47144af4c 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -41,7 +41,7 @@ import ( "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-padreader" "github.com/filecoin-project/go-state-types/abi" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" marketevents "github.com/filecoin-project/lotus/markets/loggers" @@ -87,7 +87,7 @@ func calcDealExpiration(minDuration uint64, md *dline.Info, startEpoch abi.Chain minExp := startEpoch + abi.ChainEpoch(minDuration) // Align on miners ProvingPeriodBoundary - return minExp + v0miner.WPoStProvingPeriod - (minExp % v0miner.WPoStProvingPeriod) + (md.PeriodStart % v0miner.WPoStProvingPeriod) - 1 + return minExp + miner0.WPoStProvingPeriod - (minExp % miner0.WPoStProvingPeriod) + (md.PeriodStart % miner0.WPoStProvingPeriod) - 1 } func (a *API) imgr() *importmgr.Mgr { diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 3bed0dfbb8e..76bd3926bd9 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -5,7 +5,7 @@ import ( "context" "strconv" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" @@ -24,7 +24,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/smoothing" @@ -921,7 +921,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr duration := pci.Expiration - ts.Height() // TODO: ActorUpgrade - sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw) + sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) } var powerSmoothed smoothing.FilterEstimate @@ -947,7 +947,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr } // TODO: ActorUpgrade - deposit := v0miner.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight) + deposit := miner0.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight) return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil } @@ -983,7 +983,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr duration := pci.Expiration - ts.Height() // TODO: handle changes to this function across actor upgrades. - sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw) + sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) } var ( @@ -1027,7 +1027,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr // TODO: ActorUpgrade - initialPledge := v0miner.InitialPledgeForPower( + initialPledge := miner0.InitialPledgeForPower( sectorWeight, baselinePower, pledgeCollateral, @@ -1145,7 +1145,7 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("getting reward baseline power: %w", err) } - min, max := v0market.DealProviderCollateralBounds(size, + min, max := market0.DealProviderCollateralBounds(size, verified, powClaim.RawBytePower, powClaim.QualityAdjPower, diff --git a/node/node_test.go b/node/node_test.go index 68ee178fc6e..0e404dc0b40 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -10,9 +10,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/lib/lotuslog" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" - v0power "github.com/filecoin-project/specs-actors/actors/builtin/power" - v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" logging "github.com/ipfs/go-log/v2" "github.com/filecoin-project/lotus/api/test" @@ -21,11 +21,11 @@ import ( func init() { _ = logging.SetLogLevel("*", "INFO") - v0power.ConsensusMinerMinPower = big.NewInt(2048) - v0miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ + power0.ConsensusMinerMinPower = big.NewInt(2048) + miner0.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } - v0verifreg.MinVerifiedDealSize = big.NewInt(256) + verifreg0.MinVerifiedDealSize = big.NewInt(256) } func TestAPI(t *testing.T) { @@ -68,7 +68,7 @@ func TestAPIDealFlowReal(t *testing.T) { logging.SetLogLevel("sub", "ERROR") logging.SetLogLevel("storageminer", "ERROR") - v0miner.PreCommitChallengeDelay = 5 + miner0.PreCommitChallengeDelay = 5 t.Run("basic", func(t *testing.T) { test.TestDealFlow(t, builder.Builder, time.Second, false, false) diff --git a/node/test/builder.go b/node/test/builder.go index 2b26c13fca8..c496b1e4c3f 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -37,7 +37,7 @@ import ( "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/mockstorage" "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-datastore" "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" @@ -83,7 +83,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr peerid, err := peer.IDFromPrivateKey(pk) require.NoError(t, err) - enc, err := actors.SerializeParams(&v0miner.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) + enc, err := actors.SerializeParams(&miner0.ChangePeerIDParams{NewID: abi.PeerID(peerid)}) require.NoError(t, err) msg := &types.Message{ diff --git a/paychmgr/manager.go b/paychmgr/manager.go index 4556c37be5c..d9c568cbe9e 100644 --- a/paychmgr/manager.go +++ b/paychmgr/manager.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/crypto" - v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -221,7 +221,7 @@ func (pm *Manager) GetChannelInfo(addr address.Address) (*ChannelInfo, error) { return ca.getChannelInfo(addr) } -func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher v0paych.SignedVoucher) (*api.VoucherCreateResult, error) { +func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher paych0.SignedVoucher) (*api.VoucherCreateResult, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return nil, err @@ -233,7 +233,7 @@ func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, vouche // CheckVoucherValid checks if the given voucher is valid (is or could become spendable at some point). // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) error { +func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher) error { // Get an accessor for the channel, creating it from state if necessary ca, err := pm.inboundChannelAccessor(ctx, ch) if err != nil { @@ -245,7 +245,7 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv } // CheckVoucherSpendable checks if the given voucher is currently spendable -func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (bool, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return false, err @@ -256,7 +256,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address // AddVoucherOutbound adds a voucher for an outbound channel. // Returns an error if the channel is not already in the store. -func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return types.NewInt(0), err @@ -267,7 +267,7 @@ func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, s // AddVoucherInbound adds a voucher for an inbound channel. // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { // Get an accessor for the channel, creating it from state if necessary ca, err := pm.inboundChannelAccessor(ctx, ch) if err != nil { @@ -336,7 +336,7 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address) return pm.store.TrackChannel(stateCi) } -func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { ca, err := pm.accessorByAddress(ch) if err != nil { return cid.Undef, err diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 53f16b4fce5..11dfd2a1eaf 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -12,7 +12,7 @@ import ( cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" @@ -103,7 +103,7 @@ func (ca *channelAccessor) outboundActiveByFromTo(from, to address.Address) (*Ch // nonce, signing the voucher and storing it in the local datastore. // If there are not enough funds in the channel to create the voucher, returns // the shortfall in funds. -func (ca *channelAccessor) createVoucher(ctx context.Context, ch address.Address, voucher v0paych.SignedVoucher) (*api.VoucherCreateResult, error) { +func (ca *channelAccessor) createVoucher(ctx context.Context, ch address.Address, voucher paych0.SignedVoucher) (*api.VoucherCreateResult, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -162,14 +162,14 @@ func (ca *channelAccessor) nextNonceForLane(ci *ChannelInfo, lane uint64) uint64 return maxnonce + 1 } -func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) (map[uint64]paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher) (map[uint64]paych.LaneState, error) { ca.lk.Lock() defer ca.lk.Unlock() return ca.checkVoucherValidUnlocked(ctx, ch, sv) } -func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher) (map[uint64]paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher) (map[uint64]paych.LaneState, error) { if sv.ChannelAddr != ch { return nil, xerrors.Errorf("voucher ChannelAddr doesn't match channel address, got %s, expected %s", sv.ChannelAddr, ch) } @@ -251,7 +251,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add return laneStates, nil } -func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (bool, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -290,7 +290,7 @@ func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address } } - enc, err := actors.SerializeParams(&v0paych.UpdateChannelStateParams{ + enc, err := actors.SerializeParams(&paych0.UpdateChannelStateParams{ Sv: *sv, Secret: secret, Proof: proof, @@ -325,14 +325,14 @@ func (ca *channelAccessor) getPaychRecipient(ctx context.Context, ch address.Add return state.To(), nil } -func (ca *channelAccessor) addVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (ca *channelAccessor) addVoucher(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ca.lk.Lock() defer ca.lk.Unlock() return ca.addVoucherUnlocked(ctx, ch, sv, proof, minDelta) } -func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { ci, err := ca.store.ByAddress(ch) if err != nil { return types.BigInt{}, err @@ -396,7 +396,7 @@ func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Ad return delta, ca.store.putChannelInfo(ci) } -func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *v0paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { ca.lk.Lock() defer ca.lk.Unlock() @@ -437,7 +437,7 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address } } - enc, err := actors.SerializeParams(&v0paych.UpdateChannelStateParams{ + enc, err := actors.SerializeParams(&paych0.UpdateChannelStateParams{ Sv: *sv, Secret: secret, Proof: proof, @@ -543,7 +543,7 @@ func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch } // Get the total redeemed amount across all lanes, after applying the voucher -func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]paych.LaneState, sv *v0paych.SignedVoucher) (big.Int, error) { +func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]paych.LaneState, sv *paych0.SignedVoucher) (big.Int, error) { // TODO: merges if len(sv.Merges) != 0 { return big.Int{}, xerrors.Errorf("dont currently support paych lane merges") diff --git a/paychmgr/paych_test.go b/paychmgr/paych_test.go index 434c83e9ccd..b27b1e540b1 100644 --- a/paychmgr/paych_test.go +++ b/paychmgr/paych_test.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin" - v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" tutils "github.com/filecoin-project/specs-actors/support/testing" "github.com/filecoin-project/lotus/api" @@ -339,7 +339,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 voucherLane1Amt := big.NewInt(5) - voucher := v0paych.SignedVoucher{ + voucher := paych0.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -354,7 +354,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 again, with a higher amount voucherLane1Amt = big.NewInt(8) - voucher = v0paych.SignedVoucher{ + voucher = paych0.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -369,7 +369,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that covers all the remaining funds // in the channel voucherLane2Amt := big.Sub(s.amt, voucherLane1Amt) - voucher = v0paych.SignedVoucher{ + voucher = paych0.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -383,7 +383,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that exceeds the remaining funds in the // channel voucherLane2Amt = big.Add(voucherLane2Amt, big.NewInt(1)) - voucher = v0paych.SignedVoucher{ + voucher = paych0.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -772,7 +772,7 @@ func TestCheckSpendable(t *testing.T) { // Check that the secret and proof were passed through correctly lastCall := s.mock.getLastCall() - var p v0paych.UpdateChannelStateParams + var p paych0.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(lastCall.Params)) require.NoError(t, err) require.Equal(t, otherProof, p.Proof) @@ -786,7 +786,7 @@ func TestCheckSpendable(t *testing.T) { require.True(t, spendable) lastCall = s.mock.getLastCall() - var p2 v0paych.UpdateChannelStateParams + var p2 paych0.UpdateChannelStateParams err = p2.UnmarshalCBOR(bytes.NewReader(lastCall.Params)) require.NoError(t, err) require.Equal(t, proof, p2.Proof) @@ -843,7 +843,7 @@ func TestSubmitVoucher(t *testing.T) { // Check that the secret and proof were passed through correctly msg := s.mock.pushedMessages(submitCid) - var p v0paych.UpdateChannelStateParams + var p paych0.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, submitProof, p.Proof) @@ -863,7 +863,7 @@ func TestSubmitVoucher(t *testing.T) { require.NoError(t, err) msg = s.mock.pushedMessages(submitCid) - var p2 v0paych.UpdateChannelStateParams + var p2 paych0.UpdateChannelStateParams err = p2.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, addVoucherProof2, p2.Proof) @@ -879,7 +879,7 @@ func TestSubmitVoucher(t *testing.T) { require.NoError(t, err) msg = s.mock.pushedMessages(submitCid) - var p3 v0paych.UpdateChannelStateParams + var p3 paych0.UpdateChannelStateParams err = p3.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) require.Equal(t, proof3, p3.Proof) @@ -966,8 +966,8 @@ func testGenerateKeyPair(t *testing.T) ([]byte, []byte) { return priv, pub } -func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *v0paych.SignedVoucher { - sv := &v0paych.SignedVoucher{ +func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych0.SignedVoucher { + sv := &paych0.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, @@ -982,13 +982,13 @@ func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, non return sv } -func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *v0paych.SignedVoucher { - sv := &v0paych.SignedVoucher{ +func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych0.SignedVoucher { + sv := &paych0.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, Amount: voucherAmount, - Extra: &v0paych.ModVerifyParams{ + Extra: &paych0.ModVerifyParams{ Actor: tutils.NewActorAddr(t, "act"), }, } @@ -1006,13 +1006,13 @@ type mockBestSpendableAPI struct { mgr *Manager } -func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*v0paych.SignedVoucher, error) { +func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*paych0.SignedVoucher, error) { vi, err := m.mgr.ListVouchers(ctx, ch) if err != nil { return nil, err } - out := make([]*v0paych.SignedVoucher, len(vi)) + out := make([]*paych0.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -1020,7 +1020,7 @@ func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address. return out, nil } -func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *v0paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *paych0.SignedVoucher, secret []byte, proof []byte) (bool, error) { return m.mgr.CheckVoucherSpendable(ctx, ch, voucher, secret, proof) } diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 2f6dc0593dd..46bbea62e6f 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -14,7 +14,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - v0paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -382,7 +382,7 @@ func (ca *channelAccessor) processTask(ctx context.Context, amt types.BigInt) *p // createPaych sends a message to create the channel and returns the message cid func (ca *channelAccessor) createPaych(ctx context.Context, amt types.BigInt) (cid.Cid, error) { - params, aerr := actors.SerializeParams(&v0paych.ConstructorParams{From: ca.from, To: ca.to}) + params, aerr := actors.SerializeParams(&paych0.ConstructorParams{From: ca.from, To: ca.to}) if aerr != nil { return cid.Undef, aerr } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index efbd9581792..db3ae63d9db 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/actors/builtin" - v0market "github.com/filecoin-project/specs-actors/actors/builtin/market" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" @@ -137,7 +137,7 @@ func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr return cid.Undef, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) } - ccparams, err := actors.SerializeParams(&v0market.ComputeDataCommitmentParams{ + ccparams, err := actors.SerializeParams(&market0.ComputeDataCommitmentParams{ DealIDs: deals, SectorType: sectorType, }) diff --git a/storage/miner.go b/storage/miner.go index d7780898d57..6a5d4183b64 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -5,7 +5,7 @@ import ( "errors" "time" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/go-state-types/network" @@ -146,7 +146,7 @@ func (m *Miner) Run(ctx context.Context) error { evts := events.NewEvents(ctx, m.api) adaptedAPI := NewSealingAPIAdapter(m.api) // TODO: Maybe we update this policy after actor upgrades? - pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, v0miner.MaxSectorExpirationExtension-(v0miner.WPoStProvingPeriod*2), md.PeriodStart%v0miner.WPoStProvingPeriod) + pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, miner0.MaxSectorExpirationExtension-(miner0.WPoStProvingPeriod*2), md.PeriodStart%miner0.WPoStProvingPeriod) m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingConfigFunc(m.getSealConfig), m.handleSealingNotifications) go m.sealing.Run(ctx) //nolint:errcheck // logged intside the function diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index 1a930b41a04..58014d6320c 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -19,8 +19,8 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" - v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/runtime/proof" tutils "github.com/filecoin-project/specs-actors/support/testing" @@ -134,7 +134,7 @@ func TestWDPostDoPost(t *testing.T) { // without exceeding the message sector limit require.NoError(t, err) - partitionsPerMsg := int(v0miner.AddressedSectorsMax / sectorsPerPartition) + partitionsPerMsg := int(miner0.AddressedSectorsMax / sectorsPerPartition) // Enough partitions to fill expectedMsgCount-1 messages partitionCount := (expectedMsgCount - 1) * partitionsPerMsg @@ -249,7 +249,7 @@ func (m *mockStorageMinerAPI) StateSearchMsg(ctx context.Context, cid cid.Cid) ( func (m *mockStorageMinerAPI) StateGetActor(ctx context.Context, actor address.Address, ts types.TipSetKey) (*types.Actor, error) { return &types.Actor{ - Code: v0builtin.StorageMinerActorCodeID, + Code: builtin0.StorageMinerActorCodeID, }, nil } From 35bce5a5c691c015abc6b5fc51e85e63bb4915e4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Sep 2020 15:40:49 -0700 Subject: [PATCH 068/104] revert post changes 1. Calling the specific partition/deadline APIs is faster. 2. It's _much_ easier to test this way. --- chain/actors/builtin/miner/miner.go | 2 - chain/actors/builtin/miner/v0.go | 5 -- storage/miner.go | 1 + storage/wdpost_run.go | 101 ++++++---------------------- 4 files changed, 22 insertions(+), 87 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index b9cff99daa3..d25652d30ca 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -58,8 +58,6 @@ type State interface { DeadlineInfo(epoch abi.ChainEpoch) *dline.Info - MaxAddressedSectors() (uint64, error) - // Diff helpers. Used by Diff* functions internally. sectors() (adt.Array, error) decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 26a91edd14b..37df8c21736 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -224,11 +224,6 @@ func (s *state0) NumDeadlines() (uint64, error) { return miner0.WPoStPeriodDeadlines, nil } -// Max sectors per PoSt -func (s *state0) MaxAddressedSectors() (uint64, error) { - return miner0.AddressedSectorsMax, nil -} - func (s *state0) DeadlinesChanged(other State) bool { other0, ok := other.(*state0) if !ok { diff --git a/storage/miner.go b/storage/miner.go index 6a5d4183b64..61c4000f2ba 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -77,6 +77,7 @@ type storageMinerApi interface { StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) + StateMinerPartitions(context.Context, address.Address, uint64, types.TipSetKey) ([]api.Partition, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 2f5d97b76b8..06740b108c0 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -5,6 +5,8 @@ import ( "context" "time" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" + "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-address" @@ -18,16 +20,14 @@ import ( "go.opencensus.io/trace" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/journal" + + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) func (s *WindowPoStScheduler) failPost(err error, deadline *dline.Info) { @@ -154,7 +154,7 @@ func (s *WindowPoStScheduler) checkSectors(ctx context.Context, check bitfield.B return sbf, nil } -func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []miner.Partition) ([]miner.RecoveryDeclaration, *types.SignedMessage, error) { +func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uint64, partitions []api.Partition) ([]miner.RecoveryDeclaration, *types.SignedMessage, error) { ctx, span := trace.StartSpan(ctx, "storage.checkNextRecoveries") defer span.End() @@ -164,15 +164,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin } for partIdx, partition := range partitions { - faults, err := partition.FaultySectors() - if err != nil { - return nil, nil, xerrors.Errorf("getting faults: %w", err) - } - recovering, err := partition.RecoveringSectors() - if err != nil { - return nil, nil, xerrors.Errorf("getting recovering: %w", err) - } - unrecovered, err := bitfield.SubtractBitField(faults, recovering) + unrecovered, err := bitfield.SubtractBitField(partition.FaultySectors, partition.RecoveringSectors) if err != nil { return nil, nil, xerrors.Errorf("subtracting recovered set from fault set: %w", err) } @@ -253,7 +245,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin return recoveries, sm, nil } -func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []miner.Partition) ([]miner.FaultDeclaration, *types.SignedMessage, error) { +func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, partitions []api.Partition) ([]miner.FaultDeclaration, *types.SignedMessage, error) { ctx, span := trace.StartSpan(ctx, "storage.checkNextFaults") defer span.End() @@ -263,17 +255,12 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, } for partIdx, partition := range partitions { - toCheck, err := partition.ActiveSectors() - if err != nil { - return nil, nil, xerrors.Errorf("getting active sectors: %w", err) - } - - good, err := s.checkSectors(ctx, toCheck) + good, err := s.checkSectors(ctx, partition.ActiveSectors) if err != nil { return nil, nil, xerrors.Errorf("checking sectors: %w", err) } - faulty, err := bitfield.SubtractBitField(toCheck, good) + faulty, err := bitfield.SubtractBitField(partition.ActiveSectors, good) if err != nil { return nil, nil, xerrors.Errorf("calculating faulty sector set: %w", err) } @@ -341,17 +328,6 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty ctx, span := trace.StartSpan(ctx, "storage.runPost") defer span.End() - stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.api)) - act, err := s.api.StateGetActor(context.TODO(), s.actor, ts.Key()) - if err != nil { - return nil, xerrors.Errorf("resolving actor: %w", err) - } - - mas, err := miner.Load(stor, act) - if err != nil { - return nil, xerrors.Errorf("getting miner state: %w", err) - } - go func() { // TODO: extract from runPost, run on fault cutoff boundaries @@ -359,18 +335,9 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty // late to declare them for this deadline declDeadline := (di.Index + 2) % di.WPoStPeriodDeadlines - dl, err := mas.LoadDeadline(declDeadline) + partitions, err := s.api.StateMinerPartitions(context.TODO(), s.actor, declDeadline, ts.Key()) if err != nil { - log.Errorf("loading deadline: %v", err) - return - } - var partitions []miner.Partition - err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { - partitions = append(partitions, part) - return nil - }) - if err != nil { - log.Errorf("loading partitions: %v", err) + log.Errorf("getting partitions: %v", err) return } @@ -429,24 +396,15 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return nil, xerrors.Errorf("failed to get chain randomness for window post (ts=%d; deadline=%d): %w", ts.Height(), di, err) } - dl, err := mas.LoadDeadline(di.Index) - if err != nil { - return nil, xerrors.Errorf("loading deadline: %w", err) - } - // Get the partitions for the given deadline - var partitions []miner.Partition - err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error { - partitions = append(partitions, part) - return nil - }) + partitions, err := s.api.StateMinerPartitions(ctx, s.actor, di.Index, ts.Key()) if err != nil { - return nil, xerrors.Errorf("loading partitions: %w", err) + return nil, xerrors.Errorf("getting partitions: %w", err) } // Split partitions into batches, so as not to exceed the number of sectors // allowed in a single message - partitionBatches, err := s.batchPartitions(partitions, mas) + partitionBatches, err := s.batchPartitions(partitions) if err != nil { return nil, err } @@ -475,16 +433,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty var sinfos []proof.SectorInfo for partIdx, partition := range batch { // TODO: Can do this in parallel - toProve, err := partition.ActiveSectors() - if err != nil { - return nil, xerrors.Errorf("getting active sectors: %w", err) - } - - recs, err := partition.RecoveringSectors() - if err != nil { - return nil, xerrors.Errorf("getting recovering sectors: %w", err) - } - toProve, err = bitfield.MergeBitFields(toProve, recs) + toProve, err := bitfield.MergeBitFields(partition.ActiveSectors, partition.RecoveringSectors) if err != nil { return nil, xerrors.Errorf("adding recoveries to set of sectors to prove: %w", err) } @@ -511,12 +460,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty skipCount += sc - partitionSectors, err := partition.AllSectors() - if err != nil { - return nil, xerrors.Errorf("getting partition sectors: %w", err) - } - - ssi, err := s.sectorsForProof(ctx, good, partitionSectors, ts) + ssi, err := s.sectorsForProof(ctx, good, partition.AllSectors, ts) if err != nil { return nil, xerrors.Errorf("getting sorted sector info: %w", err) } @@ -609,18 +553,13 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty return posts, nil } -func (s *WindowPoStScheduler) batchPartitions(partitions []miner.Partition, mas miner.State) ([][]miner.Partition, error) { +func (s *WindowPoStScheduler) batchPartitions(partitions []api.Partition) ([][]api.Partition, error) { // Get the number of sectors allowed in a partition, for this proof size sectorsPerPartition, err := builtin.PoStProofWindowPoStPartitionSectors(s.proofType) if err != nil { return nil, xerrors.Errorf("getting sectors per partition: %w", err) } - maxSectors, err := mas.MaxAddressedSectors() - if err != nil { - return nil, err - } - // We don't want to exceed the number of sectors allowed in a message. // So given the number of sectors in a partition, work out the number of // partitions that can be in a message without exceeding sectors per @@ -631,7 +570,9 @@ func (s *WindowPoStScheduler) batchPartitions(partitions []miner.Partition, mas // sectors per partition 3: ooo // partitions per message 2: oooOOO // <1><2> (3rd doesn't fit) - partitionsPerMsg := int(maxSectors / sectorsPerPartition) + // TODO(NETUPGRADE): we're going to need some form of policy abstraction + // where we can get policy from the future. Unfortunately, we can't just get this from the state. + partitionsPerMsg := int(miner0.AddressedSectorsMax / sectorsPerPartition) // The number of messages will be: // ceiling(number of partitions / partitions per message) @@ -641,7 +582,7 @@ func (s *WindowPoStScheduler) batchPartitions(partitions []miner.Partition, mas } // Split the partitions into batches - batches := make([][]miner.Partition, 0, batchCount) + batches := make([][]api.Partition, 0, batchCount) for i := 0; i < len(partitions); i += partitionsPerMsg { end := i + partitionsPerMsg if end > len(partitions) { From 7c3f638f6853bd155b0b4becc59f395d735ea2ce Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 19 Sep 2020 00:30:24 -0400 Subject: [PATCH 069/104] Abstract FilterEstimate, PreCommitDepositForPower, and InitialPledgeForPower --- chain/actors/builtin/builtin.go | 11 ++++-- chain/actors/builtin/power/v0.go | 5 ++- chain/actors/builtin/reward/reward.go | 3 ++ chain/actors/builtin/reward/v0.go | 29 +++++++++++++- node/impl/full/state.go | 56 ++++++++++++--------------- 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 4ce77804c0c..4906f0fa4a3 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -3,9 +3,9 @@ package builtin import ( "fmt" - "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/big" - smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" + "github.com/filecoin-project/go-state-types/network" ) type Version int @@ -24,5 +24,8 @@ func VersionForNetwork(version network.Version) Version { } } -// TODO: find some way to abstract over this. -type FilterEstimate = smoothing0.FilterEstimate +// TODO: Why does actors have 2 different versions of this? +type FilterEstimate struct { + PositionEstimate big.Int + VelocityEstimate big.Int +} diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 1d5a93d2b06..94c8f749e09 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -53,7 +53,10 @@ func (s *state0) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return *s.State.ThisEpochQAPowerSmoothed, nil + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochQAPowerSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochQAPowerSmoothed.VelocityEstimate, + }, nil } func (s *state0) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index b56292fff0f..3f887914d11 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -41,4 +41,7 @@ type State interface { CumsumBaseline() (abi.StoragePower, error) CumsumRealized() (abi.StoragePower, error) + + InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error) + PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error) } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 50ad4997118..3efcaf93adc 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -3,8 +3,10 @@ package reward import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/builtin" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/specs-actors/actors/util/smoothing" ) type state0 struct { @@ -17,7 +19,10 @@ func (s *state0) ThisEpochReward() (abi.StoragePower, error) { } func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { - return *s.State.ThisEpochRewardSmoothed, nil + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, + }, nil } func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) { @@ -43,3 +48,25 @@ func (s *state0) CumsumBaseline() (abi.StoragePower, error) { func (s *state0) CumsumRealized() (abi.StoragePower, error) { return s.State.CumsumBaseline, nil } + +func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) { + return miner0.InitialPledgeForPower( + sectorWeight, + s.State.ThisEpochBaselinePower, + networkTotalPledge, + s.State.ThisEpochRewardSmoothed, + &smoothing.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + circSupply), nil +} + +func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) { + return miner0.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed, + &smoothing.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + sectorWeight), nil +} diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 76bd3926bd9..e4400b073e1 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -5,6 +5,8 @@ import ( "context" "strconv" + builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" @@ -26,7 +28,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -924,7 +925,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) } - var powerSmoothed smoothing.FilterEstimate + var powerSmoothed builtin2.FilterEstimate if act, err := state.GetActor(power.Address); err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) } else if s, err := power.Load(store, act); err != nil { @@ -935,19 +936,20 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr powerSmoothed = p } - var rewardSmoothed smoothing.FilterEstimate - if act, err := state.GetActor(reward.Address); err != nil { + rewardActor, err := state.GetActor(reward.Address) + if err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else if s, err := reward.Load(store, act); err != nil { + } + + rewardState, err := reward.Load(store, rewardActor) + if err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else if r, err := s.ThisEpochRewardSmoothed(); err != nil { - return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) - } else { - rewardSmoothed = r } - // TODO: ActorUpgrade - deposit := miner0.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight) + deposit, err := rewardState.PreCommitDepositForPower(powerSmoothed, sectorWeight) + if err != nil { + return big.Zero(), xerrors.Errorf("calculating precommit deposit: %w", err) + } return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil } @@ -982,12 +984,12 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() - // TODO: handle changes to this function across actor upgrades. + // TODO: ActorUpgrade sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) } var ( - powerSmoothed smoothing.FilterEstimate + powerSmoothed builtin2.FilterEstimate pledgeCollateral abi.TokenAmount ) if act, err := state.GetActor(power.Address); err != nil { @@ -1003,21 +1005,14 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr pledgeCollateral = c } - var ( - rewardSmoothed smoothing.FilterEstimate - baselinePower abi.StoragePower - ) - if act, err := state.GetActor(reward.Address); err != nil { + rewardActor, err := state.GetActor(reward.Address) + if err != nil { return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) - } else if s, err := reward.Load(store, act); err != nil { + } + + rewardState, err := reward.Load(store, rewardActor) + if err != nil { return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) - } else if r, err := s.ThisEpochRewardSmoothed(); err != nil { - return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) - } else if p, err := s.ThisEpochBaselinePower(); err != nil { - return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) - } else { - rewardSmoothed = r - baselinePower = p } circSupply, err := a.StateCirculatingSupply(ctx, ts.Key()) @@ -1025,16 +1020,15 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err) } - // TODO: ActorUpgrade - - initialPledge := miner0.InitialPledgeForPower( + initialPledge, err := rewardState.InitialPledgeForPower( sectorWeight, - baselinePower, pledgeCollateral, - &rewardSmoothed, &powerSmoothed, circSupply.FilCirculating, ) + if err != nil { + return big.Zero(), xerrors.Errorf("calculating initial pledge: %w", err) + } return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil } From b25dd2a00d9c4d346087438d33a8d789a50aa8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 20 Sep 2020 23:04:45 +0200 Subject: [PATCH 070/104] More correct / fasterer GetSectorsForWinningPoSt --- chain/actors/builtin/miner/v0.go | 12 ++++++------ chain/stmgr/utils.go | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 37df8c21736..7985896f39e 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -163,9 +163,9 @@ func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ( return nil, err } - var v cbg.Deferred - if err := a.ForEach(&v, func(i int64) error { - if filter != nil { + if filter != nil { + var v cbg.Deferred + if err := a.ForEach(&v, func(i int64) error { set, err := filter.IsSet(uint64(i)) if err != nil { return xerrors.Errorf("filter check error: %w", err) @@ -176,10 +176,10 @@ func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ( return xerrors.Errorf("filtering error: %w", err) } } + return nil + }); err != nil { + return nil, err } - return nil - }); err != nil { - return nil, err } return a, nil diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 3684b9e77ac..203d4949000 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -197,12 +197,21 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } - // TODO (!!): This was partition.Sectors-partition.Faults originally, which was likely very wrong, and will need to be an upgrade - // ^ THE CURRENT THING HERE WON'T SYNC v + // TODO (!!): Actor Update: Make this active sectors - provingSectors, err := miner.AllPartSectors(mas, miner.Partition.ActiveSectors) + allSectors, err := miner.AllPartSectors(mas, miner.Partition.AllSectors) if err != nil { - return nil, xerrors.Errorf("merge partition proving sets: %w", err) + return nil, xerrors.Errorf("get all sectors: %w", err) + } + + faultySectors, err := miner.AllPartSectors(mas, miner.Partition.FaultySectors) + if err != nil { + return nil, xerrors.Errorf("get faulty sectors: %w", err) + } + + provingSectors, err := bitfield.SubtractBitField(allSectors, faultySectors) // TODO: This is wrong, as it can contain faaults, change to just ActiveSectors in an upgrade + if err != nil { + return nil, xerrors.Errorf("calc proving sectors: %w", err) } numProvSect, err := provingSectors.Count() @@ -240,7 +249,8 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, xerrors.Errorf("generating winning post challenges: %w", err) } - sectors, err := mas.LoadSectorsFromSet(&provingSectors, false) + // we don't need to filter here (and it's **very** slow) + sectors, err := mas.LoadSectorsFromSet(nil, false) if err != nil { return nil, xerrors.Errorf("loading proving sectors: %w", err) } From ed285f1114ab1a9fd2a2d5b4f149077a8c3b851c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 20 Sep 2020 17:53:46 -0400 Subject: [PATCH 071/104] Abstract SectorOnChainInfo and SectorPreCommitOnChainInfo --- chain/actors/builtin/builtin.go | 9 +++++---- chain/actors/builtin/market/v0.go | 6 +++--- chain/actors/builtin/miner/miner.go | 26 ++++++++++++++++++++++++-- chain/actors/builtin/miner/v0.go | 26 ++++++++++++++++++++++---- chain/actors/builtin/power/v0.go | 5 +---- chain/actors/builtin/reward/v0.go | 5 +---- 6 files changed, 56 insertions(+), 21 deletions(-) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 4906f0fa4a3..9ad97656442 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -3,7 +3,7 @@ package builtin import ( "fmt" - "github.com/filecoin-project/go-state-types/big" + smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/go-state-types/network" ) @@ -25,7 +25,8 @@ func VersionForNetwork(version network.Version) Version { } // TODO: Why does actors have 2 different versions of this? -type FilterEstimate struct { - PositionEstimate big.Int - VelocityEstimate big.Int +type FilterEstimate = smoothing0.FilterEstimate + +func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { + return (FilterEstimate)(v0) } diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 27eee4c5062..e184b668de2 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -26,7 +26,7 @@ func (s *state0) TotalLocked() (abi.TokenAmount, error) { func (s *state0) BalancesChanged(otherState State) bool { otherState0, ok := otherState.(*state0) if !ok { - // there's no way to compare differnt versions of the state, so let's + // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed return true } @@ -36,7 +36,7 @@ func (s *state0) BalancesChanged(otherState State) bool { func (s *state0) StatesChanged(otherState State) bool { otherState0, ok := otherState.(*state0) if !ok { - // there's no way to compare differnt versions of the state, so let's + // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed return true } @@ -54,7 +54,7 @@ func (s *state0) States() (DealStates, error) { func (s *state0) ProposalsChanged(otherState State) bool { otherState0, ok := otherState.(*state0) if !ok { - // there's no way to compare differnt versions of the state, so let's + // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed return true } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index d25652d30ca..704ea12919a 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -2,6 +2,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/dline" + "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -81,9 +82,30 @@ type Partition interface { ActiveSectors() (bitfield.BitField, error) } -type SectorOnChainInfo = miner0.SectorOnChainInfo +type SectorOnChainInfo struct { + SectorNumber abi.SectorNumber + SealProof abi.RegisteredSealProof + SealedCID cid.Cid + DealIDs []abi.DealID + Activation abi.ChainEpoch + Expiration abi.ChainEpoch + DealWeight abi.DealWeight + VerifiedDealWeight abi.DealWeight + InitialPledge abi.TokenAmount + ExpectedDayReward abi.TokenAmount + ExpectedStoragePledge abi.TokenAmount +} + type SectorPreCommitInfo = miner0.SectorPreCommitInfo -type SectorPreCommitOnChainInfo = miner0.SectorPreCommitOnChainInfo + +type SectorPreCommitOnChainInfo struct { + Info SectorPreCommitInfo + PreCommitDeposit abi.TokenAmount + PreCommitEpoch abi.ChainEpoch + DealWeight abi.DealWeight + VerifiedDealWeight abi.DealWeight +} + type PoStPartition = miner0.PoStPartition type RecoveryDeclaration = miner0.RecoveryDeclaration type FaultDeclaration = miner0.FaultDeclaration diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 7985896f39e..71306fafd94 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -62,7 +62,8 @@ func (s *state0) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { return nil, err } - return info, nil + ret := fromV0SectorOnChainInfo(*info) + return &ret, nil } func (s *state0) FindSector(num abi.SectorNumber) (*SectorLocation, error) { @@ -154,7 +155,8 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return nil, err } - return info, nil + ret := fromV0SectorPreCommitOnChainInfo(*info) + return &ret, nil } func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) { @@ -279,7 +281,11 @@ func (s *state0) sectors() (adt.Array, error) { func (s *state0) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { var si miner0.SectorOnChainInfo err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) - return si, err + if err != nil { + return SectorOnChainInfo{}, err + } + + return fromV0SectorOnChainInfo(si), nil } func (s *state0) precommits() (adt.Map, error) { @@ -289,7 +295,11 @@ func (s *state0) precommits() (adt.Map, error) { func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { var sp miner0.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) - return sp, err + if err != nil { + return SectorPreCommitOnChainInfo{}, err + } + + return fromV0SectorPreCommitOnChainInfo(sp), nil } func (d *deadline0) LoadPartition(idx uint64) (Partition, error) { @@ -336,3 +346,11 @@ func (p *partition0) FaultySectors() (bitfield.BitField, error) { func (p *partition0) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } + +func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo { + return (SectorOnChainInfo)(v0) +} + +func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { + return (SectorPreCommitOnChainInfo)(v0) +} diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 94c8f749e09..e19984f72cf 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -53,10 +53,7 @@ func (s *state0) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FilterEstimate{ - PositionEstimate: s.State.ThisEpochQAPowerSmoothed.PositionEstimate, - VelocityEstimate: s.State.ThisEpochQAPowerSmoothed.VelocityEstimate, - }, nil + return builtin.FromV0FilterEstimate(*s.State.ThisEpochQAPowerSmoothed), nil } func (s *state0) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 3efcaf93adc..981905ba576 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -19,10 +19,7 @@ func (s *state0) ThisEpochReward() (abi.StoragePower, error) { } func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { - return builtin.FilterEstimate{ - PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, - VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, - }, nil + return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil } func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) { From a95e34f742355deea28c2c1376d5ce7e4d1846b8 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Mon, 21 Sep 2020 01:58:20 -0400 Subject: [PATCH 072/104] Fix build --- chain/actors/builtin/miner/cbor_gen.go | 313 +++++++++++++++++++++++++ chain/actors/builtin/miner/v0.go | 46 +++- chain/stmgr/utils.go | 2 +- gen/main.go | 9 + 4 files changed, 358 insertions(+), 12 deletions(-) create mode 100644 chain/actors/builtin/miner/cbor_gen.go diff --git a/chain/actors/builtin/miner/cbor_gen.go b/chain/actors/builtin/miner/cbor_gen.go new file mode 100644 index 00000000000..16819d5c451 --- /dev/null +++ b/chain/actors/builtin/miner/cbor_gen.go @@ -0,0 +1,313 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package miner + +import ( + "fmt" + "io" + + abi "github.com/filecoin-project/go-state-types/abi" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +var _ = xerrors.Errorf + +var lengthBufSectorOnChainInfo = []byte{139} + +func (t *SectorOnChainInfo) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufSectorOnChainInfo); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.SectorNumber (abi.SectorNumber) (uint64) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorNumber)); err != nil { + return err + } + + // t.SealProof (abi.RegisteredSealProof) (int64) + if t.SealProof >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SealProof)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.SealProof-1)); err != nil { + return err + } + } + + // t.SealedCID (cid.Cid) (struct) + + if err := cbg.WriteCidBuf(scratch, w, t.SealedCID); err != nil { + return xerrors.Errorf("failed to write cid field t.SealedCID: %w", err) + } + + // t.DealIDs ([]abi.DealID) (slice) + if len(t.DealIDs) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.DealIDs was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.DealIDs))); err != nil { + return err + } + for _, v := range t.DealIDs { + if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { + return err + } + } + + // t.Activation (abi.ChainEpoch) (int64) + if t.Activation >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Activation)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Activation-1)); err != nil { + return err + } + } + + // t.Expiration (abi.ChainEpoch) (int64) + if t.Expiration >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Expiration)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Expiration-1)); err != nil { + return err + } + } + + // t.DealWeight (big.Int) (struct) + if err := t.DealWeight.MarshalCBOR(w); err != nil { + return err + } + + // t.VerifiedDealWeight (big.Int) (struct) + if err := t.VerifiedDealWeight.MarshalCBOR(w); err != nil { + return err + } + + // t.InitialPledge (big.Int) (struct) + if err := t.InitialPledge.MarshalCBOR(w); err != nil { + return err + } + + // t.ExpectedDayReward (big.Int) (struct) + if err := t.ExpectedDayReward.MarshalCBOR(w); err != nil { + return err + } + + // t.ExpectedStoragePledge (big.Int) (struct) + if err := t.ExpectedStoragePledge.MarshalCBOR(w); err != nil { + return err + } + return nil +} + +func (t *SectorOnChainInfo) UnmarshalCBOR(r io.Reader) error { + *t = SectorOnChainInfo{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 11 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.SectorNumber (abi.SectorNumber) (uint64) + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.SectorNumber = abi.SectorNumber(extra) + + } + // t.SealProof (abi.RegisteredSealProof) (int64) + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.SealProof = abi.RegisteredSealProof(extraI) + } + // t.SealedCID (cid.Cid) (struct) + + { + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.SealedCID: %w", err) + } + + t.SealedCID = c + + } + // t.DealIDs ([]abi.DealID) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.DealIDs: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.DealIDs = make([]abi.DealID, extra) + } + + for i := 0; i < int(extra); i++ { + + maj, val, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return xerrors.Errorf("failed to read uint64 for t.DealIDs slice: %w", err) + } + + if maj != cbg.MajUnsignedInt { + return xerrors.Errorf("value read for array t.DealIDs was not a uint, instead got %d", maj) + } + + t.DealIDs[i] = abi.DealID(val) + } + + // t.Activation (abi.ChainEpoch) (int64) + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.Activation = abi.ChainEpoch(extraI) + } + // t.Expiration (abi.ChainEpoch) (int64) + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.Expiration = abi.ChainEpoch(extraI) + } + // t.DealWeight (big.Int) (struct) + + { + + if err := t.DealWeight.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.DealWeight: %w", err) + } + + } + // t.VerifiedDealWeight (big.Int) (struct) + + { + + if err := t.VerifiedDealWeight.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.VerifiedDealWeight: %w", err) + } + + } + // t.InitialPledge (big.Int) (struct) + + { + + if err := t.InitialPledge.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.InitialPledge: %w", err) + } + + } + // t.ExpectedDayReward (big.Int) (struct) + + { + + if err := t.ExpectedDayReward.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ExpectedDayReward: %w", err) + } + + } + // t.ExpectedStoragePledge (big.Int) (struct) + + { + + if err := t.ExpectedStoragePledge.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ExpectedStoragePledge: %w", err) + } + + } + return nil +} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 71306fafd94..6d4e7c58995 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -165,26 +165,50 @@ func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ( return nil, err } - if filter != nil { - var v cbg.Deferred - if err := a.ForEach(&v, func(i int64) error { + ret := adt0.MakeEmptyArray(s.store) + var v cbg.Deferred + if err := a.ForEach(&v, func(i int64) error { + include := true + if filter != nil { set, err := filter.IsSet(uint64(i)) if err != nil { return xerrors.Errorf("filter check error: %w", err) } if set == filterOut { - err = a.Delete(uint64(i)) - if err != nil { - return xerrors.Errorf("filtering error: %w", err) - } + include = false } - return nil - }); err != nil { - return nil, err } + + if include { + var oci miner0.SectorOnChainInfo + if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { + return err + } + + noci := SectorOnChainInfo{ + SectorNumber: oci.SectorNumber, + SealProof: oci.SealProof, + SealedCID: oci.SealedCID, + DealIDs: oci.DealIDs, + Activation: oci.Activation, + Expiration: oci.Expiration, + DealWeight: oci.DealWeight, + VerifiedDealWeight: oci.VerifiedDealWeight, + InitialPledge: oci.InitialPledge, + ExpectedDayReward: oci.ExpectedDayReward, + ExpectedStoragePledge: oci.ExpectedStoragePledge, + } + + if err := ret.Set(uint64(i), &noci); err != nil { + return err + } + } + return nil + }); err != nil { + return nil, err } - return a, nil + return ret, nil } func (s *state0) LoadPreCommittedSectors() (adt.Map, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 203d4949000..20d7bd54fec 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -169,7 +169,7 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, var sset []*miner.ChainSectorInfo var v cbg.Deferred if err := sectors.ForEach(&v, func(i int64) error { - var oci miner0.SectorOnChainInfo + var oci miner.SectorOnChainInfo if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { return err } diff --git a/gen/main.go b/gen/main.go index be227663c17..90b24e3a740 100644 --- a/gen/main.go +++ b/gen/main.go @@ -4,6 +4,8 @@ import ( "fmt" "os" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + gen "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lotus/api" @@ -76,4 +78,11 @@ func main() { os.Exit(1) } + err = gen.WriteTupleEncodersToFile("./chain/actors/builtin/miner/cbor_gen.go", "miner", + miner.SectorOnChainInfo{}, + ) + if err != nil { + fmt.Println(err) + os.Exit(1) + } } From b355eb75ebd99f4c4ea84b0c1288afdcdc91c0af Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Mon, 21 Sep 2020 02:19:32 -0400 Subject: [PATCH 073/104] Add compile-time checks that actors interfaces are correctly implemented --- chain/actors/builtin/account/v0.go | 2 ++ chain/actors/builtin/init/v0.go | 2 ++ chain/actors/builtin/market/v0.go | 2 ++ chain/actors/builtin/miner/v0.go | 2 ++ chain/actors/builtin/multisig/v0.go | 2 ++ chain/actors/builtin/paych/v0.go | 2 ++ chain/actors/builtin/power/v0.go | 2 ++ chain/actors/builtin/reward/v0.go | 2 ++ chain/actors/builtin/verifreg/v0.go | 2 ++ 9 files changed, 18 insertions(+) diff --git a/chain/actors/builtin/account/v0.go b/chain/actors/builtin/account/v0.go index 535255d0e1b..30bafbfd333 100644 --- a/chain/actors/builtin/account/v0.go +++ b/chain/actors/builtin/account/v0.go @@ -6,6 +6,8 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/account" ) +var _ State = (*state0)(nil) + type state0 struct { account.State store adt.Store diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index 0e8395a08fd..717ed966907 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -13,6 +13,8 @@ import ( adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) +var _ State = (*state0)(nil) + type state0 struct { init_.State store adt.Store diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index e184b668de2..433445dab83 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -12,6 +12,8 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" ) +var _ State = (*state0)(nil) + type state0 struct { market.State store adt.Store diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 6d4e7c58995..010ae66993b 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -17,6 +17,8 @@ import ( miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) +var _ State = (*state0)(nil) + type state0 struct { miner0.State store adt.Store diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index ded834d5f06..5de5ca6ad06 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -6,6 +6,8 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/multisig" ) +var _ State = (*state0)(nil) + type state0 struct { multisig.State store adt.Store diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go index 0c4b2f218ab..b69cf46ce9f 100644 --- a/chain/actors/builtin/paych/v0.go +++ b/chain/actors/builtin/paych/v0.go @@ -9,6 +9,8 @@ import ( adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) +var _ State = (*state0)(nil) + type state0 struct { paych.State store adt.Store diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index e19984f72cf..f2fe96dadde 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -8,6 +8,8 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/adt" ) +var _ State = (*state0)(nil) + type state0 struct { power0.State store adt.Store diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 981905ba576..df7117b675e 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -9,6 +9,8 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/smoothing" ) +var _ State = (*state0)(nil) + type state0 struct { reward.State store adt.Store diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index c397d6679f9..f64c27310f3 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -11,6 +11,8 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" ) +var _ State = (*state0)(nil) + type state0 struct { verifreg0.State store adt.Store From 286fe042715cce1e11d2bcf67de8cdd28558190d Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Mon, 21 Sep 2020 02:52:45 -0400 Subject: [PATCH 074/104] Add some TODOs --- chain/stmgr/utils.go | 58 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 20d7bd54fec..1056818a6e8 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -9,11 +9,7 @@ import ( "runtime" "strings" - init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" - - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/builtin/cron" saruntime "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime/proof" @@ -28,11 +24,14 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/account" - "github.com/filecoin-project/specs-actors/actors/builtin/cron" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -89,7 +88,8 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add } func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, bool, error) { - act, err := sm.LoadActorRaw(ctx, builtin.StoragePowerActorAddr, st) + // TODO: ActorUpgrade + act, err := sm.LoadActorRaw(ctx, builtin0.StoragePowerActorAddr, st) if err != nil { return power.Claim{}, power.Claim{}, false, xerrors.Errorf("(get sset) failed to load power actor state: %w", err) } @@ -308,7 +308,8 @@ func StateMinerInfo(ctx context.Context, sm *StateManager, ts *types.TipSet, mad } func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) { - act, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) + // TODO: ActorUpgrade + act, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) if err != nil { return false, xerrors.Errorf("failed to load power actor: %w", err) } @@ -331,7 +332,8 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma } func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) { - act, err := sm.LoadActor(ctx, builtin.StorageMarketActorAddr, ts) + // TODO: ActorUpgrade + act, err := sm.LoadActor(ctx, builtin0.StorageMarketActorAddr, ts) if err != nil { return nil, xerrors.Errorf("failed to load market actor: %w", err) } @@ -375,7 +377,8 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts } func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([]address.Address, error) { - act, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) + // TODO: ActorUpgrade + act, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) if err != nil { return nil, xerrors.Errorf("failed to load power actor: %w", err) } @@ -565,16 +568,16 @@ var MethodsMap = map[cid.Cid]map[abi.MethodNum]MethodMeta{} func init() { cidToMethods := map[cid.Cid][2]interface{}{ // builtin.SystemActorCodeID: {builtin.MethodsSystem, system.Actor{} }- apparently it doesn't have methods - builtin.InitActorCodeID: {builtin.MethodsInit, init0.Actor{}}, - builtin.CronActorCodeID: {builtin.MethodsCron, cron.Actor{}}, - builtin.AccountActorCodeID: {builtin.MethodsAccount, account.Actor{}}, - builtin.StoragePowerActorCodeID: {builtin.MethodsPower, power0.Actor{}}, - builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, miner0.Actor{}}, - builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market0.Actor{}}, - builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}}, - builtin.MultisigActorCodeID: {builtin.MethodsMultisig, msig0.Actor{}}, - builtin.RewardActorCodeID: {builtin.MethodsReward, reward0.Actor{}}, - builtin.VerifiedRegistryActorCodeID: {builtin.MethodsVerifiedRegistry, verifreg0.Actor{}}, + builtin0.InitActorCodeID: {builtin0.MethodsInit, init0.Actor{}}, + builtin0.CronActorCodeID: {builtin0.MethodsCron, cron.Actor{}}, + builtin0.AccountActorCodeID: {builtin0.MethodsAccount, account0.Actor{}}, + builtin0.StoragePowerActorCodeID: {builtin0.MethodsPower, power0.Actor{}}, + builtin0.StorageMinerActorCodeID: {builtin0.MethodsMiner, miner0.Actor{}}, + builtin0.StorageMarketActorCodeID: {builtin0.MethodsMarket, market0.Actor{}}, + builtin0.PaymentChannelActorCodeID: {builtin0.MethodsPaych, paych0.Actor{}}, + builtin0.MultisigActorCodeID: {builtin0.MethodsMultisig, msig0.Actor{}}, + builtin0.RewardActorCodeID: {builtin0.MethodsReward, reward0.Actor{}}, + builtin0.VerifiedRegistryActorCodeID: {builtin0.MethodsVerifiedRegistry, verifreg0.Actor{}}, } for c, m := range cidToMethods { @@ -582,7 +585,7 @@ func init() { methods := make(map[abi.MethodNum]MethodMeta, len(exports)) // Explicitly add send, it's special. - methods[builtin.MethodSend] = MethodMeta{ + methods[builtin0.MethodSend] = MethodMeta{ Name: "Send", Params: reflect.TypeOf(new(abi.EmptyValue)), Ret: reflect.TypeOf(new(abi.EmptyValue)), @@ -622,9 +625,9 @@ func init() { } switch abi.MethodNum(number) { - case builtin.MethodSend: + case builtin0.MethodSend: panic("method 0 is reserved for Send") - case builtin.MethodConstructor: + case builtin0.MethodConstructor: if fnName != "Constructor" { panic("method 1 is reserved for Constructor") } @@ -654,7 +657,8 @@ func GetReturnType(ctx context.Context, sm *StateManager, to address.Address, me } func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Address, ts *types.TipSet) (bool, error) { - pact, err := sm.LoadActor(ctx, builtin.StoragePowerActorAddr, ts) + // TODO: ActorUpgrade + pact, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) if err != nil { return false, xerrors.Errorf("loading power actor state: %w", err) } From a307e4593a005888395db34e5af4691ee50d765d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 21 Sep 2020 09:52:57 +0200 Subject: [PATCH 075/104] wdpost: Fix TestWDPostDoPost --- storage/wdpost_run_test.go | 54 ++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index 58014d6320c..bd8e35d4f1a 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -5,18 +5,16 @@ import ( "context" "testing" - "github.com/filecoin-project/go-state-types/dline" - "github.com/stretchr/testify/require" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-bitfield" - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -24,7 +22,9 @@ import ( "github.com/filecoin-project/specs-actors/actors/runtime/proof" tutils "github.com/filecoin-project/specs-actors/support/testing" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/types" ) type mockStorageMinerAPI struct { @@ -39,7 +39,10 @@ func newMockStorageMinerAPI() *mockStorageMinerAPI { } func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Address, key types.TipSetKey) (miner.MinerInfo, error) { - panic("implement me") + return miner.MinerInfo{ + Worker: tutils.NewIDAddr(nil, 101), + Owner: tutils.NewIDAddr(nil, 101), + }, nil } func (m *mockStorageMinerAPI) StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error) { @@ -167,7 +170,13 @@ func TestWDPostDoPost(t *testing.T) { worker: workerAct, } - di := &dline.Info{} + di := &dline.Info{ + WPoStPeriodDeadlines: miner0.WPoStPeriodDeadlines, + WPoStProvingPeriod: miner0.WPoStProvingPeriod, + WPoStChallengeWindow: miner0.WPoStChallengeWindow, + WPoStChallengeLookback: miner0.WPoStChallengeLookback, + FaultDeclarationCutoff: miner0.FaultDeclarationCutoff, + } ts := mockTipSet(t) scheduler.doPost(ctx, di, ts) @@ -232,7 +241,20 @@ func (m *mockStorageMinerAPI) StateSectorPartition(ctx context.Context, maddr ad } func (m *mockStorageMinerAPI) StateMinerProvingDeadline(ctx context.Context, address address.Address, key types.TipSetKey) (*dline.Info, error) { - panic("implement me") + return &dline.Info{ + CurrentEpoch: 0, + PeriodStart: 0, + Index: 0, + Open: 0, + Close: 0, + Challenge: 0, + FaultCutoff: 0, + WPoStPeriodDeadlines: miner0.WPoStPeriodDeadlines, + WPoStProvingPeriod: miner0.WPoStProvingPeriod, + WPoStChallengeWindow: miner0.WPoStChallengeWindow, + WPoStChallengeLookback: miner0.WPoStChallengeLookback, + FaultDeclarationCutoff: miner0.FaultDeclarationCutoff, + }, nil } func (m *mockStorageMinerAPI) StateMinerPreCommitDepositForPower(ctx context.Context, address address.Address, info miner.SectorPreCommitInfo, key types.TipSetKey) (types.BigInt, error) { @@ -270,11 +292,15 @@ func (m *mockStorageMinerAPI) StateMinerRecoveries(ctx context.Context, address } func (m *mockStorageMinerAPI) StateAccountKey(ctx context.Context, address address.Address, key types.TipSetKey) (address.Address, error) { - panic("implement me") + return address, nil } func (m *mockStorageMinerAPI) GasEstimateMessageGas(ctx context.Context, message *types.Message, spec *api.MessageSendSpec, key types.TipSetKey) (*types.Message, error) { - panic("implement me") + msg := *message + msg.GasFeeCap = big.NewInt(1) + msg.GasPremium = big.NewInt(1) + msg.GasLimit = 2 + return &msg, nil } func (m *mockStorageMinerAPI) ChainHead(ctx context.Context) (*types.TipSet, error) { @@ -306,15 +332,15 @@ func (m *mockStorageMinerAPI) ChainGetTipSet(ctx context.Context, key types.TipS } func (m *mockStorageMinerAPI) WalletSign(ctx context.Context, address address.Address, bytes []byte) (*crypto.Signature, error) { - panic("implement me") + return nil, nil } func (m *mockStorageMinerAPI) WalletBalance(ctx context.Context, address address.Address) (types.BigInt, error) { - panic("implement me") + return big.NewInt(333), nil } func (m *mockStorageMinerAPI) WalletHas(ctx context.Context, address address.Address) (bool, error) { - panic("implement me") + return true, nil } var _ storageMinerApi = &mockStorageMinerAPI{} From 0b5e4a961245f09634d9db750f928249b60ff3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 21 Sep 2020 18:28:32 +0200 Subject: [PATCH 076/104] Make GetSectorsForWinningPoSt fast again --- chain/actors/adt/adt.go | 17 +++++++ chain/actors/builtin/miner/miner.go | 4 +- chain/actors/builtin/miner/v0.go | 75 +++++++++++++++-------------- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index fd5ee3f875c..81c2e3a8623 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -55,3 +55,20 @@ func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) } return nil, xerrors.Errorf("unknown network version: %d", version) } + +type ROnlyArray interface { + Get(idx uint64, v cbor.Unmarshaler) (bool, error) + ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error +} + +type ProxyArray struct { + GetFunc func(idx uint64, v cbor.Unmarshaler) (bool, error) + ForEachFunc func(v cbor.Unmarshaler, fn func(idx int64) error) error +} + +func (a *ProxyArray) Get(idx uint64, v cbor.Unmarshaler) (bool, error) { + return a.GetFunc(idx, v) +} +func (a *ProxyArray) ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error { + return a.ForEachFunc(v, fn) +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 704ea12919a..b20539b8f74 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -1,7 +1,6 @@ package miner import ( - "github.com/filecoin-project/go-state-types/dline" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" @@ -11,6 +10,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/go-state-types/dline" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -47,7 +47,7 @@ type State interface { FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) - LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) + LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.ROnlyArray, error) IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 010ae66993b..ddc0b71a93b 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -4,17 +4,19 @@ import ( "bytes" "errors" + "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/lotus/chain/actors/adt" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/libp2p/go-libp2p-core/peer" - cbg "github.com/whyrusleeping/cbor-gen" - "golang.org/x/xerrors" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" ) var _ State = (*state0)(nil) @@ -161,56 +163,55 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) { +func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.ROnlyArray, error) { a, err := adt0.AsArray(s.store, s.State.Sectors) if err != nil { return nil, err } - ret := adt0.MakeEmptyArray(s.store) - var v cbg.Deferred - if err := a.ForEach(&v, func(i int64) error { + incl := func(i uint64) (bool, error) { include := true if filter != nil { - set, err := filter.IsSet(uint64(i)) + set, err := filter.IsSet(i) if err != nil { - return xerrors.Errorf("filter check error: %w", err) + return false, xerrors.Errorf("filter check error: %w", err) } if set == filterOut { include = false } } + return include, nil + } - if include { - var oci miner0.SectorOnChainInfo - if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { - return err + return &adt.ProxyArray{ + GetFunc: func(idx uint64, v cbor.Unmarshaler) (bool, error) { + i, err := incl(idx) + if err != nil { + return false, err } - - noci := SectorOnChainInfo{ - SectorNumber: oci.SectorNumber, - SealProof: oci.SealProof, - SealedCID: oci.SealedCID, - DealIDs: oci.DealIDs, - Activation: oci.Activation, - Expiration: oci.Expiration, - DealWeight: oci.DealWeight, - VerifiedDealWeight: oci.VerifiedDealWeight, - InitialPledge: oci.InitialPledge, - ExpectedDayReward: oci.ExpectedDayReward, - ExpectedStoragePledge: oci.ExpectedStoragePledge, + if !i { + return false, nil } - if err := ret.Set(uint64(i), &noci); err != nil { - return err - } - } - return nil - }); err != nil { - return nil, err - } + // TODO: ActorUpgrade potentially convert - return ret, nil + return a.Get(idx, v) + }, + ForEachFunc: func(v cbor.Unmarshaler, fn func(int64) error) error { + // TODO: ActorUpgrade potentially convert the output + return a.ForEach(v, func(i int64) error { + include, err := incl(uint64(i)) + if err != nil { + return err + } + if !include { + return nil + } + + return fn(i) + }) + }, + }, nil } func (s *state0) LoadPreCommittedSectors() (adt.Map, error) { From 025663118f65dc50d0dd13364fd57b7cddab70ed Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 10:30:09 -0700 Subject: [PATCH 077/104] non-destructive diff --- chain/actors/adt/diff_adt.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/chain/actors/adt/diff_adt.go b/chain/actors/adt/diff_adt.go index 0784b77a2f1..160e12e19c3 100644 --- a/chain/actors/adt/diff_adt.go +++ b/chain/actors/adt/diff_adt.go @@ -27,6 +27,7 @@ type AdtArrayDiff interface { // - All values that exist in preArr and in curArr are passed to AdtArrayDiff.Modify() // - It is the responsibility of AdtArrayDiff.Modify() to determine if the values it was passed have been modified. func DiffAdtArray(preArr, curArr Array, out AdtArrayDiff) error { + notNew := make(map[int64]struct{}, curArr.Length()) prevVal := new(typegen.Deferred) if err := preArr.ForEach(prevVal, func(i int64) error { curVal := new(typegen.Deferred) @@ -47,14 +48,17 @@ func DiffAdtArray(preArr, curArr Array, out AdtArrayDiff) error { return err } } - - return curArr.Delete(uint64(i)) + notNew[i] = struct{}{} + return nil }); err != nil { return err } curVal := new(typegen.Deferred) return curArr.ForEach(curVal, func(i int64) error { + if _, ok := notNew[i]; ok { + return nil + } return out.Add(uint64(i), curVal) }) } @@ -76,6 +80,7 @@ type AdtMapDiff interface { } func DiffAdtMap(preMap, curMap Map, out AdtMapDiff) error { + notNew := make(map[string]struct{}) prevVal := new(typegen.Deferred) if err := preMap.ForEach(prevVal, func(key string) error { curVal := new(typegen.Deferred) @@ -101,14 +106,17 @@ func DiffAdtMap(preMap, curMap Map, out AdtMapDiff) error { return err } } - - return curMap.Delete(k) + notNew[key] = struct{}{} + return nil }); err != nil { return err } curVal := new(typegen.Deferred) return curMap.ForEach(curVal, func(key string) error { + if _, ok := notNew[key]; ok { + return nil + } return out.Add(key, curVal) }) } From 4cf0c105eb12685b384fad6fb3e249898687511f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 12:05:01 -0700 Subject: [PATCH 078/104] optimize sector loading And avoid exposing "arrays" via the miner abstraction. We may change these structures later. --- api/api_full.go | 6 +-- api/apistruct/struct.go | 10 ++-- chain/actors/adt/adt.go | 17 ------- chain/actors/builtin/miner/miner.go | 7 +-- chain/actors/builtin/miner/v0.go | 72 ++++++++++------------------- chain/stmgr/utils.go | 65 ++++++++------------------ cli/state.go | 6 +-- cmd/lotus-storage-miner/sectors.go | 6 +-- documentation/en/api-methods.md | 3 -- node/impl/full/state.go | 8 ++-- storage/miner.go | 2 +- storage/wdpost_run.go | 16 +++---- storage/wdpost_run_test.go | 16 +++---- 13 files changed, 78 insertions(+), 156 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 61bf1fd8d07..f39d0e9bc97 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -313,11 +313,9 @@ type FullNode interface { // StateNetworkName returns the name of the network the node is synced to StateNetworkName(context.Context) (dtypes.NetworkName, error) // StateMinerSectors returns info about the given miner's sectors. If the filter bitfield is nil, all sectors are included. - // If the filterOut boolean is set to true, any sectors in the filter are excluded. - // If false, only those sectors in the filter are included. - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) // StateMinerActiveSectors returns info about sectors that a given miner is actively proving. - StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner.ChainSectorInfo, error) + StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) // StateMinerProvingDeadline calculates the deadline at some epoch for a proving period // and returns the deadline-related calculations. StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index cbe78c5559c..91a54547999 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -162,8 +162,8 @@ type FullNodeStruct struct { ClientRetrieveTryRestartInsufficientFunds func(ctx context.Context, paymentChannel address.Address) error `perm:"write"` StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` - StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) `perm:"read"` - StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*miner.ChainSectorInfo, error) `perm:"read"` + StateMinerSectors func(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` + StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` @@ -734,11 +734,11 @@ func (c *FullNodeStruct) StateNetworkName(ctx context.Context) (dtypes.NetworkNa return c.Internal.StateNetworkName(ctx) } -func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { - return c.Internal.StateMinerSectors(ctx, addr, filter, filterOut, tsk) +func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { + return c.Internal.StateMinerSectors(ctx, addr, sectorNos, tsk) } -func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { +func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { return c.Internal.StateMinerActiveSectors(ctx, addr, tsk) } diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index 81c2e3a8623..fd5ee3f875c 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -55,20 +55,3 @@ func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) } return nil, xerrors.Errorf("unknown network version: %d", version) } - -type ROnlyArray interface { - Get(idx uint64, v cbor.Unmarshaler) (bool, error) - ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error -} - -type ProxyArray struct { - GetFunc func(idx uint64, v cbor.Unmarshaler) (bool, error) - ForEachFunc func(v cbor.Unmarshaler, fn func(idx int64) error) error -} - -func (a *ProxyArray) Get(idx uint64, v cbor.Unmarshaler) (bool, error) { - return a.GetFunc(idx, v) -} -func (a *ProxyArray) ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error { - return a.ForEachFunc(v, fn) -} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index b20539b8f74..cf5eea742ad 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -47,7 +47,7 @@ type State interface { FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) - LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.ROnlyArray, error) + LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error) IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) @@ -129,11 +129,6 @@ type MinerInfo struct { WindowPoStPartitionSectors uint64 } -type ChainSectorInfo struct { - Info SectorOnChainInfo - ID abi.SectorNumber -} - type SectorExpiration struct { OnTime abi.ChainEpoch diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index ddc0b71a93b..30ce7e73eb8 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -6,12 +6,10 @@ import ( "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" - "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/dline" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -163,59 +161,37 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state0) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.ROnlyArray, error) { - a, err := adt0.AsArray(s.store, s.State.Sectors) +func (s *state0) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) { + sectors, err := miner0.LoadSectors(s.store, s.State.Sectors) if err != nil { return nil, err } - incl := func(i uint64) (bool, error) { - include := true - if filter != nil { - set, err := filter.IsSet(i) - if err != nil { - return false, xerrors.Errorf("filter check error: %w", err) - } - if set == filterOut { - include = false - } + // If no sector numbers are specified, load all. + if snos == nil { + infos := make([]*SectorOnChainInfo, 0, sectors.Length()) + var info0 miner0.SectorOnChainInfo + if err := sectors.ForEach(&info0, func(i int64) error { + info := fromV0SectorOnChainInfo(info0) + infos[i] = &info + return nil + }); err != nil { + return nil, err } - return include, nil + return infos, nil } - return &adt.ProxyArray{ - GetFunc: func(idx uint64, v cbor.Unmarshaler) (bool, error) { - i, err := incl(idx) - if err != nil { - return false, err - } - if !i { - return false, nil - } - - // TODO: ActorUpgrade potentially convert - - return a.Get(idx, v) - }, - ForEachFunc: func(v cbor.Unmarshaler, fn func(int64) error) error { - // TODO: ActorUpgrade potentially convert the output - return a.ForEach(v, func(i int64) error { - include, err := incl(uint64(i)) - if err != nil { - return err - } - if !include { - return nil - } - - return fn(i) - }) - }, - }, nil -} - -func (s *state0) LoadPreCommittedSectors() (adt.Map, error) { - return adt0.AsMap(s.store, s.State.PreCommittedSectors) + // Otherwise, load selected. + infos0, err := sectors.Load(*snos) + if err != nil { + return nil, err + } + infos := make([]*SectorOnChainInfo, len(infos0)) + for i, info0 := range infos0 { + info := fromV0SectorOnChainInfo(*info0) + infos[i] = &info + } + return infos, nil } func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) { diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 1056818a6e8..1e670dacee8 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -150,7 +150,7 @@ func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Addres return mas.GetSector(sid) } -func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, filter *bitfield.BitField, filterOut bool) ([]*miner.ChainSectorInfo, error) { +func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, snos *bitfield.BitField) ([]*miner.SectorOnChainInfo, error) { act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) @@ -161,29 +161,7 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - sectors, err := mas.LoadSectorsFromSet(filter, filterOut) - if err != nil { - return nil, xerrors.Errorf("(get sset) failed to load sectors: %w", err) - } - - var sset []*miner.ChainSectorInfo - var v cbg.Deferred - if err := sectors.ForEach(&v, func(i int64) error { - var oci miner.SectorOnChainInfo - if err := oci.UnmarshalCBOR(bytes.NewReader(v.Raw)); err != nil { - return err - } - sset = append(sset, &miner.ChainSectorInfo{ - Info: oci, - ID: abi.SectorNumber(i), - }) - - return nil - }); err != nil { - return nil, err - } - - return sset, nil + return mas.LoadSectors(snos) } func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]proof.SectorInfo, error) { @@ -249,35 +227,30 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, xerrors.Errorf("generating winning post challenges: %w", err) } - // we don't need to filter here (and it's **very** slow) - sectors, err := mas.LoadSectorsFromSet(nil, false) + iter, err := provingSectors.BitIterator() if err != nil { - return nil, xerrors.Errorf("loading proving sectors: %w", err) + return nil, xerrors.Errorf("iterating over proving sectors: %w", err) } - out := make([]proof.SectorInfo, len(ids)) - for i, n := range ids { - sb, err := provingSectors.Slice(n, 1) - if err != nil { - return nil, err - } - - sid, err := sb.First() - if err != nil { - return nil, err - } - - var sinfo miner.SectorOnChainInfo - found, err := sectors.Get(sid, &sinfo) - + // Select winning sectors by _index_ in the all-sectors bitfield. + selectedSectors := bitfield.New() + prev := uint64(0) + for _, n := range ids { + sno, err := iter.Nth(n - prev) if err != nil { - return nil, xerrors.Errorf("loading sector info: %w", err) + return nil, xerrors.Errorf("iterating over proving sectors: %w", err) } + selectedSectors.Set(sno) + prev = n + } - if !found { - return nil, xerrors.Errorf("didn't find sector info for sector %d", n) - } + sectors, err := mas.LoadSectors(&selectedSectors) + if err != nil { + return nil, xerrors.Errorf("loading proving sectors: %w", err) + } + out := make([]proof.SectorInfo, len(sectors)) + for i, sinfo := range sectors { out[i] = proof.SectorInfo{ SealProof: spt, SectorNumber: sinfo.SectorNumber, diff --git a/cli/state.go b/cli/state.go index 2476d7c59a4..d96c93c5405 100644 --- a/cli/state.go +++ b/cli/state.go @@ -259,13 +259,13 @@ var stateSectorsCmd = &cli.Command{ return err } - sectors, err := api.StateMinerSectors(ctx, maddr, nil, true, ts.Key()) + sectors, err := api.StateMinerSectors(ctx, maddr, nil, ts.Key()) if err != nil { return err } for _, s := range sectors { - fmt.Printf("%d: %x\n", s.Info.SectorNumber, s.Info.SealedCID) + fmt.Printf("%d: %x\n", s.SectorNumber, s.SealedCID) } return nil @@ -305,7 +305,7 @@ var stateActiveSectorsCmd = &cli.Command{ } for _, s := range sectors { - fmt.Printf("%d: %x\n", s.Info.SectorNumber, s.Info.SealedCID) + fmt.Printf("%d: %x\n", s.SectorNumber, s.SealedCID) } return nil diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index e3512cfe4ff..27a5c31be91 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -176,16 +176,16 @@ var sectorsListCmd = &cli.Command{ } activeIDs := make(map[abi.SectorNumber]struct{}, len(activeSet)) for _, info := range activeSet { - activeIDs[info.ID] = struct{}{} + activeIDs[info.SectorNumber] = struct{}{} } - sset, err := fullApi.StateMinerSectors(ctx, maddr, nil, true, types.EmptyTSK) + sset, err := fullApi.StateMinerSectors(ctx, maddr, nil, types.EmptyTSK) if err != nil { return err } commitedIDs := make(map[abi.SectorNumber]struct{}, len(activeSet)) for _, info := range sset { - commitedIDs[info.ID] = struct{}{} + commitedIDs[info.SectorNumber] = struct{}{} } sort.Slice(list, func(i, j int) bool { diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 5616bbd260d..fd201f18a40 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -3714,8 +3714,6 @@ Response: ### StateMinerSectors StateMinerSectors returns info about the given miner's sectors. If the filter bitfield is nil, all sectors are included. -If the filterOut boolean is set to true, any sectors in the filter are excluded. -If false, only those sectors in the filter are included. Perms: read @@ -3727,7 +3725,6 @@ Inputs: [ 0 ], - true, [ { "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" diff --git a/node/impl/full/state.go b/node/impl/full/state.go index e4400b073e1..8d40da0ec18 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -64,15 +64,15 @@ func (a *StateAPI) StateNetworkName(ctx context.Context) (dtypes.NetworkName, er return stmgr.GetNetworkName(ctx, a.StateManager, a.Chain.GetHeaviestTipSet().ParentState()) } -func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, filterOut bool, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { +func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, addr, filter, filterOut) + return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, addr, sectorNos) } -func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { // TODO: only used in cli +func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { // TODO: only used in cli ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) @@ -93,7 +93,7 @@ func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Ad return nil, xerrors.Errorf("merge partition active sets: %w", err) } - return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, maddr, &activeSectors, false) + return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, maddr, &activeSectors) } func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { diff --git a/storage/miner.go b/storage/miner.go index 61c4000f2ba..a64ee977e74 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -71,7 +71,7 @@ type SealingStateEvt struct { type storageMinerApi interface { // Call a read only method on actors (no interaction with the chain required) StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) - StateMinerSectors(context.Context, address.Address, *bitfield.BitField, bool, types.TipSetKey) ([]*miner.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 06740b108c0..254a2f0d339 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -594,7 +594,7 @@ func (s *WindowPoStScheduler) batchPartitions(partitions []api.Partition) ([][]a } func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, allSectors bitfield.BitField, ts *types.TipSet) ([]proof.SectorInfo, error) { - sset, err := s.api.StateMinerSectors(ctx, s.actor, &goodSectors, false, ts.Key()) + sset, err := s.api.StateMinerSectors(ctx, s.actor, &goodSectors, ts.Key()) if err != nil { return nil, err } @@ -604,17 +604,17 @@ func (s *WindowPoStScheduler) sectorsForProof(ctx context.Context, goodSectors, } substitute := proof.SectorInfo{ - SectorNumber: sset[0].ID, - SealedCID: sset[0].Info.SealedCID, - SealProof: sset[0].Info.SealProof, + SectorNumber: sset[0].SectorNumber, + SealedCID: sset[0].SealedCID, + SealProof: sset[0].SealProof, } sectorByID := make(map[uint64]proof.SectorInfo, len(sset)) for _, sector := range sset { - sectorByID[uint64(sector.ID)] = proof.SectorInfo{ - SectorNumber: sector.ID, - SealedCID: sector.Info.SealedCID, - SealProof: sector.Info.SealProof, + sectorByID[uint64(sector.SectorNumber)] = proof.SectorInfo{ + SectorNumber: sector.SectorNumber, + SealedCID: sector.SealedCID, + SealProof: sector.SealProof, } } diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index bd8e35d4f1a..1797cf35cf7 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -65,14 +65,14 @@ func (m *mockStorageMinerAPI) StateMinerPartitions(ctx context.Context, a addres return m.partitions, nil } -func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, field *bitfield.BitField, b bool, key types.TipSetKey) ([]*miner.ChainSectorInfo, error) { - var sis []*miner.ChainSectorInfo - _ = field.ForEach(func(i uint64) error { - sis = append(sis, &miner.ChainSectorInfo{ - Info: miner.SectorOnChainInfo{ - SectorNumber: abi.SectorNumber(i), - }, - ID: abi.SectorNumber(i), +func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, snos *bitfield.BitField, key types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { + var sis []*miner.SectorOnChainInfo + if snos == nil { + panic("unsupported") + } + _ = snos.ForEach(func(i uint64) error { + sis = append(sis, &miner.SectorOnChainInfo{ + SectorNumber: abi.SectorNumber(i), }) return nil }) From 24ae9205fef921e1e15b59c291859c42ef5851ad Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 12:50:12 -0700 Subject: [PATCH 079/104] cross-version state tree diff --- chain/state/statetree.go | 43 ++++++++++++++++++++++++++++++++ node/impl/full/state.go | 53 +++++----------------------------------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/chain/state/statetree.go b/chain/state/statetree.go index b3a3b7cee53..fb6a14a9b09 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -1,6 +1,7 @@ package state import ( + "bytes" "context" "fmt" @@ -14,6 +15,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/builtin" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -391,3 +393,44 @@ func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error return f(addr, &act) }) } + +func Diff(oldTree, newTree *StateTree) (map[string]types.Actor, error) { + out := map[string]types.Actor{} + + var ( + ncval, ocval cbg.Deferred + buf = bytes.NewReader(nil) + ) + if err := newTree.root.ForEach(&ncval, func(k string) error { + var act types.Actor + + addr, err := address.NewFromBytes([]byte(k)) + if err != nil { + return xerrors.Errorf("address in state tree was not valid: %w", err) + } + + found, err := oldTree.root.Get(abi.AddrKey(addr), &ocval) + if err != nil { + return err + } + + if found && bytes.Equal(ocval.Raw, ncval.Raw) { + return nil // not changed + } + + buf.Reset(ncval.Raw) + err = act.UnmarshalCBOR(buf) + buf.Reset(nil) + + if err != nil { + return err + } + + out[addr.String()] = act + + return nil + }); err != nil { + return nil, err + } + return out, nil +} diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 8d40da0ec18..b64e6026048 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -16,7 +16,6 @@ import ( cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" - cbg "github.com/whyrusleeping/cbor-gen" "go.uber.org/fx" "golang.org/x/xerrors" @@ -27,7 +26,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -618,58 +616,19 @@ func (a *StateAPI) StateMarketStorageDeal(ctx context.Context, dealId abi.DealID } func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid.Cid) (map[string]types.Actor, error) { - store := adt.WrapStore(ctx, cbor.NewCborStore(a.Chain.Blockstore())) + store := a.Chain.Store(ctx) - nh, err := adt.AsMap(store, new) + oldTree, err := state.LoadStateTree(store, old) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load old state tree: %w", err) } - oh, err := adt.AsMap(store, old) + newTree, err := state.LoadStateTree(store, new) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load new state tree: %w", err) } - out := map[string]types.Actor{} - - var ( - ncval, ocval cbg.Deferred - buf = bytes.NewReader(nil) - ) - err = nh.ForEach(&ncval, func(k string) error { - var act types.Actor - - addr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return xerrors.Errorf("address in state tree was not valid: %w", err) - } - - found, err := oh.Get(abi.AddrKey(addr), &ocval) - if err != nil { - return err - } - - if found && bytes.Equal(ocval.Raw, ncval.Raw) { - return nil // not changed - } - - buf.Reset(ncval.Raw) - err = act.UnmarshalCBOR(buf) - buf.Reset(nil) - - if err != nil { - return err - } - - out[addr.String()] = act - - return nil - }) - if err != nil { - return nil, err - } - - return out, nil + state.Diff(oldTree, newTree) } func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MinerSectors, error) { From f9a896f6f2f33e30f4cbd627613255488cbc2aec Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 13:10:41 -0700 Subject: [PATCH 080/104] fix compile --- node/impl/full/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index b64e6026048..df747ba3fe5 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -628,7 +628,7 @@ func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid. return nil, xerrors.Errorf("failed to load new state tree: %w", err) } - state.Diff(oldTree, newTree) + return state.Diff(oldTree, newTree) } func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MinerSectors, error) { From 0ab2459fcec5e85ea6496174b350b201e0b1518a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 13:13:38 -0700 Subject: [PATCH 081/104] convert multisig to new actor abstractions --- chain/actors/builtin/multisig/multisig.go | 9 +++ chain/actors/builtin/multisig/v0.go | 33 +++++++- cli/multisig.go | 91 +++++++---------------- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index 86a68c178ce..226eed75b9f 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -3,9 +3,12 @@ package multisig import ( "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -31,4 +34,10 @@ type State interface { StartEpoch() abi.ChainEpoch UnlockDuration() abi.ChainEpoch InitialBalance() abi.TokenAmount + Threshold() uint64 + Signers() []address.Address + + ForEachPendingTxn(func(id int64, txn Transaction) error) error } + +type Transaction = msig0.Transaction diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index 5de5ca6ad06..e81a367cfb9 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -1,15 +1,21 @@ package multisig import ( + "encoding/binary" + + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + "golang.org/x/xerrors" + + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) var _ State = (*state0)(nil) type state0 struct { - multisig.State + msig0.State store adt.Store } @@ -28,3 +34,26 @@ func (s *state0) UnlockDuration() abi.ChainEpoch { func (s *state0) InitialBalance() abi.TokenAmount { return s.State.InitialBalance } + +func (s *state0) Threshold() uint64 { + return s.State.NumApprovalsThreshold +} + +func (s *state0) Signers() []address.Address { + return s.State.Signers +} + +func (s *state0) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { + arr, err := adt0.AsMap(s.store, s.State.PendingTxns) + if err != nil { + return err + } + var out msig0.Transaction + return arr.ForEach(&out, func(key string) error { + txid, n := binary.Varint([]byte(key)) + if n <= 0 { + return xerrors.Errorf("invalid pending transaction key: %v", key) + } + return cb(txid, (Transaction)(out)) + }) +} diff --git a/cli/multisig.go b/cli/multisig.go index 23095bf061c..2aabf5d7eed 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -2,8 +2,6 @@ package cli import ( "bytes" - "context" - "encoding/binary" "encoding/hex" "fmt" "os" @@ -12,21 +10,21 @@ import ( "text/tabwriter" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/go-address" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/urfave/cli/v2" "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/specs-actors/actors/builtin" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" - types "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" + "github.com/filecoin-project/lotus/chain/types" ) var multisigCmd = &cli.Command{ @@ -146,7 +144,7 @@ var msigCreateCmd = &cli.Command{ // get address of newly created miner - var execreturn init_.ExecReturn + var execreturn init0.ExecReturn if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return err } @@ -179,50 +177,54 @@ var msigInspectCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) + store := adt.WrapStore(ctx, cbor.NewCborStore(apibstore.NewAPIBlockstore(api))) + maddr, err := address.NewFromString(cctx.Args().First()) if err != nil { return err } - act, err := api.StateGetActor(ctx, maddr, types.EmptyTSK) + head, err := api.ChainHead(ctx) if err != nil { return err } - obj, err := api.ChainReadObj(ctx, act.Head) + act, err := api.StateGetActor(ctx, maddr, head.Key()) if err != nil { return err } - head, err := api.ChainHead(ctx) + mstate, err := multisig.Load(store, act) if err != nil { return err } - - var mstate msig0.State - if err := mstate.UnmarshalCBOR(bytes.NewReader(obj)); err != nil { + locked, err := mstate.LockedBalance(head.Height()) + if err != nil { return err } - locked := mstate.AmountLocked(head.Height() - mstate.StartEpoch) fmt.Printf("Balance: %s\n", types.FIL(act.Balance)) fmt.Printf("Spendable: %s\n", types.FIL(types.BigSub(act.Balance, locked))) if cctx.Bool("vesting") { - fmt.Printf("InitialBalance: %s\n", types.FIL(mstate.InitialBalance)) - fmt.Printf("StartEpoch: %d\n", mstate.StartEpoch) - fmt.Printf("UnlockDuration: %d\n", mstate.UnlockDuration) + fmt.Printf("InitialBalance: %s\n", types.FIL(mstate.InitialBalance())) + fmt.Printf("StartEpoch: %d\n", mstate.StartEpoch()) + fmt.Printf("UnlockDuration: %d\n", mstate.UnlockDuration()) } - fmt.Printf("Threshold: %d / %d\n", mstate.NumApprovalsThreshold, len(mstate.Signers)) + signers := mstate.Signers() + fmt.Printf("Threshold: %d / %d\n", mstate.Threshold(), len(signers)) fmt.Println("Signers:") - for _, s := range mstate.Signers { + for _, s := range signers { fmt.Printf("\t%s\n", s) } - pending, err := GetMultisigPending(ctx, api, mstate.PendingTxns) - if err != nil { - return fmt.Errorf("reading pending transactions: %w", err) + pending := make(map[int64]multisig.Transaction) + if err := mstate.ForEachPendingTxn(func(id int64, txn multisig.Transaction) error { + pending[id] = txn + return nil + }); err != nil { + return xerrors.Errorf("reading pending transactions: %w", err) } fmt.Println("Transactions: ", len(pending)) @@ -239,7 +241,7 @@ var msigInspectCmd = &cli.Command{ fmt.Fprintf(w, "ID\tState\tApprovals\tTo\tValue\tMethod\tParams\n") for _, txid := range txids { tx := pending[txid] - fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%d\t%x\n", txid, state(tx), len(tx.Approved), tx.To, types.FIL(tx.Value), tx.Method, tx.Params) + fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%d\t%x\n", txid, "pending", len(tx.Approved), tx.To, types.FIL(tx.Value), tx.Method, tx.Params) } if err := w.Flush(); err != nil { return xerrors.Errorf("flushing output: %+v", err) @@ -251,43 +253,6 @@ var msigInspectCmd = &cli.Command{ }, } -func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*msig0.Transaction, error) { - bs := apibstore.NewAPIBlockstore(lapi) - store := adt.WrapStore(ctx, cbor.NewCborStore(bs)) - - nd, err := adt.AsMap(store, hroot) - if err != nil { - return nil, err - } - - txs := make(map[int64]*msig0.Transaction) - var tx msig0.Transaction - err = nd.ForEach(&tx, func(k string) error { - txid, _ := binary.Varint([]byte(k)) - - cpy := tx // copy so we don't clobber on future iterations. - txs[txid] = &cpy - return nil - }) - if err != nil { - return nil, xerrors.Errorf("failed to iterate transactions hamt: %w", err) - } - - return txs, nil -} - -func state(tx *msig0.Transaction) string { - /* // TODO(why): I strongly disagree with not having these... but i need to move forward - if tx.Complete { - return "done" - } - if tx.Canceled { - return "canceled" - } - */ - return "pending" -} - var msigProposeCmd = &cli.Command{ Name: "propose", Usage: "Propose a multisig transaction", From a41bf74badf8586ebb20bcdba01d14cf006e5ff4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 13:25:03 -0700 Subject: [PATCH 082/104] fix: remove incorrect variable --- chain/actors/builtin/miner/miner.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index cf5eea742ad..ab20439543f 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -18,8 +18,6 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -var Address = builtin0.InitActorAddr - func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case builtin0.StorageMinerActorCodeID: From 916421b247b8a075ca808c139df7dd52aa396f81 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 13:43:47 -0700 Subject: [PATCH 083/104] convert lotus-shed balances --- chain/actors/builtin/miner/miner.go | 10 ++++++++ chain/actors/builtin/miner/v0.go | 15 ++++++++++++ cmd/lotus-shed/balances.go | 37 ++++++++++++++++------------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index ab20439543f..5f1c26013ed 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -18,6 +18,15 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +// Returns true if the specified actor code ID is a miner actor. +func Is(code cid.Cid) bool { + switch code { + case builtin0.StorageMinerActorCodeID: + return true + } + return false +} + func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case builtin0.StorageMinerActorCodeID: @@ -46,6 +55,7 @@ type State interface { GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error) + NumLiveSectors() (uint64, error) IsAllocated(abi.SectorNumber) (bool, error) LoadDeadline(idx uint64) (Deadline, error) diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 30ce7e73eb8..a5677815689 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -79,6 +79,21 @@ func (s *state0) FindSector(num abi.SectorNumber) (*SectorLocation, error) { }, nil } +func (s *state0) NumLiveSectors() (uint64, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return 0, err + } + var total uint64 + if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner0.Deadline) error { + total += dl.LiveSectors + return nil + }); err != nil { + return 0, err + } + return total, nil +} + // GetSectorExpiration returns the effective expiration of the given sector. // // If the sector isn't found or has already been terminated, this method returns diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index 248f3b26e4d..413f863755f 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -12,6 +12,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -21,9 +23,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/lib/blockstore" "github.com/filecoin-project/lotus/node/repo" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/util/adt" ) type accountInfo struct { @@ -90,7 +89,7 @@ var chainBalanceCmd = &cli.Command{ Type: string(act.Code.Hash()[2:]), } - if act.Code == builtin.StorageMinerActorCodeID { + if miner.Is(act.Code) { pow, err := api.StateMinerPower(ctx, addr, tsk) if err != nil { return xerrors.Errorf("failed to get power: %w", err) @@ -167,6 +166,7 @@ var chainBalanceStateCmd = &cli.Command{ cs := store.NewChainStore(bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier)) cst := cbor.NewCborStore(bs) + store := adt.WrapStore(ctx, cst) sm := stmgr.NewStateManager(cs) @@ -191,7 +191,7 @@ var chainBalanceStateCmd = &cli.Command{ PreCommits: types.FIL(big.NewInt(0)), } - if act.Code == builtin.StorageMinerActorCodeID && minerInfo { + if minerInfo && miner.Is(act.Code) { pow, _, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr) if err != nil { return xerrors.Errorf("failed to get power: %w", err) @@ -199,24 +199,29 @@ var chainBalanceStateCmd = &cli.Command{ ai.Power = pow.RawBytePower - var st miner.State - if err := cst.Get(ctx, act.Head, &st); err != nil { + st, err := miner.Load(store, act) + if err != nil { return xerrors.Errorf("failed to read miner state: %w", err) } - sectors, err := adt.AsArray(cs.Store(ctx), st.Sectors) + liveSectorCount, err := st.NumLiveSectors() + if err != nil { + return xerrors.Errorf("failed to compute live sector count: %w", err) + } + + lockedFunds, err := st.LockedFunds() if err != nil { - return xerrors.Errorf("failed to load sector set: %w", err) + return xerrors.Errorf("failed to compute locked funds: %w", err) } - ai.InitialPledge = types.FIL(st.InitialPledgeRequirement) - ai.LockedFunds = types.FIL(st.LockedFunds) - ai.PreCommits = types.FIL(st.PreCommitDeposits) - ai.Sectors = sectors.Length() + ai.InitialPledge = types.FIL(lockedFunds.InitialPledgeRequirement) + ai.LockedFunds = types.FIL(lockedFunds.VestingFunds) + ai.PreCommits = types.FIL(lockedFunds.PreCommitDeposits) + ai.Sectors = liveSectorCount - var minfo miner.MinerInfo - if err := cst.Get(ctx, st.Info, &minfo); err != nil { - return xerrors.Errorf("failed to read miner info: %w", err) + minfo, err := st.Info() + if err != nil { + return xerrors.Errorf("failed to get miner info: %w", err) } ai.Worker = minfo.Worker From 4bab784e401bcaec79a30ac0a36b75cc98e73fdd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 15:04:39 -0700 Subject: [PATCH 084/104] migrate lotus-shed verifreg to specs-actors abstractions --- chain/actors/builtin/verifreg/v0.go | 40 ++++++++- chain/actors/builtin/verifreg/verifreg.go | 3 + cmd/lotus-shed/verifreg.go | 98 +++++++++-------------- 3 files changed, 75 insertions(+), 66 deletions(-) diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index f64c27310f3..c59a588114b 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/big" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -18,22 +19,53 @@ type state0 struct { store adt.Store } -func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { +func getDataCap(store adt.Store, root cid.Cid, addr address.Address) (bool, abi.StoragePower, error) { if addr.Protocol() != address.ID { return false, big.Zero(), xerrors.Errorf("can only look up ID addresses") } - vh, err := adt0.AsMap(s.store, s.VerifiedClients) + vh, err := adt0.AsMap(store, root) if err != nil { - return false, big.Zero(), xerrors.Errorf("loading verified clients: %w", err) + return false, big.Zero(), xerrors.Errorf("loading verifreg: %w", err) } var dcap abi.StoragePower if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil { - return false, big.Zero(), xerrors.Errorf("looking up verified clients: %w", err) + return false, big.Zero(), xerrors.Errorf("looking up addr: %w", err) } else if !found { return false, big.Zero(), nil } return true, dcap, nil } + +func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, s.State.VerifiedClients, addr) +} + +func (s *state0) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, s.State.Verifiers, addr) +} + +func forEachCap(store adt.Store, root cid.Cid, cb func(addr address.Address, dcap abi.StoragePower) error) error { + vh, err := adt0.AsMap(store, root) + if err != nil { + return xerrors.Errorf("loading verified clients: %w", err) + } + var dcap abi.StoragePower + return vh.ForEach(&dcap, func(key string) error { + a, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(a, dcap) + }) +} + +func (s *state0) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, s.State.Verifiers, cb) +} + +func (s *state0) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, s.State.VerifiedClients, cb) +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 000a9434950..c861f862f21 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -31,4 +31,7 @@ type State interface { cbor.Marshaler VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error) + VerifierDataCap(address.Address) (bool, abi.StoragePower, error) + ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error + ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error } diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index 9f475261dd4..3e2f34f4b14 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -8,13 +8,15 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/actors/util/adt" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" cbor "github.com/ipfs/go-ipld-cbor" @@ -57,7 +59,7 @@ var verifRegAddVerifierCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&verifreg.AddVerifierParams{Address: target, Allowance: allowance}) + params, err := actors.SerializeParams(&verifreg0.AddVerifierParams{Address: target, Allowance: allowance}) if err != nil { return err } @@ -70,9 +72,9 @@ var verifRegAddVerifierCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) msg := &types.Message{ - To: builtin.VerifiedRegistryActorAddr, + To: verifreg.Address, From: fromk, - Method: builtin.MethodsVerifiedRegistry.AddVerifier, + Method: builtin0.MethodsVerifiedRegistry.AddVerifier, Params: params, } @@ -131,7 +133,7 @@ var verifRegVerifyClientCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&verifreg.AddVerifiedClientParams{Address: target, Allowance: allowance}) + params, err := actors.SerializeParams(&verifreg0.AddVerifiedClientParams{Address: target, Allowance: allowance}) if err != nil { return err } @@ -144,9 +146,9 @@ var verifRegVerifyClientCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) msg := &types.Message{ - To: builtin.VerifiedRegistryActorAddr, + To: verifreg.Address, From: fromk, - Method: builtin.MethodsVerifiedRegistry.AddVerifiedClient, + Method: builtin0.MethodsVerifiedRegistry.AddVerifiedClient, Params: params, } @@ -181,7 +183,7 @@ var verifRegListVerifiersCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK) + act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK) if err != nil { return err } @@ -189,31 +191,14 @@ var verifRegListVerifiersCmd = &cli.Command{ apibs := apibstore.NewAPIBlockstore(api) store := adt.WrapStore(ctx, cbor.NewCborStore(apibs)) - var st verifreg.State - if err := store.Get(ctx, act.Head, &st); err != nil { - return err - } - - vh, err := adt.AsMap(store, st.Verifiers) + st, err := verifreg.Load(store, act) if err != nil { return err } - - var dcap verifreg.DataCap - if err := vh.ForEach(&dcap, func(k string) error { - addr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return err - } - - fmt.Printf("%s: %s\n", addr, dcap) - - return nil - }); err != nil { + return st.ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error { + _, err := fmt.Printf("%s: %s\n", addr, dcap) return err - } - - return nil + }) }, } @@ -228,7 +213,7 @@ var verifRegListClientsCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK) + act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK) if err != nil { return err } @@ -236,31 +221,14 @@ var verifRegListClientsCmd = &cli.Command{ apibs := apibstore.NewAPIBlockstore(api) store := adt.WrapStore(ctx, cbor.NewCborStore(apibs)) - var st verifreg.State - if err := store.Get(ctx, act.Head, &st); err != nil { - return err - } - - vh, err := adt.AsMap(store, st.VerifiedClients) + st, err := verifreg.Load(store, act) if err != nil { return err } - - var dcap verifreg.DataCap - if err := vh.ForEach(&dcap, func(k string) error { - addr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return err - } - - fmt.Printf("%s: %s\n", addr, dcap) - - return nil - }); err != nil { + return st.ForEachClient(func(addr address.Address, dcap abi.StoragePower) error { + _, err := fmt.Printf("%s: %s\n", addr, dcap) return err - } - - return nil + }) }, } @@ -318,28 +286,34 @@ var verifRegCheckVerifierCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK) + head, err := api.ChainHead(ctx) if err != nil { return err } - apibs := apibstore.NewAPIBlockstore(api) - store := adt.WrapStore(ctx, cbor.NewCborStore(apibs)) + vid, err := api.StateLookupID(ctx, vaddr, head.Key()) + if err != nil { + return err + } - var st verifreg.State - if err := store.Get(ctx, act.Head, &st); err != nil { + act, err := api.StateGetActor(ctx, verifreg.Address, head.Key()) + if err != nil { return err } - vh, err := adt.AsMap(store, st.Verifiers) + apibs := apibstore.NewAPIBlockstore(api) + store := adt.WrapStore(ctx, cbor.NewCborStore(apibs)) + + st, err := verifreg.Load(store, act) if err != nil { return err } - var dcap verifreg.DataCap - if found, err := vh.Get(abi.AddrKey(vaddr), &dcap); err != nil { + found, dcap, err := st.VerifierDataCap(vid) + if err != nil { return err - } else if !found { + } + if !found { return fmt.Errorf("not found") } From 3f0106cfe5ba375b3e2ddad07dba8d5bef976a9b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 15:18:30 -0700 Subject: [PATCH 085/104] migrate lotus-shed/genesis-verify to actor abstraction --- chain/actors/builtin/miner/miner.go | 9 ------ chain/types/actor.go | 12 ++++++-- cmd/lotus-shed/balances.go | 4 +-- cmd/lotus-shed/genesis-verify.go | 48 ++++++++++++++++------------- cmd/lotus-shed/mempool-stats.go | 7 +++-- 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 5f1c26013ed..c2b2e3a0d6a 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -18,15 +18,6 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -// Returns true if the specified actor code ID is a miner actor. -func Is(code cid.Cid) bool { - switch code { - case builtin0.StorageMinerActorCodeID: - return true - } - return false -} - func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case builtin0.StorageMinerActorCodeID: diff --git a/chain/types/actor.go b/chain/types/actor.go index bb56359951c..aa3ba214648 100644 --- a/chain/types/actor.go +++ b/chain/types/actor.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" ) var ErrActorNotFound = errors.New("actor not found") @@ -19,5 +19,13 @@ type Actor struct { } func (a *Actor) IsAccountActor() bool { - return a.Code == builtin.AccountActorCodeID + return a.Code == builtin0.AccountActorCodeID +} + +func (a *Actor) IsStorageMinerActor() bool { + return a.Code == builtin0.StorageMinerActorCodeID +} + +func (a *Actor) IsMultisigActor() bool { + return a.Code == builtin0.MultisigActorCodeID } diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index 413f863755f..de92aa8b654 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -89,7 +89,7 @@ var chainBalanceCmd = &cli.Command{ Type: string(act.Code.Hash()[2:]), } - if miner.Is(act.Code) { + if act.IsStorageMinerActor() { pow, err := api.StateMinerPower(ctx, addr, tsk) if err != nil { return xerrors.Errorf("failed to get power: %w", err) @@ -191,7 +191,7 @@ var chainBalanceStateCmd = &cli.Command{ PreCommits: types.FIL(big.NewInt(0)), } - if minerInfo && miner.Is(act.Code) { + if minerInfo && act.IsStorageMinerActor() { pow, _, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr) if err != nil { return xerrors.Errorf("failed to get power: %w", err) diff --git a/cmd/lotus-shed/genesis-verify.go b/cmd/lotus-shed/genesis-verify.go index 043cb72bb8b..1225d817a10 100644 --- a/cmd/lotus-shed/genesis-verify.go +++ b/cmd/lotus-shed/genesis-verify.go @@ -14,16 +14,17 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/account" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/blockstore" - "github.com/filecoin-project/specs-actors/actors/builtin" - saacc "github.com/filecoin-project/specs-actors/actors/builtin/account" - saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner" - samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" ) type addrInfo struct { @@ -90,36 +91,41 @@ var genesisVerifyCmd = &cli.Command{ kminers := make(map[address.Address]minerInfo) ctx := context.TODO() + store := adt.WrapStore(ctx, cst) if err := stree.ForEach(func(addr address.Address, act *types.Actor) error { - switch act.Code { - case builtin.StorageMinerActorCodeID: - var st saminer.State - if err := cst.Get(ctx, act.Head, &st); err != nil { - return err + switch { + case act.IsStorageMinerActor(): + _, err := miner.Load(store, act) + if err != nil { + return xerrors.Errorf("miner actor: %w", err) } - + // TODO: actually verify something here? kminers[addr] = minerInfo{} - case builtin.MultisigActorCodeID: - var st samsig.State - if err := cst.Get(ctx, act.Head, &st); err != nil { + case act.IsMultisigActor(): + st, err := multisig.Load(store, act) + if err != nil { return xerrors.Errorf("multisig actor: %w", err) } kmultisigs[addr] = msigInfo{ Balance: types.FIL(act.Balance), - Signers: st.Signers, - Threshold: st.NumApprovalsThreshold, + Signers: st.Signers(), + Threshold: st.Threshold(), } msigAddrs = append(msigAddrs, addr) - case builtin.AccountActorCodeID: - var st saacc.State - if err := cst.Get(ctx, act.Head, &st); err != nil { - log.Warn(xerrors.Errorf("account actor %s: %w", addr, err)) + case act.IsAccountActor(): + st, err := account.Load(store, act) + if err != nil { + // TODO: magik6k: this _used_ to log instead of failing, why? + return xerrors.Errorf("account actor %s: %w", addr, err) + } + pkaddr, err := st.PubkeyAddress() + if err != nil { + return xerrors.Errorf("failed to get actor pk address %s: %w", addr, err) } - kaccounts[addr] = addrInfo{ - Key: st.Address, + Key: pkaddr, Balance: types.FIL(act.Balance.Copy()), } accAddrs = append(accAddrs, addr) diff --git a/cmd/lotus-shed/mempool-stats.go b/cmd/lotus-shed/mempool-stats.go index b81cf2704e8..165c0143243 100644 --- a/cmd/lotus-shed/mempool-stats.go +++ b/cmd/lotus-shed/mempool-stats.go @@ -14,11 +14,12 @@ import ( "go.opencensus.io/stats/view" "go.opencensus.io/tag" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/go-address" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" - "github.com/filecoin-project/specs-actors/actors/builtin" ) var ( @@ -121,7 +122,7 @@ var mpoolStatsCmd = &cli.Command{ return false, err } - ism := act.Code == builtin.StorageMinerActorCodeID + ism := act.IsStorageMinerActor() mcache[addr] = ism return ism, nil } @@ -143,7 +144,7 @@ var mpoolStatsCmd = &cli.Command{ seen: time.Now(), } - if u.Message.Message.Method == builtin.MethodsMiner.SubmitWindowedPoSt { + if u.Message.Message.Method == builtin0.MethodsMiner.SubmitWindowedPoSt { miner, err := isMiner(u.Message.Message.To) if err != nil { From 63f026f7c3fb52f894ed80d6fef7bdd1f7de8650 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 15:24:45 -0700 Subject: [PATCH 086/104] migrate some more imports --- paychmgr/store.go | 15 ++++++++------- paychmgr/util.go | 11 ++++++----- storage/adapter_storage_miner.go | 7 ++++--- storage/miner.go | 6 +++--- storage/mockstorage/preseal.go | 5 +++-- storage/wdpost_run.go | 17 ++++++++--------- storage/wdpost_run_test.go | 13 ++++++------- 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/paychmgr/store.go b/paychmgr/store.go index 46249fa361c..23916669e5e 100644 --- a/paychmgr/store.go +++ b/paychmgr/store.go @@ -12,12 +12,13 @@ import ( "github.com/filecoin-project/lotus/chain/types" cborutil "github.com/filecoin-project/go-cbor-util" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" dsq "github.com/ipfs/go-datastore/query" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/go-address" cborrpc "github.com/filecoin-project/go-cbor-util" @@ -48,7 +49,7 @@ const ( ) type VoucherInfo struct { - Voucher *paych.SignedVoucher + Voucher *paych0.SignedVoucher Proof []byte Submitted bool } @@ -102,7 +103,7 @@ func (ci *ChannelInfo) to() address.Address { // infoForVoucher gets the VoucherInfo for the given voucher. // returns nil if the channel doesn't have the voucher. -func (ci *ChannelInfo) infoForVoucher(sv *paych.SignedVoucher) (*VoucherInfo, error) { +func (ci *ChannelInfo) infoForVoucher(sv *paych0.SignedVoucher) (*VoucherInfo, error) { for _, v := range ci.Vouchers { eq, err := cborutil.Equals(sv, v.Voucher) if err != nil { @@ -115,7 +116,7 @@ func (ci *ChannelInfo) infoForVoucher(sv *paych.SignedVoucher) (*VoucherInfo, er return nil, nil } -func (ci *ChannelInfo) hasVoucher(sv *paych.SignedVoucher) (bool, error) { +func (ci *ChannelInfo) hasVoucher(sv *paych0.SignedVoucher) (bool, error) { vi, err := ci.infoForVoucher(sv) return vi != nil, err } @@ -123,7 +124,7 @@ func (ci *ChannelInfo) hasVoucher(sv *paych.SignedVoucher) (bool, error) { // markVoucherSubmitted marks the voucher, and any vouchers of lower nonce // in the same lane, as being submitted. // Note: This method doesn't write anything to the store. -func (ci *ChannelInfo) markVoucherSubmitted(sv *paych.SignedVoucher) error { +func (ci *ChannelInfo) markVoucherSubmitted(sv *paych0.SignedVoucher) error { vi, err := ci.infoForVoucher(sv) if err != nil { return err @@ -147,7 +148,7 @@ func (ci *ChannelInfo) markVoucherSubmitted(sv *paych.SignedVoucher) error { } // wasVoucherSubmitted returns true if the voucher has been submitted -func (ci *ChannelInfo) wasVoucherSubmitted(sv *paych.SignedVoucher) (bool, error) { +func (ci *ChannelInfo) wasVoucherSubmitted(sv *paych0.SignedVoucher) (bool, error) { vi, err := ci.infoForVoucher(sv) if err != nil { return false, err @@ -276,7 +277,7 @@ func (ps *Store) VouchersForPaych(ch address.Address) ([]*VoucherInfo, error) { return ci.Vouchers, nil } -func (ps *Store) MarkVoucherSubmitted(ci *ChannelInfo, sv *paych.SignedVoucher) error { +func (ps *Store) MarkVoucherSubmitted(ci *ChannelInfo, sv *paych0.SignedVoucher) error { err := ci.markVoucherSubmitted(sv) if err != nil { return err diff --git a/paychmgr/util.go b/paychmgr/util.go index 0509f8a2431..2a8181c1548 100644 --- a/paychmgr/util.go +++ b/paychmgr/util.go @@ -4,21 +4,22 @@ import ( "context" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" ) type BestSpendableAPI interface { - PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error) - PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) + PaychVoucherList(context.Context, address.Address) ([]*paych0.SignedVoucher, error) + PaychVoucherCheckSpendable(context.Context, address.Address, *paych0.SignedVoucher, []byte, []byte) (bool, error) } -func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.Address) (map[uint64]*paych.SignedVoucher, error) { +func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.Address) (map[uint64]*paych0.SignedVoucher, error) { vouchers, err := api.PaychVoucherList(ctx, ch) if err != nil { return nil, err } - bestByLane := make(map[uint64]*paych.SignedVoucher) + bestByLane := make(map[uint64]*paych0.SignedVoucher) for _, voucher := range vouchers { spendable, err := api.PaychVoucherCheckSpendable(ctx, ch, voucher, nil, nil) if err != nil { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index db3ae63d9db..380fb44715c 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -14,7 +14,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/specs-actors/actors/builtin" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/api" @@ -146,10 +147,10 @@ func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr } ccmt := &types.Message{ - To: builtin.StorageMarketActorAddr, + To: market.Address, From: maddr, Value: types.NewInt(0), - Method: builtin.MethodsMarket.ComputeDataCommitment, + Method: builtin0.MethodsMarket.ComputeDataCommitment, Params: ccparams, } r, err := s.delegate.StateCall(ctx, ccmt, tsk) diff --git a/storage/miner.go b/storage/miner.go index a64ee977e74..c1b50fe89c2 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -6,13 +6,13 @@ import ( "time" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-bitfield" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" @@ -235,9 +235,9 @@ func (wpp *StorageWpp) GenerateCandidates(ctx context.Context, randomness abi.Po return cds, nil } -func (wpp *StorageWpp) ComputeProof(ctx context.Context, ssi []proof.SectorInfo, rand abi.PoStRandomness) ([]proof.PoStProof, error) { +func (wpp *StorageWpp) ComputeProof(ctx context.Context, ssi []proof0.SectorInfo, rand abi.PoStRandomness) ([]proof0.PoStProof, error) { if build.InsecurePoStValidation { - return []proof.PoStProof{{ProofBytes: []byte("valid proof")}}, nil + return []proof0.PoStProof{{ProofBytes: []byte("valid proof")}}, nil } log.Infof("Computing WinningPoSt ;%+v; %v", ssi, rand) diff --git a/storage/mockstorage/preseal.go b/storage/mockstorage/preseal.go index da063020dbd..8ca789ba603 100644 --- a/storage/mockstorage/preseal.go +++ b/storage/mockstorage/preseal.go @@ -9,7 +9,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/extern/sector-storage/mock" - "github.com/filecoin-project/specs-actors/actors/builtin/market" + + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" @@ -48,7 +49,7 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis r := mock.CommDR(d) preseal.CommR, _ = commcid.ReplicaCommitmentV1ToCID(r[:]) preseal.SectorID = abi.SectorNumber(i + 1) - preseal.Deal = market.DealProposal{ + preseal.Deal = market0.DealProposal{ PieceCID: preseal.CommD, PieceSize: abi.PaddedPieceSize(ssize), Client: k.Address, diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 254a2f0d339..9a497f87915 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -5,8 +5,6 @@ import ( "context" "time" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-address" @@ -14,20 +12,21 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/ipfs/go-cid" "go.opencensus.io/trace" "golang.org/x/xerrors" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/journal" - - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) func (s *WindowPoStScheduler) failPost(err error, deadline *dline.Info) { @@ -219,7 +218,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin msg := &types.Message{ To: s.actor, From: s.worker, - Method: builtin.MethodsMiner.DeclareFaultsRecovered, + Method: builtin0.MethodsMiner.DeclareFaultsRecovered, Params: enc, Value: types.NewInt(0), } @@ -298,7 +297,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, msg := &types.Message{ To: s.actor, From: s.worker, - Method: builtin.MethodsMiner.DeclareFaults, + Method: builtin0.MethodsMiner.DeclareFaults, Params: enc, Value: types.NewInt(0), // TODO: Is there a fee? } @@ -555,7 +554,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty func (s *WindowPoStScheduler) batchPartitions(partitions []api.Partition) ([][]api.Partition, error) { // Get the number of sectors allowed in a partition, for this proof size - sectorsPerPartition, err := builtin.PoStProofWindowPoStPartitionSectors(s.proofType) + sectorsPerPartition, err := builtin0.PoStProofWindowPoStPartitionSectors(s.proofType) if err != nil { return nil, xerrors.Errorf("getting sectors per partition: %w", err) } @@ -647,7 +646,7 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi msg := &types.Message{ To: s.actor, From: s.worker, - Method: builtin.MethodsMiner.SubmitWindowedPoSt, + Method: builtin0.MethodsMiner.SubmitWindowedPoSt, Params: enc, Value: types.NewInt(0), } diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index 1797cf35cf7..10be2fbcd90 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -16,10 +16,9 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/specs-actors/actors/builtin" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" tutils "github.com/filecoin-project/specs-actors/support/testing" "github.com/filecoin-project/lotus/api" @@ -97,12 +96,12 @@ func (m *mockStorageMinerAPI) StateWaitMsg(ctx context.Context, cid cid.Cid, con type mockProver struct { } -func (m *mockProver) GenerateWinningPoSt(context.Context, abi.ActorID, []proof.SectorInfo, abi.PoStRandomness) ([]proof.PoStProof, error) { +func (m *mockProver) GenerateWinningPoSt(context.Context, abi.ActorID, []proof0.SectorInfo, abi.PoStRandomness) ([]proof0.PoStProof, error) { panic("implement me") } -func (m *mockProver) GenerateWindowPoSt(ctx context.Context, aid abi.ActorID, sis []proof.SectorInfo, pr abi.PoStRandomness) ([]proof.PoStProof, []abi.SectorID, error) { - return []proof.PoStProof{ +func (m *mockProver) GenerateWindowPoSt(ctx context.Context, aid abi.ActorID, sis []proof0.SectorInfo, pr abi.PoStRandomness) ([]proof0.PoStProof, []abi.SectorID, error) { + return []proof0.PoStProof{ { PoStProof: abi.RegisteredPoStProof_StackedDrgWindow2KiBV1, ProofBytes: []byte("post-proof"), @@ -131,7 +130,7 @@ func TestWDPostDoPost(t *testing.T) { mockStgMinerAPI := newMockStorageMinerAPI() // Get the number of sectors allowed in a partition for this proof type - sectorsPerPartition, err := builtin.PoStProofWindowPoStPartitionSectors(proofType) + sectorsPerPartition, err := builtin0.PoStProofWindowPoStPartitionSectors(proofType) require.NoError(t, err) // Work out the number of partitions that can be included in a message // without exceeding the message sector limit @@ -183,7 +182,7 @@ func TestWDPostDoPost(t *testing.T) { // Read the window PoST messages for i := 0; i < expectedMsgCount; i++ { msg := <-mockStgMinerAPI.pushedMessages - require.Equal(t, builtin.MethodsMiner.SubmitWindowedPoSt, msg.Method) + require.Equal(t, builtin0.MethodsMiner.SubmitWindowedPoSt, msg.Method) var params miner.SubmitWindowedPoStParams err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)) require.NoError(t, err) From d33dd4f7bc9bc79b0c6e7957ab115c430d97bc79 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Sep 2020 16:01:29 -0700 Subject: [PATCH 087/104] more renames --- chain/types/actor.go | 4 +++ markets/storageadapter/provider.go | 26 ++++++++-------- miner/miner.go | 4 +-- node/impl/full/gas.go | 7 +++-- node/impl/full/multisig.go | 49 ++++++++++++++++-------------- node/impl/full/state.go | 10 +++--- node/impl/paych/paych.go | 21 +++++++------ paychmgr/settler/settler.go | 15 ++++----- paychmgr/simple.go | 6 ++-- 9 files changed, 77 insertions(+), 65 deletions(-) diff --git a/chain/types/actor.go b/chain/types/actor.go index aa3ba214648..eb8e05c4933 100644 --- a/chain/types/actor.go +++ b/chain/types/actor.go @@ -29,3 +29,7 @@ func (a *Actor) IsStorageMinerActor() bool { func (a *Actor) IsMultisigActor() bool { return a.Code == builtin0.MultisigActorCodeID } + +func (a *Actor) IsPaymentChannelActor() bool { + return a.Code == builtin0.PaymentChannelActorCodeID +} diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 04c1055df5a..9f610d76a05 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -8,25 +8,27 @@ import ( "io" "time" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-fil-markets/shared" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/events" + + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/types" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" @@ -67,8 +69,8 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark return cid.Undef, err } - params, err := actors.SerializeParams(&market.PublishStorageDealsParams{ - Deals: []market.ClientDealProposal{deal.ClientDealProposal}, + params, err := actors.SerializeParams(&market0.PublishStorageDealsParams{ + Deals: []market0.ClientDealProposal{deal.ClientDealProposal}, }) if err != nil { @@ -77,10 +79,10 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark // TODO: We may want this to happen after fetching data smsg, err := n.MpoolPushMessage(ctx, &types.Message{ - To: builtin.StorageMarketActorAddr, + To: market.Address, From: mi.Worker, Value: types.NewInt(0), - Method: builtin.MethodsMarket.PublishStorageDeals, + Method: builtin0.MethodsMarket.PublishStorageDeals, Params: params, }, nil) if err != nil { @@ -177,10 +179,10 @@ func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr, wallet addr func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error) { // (Provider Node API) smsg, err := n.MpoolPushMessage(ctx, &types.Message{ - To: builtin.StorageMarketActorAddr, + To: market.Address, From: addr, Value: amount, - Method: builtin.MethodsMarket.AddBalance, + Method: builtin0.MethodsMarket.AddBalance, }, nil) if err != nil { return cid.Undef, err @@ -302,7 +304,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide } switch msg.Method { - case builtin.MethodsMiner.PreCommitSector: + case builtin0.MethodsMiner.PreCommitSector: var params miner.SectorPreCommitInfo if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return true, false, xerrors.Errorf("unmarshal pre commit: %w", err) @@ -317,7 +319,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide } return true, false, nil - case builtin.MethodsMiner.ProveCommitSector: + case builtin0.MethodsMiner.ProveCommitSector: var params miner.ProveCommitSectorParams if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return true, false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err) diff --git a/miner/miner.go b/miner/miner.go index 2d859199271..5e8d8cf37af 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/lotus/chain/gen/slashfilter" @@ -489,7 +489,7 @@ func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, bas } func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *types.Ticket, - eproof *types.ElectionProof, bvals []types.BeaconEntry, wpostProof []proof.PoStProof, msgs []*types.SignedMessage) (*types.BlockMsg, error) { + eproof *types.ElectionProof, bvals []types.BeaconEntry, wpostProof []proof0.PoStProof, msgs []*types.SignedMessage) (*types.BlockMsg, error) { uts := base.TipSet.MinTimestamp() + build.BlockDelaySecs*(uint64(base.NullRounds)+1) nheight := base.TipSet.Height() + base.NullRounds + 1 diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index b207a1f6d1a..f03807c8031 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -13,7 +13,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/specs-actors/actors/builtin" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -181,10 +182,10 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, return res.MsgRct.GasUsed, nil } - if !act.Code.Equals(builtin.PaymentChannelActorCodeID) { + if !act.IsPaymentChannelActor() { return res.MsgRct.GasUsed, nil } - if msgIn.Method != builtin.MethodsPaych.Collect { + if msgIn.Method != builtin0.MethodsPaych.Collect { return res.MsgRct.GasUsed, nil } diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index 2322d5a1e53..8c15a27bea9 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -9,10 +9,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" - samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" + multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" "github.com/ipfs/go-cid" "github.com/minio/blake2b-simd" @@ -46,7 +48,7 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad } // Set up constructor parameters for multisig - msigParams := &samsig.ConstructorParams{ + msigParams := &multisig0.ConstructorParams{ Signers: addrs, NumApprovalsThreshold: req, UnlockDuration: duration, @@ -58,8 +60,9 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad } // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init_.ExecParams{ - CodeCID: builtin.MultisigActorCodeID, + // TODO: network upgrade? + execParams := &init0.ExecParams{ + CodeCID: builtin0.MultisigActorCodeID, ConstructorParams: enc, } @@ -70,9 +73,9 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad // now we create the message to send this with msg := types.Message{ - To: builtin.InitActorAddr, + To: init_.Address, From: src, - Method: builtin.MethodsInit.Exec, + Method: builtin0.MethodsInit.Exec, Params: enc, Value: val, } @@ -104,7 +107,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr return cid.Undef, xerrors.Errorf("must provide source address") } - enc, actErr := actors.SerializeParams(&samsig.ProposeParams{ + enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{ To: to, Value: amt, Method: abi.MethodNum(method), @@ -118,7 +121,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr To: msig, From: src, Value: types.NewInt(0), - Method: builtin.MethodsMultisig.Propose, + Method: builtin0.MethodsMultisig.Propose, Params: enc, } @@ -136,7 +139,7 @@ func (a *MsigAPI) MsigAddPropose(ctx context.Context, msig address.Address, src return cid.Undef, actErr } - return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc) + return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.AddSigner), enc) } func (a *MsigAPI) MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (cid.Cid, error) { @@ -145,7 +148,7 @@ func (a *MsigAPI) MsigAddApprove(ctx context.Context, msig address.Address, src return cid.Undef, actErr } - return a.MsigApprove(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc) + return a.MsigApprove(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.AddSigner), enc) } func (a *MsigAPI) MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (cid.Cid, error) { @@ -154,7 +157,7 @@ func (a *MsigAPI) MsigAddCancel(ctx context.Context, msig address.Address, src a return cid.Undef, actErr } - return a.MsigCancel(ctx, msig, txID, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.AddSigner), enc) + return a.MsigCancel(ctx, msig, txID, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.AddSigner), enc) } func (a *MsigAPI) MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) { @@ -163,7 +166,7 @@ func (a *MsigAPI) MsigSwapPropose(ctx context.Context, msig address.Address, src return cid.Undef, actErr } - return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.SwapSigner), enc) + return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.SwapSigner), enc) } func (a *MsigAPI) MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) { @@ -172,7 +175,7 @@ func (a *MsigAPI) MsigSwapApprove(ctx context.Context, msig address.Address, src return cid.Undef, actErr } - return a.MsigApprove(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.SwapSigner), enc) + return a.MsigApprove(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.SwapSigner), enc) } func (a *MsigAPI) MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (cid.Cid, error) { @@ -181,7 +184,7 @@ func (a *MsigAPI) MsigSwapCancel(ctx context.Context, msig address.Address, src return cid.Undef, actErr } - return a.MsigCancel(ctx, msig, txID, msig, big.Zero(), src, uint64(builtin.MethodsMultisig.SwapSigner), enc) + return a.MsigCancel(ctx, msig, txID, msig, big.Zero(), src, uint64(builtin0.MethodsMultisig.SwapSigner), enc) } func (a *MsigAPI) MsigApprove(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (cid.Cid, error) { @@ -217,7 +220,7 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro proposer = proposerID } - p := samsig.ProposalHashData{ + p := multisig0.ProposalHashData{ Requester: proposer, To: to, Value: amt, @@ -231,8 +234,8 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro } phash := blake2b.Sum256(pser) - enc, err := actors.SerializeParams(&samsig.TxnIDParams{ - ID: samsig.TxnID(txID), + enc, err := actors.SerializeParams(&multisig0.TxnIDParams{ + ID: multisig0.TxnID(txID), ProposalHash: phash[:], }) @@ -248,9 +251,9 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro */ switch operation { case api.MsigApprove: - msigResponseMethod = builtin.MethodsMultisig.Approve + msigResponseMethod = builtin0.MethodsMultisig.Approve case api.MsigCancel: - msigResponseMethod = builtin.MethodsMultisig.Cancel + msigResponseMethod = builtin0.MethodsMultisig.Cancel default: return cid.Undef, xerrors.Errorf("Invalid operation for msigApproveOrCancel") } @@ -272,7 +275,7 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro } func serializeAddParams(new address.Address, inc bool) ([]byte, error) { - enc, actErr := actors.SerializeParams(&samsig.AddSignerParams{ + enc, actErr := actors.SerializeParams(&multisig0.AddSignerParams{ Signer: new, Increase: inc, }) @@ -284,7 +287,7 @@ func serializeAddParams(new address.Address, inc bool) ([]byte, error) { } func serializeSwapParams(old address.Address, new address.Address) ([]byte, error) { - enc, actErr := actors.SerializeParams(&samsig.SwapSignerParams{ + enc, actErr := actors.SerializeParams(&multisig0.SwapSignerParams{ From: old, To: new, }) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index df747ba3fe5..0b2d86718eb 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -7,7 +7,9 @@ import ( builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" @@ -24,8 +26,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - "github.com/filecoin-project/specs-actors/actors/builtin" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -1025,7 +1025,7 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address // Returns zero if there is no entry in the data cap table for the // address. func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) { - act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) + act, err := a.StateGetActor(ctx, builtin0.VerifiedRegistryActorAddr, tsk) if err != nil { return nil, err } @@ -1063,12 +1063,12 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } - pact, err := a.StateGetActor(ctx, builtin.StoragePowerActorAddr, tsk) + pact, err := a.StateGetActor(ctx, builtin0.StoragePowerActorAddr, tsk) if err != nil { return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor: %w", err) } - ract, err := a.StateGetActor(ctx, builtin.RewardActorAddr, tsk) + ract, err := a.StateGetActor(ctx, builtin0.RewardActorAddr, tsk) if err != nil { return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor: %w", err) } diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 94fcc320d8e..b2e6be0ca26 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -9,7 +9,8 @@ import ( "go.uber.org/fx" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" @@ -70,10 +71,10 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address return nil, err } - svs := make([]*paych.SignedVoucher, len(vouchers)) + svs := make([]*paych0.SignedVoucher, len(vouchers)) for i, v := range vouchers { - sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych.SignedVoucher{ + sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych0.SignedVoucher{ Amount: v.Amount, Lane: lane, @@ -122,15 +123,15 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid. return a.PaychMgr.Collect(ctx, addr) } -func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { +func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher) error { return a.PaychMgr.CheckVoucherValid(ctx, ch, sv) } -func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (bool, error) { return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret, proof) } -func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { return a.PaychMgr.AddVoucherInbound(ctx, ch, sv, proof, minDelta) } @@ -142,16 +143,16 @@ func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv * // If there are insufficient funds in the channel to create the voucher, // returns a nil voucher and the shortfall. func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*api.VoucherCreateResult, error) { - return a.PaychMgr.CreateVoucher(ctx, pch, paych.SignedVoucher{Amount: amt, Lane: lane}) + return a.PaychMgr.CreateVoucher(ctx, pch, paych0.SignedVoucher{Amount: amt, Lane: lane}) } -func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) { +func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych0.SignedVoucher, error) { vi, err := a.PaychMgr.ListVouchers(ctx, pch) if err != nil { return nil, err } - out := make([]*paych.SignedVoucher, len(vi)) + out := make([]*paych0.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -159,6 +160,6 @@ func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([ return out, nil } -func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret, proof) } diff --git a/paychmgr/settler/settler.go b/paychmgr/settler/settler.go index 45f24cdd988..654ed66cc23 100644 --- a/paychmgr/settler/settler.go +++ b/paychmgr/settler/settler.go @@ -13,8 +13,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -38,9 +39,9 @@ type API struct { type settlerAPI interface { PaychList(context.Context) ([]address.Address, error) PaychStatus(context.Context, address.Address) (*api.PaychStatus, error) - PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) - PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error) - PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (cid.Cid, error) + PaychVoucherCheckSpendable(context.Context, address.Address, *paych0.SignedVoucher, []byte, []byte) (bool, error) + PaychVoucherList(context.Context, address.Address) ([]*paych0.SignedVoucher, error) + PaychVoucherSubmit(context.Context, address.Address, *paych0.SignedVoucher, []byte, []byte) (cid.Cid, error) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error) } @@ -85,7 +86,7 @@ func (pcs *paymentChannelSettler) messageHandler(msg *types.Message, rec *types. if err != nil { return true, err } - go func(voucher *paych.SignedVoucher, submitMessageCID cid.Cid) { + go func(voucher *paych0.SignedVoucher, submitMessageCID cid.Cid) { defer wg.Done() msgLookup, err := pcs.api.StateWaitMsg(pcs.ctx, submitMessageCID, build.MessageConfidence) if err != nil { @@ -106,7 +107,7 @@ func (pcs *paymentChannelSettler) revertHandler(ctx context.Context, ts *types.T func (pcs *paymentChannelSettler) matcher(msg *types.Message) (matchOnce bool, matched bool, err error) { // Check if this is a settle payment channel message - if msg.Method != builtin.MethodsPaych.Settle { + if msg.Method != builtin0.MethodsPaych.Settle { return false, false, nil } // Check if this payment channel is of concern to this node (i.e. tracked in payment channel store), diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 46bbea62e6f..815b8acabb7 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" + init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/api" @@ -387,7 +387,7 @@ func (ca *channelAccessor) createPaych(ctx context.Context, amt types.BigInt) (c return cid.Undef, aerr } - enc, aerr := actors.SerializeParams(&init_.ExecParams{ + enc, aerr := actors.SerializeParams(&init0.ExecParams{ CodeCID: builtin.PaymentChannelActorCodeID, ConstructorParams: params, }) @@ -452,7 +452,7 @@ func (ca *channelAccessor) waitPaychCreateMsg(channelID string, mcid cid.Cid) er return err } - var decodedReturn init_.ExecReturn + var decodedReturn init0.ExecReturn err = decodedReturn.UnmarshalCBOR(bytes.NewReader(mwait.Receipt.Return)) if err != nil { log.Error(err) From d56da1b014b24c6d163f60546c51462ab968f383 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 22 Sep 2020 00:12:07 -0400 Subject: [PATCH 088/104] Refinements to stmgr and utils --- chain/actors/builtin/builtin.go | 8 +++ chain/actors/builtin/reward/reward.go | 3 ++ chain/stmgr/stmgr.go | 75 ++++++++++++--------------- chain/stmgr/utils.go | 15 ++---- node/impl/full/state.go | 19 +++---- 5 files changed, 56 insertions(+), 64 deletions(-) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 9ad97656442..3230705dd4d 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -3,6 +3,9 @@ package builtin import ( "fmt" + "github.com/filecoin-project/go-state-types/abi" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" "github.com/filecoin-project/go-state-types/network" @@ -30,3 +33,8 @@ type FilterEstimate = smoothing0.FilterEstimate func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { return (FilterEstimate)(v0) } + +// Doesn't change between actors v0 and v1 +func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { + return miner0.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) +} diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 3f887914d11..a4f936d9bff 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -2,6 +2,7 @@ package reward import ( "github.com/filecoin-project/go-state-types/abi" + reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" @@ -45,3 +46,5 @@ type State interface { InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error) PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error) } + +type AwardBlockRewardParams = reward0.AwardBlockRewardParams diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index e6e55793088..2f8d460aaca 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -22,8 +22,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/specs-actors/actors/builtin" - reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" @@ -169,20 +168,20 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp runCron := func() error { // TODO: this nonce-getting is a tiny bit ugly - ca, err := vmi.StateTree().GetActor(builtin.SystemActorAddr) + ca, err := vmi.StateTree().GetActor(builtin0.SystemActorAddr) if err != nil { return err } cronMsg := &types.Message{ - To: builtin.CronActorAddr, - From: builtin.SystemActorAddr, + To: builtin0.CronActorAddr, + From: builtin0.SystemActorAddr, Nonce: ca.Nonce, Value: types.NewInt(0), GasFeeCap: types.NewInt(0), GasPremium: types.NewInt(0), GasLimit: build.BlockGasLimit * 10000, // Make super sure this is never too little - Method: builtin.MethodsCron.EpochTick, + Method: builtin0.MethodsCron.EpochTick, Params: nil, } ret, err := vmi.ApplyImplicitMessage(ctx, cronMsg) @@ -247,42 +246,34 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp processedMsgs[m.Cid()] = true } - var params []byte - - nv := sm.GetNtwkVersion(ctx, epoch) - if nv < build.ActorUpgradeNetworkVersion { - params, err = actors.SerializeParams(&reward0.AwardBlockRewardParams{ - Miner: b.Miner, - Penalty: penalty, - GasReward: gasReward, - WinCount: b.WinCount, - }) - if err != nil { - return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err) - } - } else { - // TODO: ActorUpgrade - params = nil + params, err := actors.SerializeParams(&reward.AwardBlockRewardParams{ + Miner: b.Miner, + Penalty: penalty, + GasReward: gasReward, + WinCount: b.WinCount, + }) + if err != nil { + return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err) } - sysAct, err := vmi.StateTree().GetActor(builtin.SystemActorAddr) - if err != nil { + sysAct, actErr := vmi.StateTree().GetActor(builtin0.SystemActorAddr) + if actErr != nil { return cid.Undef, cid.Undef, xerrors.Errorf("failed to get system actor: %w", err) } rwMsg := &types.Message{ - From: builtin.SystemActorAddr, - To: builtin.RewardActorAddr, + From: builtin0.SystemActorAddr, + To: reward.Address, Nonce: sysAct.Nonce, Value: types.NewInt(0), GasFeeCap: types.NewInt(0), GasPremium: types.NewInt(0), GasLimit: 1 << 30, - Method: builtin.MethodsReward.AwardBlockReward, + Method: builtin0.MethodsReward.AwardBlockReward, Params: params, } - ret, err := vmi.ApplyImplicitMessage(ctx, rwMsg) - if err != nil { + ret, actErr := vmi.ApplyImplicitMessage(ctx, rwMsg) + if actErr != nil { return cid.Undef, cid.Undef, xerrors.Errorf("failed to apply reward message for miner %s: %w", b.Miner, err) } if cb != nil { @@ -725,7 +716,7 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, return api.MarketBalance{}, err } - act, err := st.GetActor(builtin.StorageMarketActorAddr) + act, err := st.GetActor(market.Address) if err != nil { return api.MarketBalance{}, err } @@ -853,7 +844,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount) var act types.Actor err = r.ForEach(&act, func(k string) error { - if act.Code == builtin.MultisigActorCodeID { + if act.Code == builtin0.MultisigActorCodeID { var s multisig.State err := sm.cs.Store(ctx).Get(ctx, act.Head, &s) if err != nil { @@ -871,7 +862,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { totalsByEpoch[s.UnlockDuration()] = s.InitialBalance() } - } else if act.Code == builtin.AccountActorCodeID { + } else if act.Code == builtin0.AccountActorCodeID { // should exclude burnt funds actor and "remainder account actor" // should only ever be "faucet" accounts in testnets kaddr, err := address.NewFromBytes([]byte(k)) @@ -879,7 +870,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return xerrors.Errorf("decoding address: %w", err) } - if kaddr != builtin.BurntFundsActorAddr { + if kaddr != builtin0.BurntFundsActorAddr { kid, err := sTree.LookupID(kaddr) if err != nil { return xerrors.Errorf("resolving address: %w", err) @@ -954,24 +945,24 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error { totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount) // 6 months - sixMonths := abi.ChainEpoch(183 * builtin.EpochsInDay) + sixMonths := abi.ChainEpoch(183 * builtin0.EpochsInDay) totalsByEpoch[sixMonths] = big.NewInt(49_929_341) totalsByEpoch[sixMonths] = big.Add(totalsByEpoch[sixMonths], big.NewInt(32_787_700)) // 1 year - oneYear := abi.ChainEpoch(365 * builtin.EpochsInDay) + oneYear := abi.ChainEpoch(365 * builtin0.EpochsInDay) totalsByEpoch[oneYear] = big.NewInt(22_421_712) // 2 years - twoYears := abi.ChainEpoch(2 * 365 * builtin.EpochsInDay) + twoYears := abi.ChainEpoch(2 * 365 * builtin0.EpochsInDay) totalsByEpoch[twoYears] = big.NewInt(7_223_364) // 3 years - threeYears := abi.ChainEpoch(3 * 365 * builtin.EpochsInDay) + threeYears := abi.ChainEpoch(3 * 365 * builtin0.EpochsInDay) totalsByEpoch[threeYears] = big.NewInt(87_637_883) // 6 years - sixYears := abi.ChainEpoch(6 * 365 * builtin.EpochsInDay) + sixYears := abi.ChainEpoch(6 * 365 * builtin0.EpochsInDay) totalsByEpoch[sixYears] = big.NewInt(100_000_000) totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000)) @@ -1020,7 +1011,7 @@ func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch, } func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { - ractor, err := st.GetActor(builtin.RewardActorAddr) + ractor, err := st.GetActor(reward.Address) if err != nil { return big.Zero(), xerrors.Errorf("failed to load reward actor state: %w", err) } @@ -1034,7 +1025,7 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err } func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { - act, err := st.GetActor(builtin.StorageMarketActorAddr) + act, err := st.GetActor(market.Address) if err != nil { return big.Zero(), xerrors.Errorf("failed to load market actor: %w", err) } @@ -1048,7 +1039,7 @@ func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmou } func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { - pactor, err := st.GetActor(builtin.StoragePowerActorAddr) + pactor, err := st.GetActor(power.Address) if err != nil { return big.Zero(), xerrors.Errorf("failed to load power actor: %w", err) } @@ -1077,7 +1068,7 @@ func (sm *StateManager) GetFilLocked(ctx context.Context, st *state.StateTree) ( } func GetFilBurnt(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { - burnt, err := st.GetActor(builtin.BurntFundsActorAddr) + burnt, err := st.GetActor(builtin0.BurntFundsActorAddr) if err != nil { return big.Zero(), xerrors.Errorf("failed to load burnt actor: %w", err) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 1e670dacee8..c9e8d32da6b 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -88,8 +88,7 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add } func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, bool, error) { - // TODO: ActorUpgrade - act, err := sm.LoadActorRaw(ctx, builtin0.StoragePowerActorAddr, st) + act, err := sm.LoadActorRaw(ctx, power.Address, st) if err != nil { return power.Claim{}, power.Claim{}, false, xerrors.Errorf("(get sset) failed to load power actor state: %w", err) } @@ -281,8 +280,7 @@ func StateMinerInfo(ctx context.Context, sm *StateManager, ts *types.TipSet, mad } func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) { - // TODO: ActorUpgrade - act, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) + act, err := sm.LoadActor(ctx, power.Address, ts) if err != nil { return false, xerrors.Errorf("failed to load power actor: %w", err) } @@ -305,8 +303,7 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma } func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) { - // TODO: ActorUpgrade - act, err := sm.LoadActor(ctx, builtin0.StorageMarketActorAddr, ts) + act, err := sm.LoadActor(ctx, market.Address, ts) if err != nil { return nil, xerrors.Errorf("failed to load market actor: %w", err) } @@ -350,8 +347,7 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts } func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([]address.Address, error) { - // TODO: ActorUpgrade - act, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) + act, err := sm.LoadActor(ctx, power.Address, ts) if err != nil { return nil, xerrors.Errorf("failed to load power actor: %w", err) } @@ -630,8 +626,7 @@ func GetReturnType(ctx context.Context, sm *StateManager, to address.Address, me } func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Address, ts *types.TipSet) (bool, error) { - // TODO: ActorUpgrade - pact, err := sm.LoadActor(ctx, builtin0.StoragePowerActorAddr, ts) + pact, err := sm.LoadActor(ctx, power.Address, ts) if err != nil { return false, xerrors.Errorf("loading power actor state: %w", err) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 0b2d86718eb..109a265ea00 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -5,11 +5,10 @@ import ( "context" "strconv" - builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin" + lotusbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" @@ -871,7 +870,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr var sectorWeight abi.StoragePower if act, err := state.GetActor(market.Address); err != nil { - return types.EmptyInt, xerrors.Errorf("loading miner actor %s: %w", maddr, err) + return types.EmptyInt, xerrors.Errorf("loading market actor %s: %w", maddr, err) } else if s, err := market.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading market actor state %s: %w", maddr, err) } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { @@ -879,14 +878,12 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr } else { // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() - - // TODO: ActorUpgrade - sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) + sectorWeight = lotusbuiltin.QAPowerForWeight(ssize, duration, w, vw) } - var powerSmoothed builtin2.FilterEstimate + var powerSmoothed lotusbuiltin.FilterEstimate if act, err := state.GetActor(power.Address); err != nil { - return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) + return types.EmptyInt, xerrors.Errorf("loading power actor: %w", err) } else if s, err := power.Load(store, act); err != nil { return types.EmptyInt, xerrors.Errorf("loading power actor state: %w", err) } else if p, err := s.TotalPowerSmoothed(); err != nil { @@ -942,13 +939,11 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr } else { // NB: not exactly accurate, but should always lead us to *over* estimate, not under duration := pci.Expiration - ts.Height() - - // TODO: ActorUpgrade - sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw) + sectorWeight = lotusbuiltin.QAPowerForWeight(ssize, duration, w, vw) } var ( - powerSmoothed builtin2.FilterEstimate + powerSmoothed lotusbuiltin.FilterEstimate pledgeCollateral abi.TokenAmount ) if act, err := state.GetActor(power.Address); err != nil { From 1dc69e397e66a0c622d5e2b0bc865c5e25241206 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 22 Sep 2020 00:35:15 -0400 Subject: [PATCH 089/104] Resolve some unnecessary actor upgrade TODOs --- chain/actors/builtin/miner/miner.go | 6 ++++ cmd/lotus-pcr/main.go | 19 +++--------- extern/storage-sealing/checks.go | 13 +++----- extern/storage-sealing/precommit_policy.go | 21 +++---------- extern/storage-sealing/sealing.go | 17 ---------- extern/storage-sealing/states_sealing.go | 36 ++++++---------------- 6 files changed, 28 insertions(+), 84 deletions(-) diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index c2b2e3a0d6a..dbb4ddd73c9 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -18,6 +18,12 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +// Unchanged between v0 and v1 actors +var PreCommitChallengeDelay = miner0.PreCommitChallengeDelay +var WPoStProvingPeriod = miner0.WPoStProvingPeriod + +const MinSectorExpiration = miner0.MinSectorExpiration + func Load(store adt.Store, act *types.Actor) (st State, err error) { switch act.Code { case builtin0.StorageMinerActorCodeID: diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index c8179d9b659..fed42427c40 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -396,24 +396,13 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu var sn abi.SectorNumber - nv, err := r.api.StateNetworkVersion(ctx, tipset.Key()) - if err != nil { - log.Warnw("failed to get network version") + var proveCommitSector miner0.ProveCommitSectorParams + if err := proveCommitSector.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { + log.Warnw("failed to decode provecommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) continue } - if nv < build.ActorUpgradeNetworkVersion { - var proveCommitSector miner0.ProveCommitSectorParams - if err := proveCommitSector.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { - log.Warnw("failed to decode provecommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) - continue - } - - sn = proveCommitSector.SectorNumber - } else { - // TODO: ActorUpgrade - sn = 0 - } + sn = proveCommitSector.SectorNumber // We use the parent tipset key because precommit information is removed when ProveCommitSector is executed precommitChainInfo, err := r.api.StateSectorPreCommitInfo(ctx, m.To, sn, tipset.Parents()) diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index 27b62f49a71..3d9aedeb400 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -4,6 +4,8 @@ import ( "bytes" "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/build" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -104,7 +106,7 @@ func checkPrecommit(ctx context.Context, maddr address.Address, si SectorInfo, t if nv < build.ActorUpgradeNetworkVersion { msd = miner0.MaxSealDuration[si.SectorType] } else { - // TODO: ActorUpgrade + // TODO: ActorUpgrade(use MaxProveCommitDuration) msd = 0 } @@ -154,13 +156,8 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte, return &ErrNoPrecommit{xerrors.Errorf("precommit info not found on-chain")} } - pccd, err := m.getPreCommitChallengeDelay(ctx, tok) - if err != nil { - return xerrors.Errorf("failed to get precommit challenge delay: %w", err) - } - - if pci.PreCommitEpoch+pccd != si.SeedEpoch { - return &ErrBadSeed{xerrors.Errorf("seed epoch doesn't match on chain info: %d != %d", pci.PreCommitEpoch+pccd, si.SeedEpoch)} + if pci.PreCommitEpoch+miner.PreCommitChallengeDelay != si.SeedEpoch { + return &ErrBadSeed{xerrors.Errorf("seed epoch doesn't match on chain info: %d != %d", pci.PreCommitEpoch+miner.PreCommitChallengeDelay, si.SeedEpoch)} } buf := new(bytes.Buffer) diff --git a/extern/storage-sealing/precommit_policy.go b/extern/storage-sealing/precommit_policy.go index 2ee6c1afc2e..0b774b56ff7 100644 --- a/extern/storage-sealing/precommit_policy.go +++ b/extern/storage-sealing/precommit_policy.go @@ -3,11 +3,11 @@ package sealing import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/go-state-types/abi" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) type PreCommitPolicy interface { @@ -52,7 +52,7 @@ func NewBasicPreCommitPolicy(api Chain, duration abi.ChainEpoch, provingBoundary // Expiration produces the pre-commit sector expiration epoch for an encoded // replica containing the provided enumeration of pieces and deals. func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error) { - tok, epoch, err := p.api.ChainHead(ctx) + _, epoch, err := p.api.ChainHead(ctx) if err != nil { return 0, err } @@ -80,20 +80,7 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi end = &tmp } - nv, err := p.api.StateNetworkVersion(ctx, tok) - if err != nil { - return 0, err - } - - var wpp abi.ChainEpoch - if nv < build.ActorUpgradeNetworkVersion { - wpp = miner0.WPoStProvingPeriod - } else { - // TODO: ActorUpgrade - wpp = 0 - } - - *end += wpp - (*end % wpp) + p.provingBoundary - 1 + *end += miner.WPoStProvingPeriod - (*end % miner.WPoStProvingPeriod) + p.provingBoundary - 1 return *end, nil } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index d5772e1d618..1ba53661a6e 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -8,9 +8,6 @@ import ( "sync" "time" - "github.com/filecoin-project/lotus/build" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" @@ -422,17 +419,3 @@ func getDealPerSectorLimit(size abi.SectorSize) uint64 { } return 512 } - -func (m *Sealing) getPreCommitChallengeDelay(ctx context.Context, tok TipSetToken) (abi.ChainEpoch, error) { - nv, err := m.api.StateNetworkVersion(ctx, tok) - if err != nil { - return -1, xerrors.Errorf("failed to get network version: %w", err) - } - - if nv < build.ActorUpgradeNetworkVersion { - return miner0.PreCommitChallengeDelay, nil - } - - // TODO: ActorUpgrade - return -1, nil -} diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 0109326fb1c..4433651600d 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -189,17 +189,14 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf } var msd abi.ChainEpoch - var mse abi.ChainEpoch if nv < build.ActorUpgradeNetworkVersion { msd = miner0.MaxSealDuration[sector.SectorType] - mse = miner0.MinSectorExpiration } else { - // TODO: ActorUpgrade + // TODO: ActorUpgrade(use MaxProveCommitDuration) msd = 0 - mse = 0 } - if minExpiration := height + msd + mse + 10; expiration < minExpiration { + if minExpiration := height + msd + miner.MinSectorExpiration + 10; expiration < minExpiration { expiration = minExpiration } // TODO: enforce a reasonable _maximum_ sector lifetime? @@ -284,12 +281,7 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er return ctx.Send(SectorChainPreCommitFailed{error: xerrors.Errorf("precommit info not found on chain")}) } - pccd, err := m.getPreCommitChallengeDelay(ctx.Context(), tok) - if err != nil { - return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("failed to get precommit challenge delay: %w", err)}) - } - - randHeight := pci.PreCommitEpoch + pccd + randHeight := pci.PreCommitEpoch + miner.PreCommitChallengeDelay err = m.events.ChainAt(func(ectx context.Context, _ TipSetToken, curH abi.ChainEpoch) error { // in case of null blocks the randomness can land after the tipset we @@ -380,24 +372,14 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo return ctx.Send(SectorCommitFailed{xerrors.Errorf("commit check error: %w", err)}) } - nv, err := m.api.StateNetworkVersion(ctx.Context(), tok) - if err != nil { - return ctx.Send(SectorCommitFailed{xerrors.Errorf("failed to get network version: %w", err)}) - } - enc := new(bytes.Buffer) - if nv < build.ActorUpgradeNetworkVersion { - params := &miner0.ProveCommitSectorParams{ - SectorNumber: sector.SectorNumber, - Proof: sector.Proof, - } + params := &miner.ProveCommitSectorParams{ + SectorNumber: sector.SectorNumber, + Proof: sector.Proof, + } - if err := params.MarshalCBOR(enc); err != nil { - return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)}) - } - } else { - // TODO: ActorUpgrade - enc = nil + if err := params.MarshalCBOR(enc); err != nil { + return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", err)}) } waddr, err := m.api.StateMinerWorkerAddress(ctx.Context(), m.maddr, tok) From fc15888697effe357f177d00c35f07fc7666330f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 10:52:23 -0700 Subject: [PATCH 090/104] fixup some imports --- markets/storageadapter/client.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 781715903e5..fabc5b19786 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -6,9 +6,9 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/go-state-types/big" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "golang.org/x/xerrors" @@ -20,6 +20,7 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/market" @@ -29,8 +30,6 @@ import ( "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" - "github.com/filecoin-project/specs-actors/actors/builtin" - samarket "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/ipfs/go-cid" ) @@ -102,10 +101,10 @@ func (c *ClientNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Sign func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error) { // (Provider Node API) smsg, err := c.MpoolPushMessage(ctx, &types.Message{ - To: builtin.StorageMarketActorAddr, + To: miner0.StorageMarketActorAddr, From: addr, Value: amount, - Method: builtin.MethodsMarket.AddBalance, + Method: miner0.MethodsMarket.AddBalance, }, nil) if err != nil { return cid.Undef, err @@ -156,15 +155,15 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor return 0, xerrors.Errorf("deal wasn't published by storage provider: from=%s, provider=%s", pubmsg.From, deal.Proposal.Provider) } - if pubmsg.To != builtin.StorageMarketActorAddr { + if pubmsg.To != miner0.StorageMarketActorAddr { return 0, xerrors.Errorf("deal publish message wasn't set to StorageMarket actor (to=%s)", pubmsg.To) } - if pubmsg.Method != builtin.MethodsMarket.PublishStorageDeals { + if pubmsg.Method != miner0.MethodsMarket.PublishStorageDeals { return 0, xerrors.Errorf("deal publish message called incorrect method (method=%s)", pubmsg.Method) } - var params samarket.PublishStorageDealsParams + var params market0.PublishStorageDealsParams if err := params.UnmarshalCBOR(bytes.NewReader(pubmsg.Params)); err != nil { return 0, err } @@ -196,7 +195,7 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor return 0, xerrors.Errorf("deal publish failed: exit=%d", ret.ExitCode) } - var res samarket.PublishStorageDealsReturn + var res market0.PublishStorageDealsReturn if err := res.UnmarshalCBOR(bytes.NewReader(ret.Return)); err != nil { return 0, err } @@ -274,7 +273,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider } switch msg.Method { - case builtin.MethodsMiner.PreCommitSector: + case miner0.MethodsMiner.PreCommitSector: var params miner.SectorPreCommitInfo if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return true, false, xerrors.Errorf("unmarshal pre commit: %w", err) @@ -289,7 +288,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider } return true, false, nil - case builtin.MethodsMiner.ProveCommitSector: + case miner0.MethodsMiner.ProveCommitSector: var params miner.ProveCommitSectorParams if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return true, false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err) @@ -411,7 +410,7 @@ func (c *ClientNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID a return nil } -func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal samarket.DealProposal) (*samarket.ClientDealProposal, error) { +func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal market0.DealProposal) (*market0.ClientDealProposal, error) { // TODO: output spec signed proposal buf, err := cborutil.Dump(&proposal) if err != nil { @@ -428,7 +427,7 @@ func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Add return nil, err } - return &samarket.ClientDealProposal{ + return &market0.ClientDealProposal{ Proposal: proposal, ClientSignature: *sig, }, nil From 5314ba8c6d1008ae2ea10aa4017c9a88a4ab4144 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 10:55:29 -0700 Subject: [PATCH 091/104] remove ptr indirection --- chain/events/state/predicates.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 56dfb981d37..909533d1501 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -303,7 +303,7 @@ func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorSta if err != nil { return false, nil, err } - return diffInitActorState(ctx, &oldState, &newState) + return diffInitActorState(ctx, oldState, newState) }) } @@ -405,7 +405,7 @@ type AddressChange struct { To AddressPair } -type DiffInitActorStateFunc func(ctx context.Context, oldState *init_.State, newState *init_.State) (changed bool, user UserData, err error) +type DiffInitActorStateFunc func(ctx context.Context, oldState init_.State, newState init_.State) (changed bool, user UserData, err error) func (i *InitActorAddressChanges) AsKey(key string) (abi.Keyer, error) { addr, err := address.NewFromBytes([]byte(key)) @@ -493,7 +493,7 @@ func (i *InitActorAddressChanges) Remove(key string, val *typegen.Deferred) erro } func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { - return func(ctx context.Context, oldState, newState *init_.State) (changed bool, user UserData, err error) { + return func(ctx context.Context, oldState, newState init_.State) (changed bool, user UserData, err error) { /*ctxStore := &contextStore{ ctx: ctx, cst: sp.cst, From ab070f2ebee287e6cddf9b43bc2abac77e9eeb9b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 11:09:41 -0700 Subject: [PATCH 092/104] copy actor object when iterating over actors This is a pretty big footgun. --- chain/state/statetree.go | 1 + 1 file changed, 1 insertion(+) diff --git a/chain/state/statetree.go b/chain/state/statetree.go index fb6a14a9b09..a654d224bb0 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -385,6 +385,7 @@ func (st *StateTree) MutateActor(addr address.Address, f func(*types.Actor) erro func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error { var act types.Actor return st.root.ForEach(&act, func(k string) error { + act := act // copy addr, err := address.NewFromBytes([]byte(k)) if err != nil { return xerrors.Errorf("invalid address (%x) found in state tree key: %w", []byte(k), err) From bc24fdbd14bde171f59f61d6f0061cbc1955b9d0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 11:09:56 -0700 Subject: [PATCH 093/104] finish migrating statemanager --- chain/actors/adt/adt.go | 8 ++++++ chain/stmgr/stmgr.go | 64 +++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index fd5ee3f875c..39dd5cebc36 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -55,3 +55,11 @@ func AsArray(store Store, root cid.Cid, version network.Version) (Array, error) } return nil, xerrors.Errorf("unknown network version: %d", version) } + +func NewArray(store Store, version builtin.Version) (Array, error) { + switch version { + case builtin.Version0: + return adt0.MakeEmptyArray(store), nil + } + return nil, xerrors.Errorf("unknown network version: %d", version) +} diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 2f8d460aaca..af729143c6b 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,12 +5,9 @@ import ( "fmt" "sync" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/actors/builtin/reward" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log/v2" @@ -22,15 +19,17 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/actors/builtin/power" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -291,7 +290,11 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp return cid.Cid{}, cid.Cid{}, err } - rectarr := adt.MakeEmptyArray(sm.cs.Store(ctx)) + // XXX: Is the height correct? Or should it be epoch-1? + rectarr, err := adt.NewArray(sm.cs.Store(ctx), builtin.VersionForNetwork(sm.GetNtwkVersion(ctx, epoch))) + if err != nil { + return cid.Undef, cid.Undef, xerrors.Errorf("failed to create receipts amt: %w", err) + } for i, receipt := range receipts { if err := rectarr.Set(uint64(i), receipt); err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("failed to build receipts amt: %w", err) @@ -689,17 +692,13 @@ func (sm *StateManager) ListAllActors(ctx context.Context, ts *types.TipSet) ([] return nil, err } - r, err := adt.AsMap(sm.cs.Store(ctx), st) + stateTree, err := sm.StateTree(st) if err != nil { return nil, err } var out []address.Address - err = r.ForEach(nil, func(k string) error { - addr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return xerrors.Errorf("address in state tree was not valid: %w", err) - } + err = stateTree.ForEach(func(addr address.Address, act *types.Actor) error { out = append(out, addr) return nil }) @@ -836,17 +835,10 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return xerrors.Errorf("setting up genesis pledge: %w", err) } - r, err := adt.AsMap(sm.cs.Store(ctx), st) - if err != nil { - return xerrors.Errorf("getting genesis actors: %w", err) - } - totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount) - var act types.Actor - err = r.ForEach(&act, func(k string) error { - if act.Code == builtin0.MultisigActorCodeID { - var s multisig.State - err := sm.cs.Store(ctx).Get(ctx, act.Head, &s) + err = sTree.ForEach(func(kaddr address.Address, act *types.Actor) error { + if act.IsMultisigActor() { + s, err := multisig.Load(sm.cs.Store(ctx), act) if err != nil { return err } @@ -862,25 +854,22 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { totalsByEpoch[s.UnlockDuration()] = s.InitialBalance() } - } else if act.Code == builtin0.AccountActorCodeID { + } else if act.IsAccountActor() { // should exclude burnt funds actor and "remainder account actor" // should only ever be "faucet" accounts in testnets - kaddr, err := address.NewFromBytes([]byte(k)) - if err != nil { - return xerrors.Errorf("decoding address: %w", err) + if kaddr == builtin0.BurntFundsActorAddr { + return nil } - if kaddr != builtin0.BurntFundsActorAddr { - kid, err := sTree.LookupID(kaddr) - if err != nil { - return xerrors.Errorf("resolving address: %w", err) - } - - gi.genesisActors = append(gi.genesisActors, genesisActor{ - addr: kid, - initBal: act.Balance, - }) + kid, err := sTree.LookupID(kaddr) + if err != nil { + return xerrors.Errorf("resolving address: %w", err) } + + gi.genesisActors = append(gi.genesisActors, genesisActor{ + addr: kid, + initBal: act.Balance, + }) } return nil }) @@ -889,6 +878,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return xerrors.Errorf("error setting up genesis infos: %w", err) } + // TODO: use network upgrade abstractions or always start at actors v0? gi.genesisMsigs = make([]msig0.State, 0, len(totalsByEpoch)) for k, v := range totalsByEpoch { ns := msig0.State{ From 441d7ff790fde269fa950d9106f591178b55648d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 11:14:55 -0700 Subject: [PATCH 094/104] cleanup imports some more --- chain/stmgr/forks.go | 12 +++++++----- chain/stmgr/utils.go | 22 ++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index bb496849b92..32e59806584 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -6,12 +6,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" - "github.com/filecoin-project/specs-actors/actors/util/adt" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" ) @@ -221,7 +223,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types return xerrors.Errorf("failed to get miner info: %w", err) } - sectorsArr, err := adt.AsArray(sm.ChainStore().Store(ctx), st.Sectors) + sectorsArr, err := adt0.AsArray(sm.ChainStore().Store(ctx), st.Sectors) if err != nil { return xerrors.Errorf("failed to load sectors array: %w", err) } @@ -245,7 +247,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types return xerrors.Errorf("failed to load miner state: %w", err) } - lbsectors, err := adt.AsArray(sm.ChainStore().Store(ctx), lbst.Sectors) + lbsectors, err := adt0.AsArray(sm.ChainStore().Store(ctx), lbst.Sectors) if err != nil { return xerrors.Errorf("failed to load lb sectors array: %w", err) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index c9e8d32da6b..3493afca3ee 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -9,11 +9,6 @@ import ( "runtime" "strings" - "github.com/filecoin-project/specs-actors/actors/builtin/cron" - - saruntime "github.com/filecoin-project/specs-actors/actors/runtime" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" - cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -22,10 +17,10 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/lotus/chain/actors/builtin/power" - "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" + cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron" init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -34,17 +29,20 @@ import ( power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" + "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/node/modules/dtypes" ) @@ -163,7 +161,7 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, return mas.LoadSectors(snos) } -func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]proof.SectorInfo, error) { +func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]proof0.SectorInfo, error) { act, err := sm.LoadActorRaw(ctx, maddr, st) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -248,9 +246,9 @@ func GetSectorsForWinningPoSt(ctx context.Context, pv ffiwrapper.Verifier, sm *S return nil, xerrors.Errorf("loading proving sectors: %w", err) } - out := make([]proof.SectorInfo, len(sectors)) + out := make([]proof0.SectorInfo, len(sectors)) for i, sinfo := range sectors { - out[i] = proof.SectorInfo{ + out[i] = proof0.SectorInfo{ SealProof: spt, SectorNumber: sinfo.SectorNumber, SealedCID: sinfo.SealedCID, @@ -538,7 +536,7 @@ func init() { cidToMethods := map[cid.Cid][2]interface{}{ // builtin.SystemActorCodeID: {builtin.MethodsSystem, system.Actor{} }- apparently it doesn't have methods builtin0.InitActorCodeID: {builtin0.MethodsInit, init0.Actor{}}, - builtin0.CronActorCodeID: {builtin0.MethodsCron, cron.Actor{}}, + builtin0.CronActorCodeID: {builtin0.MethodsCron, cron0.Actor{}}, builtin0.AccountActorCodeID: {builtin0.MethodsAccount, account0.Actor{}}, builtin0.StoragePowerActorCodeID: {builtin0.MethodsPower, power0.Actor{}}, builtin0.StorageMinerActorCodeID: {builtin0.MethodsMiner, miner0.Actor{}}, @@ -550,7 +548,7 @@ func init() { } for c, m := range cidToMethods { - exports := m[1].(saruntime.Invokee).Exports() + exports := m[1].(vm.Invokee).Exports() methods := make(map[abi.MethodNum]MethodMeta, len(exports)) // Explicitly add send, it's special. From c91774be3bb8d8fcd98cdb5de96f1654de622ffe Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 11:19:28 -0700 Subject: [PATCH 095/104] remove old comment --- cmd/lotus-shed/balances.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index de92aa8b654..c156de931ea 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -170,7 +170,6 @@ var chainBalanceStateCmd = &cli.Command{ sm := stmgr.NewStateManager(cs) - // Options: (a) encode the version in the chain or (b) pass a flag. tree, err := state.LoadStateTree(cst, sroot) if err != nil { return err From 2967c4ec109c2287b05b2732b9f04c1c101320b9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 12:02:29 -0700 Subject: [PATCH 096/104] use abstract actor type methods --- chain/stmgr/forks.go | 16 ++++++++-------- chain/vm/vm.go | 2 +- cli/multisig.go | 3 +-- cmd/lotus-pcr/main.go | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 32e59806584..f9418c4d891 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -7,13 +7,13 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" ) @@ -123,7 +123,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types // Take all excess funds away, put them into the reserve account err = fetree.ForEach(func(addr address.Address, act *types.Actor) error { switch act.Code { - case builtin.AccountActorCodeID, builtin.MultisigActorCodeID, builtin.PaymentChannelActorCodeID: + case builtin0.AccountActorCodeID, builtin0.MultisigActorCodeID, builtin0.PaymentChannelActorCodeID: sysAcc, err := isSystemAccount(addr) if err != nil { return xerrors.Errorf("checking system account: %w", err) @@ -136,7 +136,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types Amt: act.Balance, }) } - case builtin.StorageMinerActorCodeID: + case builtin0.StorageMinerActorCodeID: var st miner0.State if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) @@ -175,7 +175,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types // pull up power table to give miners back some funds proportional to their power var ps power0.State - powAct, err := tree.GetActor(builtin.StoragePowerActorAddr) + powAct, err := tree.GetActor(builtin0.StoragePowerActorAddr) if err != nil { return xerrors.Errorf("failed to load power actor: %w", err) } @@ -203,7 +203,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types } switch act.Code { - case builtin.AccountActorCodeID, builtin.MultisigActorCodeID, builtin.PaymentChannelActorCodeID: + case builtin0.AccountActorCodeID, builtin0.MultisigActorCodeID, builtin0.PaymentChannelActorCodeID: nbalance := big.Min(prevBalance, AccountCap) if nbalance.Sign() != 0 { transfersBack = append(transfersBack, transfer{ @@ -212,7 +212,7 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types Amt: nbalance, }) } - case builtin.StorageMinerActorCodeID: + case builtin0.StorageMinerActorCodeID: var st miner0.State if err := sm.ChainStore().Store(ctx).Get(ctx, act.Head, &st); err != nil { return xerrors.Errorf("failed to load miner state: %w", err) @@ -277,11 +277,11 @@ func UpgradeFaucetBurnRecovery(ctx context.Context, sm *StateManager, tree types } // transfer all burnt funds back to the reserve account - burntAct, err := tree.GetActor(builtin.BurntFundsActorAddr) + burntAct, err := tree.GetActor(builtin0.BurntFundsActorAddr) if err != nil { return xerrors.Errorf("failed to load burnt funds actor: %w", err) } - if err := doTransfer(tree, builtin.BurntFundsActorAddr, ReserveAddress, burntAct.Balance); err != nil { + if err := doTransfer(tree, builtin0.BurntFundsActorAddr, ReserveAddress, burntAct.Balance); err != nil { return xerrors.Errorf("failed to unburn funds: %w", err) } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 25c937ca3e5..049918fba39 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -384,7 +384,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, } // this should never happen, but is currently still exercised by some tests - if !fromActor.Code.Equals(builtin.AccountActorCodeID) { + if !fromActor.IsAccountActor() { gasOutputs := ZeroGasOutputs() gasOutputs.MinerPenalty = minerPenaltyAmount return &ApplyRet{ diff --git a/cli/multisig.go b/cli/multisig.go index 2aabf5d7eed..81c6502d518 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -16,7 +16,6 @@ import ( "github.com/urfave/cli/v2" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/actors/builtin" init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -330,7 +329,7 @@ var msigProposeCmd = &cli.Command{ return fmt.Errorf("failed to look up multisig %s: %w", msig, err) } - if act.Code != builtin.MultisigActorCodeID { + if !act.IsMultisigActor() { return fmt.Errorf("actor %s is not a multisig actor", msig) } diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index fed42427c40..36961a66339 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -12,10 +12,10 @@ import ( "strconv" "time" + "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -28,11 +28,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/tools/stats" ) @@ -375,7 +375,7 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu continue } - if a.Code != builtin.StorageMinerActorCodeID { + if !a.IsStorageMinerActor() { continue } From 46fb0e74cd3d23c5fd0c49c2022106839dbb6051 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 14:09:33 -0700 Subject: [PATCH 097/104] add deal state iterator --- chain/actors/builtin/market/market.go | 1 + chain/actors/builtin/market/v0.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index fa5f027b329..9cb0ffc132e 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -50,6 +50,7 @@ type BalanceTable interface { } type DealStates interface { + ForEach(cb func(id abi.DealID, ds DealState) error) error Get(id abi.DealID) (*DealState, bool, error) array() adt.Array diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 433445dab83..14b8b7d93e9 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -126,6 +126,13 @@ func (s *dealStates0) Get(dealID abi.DealID) (*DealState, bool, error) { return &deal, true, nil } +func (s *dealStates0) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds0 market.DealState + return s.Array.ForEach(&ds0, func(idx int64) error { + return cb(abi.DealID(idx), fromV0DealState(ds0)) + }) +} + func (s *dealStates0) decode(val *cbg.Deferred) (*DealState, error) { var ds0 market.DealState if err := ds0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { From 77f81fc49be3d0fd67438795e41416bb5af18476 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 22 Sep 2020 19:07:32 -0400 Subject: [PATCH 098/104] Test fix --- node/node_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/node/node_test.go b/node/node_test.go index 0e404dc0b40..54498eec33b 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + builder "github.com/filecoin-project/lotus/node/test" "github.com/filecoin-project/go-state-types/abi" @@ -68,6 +70,8 @@ func TestAPIDealFlowReal(t *testing.T) { logging.SetLogLevel("sub", "ERROR") logging.SetLogLevel("storageminer", "ERROR") + // TODO: Do this better. + miner.PreCommitChallengeDelay = 5 miner0.PreCommitChallengeDelay = 5 t.Run("basic", func(t *testing.T) { From 773714792f18a503ca1ad4d586734a7be7bc1223 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 22 Sep 2020 18:40:03 -0700 Subject: [PATCH 099/104] update oni --- extern/oni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/oni b/extern/oni index 8b7e7d438c4..9a0d5cd739d 160000 --- a/extern/oni +++ b/extern/oni @@ -1 +1 @@ -Subproject commit 8b7e7d438c4cc38a0d2d671876d4590ad20655b3 +Subproject commit 9a0d5cd739de77b357589ac1fc8b756ed27299be From ed4bf9b8fe26ce6fc98d0f3bdb1147523116b8ce Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 23 Sep 2020 00:48:35 -0400 Subject: [PATCH 100/104] API shouldn't depend on actors directly --- api/api_full.go | 8 ++++---- api/apistruct/struct.go | 2 +- chain/actors/builtin/builtin.go | 3 +++ chain/actors/builtin/paych/paych.go | 4 ++++ node/impl/paych/paych.go | 21 ++++++++++----------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index f39d0e9bc97..11060a9eabf 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -21,9 +21,9 @@ import ( "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" @@ -788,7 +788,7 @@ type CirculatingSupply struct { type MiningBaseInfo struct { MinerPower types.BigInt NetworkPower types.BigInt - Sectors []proof.SectorInfo + Sectors []builtin.SectorInfo WorkerKey address.Address SectorSize abi.SectorSize PrevBeaconEntry types.BeaconEntry @@ -805,7 +805,7 @@ type BlockTemplate struct { Messages []*types.SignedMessage Epoch abi.ChainEpoch Timestamp uint64 - WinningPoStProof []proof.PoStProof + WinningPoStProof []builtin.PoStProof } type DataSize struct { diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 91a54547999..aea7aae8c39 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -29,12 +29,12 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" marketevents "github.com/filecoin-project/lotus/markets/loggers" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" ) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 3230705dd4d..4079e694a7b 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -5,6 +5,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" @@ -28,6 +29,8 @@ func VersionForNetwork(version network.Version) Version { } // TODO: Why does actors have 2 different versions of this? +type SectorInfo = proof0.SectorInfo +type PoStProof = proof0.PoStProof type FilterEstimate = smoothing0.FilterEstimate func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go index 5eec5f08b5e..0413dcdd0a8 100644 --- a/chain/actors/builtin/paych/paych.go +++ b/chain/actors/builtin/paych/paych.go @@ -8,6 +8,7 @@ import ( big "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/cbor" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -54,3 +55,6 @@ type LaneState interface { Redeemed() big.Int Nonce() uint64 } + +type SignedVoucher = paych0.SignedVoucher +type ModVerifyParams = paych0.ModVerifyParams diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index b2e6be0ca26..af0a1db153e 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -10,9 +10,8 @@ import ( "github.com/filecoin-project/go-address" - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" full "github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/paychmgr" @@ -71,10 +70,10 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address return nil, err } - svs := make([]*paych0.SignedVoucher, len(vouchers)) + svs := make([]*paych.SignedVoucher, len(vouchers)) for i, v := range vouchers { - sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych0.SignedVoucher{ + sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych.SignedVoucher{ Amount: v.Amount, Lane: lane, @@ -123,15 +122,15 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid. return a.PaychMgr.Collect(ctx, addr) } -func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher) error { +func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { return a.PaychMgr.CheckVoucherValid(ctx, ch, sv) } -func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret, proof) } -func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { return a.PaychMgr.AddVoucherInbound(ctx, ch, sv, proof, minDelta) } @@ -143,16 +142,16 @@ func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv * // If there are insufficient funds in the channel to create the voucher, // returns a nil voucher and the shortfall. func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*api.VoucherCreateResult, error) { - return a.PaychMgr.CreateVoucher(ctx, pch, paych0.SignedVoucher{Amount: amt, Lane: lane}) + return a.PaychMgr.CreateVoucher(ctx, pch, paych.SignedVoucher{Amount: amt, Lane: lane}) } -func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych0.SignedVoucher, error) { +func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) { vi, err := a.PaychMgr.ListVouchers(ctx, pch) if err != nil { return nil, err } - out := make([]*paych0.SignedVoucher, len(vi)) + out := make([]*paych.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -160,6 +159,6 @@ func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([ return out, nil } -func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret, proof) } From e27fc03f5541288ef4a6c4080af9587ac706144a Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 23 Sep 2020 01:36:55 -0400 Subject: [PATCH 101/104] Reward state interface only needs cbor.Marshaler --- chain/actors/builtin/reward/reward.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index a4f936d9bff..cfa82c77442 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -29,7 +29,7 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { } type State interface { - cbor.Er + cbor.Marshaler ThisEpochBaselinePower() (abi.StoragePower, error) ThisEpochReward() (abi.StoragePower, error) From 476e7992e8e58de64c848081b03136a5e51c1644 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 23 Sep 2020 01:19:43 -0400 Subject: [PATCH 102/104] Add an error return to all actor state interface methods --- chain/actors/builtin/market/market.go | 6 +- chain/actors/builtin/market/v0.go | 18 ++--- chain/actors/builtin/miner/miner.go | 6 +- chain/actors/builtin/miner/v0.go | 16 ++--- chain/actors/builtin/multisig/multisig.go | 10 +-- chain/actors/builtin/multisig/v0.go | 20 +++--- chain/actors/builtin/paych/mock/mock.go | 24 +++---- chain/actors/builtin/paych/paych.go | 12 ++-- chain/actors/builtin/paych/v0.go | 24 +++---- chain/events/state/predicates.go | 37 ++++++++-- chain/stmgr/stmgr.go | 23 +++++-- cli/multisig.go | 29 ++++++-- cli/paych_test.go | 4 +- cmd/lotus-chainwatch/processor/miner.go | 6 +- cmd/lotus-shed/genesis-verify.go | 13 +++- node/impl/full/state.go | 7 +- paychmgr/paych.go | 83 +++++++++++++++++------ paychmgr/simple.go | 6 +- paychmgr/state.go | 12 +++- 19 files changed, 245 insertions(+), 111 deletions(-) diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 9cb0ffc132e..84872b04b06 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -31,13 +31,13 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) { type State interface { cbor.Marshaler - BalancesChanged(State) bool + BalancesChanged(State) (bool, error) EscrowTable() (BalanceTable, error) LockedTable() (BalanceTable, error) TotalLocked() (abi.TokenAmount, error) - StatesChanged(State) bool + StatesChanged(State) (bool, error) States() (DealStates, error) - ProposalsChanged(State) bool + ProposalsChanged(State) (bool, error) Proposals() (DealProposals, error) VerifyDealsForActivation( minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 14b8b7d93e9..2727f513d23 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -25,24 +25,24 @@ func (s *state0) TotalLocked() (abi.TokenAmount, error) { return fml, nil } -func (s *state0) BalancesChanged(otherState State) bool { +func (s *state0) BalancesChanged(otherState State) (bool, error) { otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed - return true + return true, nil } - return !s.State.EscrowTable.Equals(otherState0.State.EscrowTable) || !s.State.LockedTable.Equals(otherState0.State.LockedTable) + return !s.State.EscrowTable.Equals(otherState0.State.EscrowTable) || !s.State.LockedTable.Equals(otherState0.State.LockedTable), nil } -func (s *state0) StatesChanged(otherState State) bool { +func (s *state0) StatesChanged(otherState State) (bool, error) { otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed - return true + return true, nil } - return !s.State.States.Equals(otherState0.State.States) + return !s.State.States.Equals(otherState0.State.States), nil } func (s *state0) States() (DealStates, error) { @@ -53,14 +53,14 @@ func (s *state0) States() (DealStates, error) { return &dealStates0{stateArray}, nil } -func (s *state0) ProposalsChanged(otherState State) bool { +func (s *state0) ProposalsChanged(otherState State) (bool, error) { otherState0, ok := otherState.(*state0) if !ok { // there's no way to compare different versions of the state, so let's // just say that means the state of balances has changed - return true + return true, nil } - return !s.State.Proposals.Equals(otherState0.State.Proposals) + return !s.State.Proposals.Equals(otherState0.State.Proposals), nil } func (s *state0) Proposals() (DealProposals, error) { diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index dbb4ddd73c9..50a0fc5ca9d 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -58,11 +58,11 @@ type State interface { LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) - DeadlinesChanged(State) bool + DeadlinesChanged(State) (bool, error) Info() (MinerInfo, error) - DeadlineInfo(epoch abi.ChainEpoch) *dline.Info + DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) // Diff helpers. Used by Diff* functions internally. sectors() (adt.Array, error) @@ -76,7 +76,7 @@ type Deadline interface { ForEachPartition(cb func(idx uint64, part Partition) error) error PostSubmissions() (bitfield.BitField, error) - PartitionsChanged(Deadline) bool + PartitionsChanged(Deadline) (bool, error) } type Partition interface { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index a5677815689..e515b9ed614 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -244,14 +244,14 @@ func (s *state0) NumDeadlines() (uint64, error) { return miner0.WPoStPeriodDeadlines, nil } -func (s *state0) DeadlinesChanged(other State) bool { +func (s *state0) DeadlinesChanged(other State) (bool, error) { other0, ok := other.(*state0) if !ok { // treat an upgrade as a change, always - return true + return true, nil } - return s.State.Deadlines.Equals(other0.Deadlines) + return s.State.Deadlines.Equals(other0.Deadlines), nil } func (s *state0) Info() (MinerInfo, error) { @@ -288,8 +288,8 @@ func (s *state0) Info() (MinerInfo, error) { return mi, nil } -func (s *state0) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info { - return s.State.DeadlineInfo(epoch) +func (s *state0) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) { + return s.State.DeadlineInfo(epoch), nil } func (s *state0) sectors() (adt.Array, error) { @@ -339,14 +339,14 @@ func (d *deadline0) ForEachPartition(cb func(uint64, Partition) error) error { }) } -func (d *deadline0) PartitionsChanged(other Deadline) bool { +func (d *deadline0) PartitionsChanged(other Deadline) (bool, error) { other0, ok := other.(*deadline0) if !ok { // treat an upgrade as a change, always - return true + return true, nil } - return d.Deadline.Partitions.Equals(other0.Deadline.Partitions) + return d.Deadline.Partitions.Equals(other0.Deadline.Partitions), nil } func (d *deadline0) PostSubmissions() (bitfield.BitField, error) { diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index 226eed75b9f..884b6f493e1 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -31,11 +31,11 @@ type State interface { cbor.Marshaler LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error) - StartEpoch() abi.ChainEpoch - UnlockDuration() abi.ChainEpoch - InitialBalance() abi.TokenAmount - Threshold() uint64 - Signers() []address.Address + StartEpoch() (abi.ChainEpoch, error) + UnlockDuration() (abi.ChainEpoch, error) + InitialBalance() (abi.TokenAmount, error) + Threshold() (uint64, error) + Signers() ([]address.Address, error) ForEachPendingTxn(func(id int64, txn Transaction) error) error } diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index e81a367cfb9..ae0a7ac0e2c 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -23,24 +23,24 @@ func (s *state0) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } -func (s *state0) StartEpoch() abi.ChainEpoch { - return s.State.StartEpoch +func (s *state0) StartEpoch() (abi.ChainEpoch, error) { + return s.State.StartEpoch, nil } -func (s *state0) UnlockDuration() abi.ChainEpoch { - return s.State.UnlockDuration +func (s *state0) UnlockDuration() (abi.ChainEpoch, error) { + return s.State.UnlockDuration, nil } -func (s *state0) InitialBalance() abi.TokenAmount { - return s.State.InitialBalance +func (s *state0) InitialBalance() (abi.TokenAmount, error) { + return s.State.InitialBalance, nil } -func (s *state0) Threshold() uint64 { - return s.State.NumApprovalsThreshold +func (s *state0) Threshold() (uint64, error) { + return s.State.NumApprovalsThreshold, nil } -func (s *state0) Signers() []address.Address { - return s.State.Signers +func (s *state0) Signers() ([]address.Address, error) { + return s.State.Signers, nil } func (s *state0) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { diff --git a/chain/actors/builtin/paych/mock/mock.go b/chain/actors/builtin/paych/mock/mock.go index 31f7fba93b1..c4903f3ac25 100644 --- a/chain/actors/builtin/paych/mock/mock.go +++ b/chain/actors/builtin/paych/mock/mock.go @@ -45,23 +45,23 @@ func (ms *mockState) MarshalCBOR(io.Writer) error { } // Channel owner, who has funded the actor -func (ms *mockState) From() address.Address { - return ms.from +func (ms *mockState) From() (address.Address, error) { + return ms.from, nil } // Recipient of payouts from channel -func (ms *mockState) To() address.Address { - return ms.to +func (ms *mockState) To() (address.Address, error) { + return ms.to, nil } // Height at which the channel can be `Collected` -func (ms *mockState) SettlingAt() abi.ChainEpoch { - return ms.settlingAt +func (ms *mockState) SettlingAt() (abi.ChainEpoch, error) { + return ms.settlingAt, nil } // Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (ms *mockState) ToSend() abi.TokenAmount { - return ms.toSend +func (ms *mockState) ToSend() (abi.TokenAmount, error) { + return ms.toSend, nil } // Get total number of lanes @@ -80,10 +80,10 @@ func (ms *mockState) ForEachLaneState(cb func(idx uint64, dl paych.LaneState) er return lastErr } -func (mls *mockLaneState) Redeemed() big.Int { - return mls.redeemed +func (mls *mockLaneState) Redeemed() (big.Int, error) { + return mls.redeemed, nil } -func (mls *mockLaneState) Nonce() uint64 { - return mls.nonce +func (mls *mockLaneState) Nonce() (uint64, error) { + return mls.nonce, nil } diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go index 0413dcdd0a8..dad54163fee 100644 --- a/chain/actors/builtin/paych/paych.go +++ b/chain/actors/builtin/paych/paych.go @@ -33,15 +33,15 @@ func Load(store adt.Store, act *types.Actor) (State, error) { type State interface { cbor.Marshaler // Channel owner, who has funded the actor - From() address.Address + From() (address.Address, error) // Recipient of payouts from channel - To() address.Address + To() (address.Address, error) // Height at which the channel can be `Collected` - SettlingAt() abi.ChainEpoch + SettlingAt() (abi.ChainEpoch, error) // Amount successfully redeemed through the payment channel, paid out on `Collect()` - ToSend() abi.TokenAmount + ToSend() (abi.TokenAmount, error) // Get total number of lanes LaneCount() (uint64, error) @@ -52,8 +52,8 @@ type State interface { // LaneState is an abstract copy of the state of a single lane type LaneState interface { - Redeemed() big.Int - Nonce() uint64 + Redeemed() (big.Int, error) + Nonce() (uint64, error) } type SignedVoucher = paych0.SignedVoucher diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go index b69cf46ce9f..c0eea100076 100644 --- a/chain/actors/builtin/paych/v0.go +++ b/chain/actors/builtin/paych/v0.go @@ -18,23 +18,23 @@ type state0 struct { } // Channel owner, who has funded the actor -func (s *state0) From() address.Address { - return s.State.From +func (s *state0) From() (address.Address, error) { + return s.State.From, nil } // Recipient of payouts from channel -func (s *state0) To() address.Address { - return s.State.To +func (s *state0) To() (address.Address, error) { + return s.State.To, nil } // Height at which the channel can be `Collected` -func (s *state0) SettlingAt() abi.ChainEpoch { - return s.State.SettlingAt +func (s *state0) SettlingAt() (abi.ChainEpoch, error) { + return s.State.SettlingAt, nil } // Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state0) ToSend() abi.TokenAmount { - return s.State.ToSend +func (s *state0) ToSend() (abi.TokenAmount, error) { + return s.State.ToSend, nil } func (s *state0) getOrLoadLsAmt() (*adt0.Array, error) { @@ -82,10 +82,10 @@ type laneState0 struct { paych.LaneState } -func (ls *laneState0) Redeemed() big.Int { - return ls.LaneState.Redeemed +func (ls *laneState0) Redeemed() (big.Int, error) { + return ls.LaneState.Redeemed, nil } -func (ls *laneState0) Nonce() uint64 { - return ls.LaneState.Nonce +func (ls *laneState0) Nonce() (uint64, error) { + return ls.LaneState.Nonce, nil } diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index 909533d1501..e6c2fa084a6 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -97,7 +97,12 @@ type DiffBalanceTablesFunc func(ctx context.Context, oldBalanceTable, newBalance // OnBalanceChanged runs when the escrow table for available balances changes func (sp *StatePredicates) OnBalanceChanged(diffBalances DiffBalanceTablesFunc) DiffStorageMarketStateFunc { return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { - if !oldState.BalancesChanged(newState) { + bc, err := oldState.BalancesChanged(newState) + if err != nil { + return false, nil, err + } + + if !bc { return false, nil, nil } @@ -132,7 +137,12 @@ type DiffAdtArraysFunc func(ctx context.Context, oldDealStateRoot, newDealStateR // OnDealStateChanged calls diffDealStates when the market deal state changes func (sp *StatePredicates) OnDealStateChanged(diffDealStates DiffDealStatesFunc) DiffStorageMarketStateFunc { return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { - if !oldState.StatesChanged(newState) { + sc, err := oldState.StatesChanged(newState) + if err != nil { + return false, nil, err + } + + if !sc { return false, nil, nil } @@ -152,7 +162,12 @@ func (sp *StatePredicates) OnDealStateChanged(diffDealStates DiffDealStatesFunc) // OnDealProposalChanged calls diffDealProps when the market proposal state changes func (sp *StatePredicates) OnDealProposalChanged(diffDealProps DiffDealProposalsFunc) DiffStorageMarketStateFunc { return func(ctx context.Context, oldState market.State, newState market.State) (changed bool, user UserData, err error) { - if !oldState.ProposalsChanged(newState) { + pc, err := oldState.ProposalsChanged(newState) + if err != nil { + return false, nil, err + } + + if !pc { return false, nil, nil } @@ -379,12 +394,22 @@ type PayChToSendChange struct { // OnToSendAmountChanges monitors changes on the total amount to send from one party to the other on a payment channel func (sp *StatePredicates) OnToSendAmountChanges() DiffPaymentChannelStateFunc { return func(ctx context.Context, oldState paych.State, newState paych.State) (changed bool, user UserData, err error) { - if oldState.ToSend().Equals(newState.ToSend()) { + ots, err := oldState.ToSend() + if err != nil { + return false, nil, err + } + + nts, err := newState.ToSend() + if err != nil { + return false, nil, err + } + + if ots.Equals(nts) { return false, nil, nil } return true, &PayChToSendChange{ - OldToSend: oldState.ToSend(), - NewToSend: newState.ToSend(), + OldToSend: ots, + NewToSend: nts, }, nil } } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index af729143c6b..eaf9215dbd2 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -843,15 +843,30 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error { return err } - if s.StartEpoch() != 0 { + se, err := s.StartEpoch() + if err != nil { + return err + } + + if se != 0 { return xerrors.New("genesis multisig doesn't start vesting at epoch 0!") } - ot, f := totalsByEpoch[s.UnlockDuration()] + ud, err := s.UnlockDuration() + if err != nil { + return err + } + + ib, err := s.InitialBalance() + if err != nil { + return err + } + + ot, f := totalsByEpoch[ud] if f { - totalsByEpoch[s.UnlockDuration()] = big.Add(ot, s.InitialBalance()) + totalsByEpoch[ud] = big.Add(ot, ib) } else { - totalsByEpoch[s.UnlockDuration()] = s.InitialBalance() + totalsByEpoch[ud] = ib } } else if act.IsAccountActor() { diff --git a/cli/multisig.go b/cli/multisig.go index 81c6502d518..0cb4028a979 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -206,13 +206,32 @@ var msigInspectCmd = &cli.Command{ fmt.Printf("Spendable: %s\n", types.FIL(types.BigSub(act.Balance, locked))) if cctx.Bool("vesting") { - fmt.Printf("InitialBalance: %s\n", types.FIL(mstate.InitialBalance())) - fmt.Printf("StartEpoch: %d\n", mstate.StartEpoch()) - fmt.Printf("UnlockDuration: %d\n", mstate.UnlockDuration()) + ib, err := mstate.InitialBalance() + if err != nil { + return err + } + fmt.Printf("InitialBalance: %s\n", types.FIL(ib)) + se, err := mstate.StartEpoch() + if err != nil { + return err + } + fmt.Printf("StartEpoch: %d\n", se) + ud, err := mstate.UnlockDuration() + if err != nil { + return err + } + fmt.Printf("UnlockDuration: %d\n", ud) } - signers := mstate.Signers() - fmt.Printf("Threshold: %d / %d\n", mstate.Threshold(), len(signers)) + signers, err := mstate.Signers() + if err != nil { + return err + } + threshold, err := mstate.Threshold() + if err != nil { + return err + } + fmt.Printf("Threshold: %d / %d\n", threshold, len(signers)) fmt.Println("Signers:") for _, s := range signers { fmt.Printf("\t%s\n", s) diff --git a/cli/paych_test.go b/cli/paych_test.go index 49631f1fcb0..47a84fe5e3e 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -89,7 +89,9 @@ func TestPaymentChannels(t *testing.T) { // Wait for the chain to reach the settle height chState := getPaychState(ctx, t, paymentReceiver, chAddr) - waitForHeight(ctx, t, paymentReceiver, chState.SettlingAt()) + sa, err := chState.SettlingAt() + require.NoError(t, err) + waitForHeight(ctx, t, paymentReceiver, sa) // receiver: paych collect cmd = []string{chAddr.String()} diff --git a/cmd/lotus-chainwatch/processor/miner.go b/cmd/lotus-chainwatch/processor/miner.go index 17eef3afab0..3a37a82f800 100644 --- a/cmd/lotus-chainwatch/processor/miner.go +++ b/cmd/lotus-chainwatch/processor/miner.go @@ -684,7 +684,11 @@ func (p *Processor) diffMinerPartitions(ctx context.Context, m minerActorInfo, e return err } curMiner := m.state - if !prevMiner.DeadlinesChanged(curMiner) { + dc, err := prevMiner.DeadlinesChanged(curMiner) + if err != nil { + return err + } + if !dc { return nil } panic("TODO") diff --git a/cmd/lotus-shed/genesis-verify.go b/cmd/lotus-shed/genesis-verify.go index 1225d817a10..da2c8235992 100644 --- a/cmd/lotus-shed/genesis-verify.go +++ b/cmd/lotus-shed/genesis-verify.go @@ -108,10 +108,19 @@ var genesisVerifyCmd = &cli.Command{ return xerrors.Errorf("multisig actor: %w", err) } + signers, err := st.Signers() + if err != nil { + return xerrors.Errorf("multisig actor: %w", err) + } + threshold, err := st.Threshold() + if err != nil { + return xerrors.Errorf("multisig actor: %w", err) + } + kmultisigs[addr] = msigInfo{ Balance: types.FIL(act.Balance), - Signers: st.Signers(), - Threshold: st.Threshold(), + Signers: signers, + Threshold: threshold, } msigAddrs = append(msigAddrs, addr) case act.IsAccountActor(): diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 109a265ea00..f8bf92a926f 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -212,7 +212,12 @@ func (a *StateAPI) StateMinerProvingDeadline(ctx context.Context, addr address.A return nil, xerrors.Errorf("failed to load miner actor state: %w", err) } - return mas.DeadlineInfo(ts.Height()).NextNotElapsed(), nil + di, err := mas.DeadlineInfo(ts.Height()) + if err != nil { + return nil, xerrors.Errorf("failed to get deadline info: %w", err) + } + + return di.NextNotElapsed(), nil } func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) { diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 11dfd2a1eaf..f856b98900d 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -48,12 +48,12 @@ type laneState struct { nonce uint64 } -func (ls laneState) Redeemed() big.Int { - return ls.redeemed +func (ls laneState) Redeemed() (big.Int, error) { + return ls.redeemed, nil } -func (ls laneState) Nonce() uint64 { - return ls.nonce +func (ls laneState) Nonce() (uint64, error) { + return ls.nonce, nil } // channelAccessor is used to simplify locking when accessing a channel @@ -181,7 +181,12 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add } // Load channel "From" account actor state - from, err := ca.api.ResolveToKeyAddress(ctx, pchState.From(), nil) + f, err := pchState.From() + if err != nil { + return nil, err + } + + from, err := ca.api.ResolveToKeyAddress(ctx, f, nil) if err != nil { return nil, err } @@ -208,13 +213,24 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add // If the new voucher nonce value is less than the highest known // nonce for the lane ls, lsExists := laneStates[sv.Lane] - if lsExists && sv.Nonce <= ls.Nonce() { - return nil, fmt.Errorf("nonce too low") - } + if lsExists { + n, err := ls.Nonce() + if err != nil { + return nil, err + } - // If the voucher amount is less than the highest known voucher amount - if lsExists && sv.Amount.LessThanEqual(ls.Redeemed()) { - return nil, fmt.Errorf("voucher amount is lower than amount for voucher with lower nonce") + if sv.Nonce <= n { + return nil, fmt.Errorf("nonce too low") + } + + // If the voucher amount is less than the highest known voucher amount + r, err := ls.Redeemed() + if err != nil { + return nil, err + } + if sv.Amount.LessThanEqual(r) { + return nil, fmt.Errorf("voucher amount is lower than amount for voucher with lower nonce") + } } // Total redeemed is the total redeemed amount for all lanes, including @@ -239,7 +255,12 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add // Total required balance = total redeemed + toSend // Must not exceed actor balance - newTotal := types.BigAdd(totalRedeemed, pchState.ToSend()) + ts, err := pchState.ToSend() + if err != nil { + return nil, err + } + + newTotal := types.BigAdd(totalRedeemed, ts) if act.Balance.LessThan(newTotal) { return nil, newErrInsufficientFunds(types.BigSub(newTotal, act.Balance)) } @@ -322,7 +343,7 @@ func (ca *channelAccessor) getPaychRecipient(ctx context.Context, ch address.Add return address.Address{}, err } - return state.To(), nil + return state.To() } func (ca *channelAccessor) addVoucher(ctx context.Context, ch address.Address, sv *paych0.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { @@ -376,7 +397,10 @@ func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Ad laneState, exists := laneStates[sv.Lane] redeemed := big.NewInt(0) if exists { - redeemed = laneState.Redeemed() + redeemed, err = laneState.Redeemed() + if err != nil { + return types.NewInt(0), err + } } delta := types.BigSub(sv.Amount, redeemed) @@ -531,9 +555,14 @@ func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch // If there's a voucher for a lane that isn't in chain state just // create it ls, ok := laneStates[v.Voucher.Lane] - - if ok && v.Voucher.Nonce < ls.Nonce() { - continue + if ok { + n, err := ls.Nonce() + if err != nil { + return nil, err + } + if v.Voucher.Nonce < n { + continue + } } laneStates[v.Voucher.Lane] = laneState{v.Voucher.Amount, v.Voucher.Nonce} @@ -551,17 +580,31 @@ func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]paych. total := big.NewInt(0) for _, ls := range laneStates { - total = big.Add(total, ls.Redeemed()) + r, err := ls.Redeemed() + if err != nil { + return big.Int{}, err + } + total = big.Add(total, r) } lane, ok := laneStates[sv.Lane] if ok { // If the voucher is for an existing lane, and the voucher nonce // is higher than the lane nonce - if sv.Nonce > lane.Nonce() { + n, err := lane.Nonce() + if err != nil { + return big.Int{}, err + } + + if sv.Nonce > n { // Add the delta between the redeemed amount and the voucher // amount to the total - delta := big.Sub(sv.Amount, lane.Redeemed()) + r, err := lane.Redeemed() + if err != nil { + return big.Int{}, err + } + + delta := big.Sub(sv.Amount, r) total = big.Add(total, delta) } } else { diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 815b8acabb7..d2a42a6736a 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -317,7 +317,11 @@ func (ca *channelAccessor) currentAvailableFunds(channelID string, queuedAmt typ } for _, ls := range laneStates { - totalRedeemed = types.BigAdd(totalRedeemed, ls.Redeemed()) + r, err := ls.Redeemed() + if err != nil { + return nil, err + } + totalRedeemed = types.BigAdd(totalRedeemed, r) } } diff --git a/paychmgr/state.go b/paychmgr/state.go index 2571ef73e83..65963d2a0ec 100644 --- a/paychmgr/state.go +++ b/paychmgr/state.go @@ -24,11 +24,19 @@ func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Ad } // Load channel "From" account actor state - from, err := ca.sm.ResolveToKeyAddress(ctx, st.From(), nil) + f, err := st.From() if err != nil { return nil, err } - to, err := ca.sm.ResolveToKeyAddress(ctx, st.To(), nil) + from, err := ca.sm.ResolveToKeyAddress(ctx, f, nil) + if err != nil { + return nil, err + } + t, err := st.To() + if err != nil { + return nil, err + } + to, err := ca.sm.ResolveToKeyAddress(ctx, t, nil) if err != nil { return nil, err } From 819180f739c7d6c15eb7d4c00ab5218c7d30096f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 23 Sep 2020 02:14:28 -0400 Subject: [PATCH 103/104] Implement inefficient OnAddressMapChange predicate --- chain/events/state/predicates.go | 72 ++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index e6c2fa084a6..99b8480dc52 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -519,32 +519,72 @@ func (i *InitActorAddressChanges) Remove(key string, val *typegen.Deferred) erro func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return func(ctx context.Context, oldState, newState init_.State) (changed bool, user UserData, err error) { - /*ctxStore := &contextStore{ - ctx: ctx, - cst: sp.cst, - } - addressChanges := &InitActorAddressChanges{ Added: []AddressPair{}, Modified: []AddressChange{}, Removed: []AddressPair{}, } - if oldState.AddressMap.Equals(newState.AddressMap) { - return false, nil, nil - } + err = oldState.ForEachActor(func(oldId abi.ActorID, oldAddress address.Address) error { + oldIdAddress, err := address.NewIDAddress(uint64(oldId)) + if err != nil { + return err + } - oldAddrs, err := adt0.AsMap(ctxStore, oldState.AddressMap) - if err != nil { - return false, nil, err - } + newIdAddress, found, err := newState.ResolveAddress(oldAddress) + if err != nil { + return err + } + + if !found { + addressChanges.Removed = append(addressChanges.Removed, AddressPair{ + ID: oldIdAddress, + PK: oldAddress, + }) + } + + if oldIdAddress != newIdAddress { + addressChanges.Modified = append(addressChanges.Modified, AddressChange{ + From: AddressPair{ + ID: oldIdAddress, + PK: oldAddress, + }, + To: AddressPair{ + ID: newIdAddress, + PK: oldAddress, + }, + }) + } + + return nil + }) - newAddrs, err := adt0.AsMap(ctxStore, newState.AddressMap) if err != nil { return false, nil, err } - if err := adt.DiffAdtMap(oldAddrs, newAddrs, addressChanges); err != nil { + err = newState.ForEachActor(func(newId abi.ActorID, newAddress address.Address) error { + newIdAddress, err := address.NewIDAddress(uint64(newId)) + if err != nil { + return err + } + + _, found, err := newState.ResolveAddress(newAddress) + if err != nil { + return err + } + + if !found { + addressChanges.Added = append(addressChanges.Added, AddressPair{ + ID: newIdAddress, + PK: newAddress, + }) + } + + return nil + }) + + if err != nil { return false, nil, err } @@ -552,8 +592,6 @@ func (sp *StatePredicates) OnAddressMapChange() DiffInitActorStateFunc { return false, nil, nil } - return true, addressChanges, nil*/ - - panic("TODO") + return true, addressChanges, nil } } From a876a0ba443afee1477567b06679edf2f3ce21f2 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 23 Sep 2020 02:18:52 -0400 Subject: [PATCH 104/104] Use actor state addresses --- chain/actors/builtin/market/market.go | 7 +++++ chain/gen/genesis/miners.go | 37 +++++++++++++++------------ chain/market/fundmgr.go | 3 ++- chain/market/fundmgr_test.go | 3 ++- chain/stmgr/forks_test.go | 3 ++- chain/store/weight.go | 3 +-- chain/sync.go | 3 +-- chain/vm/vm.go | 3 ++- paychmgr/paychget_test.go | 9 ++++--- paychmgr/simple.go | 3 ++- 10 files changed, 45 insertions(+), 29 deletions(-) diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 84872b04b06..fef0c03f9dc 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -65,6 +66,12 @@ type DealProposals interface { decode(*cbg.Deferred) (*DealProposal, error) } +type PublishStorageDealsParams = market0.PublishStorageDealsParams +type PublishStorageDealsReturn = market0.PublishStorageDealsReturn +type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams + +type ClientDealProposal = market0.ClientDealProposal + type DealState struct { SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 853c9c4a0ac..1023e5efaab 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -6,6 +6,12 @@ import ( "fmt" "math/rand" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + + "github.com/filecoin-project/lotus/chain/actors/builtin/power" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" + + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/ipfs/go-cid" @@ -19,7 +25,6 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" @@ -109,7 +114,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } params := mustEnc(constructorParams) - rval, err := doExecValue(ctx, vm, builtin.StoragePowerActorAddr, m.Owner, m.PowerBalance, builtin.MethodsPower.CreateMiner, params) + rval, err := doExecValue(ctx, vm, power.Address, m.Owner, m.PowerBalance, builtin.MethodsPower.CreateMiner, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) } @@ -141,7 +146,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid if m.MarketBalance.GreaterThan(big.Zero()) { params := mustEnc(&minerInfos[i].maddr) - _, err := doExecValue(ctx, vm, builtin.StorageMarketActorAddr, m.Worker, m.MarketBalance, builtin.MethodsMarket.AddBalance, params) + _, err := doExecValue(ctx, vm, market.Address, m.Worker, m.MarketBalance, builtin.MethodsMarket.AddBalance, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner (add balance): %w", err) } @@ -153,7 +158,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid publish := func(params *market.PublishStorageDealsParams) error { fmt.Printf("publishing %d storage deals on miner %s with worker %s\n", len(params.Deals), params.Deals[0].Proposal.Provider, m.Worker) - ret, err := doExecValue(ctx, vm, builtin.StorageMarketActorAddr, m.Worker, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, mustEnc(params)) + ret, err := doExecValue(ctx, vm, market.Address, m.Worker, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, mustEnc(params)) if err != nil { return xerrors.Errorf("failed to create genesis miner (publish deals): %w", err) } @@ -210,7 +215,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } } - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { + err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { st.TotalQualityAdjPower = qaPow st.TotalRawBytePower = rawPow @@ -222,7 +227,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("mutating state: %w", err) } - err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward0.State) error { + err = vm.MutateState(ctx, reward.Address, func(sct cbor.IpldStore, st *reward0.State) error { *st = *reward0.ConstructState(qaPow) return nil }) @@ -252,7 +257,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid sectorWeight := miner0.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) // we've added fake power for this sector above, remove it now - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { + err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) //nolint:scopelint st.TotalRawBytePower = types.BigSub(st.TotalRawBytePower, types.NewInt(uint64(m.SectorSize))) return nil @@ -295,7 +300,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Sectors: []abi.SectorNumber{preseal.SectorID}, } - _, err = doExecValue(ctx, vm, minerInfos[i].maddr, builtin.StoragePowerActorAddr, big.Zero(), builtin.MethodsMiner.ConfirmSectorProofsValid, mustEnc(confirmParams)) + _, err = doExecValue(ctx, vm, minerInfos[i].maddr, power.Address, big.Zero(), builtin.MethodsMiner.ConfirmSectorProofsValid, mustEnc(confirmParams)) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } @@ -304,7 +309,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } // Sanity-check total network power - err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power0.State) error { + err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { if !st.TotalRawBytePower.Equals(rawPow) { return xerrors.Errorf("st.TotalRawBytePower doesn't match previously calculated rawPow") } @@ -344,7 +349,7 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry } func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { - pwret, err := doExecValue(ctx, vm, builtin.StoragePowerActorAddr, maddr, big.Zero(), builtin.MethodsPower.CurrentTotalPower, nil) + pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin.MethodsPower.CurrentTotalPower, nil) if err != nil { return nil, err } @@ -356,33 +361,33 @@ func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (* return &pwr, nil } -func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch) (market.VerifyDealsForActivationReturn, error) { +func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch) (market0.VerifyDealsForActivationReturn, error) { params := &market.VerifyDealsForActivationParams{ DealIDs: dealIDs, SectorStart: sectorStart, SectorExpiry: sectorExpiry, } - var dealWeights market.VerifyDealsForActivationReturn + var dealWeights market0.VerifyDealsForActivationReturn ret, err := doExecValue(ctx, vm, - builtin.StorageMarketActorAddr, + market.Address, maddr, abi.NewTokenAmount(0), builtin.MethodsMarket.VerifyDealsForActivation, mustEnc(params), ) if err != nil { - return market.VerifyDealsForActivationReturn{}, err + return market0.VerifyDealsForActivationReturn{}, err } if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil { - return market.VerifyDealsForActivationReturn{}, err + return market0.VerifyDealsForActivationReturn{}, err } return dealWeights, nil } func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*reward0.ThisEpochRewardReturn, error) { - rwret, err := doExecValue(ctx, vm, builtin.RewardActorAddr, maddr, big.Zero(), builtin.MethodsReward.ThisEpochReward, nil) + rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), builtin.MethodsReward.ThisEpochReward, nil) if err != nil { return nil, err } diff --git a/chain/market/fundmgr.go b/chain/market/fundmgr.go index edf73d9bd62..aef3b98ebf7 100644 --- a/chain/market/fundmgr.go +++ b/chain/market/fundmgr.go @@ -15,6 +15,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/types" @@ -151,7 +152,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add } smsg, err := fm.api.MpoolPushMessage(ctx, &types.Message{ - To: builtin.StorageMarketActorAddr, + To: market.Address, From: wallet, Value: toAdd, Method: builtin.MethodsMarket.AddBalance, diff --git a/chain/market/fundmgr_test.go b/chain/market/fundmgr_test.go index c0e69c51c01..b05db55d87a 100644 --- a/chain/market/fundmgr_test.go +++ b/chain/market/fundmgr_test.go @@ -17,6 +17,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/types" ) @@ -47,7 +48,7 @@ func (fapi *fakeAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, s func addFundsMsg(toAdd abi.TokenAmount, addr address.Address, wallet address.Address) *types.Message { params, _ := actors.SerializeParams(&addr) return &types.Message{ - To: builtin.StorageMarketActorAddr, + To: market.Address, From: wallet, Value: toAdd, Method: builtin.MethodsMarket.AddBalance, diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 87d328ce199..8c6d2ce40c6 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -19,6 +19,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/aerrors" + lotusinit "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/stmgr" . "github.com/filecoin-project/lotus/chain/stmgr" @@ -168,7 +169,7 @@ func TestForkHeightTriggers(t *testing.T) { m := &types.Message{ From: cg.Banker(), - To: builtin.InitActorAddr, + To: lotusinit.Address, Method: builtin.MethodsInit.Exec, Params: enc, GasLimit: types.TestGasLimit, diff --git a/chain/store/weight.go b/chain/store/weight.go index 2d83738c541..9100df31547 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" ) @@ -35,7 +34,7 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn return types.NewInt(0), xerrors.Errorf("load state tree: %w", err) } - act, err := state.GetActor(builtin.StoragePowerActorAddr) + act, err := state.GetActor(power.Address) if err != nil { return types.NewInt(0), xerrors.Errorf("get power actor: %w", err) } diff --git a/chain/sync.go b/chain/sync.go index 972321787b7..f641f078b23 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -33,7 +33,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" blst "github.com/supranational/blst/bindings/go" @@ -640,7 +639,7 @@ func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet) } func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, baseTs *types.TipSet) error { - act, err := syncer.sm.LoadActor(ctx, builtin.StoragePowerActorAddr, baseTs) + act, err := syncer.sm.LoadActor(ctx, power.Address, baseTs) if err != nil { return xerrors.Errorf("failed to load power actor: %w", err) } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 049918fba39..35ece7c5706 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/builtin/account" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/blockstore" @@ -493,7 +494,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, return nil, xerrors.Errorf("failed to burn base fee: %w", err) } - if err := vm.transferFromGasHolder(builtin.RewardActorAddr, gasHolder, gasOutputs.MinerTip); err != nil { + if err := vm.transferFromGasHolder(reward.Address, gasHolder, gasOutputs.MinerTip); err != nil { return nil, xerrors.Errorf("failed to give miner gas reward: %w", err) } diff --git a/paychmgr/paychget_test.go b/paychmgr/paychget_test.go index 93233c54fe3..430e66c6797 100644 --- a/paychmgr/paychget_test.go +++ b/paychmgr/paychget_test.go @@ -19,6 +19,7 @@ import ( init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" tutils "github.com/filecoin-project/specs-actors/support/testing" + lotusinit "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" paychmock "github.com/filecoin-project/lotus/chain/actors/builtin/paych/mock" "github.com/filecoin-project/lotus/chain/types" @@ -60,7 +61,7 @@ func TestPaychGetCreateChannelMsg(t *testing.T) { pushedMsg := mock.pushedMessages(mcid) require.Equal(t, from, pushedMsg.Message.From) - require.Equal(t, builtin.InitActorAddr, pushedMsg.Message.To) + require.Equal(t, lotusinit.Address, pushedMsg.Message.To) require.Equal(t, amt, pushedMsg.Message.Value) } @@ -712,7 +713,7 @@ func TestPaychGetMergeAddFunds(t *testing.T) { // Check create message amount is correct createMsg := mock.pushedMessages(createMsgCid) require.Equal(t, from, createMsg.Message.From) - require.Equal(t, builtin.InitActorAddr, createMsg.Message.To) + require.Equal(t, lotusinit.Address, createMsg.Message.To) require.Equal(t, createAmt, createMsg.Message.Value) // Check merged add funds amount is the sum of the individual @@ -808,7 +809,7 @@ func TestPaychGetMergeAddFundsCtxCancelOne(t *testing.T) { // Check create message amount is correct createMsg := mock.pushedMessages(createMsgCid) require.Equal(t, from, createMsg.Message.From) - require.Equal(t, builtin.InitActorAddr, createMsg.Message.To) + require.Equal(t, lotusinit.Address, createMsg.Message.To) require.Equal(t, createAmt, createMsg.Message.Value) // Check merged add funds amount only includes the second add funds amount @@ -890,7 +891,7 @@ func TestPaychGetMergeAddFundsCtxCancelAll(t *testing.T) { // Check create message amount is correct createMsg := mock.pushedMessages(createMsgCid) require.Equal(t, from, createMsg.Message.From) - require.Equal(t, builtin.InitActorAddr, createMsg.Message.To) + require.Equal(t, lotusinit.Address, createMsg.Message.To) require.Equal(t, createAmt, createMsg.Message.Value) } diff --git a/paychmgr/simple.go b/paychmgr/simple.go index d2a42a6736a..d49ccafe605 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -19,6 +19,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" + lotusinit "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/types" ) @@ -400,7 +401,7 @@ func (ca *channelAccessor) createPaych(ctx context.Context, amt types.BigInt) (c } msg := &types.Message{ - To: builtin.InitActorAddr, + To: lotusinit.Address, From: ca.from, Value: amt, Method: builtin.MethodsInit.Exec,