From 237f8e8018ad864ada961d58bcbb9c958332093f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 28 Oct 2019 09:15:08 +0100 Subject: [PATCH] Set proving params matching the spec more closely --- build/params.go | 29 ++++++++++++++++------------- chain/actors/actor_miner.go | 4 ++-- chain/gen/gen.go | 2 +- chain/sync.go | 2 +- storage/post.go | 12 ++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/build/params.go b/build/params.go index 9185a5b0c..480b90230 100644 --- a/build/params.go +++ b/build/params.go @@ -33,14 +33,6 @@ func SupportedSectorSize(ssize uint64) bool { // Blocks const PaymentChannelClosingDelay = 6 * 60 * 2 // six hours -// Blocks -const DealVoucherSkewLimit = 10 - -// Blocks -const MinDealVoucherIncrement = ProvingPeriodDuration - -const MaxVouchersPerDeal = 768 // roughly one voucher per 10h over a year - // ///// // Consensus / Network @@ -57,16 +49,27 @@ const ForkLengthThreshold = 100 const BlocksPerEpoch = 1 // ///// -// Proofs / Mining - -// Blocks -const RandomnessLookback = 20 +// Proofs // Blocks const ProvingPeriodDuration = 40 +// PoStChallangeTime sets the window in which post computation should happen // Blocks -const PoSTChallangeTime = 35 +const PoStChallangeTime = ProvingPeriodDuration - 5 + +// PoStRandomnessLookback is additional randomness lookback for PoSt computation +// To compute randomness epoch in a given proving period: +// RandH = PPE - PoStChallangeTime - PoStRandomnessLookback +// +// Blocks +const PoStRandomnessLookback = 1 + +// ///// +// Mining + +// Blocks +const EcRandomnessLookback = 300 const PowerCollateralProportion = 5 const PerCapitaCollateralProportion = 1 diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index dc5f8c530..baa35d0d5 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -360,7 +360,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext, var seed [sectorbuilder.CommLen]byte { - randHeight := currentProvingPeriodEnd - build.PoSTChallangeTime + randHeight := currentProvingPeriodEnd - build.PoStChallangeTime - build.PoStRandomnessLookback if vmctx.BlockHeight() <= randHeight { // TODO: spec, retcode return nil, aerrors.Newf(1, "submit PoSt called outside submission window (%d < %d)", vmctx.BlockHeight(), randHeight) @@ -658,7 +658,7 @@ func (sma StorageMinerActor) AddFaults(act *types.Actor, vmctx types.VMContext, return nil, aerr } - challengeHeight := self.ProvingPeriodEnd - build.PoSTChallangeTime + challengeHeight := self.ProvingPeriodEnd - build.PoStChallangeTime if vmctx.BlockHeight() < challengeHeight { // TODO: optimized bitfield methods diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 6032dd61c..91d7947c4 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -399,7 +399,7 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*ty } func IsRoundWinner(ctx context.Context, ts *types.TipSet, ticks []*types.Ticket, miner address.Address, a MiningCheckAPI) (bool, types.ElectionProof, error) { - r, err := a.ChainGetRandomness(ctx, ts, ticks, build.RandomnessLookback) + r, err := a.ChainGetRandomness(ctx, ts, ticks, build.EcRandomnessLookback) if err != nil { return false, nil, xerrors.Errorf("chain get randomness: %w", err) } diff --git a/chain/sync.go b/chain/sync.go index 40af03964..dac2a79e5 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -495,7 +495,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return xerrors.Errorf("validating block tickets failed: %w", err) } - rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), h.Tickets, build.RandomnessLookback) + rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), h.Tickets, build.EcRandomnessLookback) if err != nil { return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err) } diff --git a/storage/post.go b/storage/post.go index d34069894..ee024acbb 100644 --- a/storage/post.go +++ b/storage/post.go @@ -44,12 +44,12 @@ func (m *Miner) beginPosting(ctx context.Context) { m.schedLk.Unlock() - log.Infof("Scheduling post at height %d", ppe-build.PoSTChallangeTime) + log.Infof("Scheduling post at height %d", ppe-build.PoStChallangeTime) err = m.events.ChainAt(m.computePost(m.schedPost), func(ts *types.TipSet) error { // Revert // TODO: Cancel post log.Errorf("TODO: Cancel PoSt, re-run") return nil - }, PoStConfidence, ppe-build.PoSTChallangeTime) + }, PoStConfidence, ppe-build.PoStChallangeTime) if err != nil { // TODO: This is BAD, figure something out log.Errorf("scheduling PoSt failed: %s", err) @@ -82,13 +82,13 @@ func (m *Miner) scheduleNextPost(ppe uint64) { m.schedPost = ppe m.schedLk.Unlock() - log.Infow("scheduling PoSt", "post-height", ppe-build.PoSTChallangeTime, + log.Infow("scheduling PoSt", "post-height", ppe-build.PoStChallangeTime, "height", ts.Height(), "ppe", ppe, "proving-period", provingPeriod) err = m.events.ChainAt(m.computePost(ppe), func(ts *types.TipSet) error { // Revert // TODO: Cancel post log.Errorf("TODO: Cancel PoSt, re-run") return nil - }, PoStConfidence, ppe-build.PoSTChallangeTime) + }, PoStConfidence, ppe-build.PoStChallangeTime) if err != nil { // TODO: This is BAD, figure something out log.Errorf("scheduling PoSt failed: %+v", err) @@ -113,13 +113,13 @@ func (m *Miner) computePost(ppe uint64) func(ts *types.TipSet, curH uint64) erro return xerrors.Errorf("failed to get proving set for miner: %w", err) } - r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoSTChallangeTime))) // TODO: review: check math + r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoStChallangeTime)+int64(build.PoStRandomnessLookback))) // TODO: review: check math if err != nil { return xerrors.Errorf("failed to get chain randomness for post (ts=%d; ppe=%d): %w", ts.Height(), ppe, err) } log.Infow("running PoSt", "delayed-by", - int64(ts.Height())-(int64(ppe)-int64(build.PoSTChallangeTime)), + int64(ts.Height())-(int64(ppe)-int64(build.PoStChallangeTime)), "chain-random", r, "ppe", ppe, "height", ts.Height()) tsStart := time.Now()