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

fixing #799 (passing in data for confirmSectorProofValid) #1480

Merged
merged 12 commits into from
Sep 23, 2021
148 changes: 148 additions & 0 deletions actors/builtin/cbor_gen.go

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

45 changes: 35 additions & 10 deletions actors/builtin/miner/miner_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,10 @@ func (a Actor) ProveCommitAggregate(rt Runtime, params *ProveCommitAggregatePara
AggregateProof: abi.RegisteredAggregationProof_SnarkPackV1,
})
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalArgument, "aggregate seal verify failed")
confirmSectorProofsValid(rt, precommitsToConfirm)

confirmSectorProofsValid(rt, precommitsToConfirm, &builtin.ConfirmSectorProofsParams{
PrecomputeRewardPowerStats: false,
})

// Compute and burn the aggregate network fee. We need to re-load the state as
// confirmSectorProofsValid can change it.
Expand Down Expand Up @@ -1061,15 +1064,33 @@ 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)
confirmSectorProofsValid(rt, precommittedSectors, params)

return nil
}

func confirmSectorProofsValid(rt Runtime, preCommits []*SectorPreCommitOnChainInfo) {
// get network stats from other actors
rewardStats := requestCurrentEpochBlockReward(rt)
pwrTotal := requestCurrentTotalPower(rt)
func confirmSectorProofsValid(rt Runtime, preCommits []*SectorPreCommitOnChainInfo, params *builtin.ConfirmSectorProofsParams) {
var rewardStatsThisEpochBaselinePower big.Int
var rewardStatsThisEpochRewardSmoothed smoothing.FilterEstimate
var pwrTotalQualityAdjPowerSmoothed smoothing.FilterEstimate

if params.PrecomputeRewardPowerStats {
laudiacay marked this conversation as resolved.
Show resolved Hide resolved
rewardStatsThisEpochRewardSmoothed = params.RewardStatsThisEpochRewardSmoothed
rewardStatsThisEpochBaselinePower = params.RewardStatsThisEpochBaselinePower
pwrTotalQualityAdjPowerSmoothed = params.PwrTotalQualityAdjPowerSmoothed
} else {
var rewret reward.ThisEpochRewardReturn
rewretcode := rt.Send(builtin.RewardActorAddr, builtin.MethodsReward.ThisEpochReward, nil, big.Zero(), &rewret)
builtin.RequireSuccess(rt, rewretcode, "failed to check epoch baseline power")
var pwr power.CurrentTotalPowerReturn
powretcode := rt.Send(builtin.StoragePowerActorAddr, builtin.MethodsPower.CurrentTotalPower, nil, big.Zero(), &pwr)
builtin.RequireSuccess(rt, powretcode, "failed to check current power")

rewardStatsThisEpochRewardSmoothed = rewret.ThisEpochRewardSmoothed
rewardStatsThisEpochBaselinePower = rewret.ThisEpochBaselinePower
pwrTotalQualityAdjPowerSmoothed = pwr.QualityAdjPowerSmoothed
}

circulatingSupply := rt.TotalFilCircSupply()

// 1. Activate deals, skipping pre-commits with invalid deals.
Expand Down Expand Up @@ -1152,13 +1173,14 @@ func confirmSectorProofsValid(rt Runtime, preCommits []*SectorPreCommitOnChainIn
continue
}
pwr := QAPowerForWeight(info.SectorSize, duration, precommit.DealWeight, precommit.VerifiedDealWeight)
dayReward := ExpectedRewardForPower(rewardStats.ThisEpochRewardSmoothed, pwrTotal.QualityAdjPowerSmoothed, pwr, builtin.EpochsInDay)

dayReward := ExpectedRewardForPower(rewardStatsThisEpochRewardSmoothed, pwrTotalQualityAdjPowerSmoothed, pwr, builtin.EpochsInDay)
// The storage pledge is recorded for use in computing the penalty if this sector is terminated
// before its declared expiration.
// It's not capped to 1 FIL, so can exceed the actual initial pledge requirement.
storagePledge := ExpectedRewardForPower(rewardStats.ThisEpochRewardSmoothed, pwrTotal.QualityAdjPowerSmoothed, pwr, InitialPledgeProjectionPeriod)
initialPledge := InitialPledgeForPower(pwr, rewardStats.ThisEpochBaselinePower, rewardStats.ThisEpochRewardSmoothed,
pwrTotal.QualityAdjPowerSmoothed, circulatingSupply)
storagePledge := ExpectedRewardForPower(rewardStatsThisEpochRewardSmoothed, pwrTotalQualityAdjPowerSmoothed, pwr, InitialPledgeProjectionPeriod)
initialPledge := InitialPledgeForPower(pwr, rewardStatsThisEpochBaselinePower, rewardStatsThisEpochRewardSmoothed,
pwrTotalQualityAdjPowerSmoothed, circulatingSupply)

// Lower-bound the pledge by that of the sector being replaced.
// Record the replaced age and reward rate for termination fee calculations.
Expand Down Expand Up @@ -2104,6 +2126,9 @@ 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
// TODO #2: for the fix to issue 799 we precompute these in OnEpochTickEnd and
laudiacay marked this conversation as resolved.
Show resolved Hide resolved
// pass them in to another function. perhaps could do that here too?
// but unsure with above TODO.
rewardStats := requestCurrentEpochBlockReward(rt)
pwrTotal := requestCurrentTotalPower(rt)

Expand Down
18 changes: 12 additions & 6 deletions actors/builtin/miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5073,7 +5073,7 @@ func (h *actorHarness) proveCommitAggregateSector(rt *mock.Runtime, conf proveCo

// confirmSectorProofsValid
{
h.confirmSectorProofsValidInternal(rt, conf, precommits...)
h.confirmSectorProofsValidInternal(rt, conf, false, precommits...)
}

// burn networkFee
Expand All @@ -5088,9 +5088,11 @@ func (h *actorHarness) proveCommitAggregateSector(rt *mock.Runtime, conf proveCo
rt.Verify()
}

func (h *actorHarness) confirmSectorProofsValidInternal(rt *mock.Runtime, conf proveCommitConf, precommits ...*miner.SectorPreCommitOnChainInfo) {
// expect calls to get network stats
expectQueryNetworkInfo(rt, h)
func (h *actorHarness) confirmSectorProofsValidInternal(rt *mock.Runtime, conf proveCommitConf, isPrecomputed bool, precommits ...*miner.SectorPreCommitOnChainInfo) {
// expect calls to get network stats if we haven't precomputed
if !isPrecomputed {
expectQueryNetworkInfo(rt, h)
}

// Prepare for and receive call to ConfirmSectorProofsValid.
var validPrecommits []*miner.SectorPreCommitOnChainInfo
Expand Down Expand Up @@ -5145,14 +5147,18 @@ func (h *actorHarness) confirmSectorProofsValidInternal(rt *mock.Runtime, conf p
}

func (h *actorHarness) confirmSectorProofsValid(rt *mock.Runtime, conf proveCommitConf, precommits ...*miner.SectorPreCommitOnChainInfo) {
h.confirmSectorProofsValidInternal(rt, conf, precommits...)
h.confirmSectorProofsValidInternal(rt, conf, false, precommits...)
var allSectorNumbers []abi.SectorNumber
for _, precommit := range precommits {
allSectorNumbers = append(allSectorNumbers, precommit.Info.SectorNumber)
}
rt.SetCaller(builtin.StoragePowerActorAddr, builtin.StoragePowerActorCodeID)
rt.ExpectValidateCallerAddr(builtin.StoragePowerActorAddr)
rt.Call(h.a.ConfirmSectorProofsValid, &builtin.ConfirmSectorProofsParams{Sectors: allSectorNumbers})

rt.Call(h.a.ConfirmSectorProofsValid, &builtin.ConfirmSectorProofsParams{
Sectors: allSectorNumbers,
PrecomputeRewardPowerStats: false,
})
rt.Verify()
}

Expand Down
18 changes: 17 additions & 1 deletion actors/builtin/power/power_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/exitcode"
rtt "github.com/filecoin-project/go-state-types/rt"

//"github.com/filecoin-project/specs-actors/actors/builtin/power"
laudiacay marked this conversation as resolved.
Show resolved Hide resolved

power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/specs-actors/v6/actors/builtin"
initact "github.com/filecoin-project/specs-actors/v6/actors/builtin/init"
"github.com/filecoin-project/specs-actors/v6/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/v6/actors/runtime"
"github.com/filecoin-project/specs-actors/v6/actors/runtime/proof"
"github.com/filecoin-project/specs-actors/v6/actors/util/adt"
Expand Down Expand Up @@ -386,6 +390,14 @@ func (a Actor) processBatchProofVerifies(rt Runtime) {
res, err := rt.BatchVerifySeals(verifies)
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to batch verify")

var rewret reward.ThisEpochRewardReturn
rewretcode := rt.Send(builtin.RewardActorAddr, builtin.MethodsReward.ThisEpochReward, nil, big.Zero(), &rewret)
builtin.RequireSuccess(rt, rewretcode, "failed to check epoch baseline power")

var pwr CurrentTotalPowerReturn
powretcode := rt.Send(builtin.StoragePowerActorAddr, builtin.MethodsPower.CurrentTotalPower, nil, big.Zero(), &pwr)
laudiacay marked this conversation as resolved.
Show resolved Hide resolved
builtin.RequireSuccess(rt, powretcode, "failed to check current power")

for _, m := range miners {
vres, ok := res[m]
if !ok {
Expand Down Expand Up @@ -415,7 +427,11 @@ func (a Actor) processBatchProofVerifies(rt Runtime) {
_ = rt.Send(
m,
builtin.MethodsMiner.ConfirmSectorProofsValid,
&builtin.ConfirmSectorProofsParams{Sectors: successful},
&builtin.ConfirmSectorProofsParams{Sectors: successful,
laudiacay marked this conversation as resolved.
Show resolved Hide resolved
PrecomputeRewardPowerStats: true,
RewardStatsThisEpochRewardSmoothed: rewret.ThisEpochRewardSmoothed,
RewardStatsThisEpochBaselinePower: rewret.ThisEpochBaselinePower,
PwrTotalQualityAdjPowerSmoothed: pwr.QualityAdjPowerSmoothed},
abi.NewTokenAmount(0),
&builtin.Discard{},
)
Expand Down
Loading