Abstract SectorOnChainInfo and SectorPreCommitOnChainInfo

This commit is contained in:
Aayush Rajasekaran 2020-09-20 17:53:46 -04:00
parent b25dd2a00d
commit ed285f1114
6 changed files with 56 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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