From 9f1bed0c3de122ea4f9173cc760fdbcead3c3492 Mon Sep 17 00:00:00 2001 From: Alex <445306+anorth@users.noreply.github.com> Date: Thu, 13 Jan 2022 11:01:26 +1100 Subject: [PATCH] Remove methods from FilterEstimate so struct can be aliased from prior versions (#1564) --- actors/builtin/cbor_gen.go | 237 ------------------ actors/builtin/miner/miner_actor.go | 2 +- actors/builtin/miner/miner_test.go | 2 +- actors/builtin/miner/monies.go | 6 +- actors/builtin/power/cbor_gen.go | 90 ------- actors/builtin/power/power_actor.go | 16 +- actors/builtin/reward/cbor_gen.go | 62 ----- actors/builtin/reward/reward_actor.go | 12 +- actors/builtin/shared.go | 28 +-- actors/util/smoothing/alpha_beta_filter.go | 36 +-- .../util/smoothing/alpha_beta_filter_test.go | 4 +- actors/util/smoothing/cbor_gen.go | 75 ------ gen/gen.go | 34 ++- 13 files changed, 70 insertions(+), 534 deletions(-) delete mode 100644 actors/builtin/cbor_gen.go delete mode 100644 actors/util/smoothing/cbor_gen.go diff --git a/actors/builtin/cbor_gen.go b/actors/builtin/cbor_gen.go deleted file mode 100644 index 973858694..000000000 --- a/actors/builtin/cbor_gen.go +++ /dev/null @@ -1,237 +0,0 @@ -// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. - -package builtin - -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 lengthBufConfirmSectorProofsParams = []byte{132} - -func (t *ConfirmSectorProofsParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufConfirmSectorProofsParams); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Sectors ([]abi.SectorNumber) (slice) - if len(t.Sectors) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Sectors was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Sectors))); err != nil { - return err - } - for _, v := range t.Sectors { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { - return err - } - } - - // t.RewardSmoothed (smoothing.FilterEstimate) (struct) - if err := t.RewardSmoothed.MarshalCBOR(w); err != nil { - return err - } - - // t.RewardBaselinePower (big.Int) (struct) - if err := t.RewardBaselinePower.MarshalCBOR(w); err != nil { - return err - } - - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - if err := t.QualityAdjPowerSmoothed.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *ConfirmSectorProofsParams) UnmarshalCBOR(r io.Reader) error { - *t = ConfirmSectorProofsParams{} - - 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 != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Sectors ([]abi.SectorNumber) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Sectors: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Sectors = make([]abi.SectorNumber, 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.Sectors slice: %w", err) - } - - if maj != cbg.MajUnsignedInt { - return xerrors.Errorf("value read for array t.Sectors was not a uint, instead got %d", maj) - } - - t.Sectors[i] = abi.SectorNumber(val) - } - - // t.RewardSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.RewardSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.RewardSmoothed: %w", err) - } - - } - // t.RewardBaselinePower (big.Int) (struct) - - { - - if err := t.RewardBaselinePower.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.RewardBaselinePower: %w", err) - } - - } - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.QualityAdjPowerSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.QualityAdjPowerSmoothed: %w", err) - } - - } - return nil -} - -var lengthBufDeferredCronEventParams = []byte{131} - -func (t *DeferredCronEventParams) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufDeferredCronEventParams); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.EventPayload ([]uint8) (slice) - if len(t.EventPayload) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.EventPayload was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.EventPayload))); err != nil { - return err - } - - if _, err := w.Write(t.EventPayload[:]); err != nil { - return err - } - - // t.RewardSmoothed (smoothing.FilterEstimate) (struct) - if err := t.RewardSmoothed.MarshalCBOR(w); err != nil { - return err - } - - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - if err := t.QualityAdjPowerSmoothed.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *DeferredCronEventParams) UnmarshalCBOR(r io.Reader) error { - *t = DeferredCronEventParams{} - - 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.EventPayload ([]uint8) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.EventPayload: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - - if extra > 0 { - t.EventPayload = make([]uint8, extra) - } - - if _, err := io.ReadFull(br, t.EventPayload[:]); err != nil { - return err - } - // t.RewardSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.RewardSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.RewardSmoothed: %w", err) - } - - } - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.QualityAdjPowerSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.QualityAdjPowerSmoothed: %w", err) - } - - } - return nil -} diff --git a/actors/builtin/miner/miner_actor.go b/actors/builtin/miner/miner_actor.go index 55821deb3..a7c0edefd 100644 --- a/actors/builtin/miner/miner_actor.go +++ b/actors/builtin/miner/miner_actor.go @@ -1917,7 +1917,7 @@ func (a Actor) ReportConsensusFault(rt Runtime, params *ReportConsensusFaultPara rewardStats := requestCurrentEpochBlockReward(rt) // The policy amounts we should burn and send to reporter // These may differ from actual funds send when miner goes into fee debt - thisEpochReward := rewardStats.ThisEpochRewardSmoothed.Estimate() + thisEpochReward := smoothing.Estimate(&rewardStats.ThisEpochRewardSmoothed) faultPenalty := ConsensusFaultPenalty(thisEpochReward) slasherReward := RewardForConsensusSlashReport(thisEpochReward) pledgeDelta := big.Zero() diff --git a/actors/builtin/miner/miner_test.go b/actors/builtin/miner/miner_test.go index d4be76384..6af3a4d90 100644 --- a/actors/builtin/miner/miner_test.go +++ b/actors/builtin/miner/miner_test.go @@ -4743,7 +4743,7 @@ func (h *actorHarness) reportConsensusFault(rt *mock.Runtime, from addr.Address, } rt.ExpectSend(builtin.RewardActorAddr, builtin.MethodsReward.ThisEpochReward, nil, big.Zero(), ¤tReward, exitcode.Ok) - thisEpochReward := h.epochRewardSmooth.Estimate() + thisEpochReward := smoothing.Estimate(&h.epochRewardSmooth) penaltyTotal := miner.ConsensusFaultPenalty(thisEpochReward) rewardTotal := miner.RewardForConsensusSlashReport(thisEpochReward) rt.ExpectSend(from, builtin.MethodSend, nil, rewardTotal, nil, exitcode.Ok) diff --git a/actors/builtin/miner/monies.go b/actors/builtin/miner/monies.go index f77c59c8a..8a2d58c76 100644 --- a/actors/builtin/miner/monies.go +++ b/actors/builtin/miner/monies.go @@ -74,9 +74,9 @@ var BasePenaltyForDisputedWindowPoSt = big.Mul(big.NewInt(20), builtin.TokenPrec // ProjectedRewardFraction(t) is the sum of estimated reward over estimated total power // over all epochs in the projection period [t t+projectionDuration] func ExpectedRewardForPower(rewardEstimate, networkQAPowerEstimate smoothing.FilterEstimate, qaSectorPower abi.StoragePower, projectionDuration abi.ChainEpoch) abi.TokenAmount { - networkQAPowerSmoothed := networkQAPowerEstimate.Estimate() + networkQAPowerSmoothed := smoothing.Estimate(&networkQAPowerEstimate) if networkQAPowerSmoothed.IsZero() { - return rewardEstimate.Estimate() + return smoothing.Estimate(&rewardEstimate) } expectedRewardForProvingPeriod := smoothing.ExtrapolatedCumSumOfRatio(projectionDuration, 0, rewardEstimate, networkQAPowerEstimate) br128 := big.Mul(qaSectorPower, expectedRewardForProvingPeriod) // Q.0 * Q.128 => Q.128 @@ -170,7 +170,7 @@ func InitialPledgeForPower(qaPower, baselinePower abi.StoragePower, rewardEstima lockTargetNum := big.Mul(InitialPledgeLockTarget.Numerator, circulatingSupply) lockTargetDenom := InitialPledgeLockTarget.Denominator pledgeShareNum := qaPower - networkQAPower := networkQAPowerEstimate.Estimate() + networkQAPower := smoothing.Estimate(&networkQAPowerEstimate) pledgeShareDenom := big.Max(big.Max(networkQAPower, baselinePower), qaPower) // use qaPower in case others are 0 additionalIPNum := big.Mul(lockTargetNum, pledgeShareNum) additionalIPDenom := big.Mul(lockTargetDenom, pledgeShareDenom) diff --git a/actors/builtin/power/cbor_gen.go b/actors/builtin/power/cbor_gen.go index 4510713d8..a1f3fdedc 100644 --- a/actors/builtin/power/cbor_gen.go +++ b/actors/builtin/power/cbor_gen.go @@ -537,93 +537,3 @@ func (t *CronEvent) UnmarshalCBOR(r io.Reader) error { } return nil } - -var lengthBufCurrentTotalPowerReturn = []byte{132} - -func (t *CurrentTotalPowerReturn) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufCurrentTotalPowerReturn); err != nil { - return err - } - - // t.RawBytePower (big.Int) (struct) - if err := t.RawBytePower.MarshalCBOR(w); err != nil { - return err - } - - // t.QualityAdjPower (big.Int) (struct) - if err := t.QualityAdjPower.MarshalCBOR(w); err != nil { - return err - } - - // t.PledgeCollateral (big.Int) (struct) - if err := t.PledgeCollateral.MarshalCBOR(w); err != nil { - return err - } - - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - if err := t.QualityAdjPowerSmoothed.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *CurrentTotalPowerReturn) UnmarshalCBOR(r io.Reader) error { - *t = CurrentTotalPowerReturn{} - - 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 != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.RawBytePower (big.Int) (struct) - - { - - if err := t.RawBytePower.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.RawBytePower: %w", err) - } - - } - // t.QualityAdjPower (big.Int) (struct) - - { - - if err := t.QualityAdjPower.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.QualityAdjPower: %w", err) - } - - } - // t.PledgeCollateral (big.Int) (struct) - - { - - if err := t.PledgeCollateral.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.PledgeCollateral: %w", err) - } - - } - // t.QualityAdjPowerSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.QualityAdjPowerSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.QualityAdjPowerSmoothed: %w", err) - } - - } - return nil -} diff --git a/actors/builtin/power/power_actor.go b/actors/builtin/power/power_actor.go index e9e3bad03..0688fede2 100644 --- a/actors/builtin/power/power_actor.go +++ b/actors/builtin/power/power_actor.go @@ -13,6 +13,7 @@ import ( power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power" + power6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/power" "github.com/ipfs/go-cid" "github.com/filecoin-project/specs-actors/v7/actors/builtin" @@ -21,7 +22,6 @@ import ( "github.com/filecoin-project/specs-actors/v7/actors/runtime" "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" "github.com/filecoin-project/specs-actors/v7/actors/util/adt" - "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing" ) type Runtime = runtime.Runtime @@ -310,13 +310,13 @@ func (a Actor) SubmitPoRepForBulkVerify(rt Runtime, sealInfo *proof.SealVerifyIn // Changed since v0: // - QualityAdjPowerSmoothed is not a pointer -// Not aliased to prior versions because smoothing.FilterEstimate is not pure data -type CurrentTotalPowerReturn struct { - RawBytePower abi.StoragePower - QualityAdjPower abi.StoragePower - PledgeCollateral abi.TokenAmount - QualityAdjPowerSmoothed smoothing.FilterEstimate -} +//type CurrentTotalPowerReturn struct { +// RawBytePower abi.StoragePower +// QualityAdjPower abi.StoragePower +// PledgeCollateral abi.TokenAmount +// QualityAdjPowerSmoothed smoothing.FilterEstimate +//} +type CurrentTotalPowerReturn = power6.CurrentTotalPowerReturn // Returns the total power and pledge recorded by the power actor. // The returned values are frozen during the cron tick before this epoch diff --git a/actors/builtin/reward/cbor_gen.go b/actors/builtin/reward/cbor_gen.go index 44557474c..73b775cb0 100644 --- a/actors/builtin/reward/cbor_gen.go +++ b/actors/builtin/reward/cbor_gen.go @@ -246,65 +246,3 @@ func (t *State) UnmarshalCBOR(r io.Reader) error { } return nil } - -var lengthBufThisEpochRewardReturn = []byte{130} - -func (t *ThisEpochRewardReturn) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufThisEpochRewardReturn); err != nil { - return err - } - - // t.ThisEpochRewardSmoothed (smoothing.FilterEstimate) (struct) - if err := t.ThisEpochRewardSmoothed.MarshalCBOR(w); err != nil { - return err - } - - // t.ThisEpochBaselinePower (big.Int) (struct) - if err := t.ThisEpochBaselinePower.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *ThisEpochRewardReturn) UnmarshalCBOR(r io.Reader) error { - *t = ThisEpochRewardReturn{} - - 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 != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.ThisEpochRewardSmoothed (smoothing.FilterEstimate) (struct) - - { - - if err := t.ThisEpochRewardSmoothed.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.ThisEpochRewardSmoothed: %w", err) - } - - } - // t.ThisEpochBaselinePower (big.Int) (struct) - - { - - if err := t.ThisEpochBaselinePower.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.ThisEpochBaselinePower: %w", err) - } - - } - return nil -} diff --git a/actors/builtin/reward/reward_actor.go b/actors/builtin/reward/reward_actor.go index 9513d0da1..97f3dc388 100644 --- a/actors/builtin/reward/reward_actor.go +++ b/actors/builtin/reward/reward_actor.go @@ -7,11 +7,11 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" rtt "github.com/filecoin-project/go-state-types/rt" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" + reward6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/reward" "github.com/ipfs/go-cid" "github.com/filecoin-project/specs-actors/v7/actors/builtin" "github.com/filecoin-project/specs-actors/v7/actors/runtime" - "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing" ) // PenaltyMultiplier is the factor miner penaltys are scaled up by @@ -134,11 +134,11 @@ func (a Actor) AwardBlockReward(rt runtime.Runtime, params *AwardBlockRewardPara // Changed since v0: // - removed ThisEpochReward (unsmoothed) -// This is not aliased to earlier version due to use of smoothing.FilterEstimate, which is not pure state. -type ThisEpochRewardReturn struct { - ThisEpochRewardSmoothed smoothing.FilterEstimate - ThisEpochBaselinePower abi.StoragePower -} +//type ThisEpochRewardReturn struct { +// ThisEpochRewardSmoothed smoothing.FilterEstimate +// ThisEpochBaselinePower abi.StoragePower +//} +type ThisEpochRewardReturn = reward6.ThisEpochRewardReturn // The award value used for the current epoch, updated at the end of an epoch // through cron tick. In the case previous epochs were null blocks this diff --git a/actors/builtin/shared.go b/actors/builtin/shared.go index a6bdead95..84be24a73 100644 --- a/actors/builtin/shared.go +++ b/actors/builtin/shared.go @@ -11,8 +11,8 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" "github.com/filecoin-project/specs-actors/v7/actors/runtime" - "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing" ) ///// Code shared by multiple built-in actors. ///// @@ -97,20 +97,20 @@ func RequestMinerControlAddrs(rt runtime.Runtime, minerAddr addr.Address) (owner //} type MinerAddrs = builtin0.MinerAddrs -// Not aliased to prior versions because smoothing.FilterEstimate is not pure data -type DeferredCronEventParams struct { - EventPayload []byte - RewardSmoothed smoothing.FilterEstimate - QualityAdjPowerSmoothed smoothing.FilterEstimate -} +//type DeferredCronEventParams struct { +// EventPayload []byte +// RewardSmoothed smoothing.FilterEstimate +// QualityAdjPowerSmoothed smoothing.FilterEstimate +//} +type DeferredCronEventParams = builtin6.DeferredCronEventParams -// Not aliased to prior versions because smoothing.FilterEstimate is not pure data -type ConfirmSectorProofsParams struct { - Sectors []abi.SectorNumber - RewardSmoothed smoothing.FilterEstimate - RewardBaselinePower abi.StoragePower - QualityAdjPowerSmoothed smoothing.FilterEstimate -} +//type ConfirmSectorProofsParams struct { +// Sectors []abi.SectorNumber +// RewardSmoothed smoothing.FilterEstimate +// RewardBaselinePower abi.StoragePower +// QualityAdjPowerSmoothed smoothing.FilterEstimate +//} +type ConfirmSectorProofsParams = builtin6.ConfirmSectorProofsParams // ResolveToIDAddr resolves the given address to it's ID address form. // If an ID address for the given address dosen't exist yet, it tries to create one by sending a zero balance to the given address. diff --git a/actors/util/smoothing/alpha_beta_filter.go b/actors/util/smoothing/alpha_beta_filter.go index c03a6c01c..ca3ec3b68 100644 --- a/actors/util/smoothing/alpha_beta_filter.go +++ b/actors/util/smoothing/alpha_beta_filter.go @@ -3,6 +3,7 @@ package smoothing import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + smoothing6 "github.com/filecoin-project/specs-actors/v6/actors/util/smoothing" "github.com/filecoin-project/specs-actors/v7/actors/util/math" ) @@ -36,16 +37,29 @@ func init() { // Alpha Beta Filter "position" (value) and "velocity" (rate of change of value) estimates // Estimates are in Q.128 format -type FilterEstimate struct { - PositionEstimate big.Int // Q.128 - VelocityEstimate big.Int // Q.128 -} +//type FilterEstimate struct { +// PositionEstimate big.Int // Q.128 +// VelocityEstimate big.Int // Q.128 +//} +type FilterEstimate = smoothing6.FilterEstimate // Returns the Q.0 position estimate of the filter -func (fe *FilterEstimate) Estimate() big.Int { +func Estimate(fe *FilterEstimate) big.Int { return big.Rsh(fe.PositionEstimate, math.Precision128) // Q.128 => Q.0 } +// Extrapolate filter "position" delta epochs in the future. +// Note this is currently only used in testing. +// Output is Q.256 format for use in numerator of ratio in test caller +func Extrapolate(fe *FilterEstimate, delta abi.ChainEpoch) big.Int { + deltaT := big.NewInt(int64(delta)) // Q.0 + deltaT = big.Lsh(deltaT, math.Precision128) // Q.0 => Q.128 + extrapolation := big.Mul(fe.VelocityEstimate, deltaT) // Q.128 * Q.128 => Q.256 + position := big.Lsh(fe.PositionEstimate, math.Precision128) // Q.128 => Q.256 + extrapolation = big.Sum(position, extrapolation) + return extrapolation // Q.256 +} + func DefaultInitialEstimate() FilterEstimate { return FilterEstimate{ PositionEstimate: defaultInitialPosition, @@ -148,15 +162,3 @@ func ExtrapolatedCumSumOfRatio(delta abi.ChainEpoch, relativeStart abi.ChainEpoc return cumsumRatio } - -// Extrapolate filter "position" delta epochs in the future. -// Note this is currently only used in testing. -// Output is Q.256 format for use in numerator of ratio in test caller -func (fe *FilterEstimate) Extrapolate(delta abi.ChainEpoch) big.Int { - deltaT := big.NewInt(int64(delta)) // Q.0 - deltaT = big.Lsh(deltaT, math.Precision128) // Q.0 => Q.128 - extrapolation := big.Mul(fe.VelocityEstimate, deltaT) // Q.128 * Q.128 => Q.256 - position := big.Lsh(fe.PositionEstimate, math.Precision128) // Q.128 => Q.256 - extrapolation = big.Sum(position, extrapolation) - return extrapolation // Q.256 -} diff --git a/actors/util/smoothing/alpha_beta_filter_test.go b/actors/util/smoothing/alpha_beta_filter_test.go index 13f435371..2f2c58f02 100644 --- a/actors/util/smoothing/alpha_beta_filter_test.go +++ b/actors/util/smoothing/alpha_beta_filter_test.go @@ -44,8 +44,8 @@ func TestCumSumRatioProjection(t *testing.T) { iterativeCumSumOfRatio := func(num, denom smoothing.FilterEstimate, t0, delta abi.ChainEpoch) big.Int { ratio := big.Zero() // Q.128 for i := abi.ChainEpoch(0); i < delta; i++ { - numEpsilon := num.Extrapolate(t0 + i) // Q.256 - denomEpsilon := denom.Extrapolate(t0 + i) // Q.256 + numEpsilon := smoothing.Extrapolate(&num, t0+i) // Q.256 + denomEpsilon := smoothing.Extrapolate(&denom, t0+i) // Q.256 denomEpsilon = big.Rsh(denomEpsilon, math.Precision128) // Q.256 => Q.128 epsilon := big.Div(numEpsilon, denomEpsilon) // Q.256 / Q.128 => Q.128 if i != abi.ChainEpoch(0) && i != delta-1 { diff --git a/actors/util/smoothing/cbor_gen.go b/actors/util/smoothing/cbor_gen.go deleted file mode 100644 index c7742efa1..000000000 --- a/actors/util/smoothing/cbor_gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. - -package smoothing - -import ( - "fmt" - "io" - - cbg "github.com/whyrusleeping/cbor-gen" - xerrors "golang.org/x/xerrors" -) - -var _ = xerrors.Errorf - -var lengthBufFilterEstimate = []byte{130} - -func (t *FilterEstimate) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufFilterEstimate); err != nil { - return err - } - - // t.PositionEstimate (big.Int) (struct) - if err := t.PositionEstimate.MarshalCBOR(w); err != nil { - return err - } - - // t.VelocityEstimate (big.Int) (struct) - if err := t.VelocityEstimate.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *FilterEstimate) UnmarshalCBOR(r io.Reader) error { - *t = FilterEstimate{} - - 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 != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.PositionEstimate (big.Int) (struct) - - { - - if err := t.PositionEstimate.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.PositionEstimate: %w", err) - } - - } - // t.VelocityEstimate (big.Int) (struct) - - { - - if err := t.VelocityEstimate.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.VelocityEstimate: %w", err) - } - - } - return nil -} diff --git a/gen/gen.go b/gen/gen.go index 360b12c67..0c03c2a84 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -1,7 +1,6 @@ package main import ( - "github.com/filecoin-project/specs-actors/v7/actors/builtin" gen "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/specs-actors/v7/actors/builtin/account" @@ -16,7 +15,6 @@ import ( "github.com/filecoin-project/specs-actors/v7/actors/builtin/system" "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing" "github.com/filecoin-project/specs-actors/v7/support/vm" ) @@ -33,14 +31,14 @@ func main() { panic(err) } - if err := gen.WriteTupleEncodersToFile("./actors/builtin/cbor_gen.go", "builtin", - //builtin.MinerAddrs{}, // Aliased from v0 - builtin.ConfirmSectorProofsParams{}, // Not pure data - builtin.DeferredCronEventParams{}, // Not pure data - // builtin.ApplyRewardParams{}, // Aliased from v2 - ); err != nil { - panic(err) - } + //if err := gen.WriteTupleEncodersToFile("./actors/builtin/cbor_gen.go", "builtin", + // //builtin.MinerAddrs{}, // Aliased from v0 + // //builtin.ConfirmSectorProofsParams{}, // Aliased from v6 + // //builtin.DeferredCronEventParams{}, // Aliased from v6 + // //builtin.ApplyRewardParams{}, // Aliased from v2 + //); err != nil { + // panic(err) + //} // if err := gen.WriteTupleEncodersToFile("./actors/states/cbor_gen.go", "states", // states.Actor{}, // Aliased from v0 @@ -89,7 +87,7 @@ func main() { reward.State{}, // method params and returns //reward.AwardBlockRewardParams{}, // Aliased from v0 - reward.ThisEpochRewardReturn{}, // Not pure data + //reward.ThisEpochRewardReturn{}, // Aliased from v6 ); err != nil { panic(err) } @@ -139,7 +137,7 @@ func main() { //power.CreateMinerReturn{}, // Aliased from v0 //power.EnrollCronEventParams{}, // Aliased from v0 //power.UpdateClaimedPowerParams{}, // Aliased from v0 - power.CurrentTotalPowerReturn{}, // Not pure data + //power.CurrentTotalPowerReturn{}, // Aliased from v6 // other types //power.MinerConstructorParams{}, // Aliased from v3 ); err != nil { @@ -149,6 +147,7 @@ func main() { if err := gen.WriteTupleEncodersToFile("./actors/builtin/market/cbor_gen.go", "market", // actor state market.State{}, + market.DealState{}, // method params and returns //market.WithdrawBalanceParams{}, // Aliased from v0 // market.PublishStorageDealsParams{}, // Aliased from v0 @@ -165,7 +164,6 @@ func main() { //market.SectorDeals{}, // Aliased from v3 //market.SectorWeights{}, // Aliased from v3 //market.SectorDataSpec{}, // Aliased from v5 - market.DealState{}, ); err != nil { panic(err) } @@ -239,11 +237,11 @@ func main() { panic(err) } - if err := gen.WriteTupleEncodersToFile("./actors/util/smoothing/cbor_gen.go", "smoothing", - smoothing.FilterEstimate{}, // Not pure data - ); err != nil { - panic(err) - } + //if err := gen.WriteTupleEncodersToFile("./actors/util/smoothing/cbor_gen.go", "smoothing", + // //smoothing.FilterEstimate{}, // Aliased from v0 + //); err != nil { + // panic(err) + //} // Support if err := gen.WriteTupleEncodersToFile("./support/vm/cbor_gen.go", "vm",