fixup v1 actors for new methods
Also, correctly handle multiple ADT versions.
This commit is contained in:
parent
ebad0ded3d
commit
35562bd2f9
@ -8,7 +8,9 @@ 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"
|
||||
|
||||
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
adt1 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
||||
)
|
||||
|
||||
type Map interface {
|
||||
@ -25,6 +27,8 @@ func AsMap(store Store, root cid.Cid, version builtin.Version) (Map, error) {
|
||||
switch version {
|
||||
case builtin.Version0:
|
||||
return adt0.AsMap(store, root)
|
||||
case builtin.Version1:
|
||||
return adt1.AsMap(store, root)
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown network version: %d", version)
|
||||
}
|
||||
@ -33,6 +37,8 @@ func NewMap(store Store, version builtin.Version) (Map, error) {
|
||||
switch version {
|
||||
case builtin.Version0:
|
||||
return adt0.MakeEmptyMap(store), nil
|
||||
case builtin.Version1:
|
||||
return adt1.MakeEmptyMap(store), nil
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown network version: %d", version)
|
||||
}
|
||||
@ -52,6 +58,8 @@ func AsArray(store Store, root cid.Cid, version network.Version) (Array, error)
|
||||
switch builtin.VersionForNetwork(version) {
|
||||
case builtin.Version0:
|
||||
return adt0.AsArray(store, root)
|
||||
case builtin.Version1:
|
||||
return adt1.AsArray(store, root)
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown network version: %d", version)
|
||||
}
|
||||
@ -60,6 +68,8 @@ func NewArray(store Store, version builtin.Version) (Array, error) {
|
||||
switch version {
|
||||
case builtin.Version0:
|
||||
return adt0.MakeEmptyArray(store), nil
|
||||
case builtin.Version1:
|
||||
return adt1.MakeEmptyArray(store), nil
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown network version: %d", version)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ type Version int
|
||||
|
||||
const (
|
||||
Version0 = iota
|
||||
Version1
|
||||
)
|
||||
|
||||
// Converts a network version into a specs-actors version.
|
||||
|
@ -6,11 +6,10 @@ import (
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
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"
|
||||
|
||||
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
@ -45,3 +46,21 @@ func (s *state1) ForEachActor(cb func(id abi.ActorID, address address.Address) e
|
||||
func (s *state1) NetworkName() (dtypes.NetworkName, error) {
|
||||
return dtypes.NetworkName(s.State.NetworkName), nil
|
||||
}
|
||||
|
||||
func (s *state1) Remove(addrs ...address.Address) (err error) {
|
||||
m, err := adt1.AsMap(s.store, s.State.AddressMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
if err = m.Delete(abi.AddrKey(addr)); err != nil {
|
||||
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
|
||||
}
|
||||
}
|
||||
amr, err := m.Root()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get address map root: %w", err)
|
||||
}
|
||||
s.State.AddressMap = amr
|
||||
return nil
|
||||
}
|
||||
|
@ -25,24 +25,24 @@ func (s *state1) TotalLocked() (abi.TokenAmount, error) {
|
||||
return fml, nil
|
||||
}
|
||||
|
||||
func (s *state1) BalancesChanged(otherState State) bool {
|
||||
func (s *state1) BalancesChanged(otherState State) (bool, error) {
|
||||
otherState1, ok := otherState.(*state1)
|
||||
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(otherState1.State.EscrowTable) || !s.State.LockedTable.Equals(otherState1.State.LockedTable)
|
||||
return !s.State.EscrowTable.Equals(otherState1.State.EscrowTable) || !s.State.LockedTable.Equals(otherState1.State.LockedTable), nil
|
||||
}
|
||||
|
||||
func (s *state1) StatesChanged(otherState State) bool {
|
||||
func (s *state1) StatesChanged(otherState State) (bool, error) {
|
||||
otherState1, ok := otherState.(*state1)
|
||||
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(otherState1.State.States)
|
||||
return !s.State.States.Equals(otherState1.State.States), nil
|
||||
}
|
||||
|
||||
func (s *state1) States() (DealStates, error) {
|
||||
@ -53,14 +53,14 @@ func (s *state1) States() (DealStates, error) {
|
||||
return &dealStates1{stateArray}, nil
|
||||
}
|
||||
|
||||
func (s *state1) ProposalsChanged(otherState State) bool {
|
||||
func (s *state1) ProposalsChanged(otherState State) (bool, error) {
|
||||
otherState1, ok := otherState.(*state1)
|
||||
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(otherState1.State.Proposals)
|
||||
return !s.State.Proposals.Equals(otherState1.State.Proposals), nil
|
||||
}
|
||||
|
||||
func (s *state1) Proposals() (DealProposals, error) {
|
||||
@ -127,6 +127,13 @@ func (s *dealStates1) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||
return &deal, true, nil
|
||||
}
|
||||
|
||||
func (s *dealStates1) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||
var ds1 market.DealState
|
||||
return s.Array.ForEach(&ds1, func(idx int64) error {
|
||||
return cb(abi.DealID(idx), fromV1DealState(ds1))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *dealStates1) decode(val *cbg.Deferred) (*DealState, error) {
|
||||
var ds1 market.DealState
|
||||
if err := ds1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
adt1 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
miner1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
||||
)
|
||||
@ -79,6 +78,21 @@ func (s *state1) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state1) 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 *miner1.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
|
||||
@ -162,60 +176,37 @@ func (s *state1) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (s *state1) LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) (adt.Array, error) {
|
||||
a, err := adt1.AsArray(s.store, s.State.Sectors)
|
||||
func (s *state1) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
||||
sectors, err := miner1.LoadSectors(s.store, s.State.Sectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := adt1.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 {
|
||||
include = false
|
||||
}
|
||||
// If no sector numbers are specified, load all.
|
||||
if snos == nil {
|
||||
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
||||
var info1 miner1.SectorOnChainInfo
|
||||
if err := sectors.ForEach(&info1, func(_ int64) error {
|
||||
info := fromV1SectorOnChainInfo(info1)
|
||||
infos = append(infos, &info)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if include {
|
||||
var oci miner1.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 infos, nil
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *state1) LoadPreCommittedSectors() (adt.Map, error) {
|
||||
return adt1.AsMap(s.store, s.State.PreCommittedSectors)
|
||||
// Otherwise, load selected.
|
||||
infos1, err := sectors.Load(*snos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos := make([]*SectorOnChainInfo, len(infos1))
|
||||
for i, info1 := range infos1 {
|
||||
info := fromV1SectorOnChainInfo(*info1)
|
||||
infos[i] = &info
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (s *state1) IsAllocated(num abi.SectorNumber) (bool, error) {
|
||||
@ -253,14 +244,14 @@ func (s *state1) NumDeadlines() (uint64, error) {
|
||||
return miner1.WPoStPeriodDeadlines, nil
|
||||
}
|
||||
|
||||
func (s *state1) DeadlinesChanged(other State) bool {
|
||||
func (s *state1) DeadlinesChanged(other State) (bool, error) {
|
||||
other1, ok := other.(*state1)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return s.State.Deadlines.Equals(other1.Deadlines)
|
||||
return s.State.Deadlines.Equals(other1.Deadlines), nil
|
||||
}
|
||||
|
||||
func (s *state1) Info() (MinerInfo, error) {
|
||||
@ -297,8 +288,8 @@ func (s *state1) Info() (MinerInfo, error) {
|
||||
return mi, nil
|
||||
}
|
||||
|
||||
func (s *state1) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info {
|
||||
return s.State.DeadlineInfo(epoch)
|
||||
func (s *state1) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
||||
return s.State.DeadlineInfo(epoch), nil
|
||||
}
|
||||
|
||||
func (s *state1) sectors() (adt.Array, error) {
|
||||
@ -312,8 +303,7 @@ func (s *state1) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo,
|
||||
return SectorOnChainInfo{}, err
|
||||
}
|
||||
|
||||
ret := fromV1SectorOnChainInfo(si)
|
||||
return ret, nil
|
||||
return fromV1SectorOnChainInfo(si), nil
|
||||
}
|
||||
|
||||
func (s *state1) precommits() (adt.Map, error) {
|
||||
@ -327,8 +317,7 @@ func (s *state1) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
|
||||
return SectorPreCommitOnChainInfo{}, err
|
||||
}
|
||||
|
||||
ret := fromV1SectorPreCommitOnChainInfo(sp)
|
||||
return ret, nil
|
||||
return fromV1SectorPreCommitOnChainInfo(sp), nil
|
||||
}
|
||||
|
||||
func (d *deadline1) LoadPartition(idx uint64) (Partition, error) {
|
||||
@ -350,14 +339,14 @@ func (d *deadline1) ForEachPartition(cb func(uint64, Partition) error) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (d *deadline1) PartitionsChanged(other Deadline) bool {
|
||||
func (d *deadline1) PartitionsChanged(other Deadline) (bool, error) {
|
||||
other1, ok := other.(*deadline1)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return d.Deadline.Partitions.Equals(other1.Deadline.Partitions)
|
||||
return d.Deadline.Partitions.Equals(other1.Deadline.Partitions), nil
|
||||
}
|
||||
|
||||
func (d *deadline1) PostSubmissions() (bitfield.BitField, error) {
|
||||
|
@ -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/v2/actors/builtin/multisig"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
msig1 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
adt1 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state1)(nil)
|
||||
|
||||
type state1 struct {
|
||||
multisig.State
|
||||
msig1.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
@ -17,14 +23,37 @@ func (s *state1) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error
|
||||
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
||||
}
|
||||
|
||||
func (s *state1) StartEpoch() abi.ChainEpoch {
|
||||
return s.State.StartEpoch
|
||||
func (s *state1) StartEpoch() (abi.ChainEpoch, error) {
|
||||
return s.State.StartEpoch, nil
|
||||
}
|
||||
|
||||
func (s *state1) UnlockDuration() abi.ChainEpoch {
|
||||
return s.State.UnlockDuration
|
||||
func (s *state1) UnlockDuration() (abi.ChainEpoch, error) {
|
||||
return s.State.UnlockDuration, nil
|
||||
}
|
||||
|
||||
func (s *state1) InitialBalance() abi.TokenAmount {
|
||||
return s.State.InitialBalance
|
||||
func (s *state1) InitialBalance() (abi.TokenAmount, error) {
|
||||
return s.State.InitialBalance, nil
|
||||
}
|
||||
|
||||
func (s *state1) Threshold() (uint64, error) {
|
||||
return s.State.NumApprovalsThreshold, nil
|
||||
}
|
||||
|
||||
func (s *state1) Signers() ([]address.Address, error) {
|
||||
return s.State.Signers, nil
|
||||
}
|
||||
|
||||
func (s *state1) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
||||
arr, err := adt1.AsMap(s.store, s.State.PendingTxns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var out msig1.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))
|
||||
})
|
||||
}
|
||||
|
@ -18,23 +18,23 @@ type state1 struct {
|
||||
}
|
||||
|
||||
// Channel owner, who has funded the actor
|
||||
func (s *state1) From() address.Address {
|
||||
return s.State.From
|
||||
func (s *state1) From() (address.Address, error) {
|
||||
return s.State.From, nil
|
||||
}
|
||||
|
||||
// Recipient of payouts from channel
|
||||
func (s *state1) To() address.Address {
|
||||
return s.State.To
|
||||
func (s *state1) To() (address.Address, error) {
|
||||
return s.State.To, nil
|
||||
}
|
||||
|
||||
// Height at which the channel can be `Collected`
|
||||
func (s *state1) SettlingAt() abi.ChainEpoch {
|
||||
return s.State.SettlingAt
|
||||
func (s *state1) SettlingAt() (abi.ChainEpoch, error) {
|
||||
return s.State.SettlingAt, nil
|
||||
}
|
||||
|
||||
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||
func (s *state1) ToSend() abi.TokenAmount {
|
||||
return s.State.ToSend
|
||||
func (s *state1) ToSend() (abi.TokenAmount, error) {
|
||||
return s.State.ToSend, nil
|
||||
}
|
||||
|
||||
func (s *state1) getOrLoadLsAmt() (*adt1.Array, error) {
|
||||
@ -82,10 +82,10 @@ type laneState1 struct {
|
||||
paych.LaneState
|
||||
}
|
||||
|
||||
func (ls *laneState1) Redeemed() big.Int {
|
||||
return ls.LaneState.Redeemed
|
||||
func (ls *laneState1) Redeemed() (big.Int, error) {
|
||||
return ls.LaneState.Redeemed, nil
|
||||
}
|
||||
|
||||
func (ls *laneState1) Nonce() uint64 {
|
||||
return ls.LaneState.Nonce
|
||||
func (ls *laneState1) Nonce() (uint64, error) {
|
||||
return ls.LaneState.Nonce, nil
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ 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/lotus/chain/actors/builtin"
|
||||
|
||||
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state0)(nil)
|
||||
@ -35,7 +37,7 @@ func (s *state0) TotalCommitted() (Claim, error) {
|
||||
}
|
||||
|
||||
func (s *state0) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||
claims, err := adt.AsMap(s.store, s.Claims)
|
||||
claims, err := adt0.AsMap(s.store, s.Claims)
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
@ -63,7 +65,7 @@ func (s *state0) MinerCounts() (uint64, uint64, error) {
|
||||
}
|
||||
|
||||
func (s *state0) ListAllMiners() ([]address.Address, error) {
|
||||
claims, err := adt.AsMap(s.store, s.Claims)
|
||||
claims, err := adt0.AsMap(s.store, s.Claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ 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/lotus/chain/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
|
||||
adt1 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
power1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power"
|
||||
)
|
||||
|
||||
@ -35,7 +37,7 @@ func (s *state1) TotalCommitted() (Claim, error) {
|
||||
}
|
||||
|
||||
func (s *state1) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||
claims, err := adt.AsMap(s.store, s.Claims)
|
||||
claims, err := adt1.AsMap(s.store, s.Claims)
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
@ -63,7 +65,7 @@ func (s *state1) MinerCounts() (uint64, uint64, error) {
|
||||
}
|
||||
|
||||
func (s *state1) ListAllMiners() ([]address.Address, error) {
|
||||
claims, err := adt.AsMap(s.store, s.Claims)
|
||||
claims, err := adt1.AsMap(s.store, s.Claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,17 +2,18 @@ package reward
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"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"
|
||||
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
||||
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
||||
)
|
||||
|
||||
var _ State = (*state0)(nil)
|
||||
|
||||
type state0 struct {
|
||||
reward.State
|
||||
reward0.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
@ -54,7 +55,7 @@ func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTot
|
||||
s.State.ThisEpochBaselinePower,
|
||||
networkTotalPledge,
|
||||
s.State.ThisEpochRewardSmoothed,
|
||||
&smoothing.FilterEstimate{
|
||||
&smoothing0.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
@ -63,7 +64,7 @@ func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTot
|
||||
|
||||
func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||
return miner0.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||
&smoothing.FilterEstimate{
|
||||
&smoothing0.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
|
@ -2,17 +2,18 @@ package reward
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
|
||||
miner1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
|
||||
"github.com/filecoin-project/specs-actors/v2/actors/util/smoothing"
|
||||
reward1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
|
||||
smoothing1 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing"
|
||||
)
|
||||
|
||||
var _ State = (*state1)(nil)
|
||||
|
||||
type state1 struct {
|
||||
reward.State
|
||||
reward1.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
@ -56,7 +57,7 @@ func (s *state1) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPle
|
||||
qaPower,
|
||||
s.State.ThisEpochBaselinePower,
|
||||
s.State.ThisEpochRewardSmoothed,
|
||||
smoothing.FilterEstimate{
|
||||
smoothing1.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
@ -66,7 +67,7 @@ func (s *state1) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPle
|
||||
|
||||
func (s *state1) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||
return miner1.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||
smoothing.FilterEstimate{
|
||||
smoothing1.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
|
46
chain/actors/builtin/verifreg/util.go
Normal file
46
chain/actors/builtin/verifreg/util.go
Normal file
@ -0,0 +1,46 @@
|
||||
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"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
"github.com/ipfs/go-cid"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func getDataCap(store adt.Store, ver builtin.Version, 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 := adt.AsMap(store, root, ver)
|
||||
if err != nil {
|
||||
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 addr: %w", err)
|
||||
} else if !found {
|
||||
return false, big.Zero(), nil
|
||||
}
|
||||
|
||||
return true, dcap, nil
|
||||
}
|
||||
|
||||
func forEachCap(store adt.Store, ver builtin.Version, root cid.Cid, cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
vh, err := adt.AsMap(store, root, ver)
|
||||
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)
|
||||
})
|
||||
}
|
@ -3,13 +3,11 @@ 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"
|
||||
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"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
||||
)
|
||||
|
||||
var _ State = (*state0)(nil)
|
||||
@ -19,53 +17,18 @@ type state0 struct {
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
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(store, root)
|
||||
if err != nil {
|
||||
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 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)
|
||||
return getDataCap(s.store, builtin.Version0, 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)
|
||||
})
|
||||
return getDataCap(s.store, builtin.Version0, s.State.Verifiers, addr)
|
||||
}
|
||||
|
||||
func (s *state0) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, s.State.Verifiers, cb)
|
||||
return forEachCap(s.store, builtin.Version0, 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)
|
||||
return forEachCap(s.store, builtin.Version0, s.State.VerifiedClients, cb)
|
||||
}
|
||||
|
@ -3,12 +3,11 @@ 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"
|
||||
adt1 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
verifreg1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
verifreg1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg"
|
||||
)
|
||||
|
||||
var _ State = (*state1)(nil)
|
||||
@ -19,21 +18,17 @@ type state1 struct {
|
||||
}
|
||||
|
||||
func (s *state1) 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 := adt1.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
|
||||
return getDataCap(s.store, builtin.Version1, s.State.VerifiedClients, addr)
|
||||
}
|
||||
|
||||
func (s *state1) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
return getDataCap(s.store, builtin.Version1, s.State.Verifiers, addr)
|
||||
}
|
||||
|
||||
func (s *state1) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, builtin.Version1, s.State.Verifiers, cb)
|
||||
}
|
||||
|
||||
func (s *state1) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, builtin.Version1, s.State.VerifiedClients, cb)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user