From e0632a93ab7d3c0998a5ad1673939e4f6c21c340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 27 Sep 2019 21:47:47 +0200 Subject: [PATCH] Share ProvingPeriodEnd math --- chain/actors/actor_miner.go | 12 +++++++++--- storage/post.go | 8 ++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index d406815ea..88f72d227 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -295,6 +295,14 @@ type SubmitPoStParams struct { // TODO: once the spec changes finish, we have more work to do here... } +func ProvingPeriodEnd(setPeriodEnd, height uint64) (uint64, uint64) { + offset := setPeriodEnd % build.ProvingPeriodDuration + period := ((height - offset - 1) / build.ProvingPeriodDuration) + 1 + end := (period * build.ProvingPeriodDuration) + offset + + return end, period +} + // TODO: this is a dummy method that allows us to plumb in other parts of the // system for now. func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext, params *SubmitPoStParams) ([]byte, ActorError) { @@ -312,9 +320,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext, return nil, aerrors.New(1, "not authorized to submit post for miner") } - provingPeriodOffset := self.ProvingPeriodEnd % build.ProvingPeriodDuration - provingPeriod := (vmctx.BlockHeight()-provingPeriodOffset-1)/build.ProvingPeriodDuration + 1 - currentProvingPeriodEnd := provingPeriod*build.ProvingPeriodDuration + provingPeriodOffset + currentProvingPeriodEnd, _ := ProvingPeriodEnd(self.ProvingPeriodEnd, vmctx.BlockHeight()) feesRequired := types.NewInt(0) diff --git a/storage/post.go b/storage/post.go index 1d07065fc..8f6748ba3 100644 --- a/storage/post.go +++ b/storage/post.go @@ -37,9 +37,7 @@ func (m *Miner) beginPosting(ctx context.Context) { return } - provingPeriodOffset := ppe % build.ProvingPeriodDuration - provingPeriod := (ts.Height()-provingPeriodOffset)/build.ProvingPeriodDuration + 1 - m.schedPost = provingPeriod*build.ProvingPeriodDuration + provingPeriodOffset + m.schedPost, _ = actors.ProvingPeriodEnd(ppe, ts.Height()) m.schedLk.Unlock() @@ -64,9 +62,7 @@ func (m *Miner) scheduleNextPost(ppe uint64) { return } - provingPeriodOffset := ppe % build.ProvingPeriodDuration - provingPeriod := (ts.Height()-provingPeriodOffset-1)/build.ProvingPeriodDuration + 1 - headPPE := provingPeriod*build.ProvingPeriodDuration + provingPeriodOffset + headPPE, provingPeriod := actors.ProvingPeriodEnd(ppe, ts.Height()) if headPPE > ppe { log.Warn("PoSt computation running behind chain") ppe = headPPE