From e586232e299143205d5b4143bed46e560dc4d982 Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Sun, 26 Sep 2021 16:17:28 -0400 Subject: [PATCH] Tests pass --- actors/builtin/miner/miner_commitment_test.go | 24 ++++++++++++++----- actors/builtin/miner/miner_test.go | 9 ++++--- actors/test/commit_post_test.go | 14 +++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/actors/builtin/miner/miner_commitment_test.go b/actors/builtin/miner/miner_commitment_test.go index 3626685ee..f25b4dbd0 100644 --- a/actors/builtin/miner/miner_commitment_test.go +++ b/actors/builtin/miner/miner_commitment_test.go @@ -440,6 +440,7 @@ func TestPreCommitBatch(t *testing.T) { name string batchSize int balanceSurplus abi.TokenAmount + baseFee abi.TokenAmount deals []dealSpec exit exitcode.ExitCode error string @@ -447,14 +448,17 @@ func TestPreCommitBatch(t *testing.T) { name: "one sector", batchSize: 1, balanceSurplus: big.Zero(), + baseFee: big.Zero(), }, { name: "max sectors", batchSize: 32, balanceSurplus: big.Zero(), + baseFee: big.Zero(), }, { name: "one deal", batchSize: 3, balanceSurplus: big.Zero(), + baseFee: big.Zero(), deals: []dealSpec{{ size: 32 << 30, verifiedSize: 0, @@ -464,6 +468,7 @@ func TestPreCommitBatch(t *testing.T) { name: "many deals", batchSize: 3, balanceSurplus: big.Zero(), + baseFee: big.Zero(), deals: []dealSpec{{ size: 32 << 30, verifiedSize: 0, @@ -481,17 +486,20 @@ func TestPreCommitBatch(t *testing.T) { name: "empty batch", batchSize: 0, balanceSurplus: big.Zero(), + baseFee: big.Zero(), exit: exitcode.ErrIllegalArgument, error: "batch empty", }, { name: "too many sectors", batchSize: 257, balanceSurplus: big.Zero(), + baseFee: big.Zero(), exit: exitcode.ErrIllegalArgument, error: "batch of 257 too large", }, { name: "insufficient balance", batchSize: 10, + baseFee: big.Zero(), balanceSurplus: abi.NewTokenAmount(1).Neg(), exit: exitcode.ErrInsufficientFunds, error: "insufficient funds", @@ -522,6 +530,7 @@ func TestPreCommitBatch(t *testing.T) { firstForMiner: true, } deposits := make([]big.Int, batchSize) + for i := 0; i < batchSize; i++ { deals := dealSpec{} if len(test.deals) > i { @@ -539,13 +548,16 @@ func TestPreCommitBatch(t *testing.T) { } pwrEstimate := miner.QAPowerForWeight(actor.sectorSize, sectors[i].Expiration-precommitEpoch, dealWeight, verifiedDealWeight) deposits[i] = miner.PreCommitDepositForPower(actor.epochRewardSmooth, actor.epochQAPowerSmooth, pwrEstimate) + } + netFee := miner.AggregatePreCommitNetworkFee(batchSize, test.baseFee) totalDeposit := big.Sum(deposits...) - rt.SetBalance(big.Add(totalDeposit, test.balanceSurplus)) + totalBalance := big.Add(netFee, totalDeposit) + rt.SetBalance(big.Add(totalBalance, test.balanceSurplus)) if test.exit != exitcode.Ok { rt.ExpectAbortContainsMessage(test.exit, test.error, func() { - actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf) + actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, test.baseFee) // State untouched. st := getState(rt) @@ -555,7 +567,7 @@ func TestPreCommitBatch(t *testing.T) { }) return } - precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf) + precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, test.baseFee) // Check precommits st := getState(rt) @@ -607,7 +619,7 @@ func TestPreCommitBatch(t *testing.T) { } rt.ExpectAbortContainsMessage(exitcode.ErrIllegalArgument, "sector expiration", func() { - actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}) + actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}, big.Zero()) }) }) @@ -628,7 +640,7 @@ func TestPreCommitBatch(t *testing.T) { *actor.makePreCommit(100, precommitEpoch-1, sectorExpiration, nil), } rt.ExpectAbortContainsMessage(exitcode.ErrIllegalArgument, "duplicate sector number 100", func() { - actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}) + actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}, big.Zero()) }) }) } @@ -789,7 +801,7 @@ func TestProveCommit(t *testing.T) { firstForMiner: true, } - precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf) + precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, big.Zero()) rt.SetEpoch(proveCommitEpoch) noDealPower := miner.QAPowerForWeight(actor.sectorSize, sectorExpiration-proveCommitEpoch, big.Zero(), big.Zero()) diff --git a/actors/builtin/miner/miner_test.go b/actors/builtin/miner/miner_test.go index 14f03868f..62f71d9ef 100644 --- a/actors/builtin/miner/miner_test.go +++ b/actors/builtin/miner/miner_test.go @@ -4892,7 +4892,7 @@ type preCommitBatchConf struct { firstForMiner bool } -func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreCommitSectorBatchParams, conf preCommitBatchConf) []*miner.SectorPreCommitOnChainInfo { +func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreCommitSectorBatchParams, conf preCommitBatchConf, baseFee abi.TokenAmount) []*miner.SectorPreCommitOnChainInfo { rt.SetCaller(h.worker, builtin.AccountActorCodeID) rt.ExpectValidateCallerAddr(append(h.controlAddrs, h.owner, h.worker)...) { @@ -4933,8 +4933,11 @@ func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreC rt.ExpectSend(builtin.StorageMarketActorAddr, builtin.MethodsMarket.VerifyDealsForActivation, &vdParams, big.Zero(), &vdReturn, exitcode.Ok) } st := getState(rt) - if st.FeeDebt.GreaterThan(big.Zero()) { - rt.ExpectSend(builtin.BurntFundsActorAddr, builtin.MethodSend, nil, st.FeeDebt, nil, exitcode.Ok) + // burn networkFee + if st.FeeDebt.GreaterThan(big.Zero()) || len(params.Sectors) > 1 { + expectedNetworkFee := miner.AggregatePreCommitNetworkFee(len(params.Sectors), baseFee) + expectedBurn := big.Add(expectedNetworkFee, st.FeeDebt) + rt.ExpectSend(builtin.BurntFundsActorAddr, builtin.MethodSend, nil, expectedBurn, nil, exitcode.Ok) } if conf.firstForMiner { diff --git a/actors/test/commit_post_test.go b/actors/test/commit_post_test.go index e85843bad..669aa7194 100644 --- a/actors/test/commit_post_test.go +++ b/actors/test/commit_post_test.go @@ -879,14 +879,12 @@ func preCommitSectors(t *testing.T, v *vm.VM, count, batchSize int, worker, mAdd {To: builtin.RewardActorAddr, Method: builtin.MethodsReward.ThisEpochReward}, {To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.CurrentTotalPower}, } - invocsFirst := append(invocsCommon, vm.ExpectInvocation{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.EnrollCronEvent}) + invocFirst := vm.ExpectInvocation{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.EnrollCronEvent} sectorIndex := 0 for sectorIndex < count { + msgSectorIndexStart := sectorIndex invocs := invocsCommon - if expectCronEnrollment && sectorIndex == 0 { - invocs = invocsFirst - } // Prepare message. params := miner.PreCommitSectorBatchParams{Sectors: make([]miner0.SectorPreCommitInfo, batchSize)} @@ -907,6 +905,14 @@ func preCommitSectors(t *testing.T, v *vm.VM, count, batchSize int, worker, mAdd // Trim the last, partial batch. params.Sectors = params.Sectors[:sectorIndex%batchSize] } + + // Finalize invocation expectation list + if len(params.Sectors) > 1 { + invocs = append(invocs, vm.ExpectInvocation{To: builtin.BurntFundsActorAddr, Method: builtin.MethodSend}) + } + if expectCronEnrollment && msgSectorIndexStart == 0 { + invocs = append(invocs, invocFirst) + } vm.ApplyOk(t, v, worker, mAddr, big.Zero(), builtin.MethodsMiner.PreCommitSectorBatch, ¶ms) vm.ExpectInvocation{ To: mAddr,