Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Fix #1486 (#1489)
Browse files Browse the repository at this point in the history
* two more failing tests but otherwise working
* code review? code reviewed.
* tests passin\'
* https://www.youtube.com/watch?v=W1i4mTyidOc check pass
* found the source of the cbor errors.... forgot about gen.go.
* fixes for code review
* bump determinism hash
Co-authored-by: ZenGround0 <[email protected]>
  • Loading branch information
laudiacay authored Oct 1, 2021
1 parent 12dfdc3 commit ea6fa6b
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 136 deletions.
128 changes: 113 additions & 15 deletions actors/builtin/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 27 additions & 26 deletions actors/builtin/miner/miner_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,10 @@ func (a Actor) ProveCommitAggregate(rt Runtime, params *ProveCommitAggregatePara
})
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalArgument, "aggregate seal verify failed")

rewret := requestCurrentEpochBlockReward(rt)
rew := requestCurrentEpochBlockReward(rt)
pwr := requestCurrentTotalPower(rt)

confirmSectorProofsValid(rt, precommitsToConfirm, rewret.ThisEpochBaselinePower, rewret.ThisEpochRewardSmoothed, pwr.QualityAdjPowerSmoothed)
confirmSectorProofsValid(rt, precommitsToConfirm, rew.ThisEpochBaselinePower, rew.ThisEpochRewardSmoothed, pwr.QualityAdjPowerSmoothed)

// Compute and burn the aggregate network fee. We need to re-load the state as
// confirmSectorProofsValid can change it.
Expand Down Expand Up @@ -1065,8 +1065,7 @@ func (a Actor) ConfirmSectorProofsValid(rt Runtime, params *builtin.ConfirmSecto
precommittedSectors, err := st.FindPrecommittedSectors(store, params.Sectors...)
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to load pre-committed sectors")

confirmSectorProofsValid(rt, precommittedSectors, params.RewardStatsThisEpochBaselinePower,
params.RewardStatsThisEpochRewardSmoothed, params.PwrTotalQualityAdjPowerSmoothed)
confirmSectorProofsValid(rt, precommittedSectors, params.RewardBaselinePower, params.RewardSmoothed, params.QualityAdjPowerSmoothed)

return nil
}
Expand Down Expand Up @@ -1550,8 +1549,11 @@ func (a Actor) TerminateSectors(rt Runtime, params *TerminateSectorsParams) *Ter
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to save deadlines")
})

epochReward := requestCurrentEpochBlockReward(rt)
pwrTotal := requestCurrentTotalPower(rt)

// Now, try to process these sectors.
more := processEarlyTerminations(rt)
more := processEarlyTerminations(rt, epochReward.ThisEpochRewardSmoothed, pwrTotal.QualityAdjPowerSmoothed)
if more && !hadEarlyTerminations {
// We have remaining terminations, and we didn't _previously_
// have early terminations to process, schedule a cron job.
Expand Down Expand Up @@ -2096,23 +2098,27 @@ const (
CronEventProcessEarlyTerminations = miner0.CronEventProcessEarlyTerminations
)

func (a Actor) OnDeferredCronEvent(rt Runtime, payload *CronEventPayload) *abi.EmptyValue {
func (a Actor) OnDeferredCronEvent(rt Runtime, params *builtin.DeferredCronEventParams) *abi.EmptyValue {
rt.ValidateImmediateCallerIs(builtin.StoragePowerActorAddr)

var payload miner0.CronEventPayload
err := payload.UnmarshalCBOR(bytes.NewBuffer(params.EventPayload))
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to unmarshal miner cron payload into expected structure")

switch payload.EventType {
case CronEventProvingDeadline:
handleProvingDeadline(rt)
handleProvingDeadline(rt, params.RewardSmoothed, params.QualityAdjPowerSmoothed)
case CronEventProcessEarlyTerminations:
if processEarlyTerminations(rt) {
if processEarlyTerminations(rt, params.RewardSmoothed, params.QualityAdjPowerSmoothed) {
scheduleEarlyTerminationWork(rt)
}
default:
rt.Log(rtt.ERROR, "unhandled payload EventType in OnDeferredCronEvent")
rt.Log(rtt.ERROR, "onDeferredCronEvent invalid event type: %v", payload.EventType)
}

var st State
rt.StateReadonly(&st)
err := st.CheckBalanceInvariants(rt.CurrentBalance())
err = st.CheckBalanceInvariants(rt.CurrentBalance())
builtin.RequireNoErr(rt, err, ErrBalanceInvariantBroken, "balance invariants broken")
return nil
}
Expand All @@ -2121,15 +2127,12 @@ func (a Actor) OnDeferredCronEvent(rt Runtime, payload *CronEventPayload) *abi.E
// Utility functions & helpers
////////////////////////////////////////////////////////////////////////////////

func processEarlyTerminations(rt Runtime) (more bool) {
// TODO: We're using the current power+epoch reward. Technically, we
// should use the power/reward at the time of termination.
// https://github.com/filecoin-project/specs-actors/v6/pull/648
func processEarlyTerminations(rt Runtime, rewardSmoothed smoothing.FilterEstimate, qualityAdjPowerSmoothed smoothing.FilterEstimate) (more bool) {
store := adt.AsStore(rt)

// TODO: We're using the current power+epoch reward. Technically, we
// should use the power/reward at the time of termination.
// https://github.com/filecoin-project/specs-actors/v6/pull/648
rewardStats := requestCurrentEpochBlockReward(rt)
pwrTotal := requestCurrentTotalPower(rt)

var (
result TerminationResult
dealsToTerminate []market.OnMinerSectorsTerminateParams
Expand Down Expand Up @@ -2170,7 +2173,7 @@ func processEarlyTerminations(rt Runtime) (more bool) {
totalInitialPledge = big.Add(totalInitialPledge, sector.InitialPledge)
}
penalty = big.Add(penalty, terminationPenalty(info.SectorSize, epoch,
rewardStats.ThisEpochRewardSmoothed, pwrTotal.QualityAdjPowerSmoothed, sectors))
rewardSmoothed, qualityAdjPowerSmoothed, sectors))
dealsToTerminate = append(dealsToTerminate, params)

return nil
Expand Down Expand Up @@ -2215,13 +2218,12 @@ func processEarlyTerminations(rt Runtime) (more bool) {
}

// Invoked at the end of the last epoch for each proving deadline.
func handleProvingDeadline(rt Runtime) {
func handleProvingDeadline(rt Runtime,
rewardSmoothed smoothing.FilterEstimate,
qualityAdjPowerSmoothed smoothing.FilterEstimate) {
currEpoch := rt.CurrEpoch()
store := adt.AsStore(rt)

epochReward := requestCurrentEpochBlockReward(rt)
pwrTotal := requestCurrentTotalPower(rt)

hadEarlyTerminations := false

powerDeltaTotal := NewPowerPairZero()
Expand Down Expand Up @@ -2265,8 +2267,8 @@ func handleProvingDeadline(rt Runtime) {
// Faults detected by this missed PoSt pay no penalty, but sectors that were already faulty
// and remain faulty through this deadline pay the fault fee.
penaltyTarget := PledgePenaltyForContinuedFault(
epochReward.ThisEpochRewardSmoothed,
pwrTotal.QualityAdjPowerSmoothed,
rewardSmoothed,
qualityAdjPowerSmoothed,
result.PreviouslyFaultyPower.QA,
)

Expand All @@ -2287,7 +2289,6 @@ func handleProvingDeadline(rt Runtime) {
st.DeadlineCronActive = false
}
})

// Remove power for new faults, and burn penalties.
requestUpdatePower(rt, powerDeltaTotal)
burnFunds(rt, penaltyTotal)
Expand All @@ -2310,7 +2311,7 @@ func handleProvingDeadline(rt Runtime) {
// handle them at the next epoch.
if !hadEarlyTerminations && hasEarlyTerminations {
// First, try to process some of these terminations.
if processEarlyTerminations(rt) {
if processEarlyTerminations(rt, rewardSmoothed, qualityAdjPowerSmoothed) {
// If that doesn't work, just defer till the next epoch.
scheduleEarlyTerminationWork(rt)
}
Expand Down
33 changes: 12 additions & 21 deletions actors/builtin/miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5153,10 +5153,10 @@ func (h *actorHarness) confirmSectorProofsValid(rt *mock.Runtime, conf proveComm
rt.ExpectValidateCallerAddr(builtin.StoragePowerActorAddr)

rt.Call(h.a.ConfirmSectorProofsValid, &builtin.ConfirmSectorProofsParams{
Sectors: allSectorNumbers,
RewardStatsThisEpochRewardSmoothed: h.epochRewardSmooth,
RewardStatsThisEpochBaselinePower: h.baselinePower,
PwrTotalQualityAdjPowerSmoothed: h.epochQAPowerSmooth,
Sectors: allSectorNumbers,
RewardSmoothed: h.epochRewardSmooth,
RewardBaselinePower: h.baselinePower,
QualityAdjPowerSmoothed: h.epochQAPowerSmooth,
})
rt.Verify()
}
Expand Down Expand Up @@ -5776,21 +5776,6 @@ func (h *actorHarness) onDeadlineCron(rt *mock.Runtime, config *cronConfig) {
rt.ExpectValidateCallerAddr(builtin.StoragePowerActorAddr)

// Preamble
rwd := reward.ThisEpochRewardReturn{
ThisEpochBaselinePower: h.baselinePower,
ThisEpochRewardSmoothed: h.epochRewardSmooth,
}
rt.ExpectSend(builtin.RewardActorAddr, builtin.MethodsReward.ThisEpochReward, nil, big.Zero(), &rwd, exitcode.Ok)
networkPower := big.NewIntUnsigned(1 << 50)
rt.ExpectSend(builtin.StoragePowerActorAddr, builtin.MethodsPower.CurrentTotalPower, nil, big.Zero(),
&power.CurrentTotalPowerReturn{
RawBytePower: networkPower,
QualityAdjPower: networkPower,
PledgeCollateral: h.networkPledge,
QualityAdjPowerSmoothed: h.epochQAPowerSmooth,
},
exitcode.Ok)

powerDelta := miner.NewPowerPairZero()
if config.detectedFaultsPowerDelta != nil {
powerDelta = powerDelta.Add(*config.detectedFaultsPowerDelta)
Expand Down Expand Up @@ -5852,9 +5837,15 @@ func (h *actorHarness) onDeadlineCron(rt *mock.Runtime, config *cronConfig) {
makeDeadlineCronEventParams(h.t, config.expectedEnrollment), big.Zero(), nil, exitcode.Ok)
}

eventPayloadBuf := bytes.Buffer{}
payload := &miner0.CronEventPayload{EventType: miner.CronEventProvingDeadline}
require.NoError(h.t, payload.MarshalCBOR(&eventPayloadBuf), "failed to marshal event payload")

rt.SetCaller(builtin.StoragePowerActorAddr, builtin.StoragePowerActorCodeID)
rt.Call(h.a.OnDeferredCronEvent, &miner.CronEventPayload{
EventType: miner.CronEventProvingDeadline,
rt.Call(h.a.OnDeferredCronEvent, &builtin.DeferredCronEventParams{
EventPayload: eventPayloadBuf.Bytes(),
RewardSmoothed: h.epochRewardSmooth,
QualityAdjPowerSmoothed: h.epochQAPowerSmooth,
})
rt.Verify()
}
Expand Down
Loading

0 comments on commit ea6fa6b

Please sign in to comment.