Use nicer DeadlineInfo struct

This commit is contained in:
Łukasz Magiera 2020-04-20 19:34:08 +02:00
parent 6dd2f5369e
commit a86595bc88
7 changed files with 66 additions and 59 deletions

View File

@ -15,7 +15,7 @@ func init() {
var SectorSizes = []abi.SectorSize{2048}
// Seconds
const BlockDelay = 6
const BlockDelay = 2
const PropagationDelay = 3

View File

@ -438,6 +438,18 @@ var chainGetCmd = &cli.Command{
- /ipfs/[cid]/@Hu:123 - get uvarint elem 123 from hamt
- /ipfs/[cid]/@Ha:t01 - get element under Addr(t01).Bytes
- /ipfs/[cid]/@A:10 - get 10th amt element
List of --as-type types:
- raw
- block
- message
- smessage, signedmessage
- actor
- amt
- hamt-epoch
- hamt-address
- cronevent
- account-state
`,
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)

View File

@ -52,35 +52,50 @@ var provingInfoCmd = &cli.Command{
return xerrors.Errorf("getting miner info: %w", err)
}
pps, _ := (&miner.State{Info: mi}).ProvingPeriodStart(head.Height())
npp := pps + miner.WPoStProvingPeriod
cd, chg := miner.ComputeCurrentDeadline(pps, head.Height())
cd, _ := miner.ComputeProvingPeriodDeadline(mi.ProvingPeriodBoundary, head.Height())
deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key())
if err != nil {
return xerrors.Errorf("getting miner deadlines: %w", err)
}
curDeadlineSectors, err := deadlines.Due[cd].Count()
curDeadlineSectors, err := deadlines.Due[cd.Index].Count()
if err != nil {
return xerrors.Errorf("counting deadline sectors: %w", err)
}
fmt.Printf("Proving Period Boundary: %d\n", mi.ProvingPeriodBoundary)
fmt.Printf("Current Epoch: %d\n", head.Height())
fmt.Printf("Proving Period Start: %d (%s ago)\n", pps, time.Second*time.Duration(build.BlockDelay*(head.Height()-pps)))
fmt.Printf("Next Proving Period: %d (in %s)\n\n", npp, time.Second*time.Duration(build.BlockDelay*(npp-head.Height())))
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
fmt.Printf("Chain Period: %d\n", cd.CurrentEpoch / miner.WPoStProvingPeriod)
fmt.Printf("Chain Period Start: %s\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch / miner.WPoStProvingPeriod) * miner.WPoStProvingPeriod))
fmt.Printf("Chain Period End: %s\n\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch / miner.WPoStProvingPeriod + 1) * miner.WPoStProvingPeriod))
fmt.Printf("Deadline: %d\n", cd)
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
fmt.Printf("Deadline Start: %d\n", pps+(abi.ChainEpoch(cd)*miner.WPoStChallengeWindow))
fmt.Printf("Challenge Epoch: %d\n", chg)
fmt.Printf("Time left: %s\n", time.Second*time.Duration(build.BlockDelay*((pps+((1+abi.ChainEpoch(cd))*miner.WPoStChallengeWindow))-head.Height())))
fmt.Printf("Proving Period Boundary: %d\n", mi.ProvingPeriodBoundary)
fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart))
fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart + miner.WPoStProvingPeriod))
fmt.Printf("Deadline Index: %d\n", cd.Index)
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
fmt.Printf("Deadline Open: %s\n", epochTime(cd.CurrentEpoch, cd.Open))
fmt.Printf("Deadline Close: %s\n", epochTime(cd.CurrentEpoch, cd.Close))
fmt.Printf("Deadline Challenge: %s\n", epochTime(cd.CurrentEpoch, cd.Challenge))
fmt.Printf("Deadline FaultCutoff: %s\n", epochTime(cd.CurrentEpoch, cd.FaultCutoff))
return nil
},
}
func epochTime(curr, e abi.ChainEpoch) string {
switch {
case curr > e:
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(build.BlockDelay*(curr - e)))
case curr == e:
return fmt.Sprintf("%d (now)", e)
case curr < e:
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(build.BlockDelay*(e - curr)))
}
panic("math broke")
}
var provingDeadlinesCmd = &cli.Command{
Name: "deadlines",
Action: func(cctx *cli.Context) error {

2
go.mod
View File

@ -24,7 +24,7 @@ require (
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/sector-storage v0.0.0-20200417225459-e75536581a08
github.com/filecoin-project/specs-actors v0.0.0-20200416213853-1bd9b52a4621
github.com/filecoin-project/specs-actors v0.0.0-20200420172552-09dec8ff055a
github.com/filecoin-project/specs-storage v0.0.0-20200417134612-61b2d91a6102
github.com/filecoin-project/storage-fsm v0.0.0-20200417194744-f2744cf09977
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1

2
go.sum
View File

@ -180,6 +180,8 @@ github.com/filecoin-project/specs-actors v0.0.0-20200415170224-54c7b2a42e71 h1:k
github.com/filecoin-project/specs-actors v0.0.0-20200415170224-54c7b2a42e71/go.mod h1:M2HNOBpYbgXl/V4GmJFOsY7lQNuAmOtrCQMa6Yfpfrc=
github.com/filecoin-project/specs-actors v0.0.0-20200416213853-1bd9b52a4621 h1:czpP1yymltKqEjCfQptXkn01rkkAqgf1nEmIPcRbO/I=
github.com/filecoin-project/specs-actors v0.0.0-20200416213853-1bd9b52a4621/go.mod h1:qNIpwxs7WCtxbcbG4ZiS+Wf3qn36eyfqktlXJhi46X4=
github.com/filecoin-project/specs-actors v0.0.0-20200420172552-09dec8ff055a h1:xmXbRbOoiD/vYEChgiVmigvxCbegqfDZGrCEB3Wowik=
github.com/filecoin-project/specs-actors v0.0.0-20200420172552-09dec8ff055a/go.mod h1:qNIpwxs7WCtxbcbG4ZiS+Wf3qn36eyfqktlXJhi46X4=
github.com/filecoin-project/specs-storage v0.0.0-20200410185809-9fbaaa08f275 h1:6OTcpsTQBQM0f/A67oEi4E4YtYd6fzkMqbU8cPIWMMs=
github.com/filecoin-project/specs-storage v0.0.0-20200410185809-9fbaaa08f275/go.mod h1:xJ1/xl9+8zZeSSSFmDC3Wr6uusCTxyYPI0VeNVSFmPE=
github.com/filecoin-project/specs-storage v0.0.0-20200417134612-61b2d91a6102 h1:T3f/zkuvgtgqcXrb0NO3BicuveGOxxUAMPa/Yif2kuE=

View File

@ -17,7 +17,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
func (s *WindowPoStScheduler) failPost(deadline *Deadline) {
func (s *WindowPoStScheduler) failPost(deadline *miner.DeadlineInfo) {
log.Errorf("TODO")
/*s.failLk.Lock()
if eps > s.failed {
@ -26,7 +26,7 @@ func (s *WindowPoStScheduler) failPost(deadline *Deadline) {
s.failLk.Unlock()*/
}
func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *Deadline, ts *types.TipSet) {
func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *miner.DeadlineInfo, ts *types.TipSet) {
ctx, abort := context.WithCancel(ctx)
s.abort = abort
@ -83,7 +83,7 @@ func (s *WindowPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorN
return faultIDs, nil
}
func (s *WindowPoStScheduler) runPost(ctx context.Context, di Deadline, ts *types.TipSet) (*miner.SubmitWindowedPoStParams, error) {
func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo, ts *types.TipSet) (*miner.SubmitWindowedPoStParams, error) {
ctx, span := trace.StartSpan(ctx, "storage.runPost")
defer span.End()
@ -91,7 +91,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di Deadline, ts *type
if err := s.actor.MarshalCBOR(buf); err != nil {
return nil, xerrors.Errorf("failed to marshal address to cbor: %w", err)
}
rand, err := s.api.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_WindowedPoStChallengeSeed, di.challengeEpoch, buf.Bytes())
rand, err := s.api.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_WindowedPoStChallengeSeed, di.Challenge, buf.Bytes())
if err != nil {
return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; deadline=%d): %w", ts.Height(), di, err)
}
@ -101,12 +101,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di Deadline, ts *type
return nil, err
}
firstPartition, _, err := miner.PartitionsForDeadline(deadlines, di.deadlineIdx)
firstPartition, _, err := miner.PartitionsForDeadline(deadlines, di.Index)
if err != nil {
return nil, xerrors.Errorf("getting partitions for deadline: %w", err)
}
partitionCount, _, err := miner.DeadlineCount(deadlines, di.deadlineIdx)
partitionCount, _, err := miner.DeadlineCount(deadlines, di.Index)
if err != nil {
return nil, xerrors.Errorf("getting deadline partition count: %w", err)
}
@ -120,7 +120,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di Deadline, ts *type
partitions[i] = firstPartition + uint64(i)
}
ssi, err := s.sortedSectorInfo(ctx, deadlines.Due[di.deadlineIdx], ts)
ssi, err := s.sortedSectorInfo(ctx, deadlines.Due[di.Index], ts)
if err != nil {
return nil, xerrors.Errorf("getting sorted sector info: %w", err)
}

View File

@ -30,7 +30,7 @@ type WindowPoStScheduler struct {
cur *types.TipSet
// if a post is in progress, this indicates for which ElectionPeriodStart
activeDeadline *Deadline
activeDeadline *miner.DeadlineInfo
abort context.CancelFunc
//failed abi.ChainEpoch // eps
@ -56,19 +56,12 @@ func NewWindowedPoStScheduler(api storageMinerApi, sb storage.Prover, actor addr
return &WindowPoStScheduler{api: api, prover: sb, actor: actor, worker: worker, proofType: rt}, nil
}
type Deadline struct {
provingPeriodStart abi.ChainEpoch
deadlineIdx uint64
challengeEpoch abi.ChainEpoch
}
func (d *Deadline) Equals(other *Deadline) bool {
if d == nil || other == nil {
return d == other
func deadlineEquals(a, b *miner.DeadlineInfo) bool {
if a == nil || b == nil {
return b == a
}
return d.provingPeriodStart == other.provingPeriodStart &&
d.deadlineIdx == other.deadlineIdx
return a.PeriodStart == b.PeriodStart && a.Index == b.Index && a.Challenge == b.Challenge
}
func (s *WindowPoStScheduler) Run(ctx context.Context) {
@ -159,9 +152,9 @@ func (s *WindowPoStScheduler) revert(ctx context.Context, newLowest *types.TipSe
return err
}
newDeadline := deadlineInfo(mi, newLowest)
newDeadline, _ := deadlineInfo(mi, newLowest)
if !s.activeDeadline.Equals(newDeadline) {
if !deadlineEquals(s.activeDeadline, newDeadline) {
s.abortActivePoSt()
}
@ -178,18 +171,18 @@ func (s *WindowPoStScheduler) update(ctx context.Context, new *types.TipSet) err
return err
}
di := deadlineInfo(mi, new)
if s.activeDeadline.Equals(di) {
di, nn := deadlineInfo(mi, new)
if deadlineEquals(s.activeDeadline, di) {
return nil // already working on this deadline
}
if di == nil {
if !nn {
return nil // not proving anything yet
}
s.abortActivePoSt()
if di.challengeEpoch+StartConfidence >= new.Height() {
log.Info("not starting windowPost yet, waiting for startconfidence", di.challengeEpoch, di.challengeEpoch+StartConfidence, new.Height())
if di.Challenge+StartConfidence >= new.Height() {
log.Info("not starting windowPost yet, waiting for startconfidence", di.Challenge, di.Challenge+StartConfidence, new.Height())
return nil
}
@ -220,21 +213,6 @@ func (s *WindowPoStScheduler) abortActivePoSt() {
s.abort = nil
}
func deadlineInfo(mi miner.MinerInfo, new *types.TipSet) *Deadline {
pps, nonNegative := provingPeriodStart(mi, new.Height())
if !nonNegative {
return nil // proving didn't start yet
}
deadlineIdx, challengeEpoch := miner.ComputeCurrentDeadline(pps, new.Height())
return &Deadline{
provingPeriodStart: pps,
deadlineIdx: deadlineIdx,
challengeEpoch: challengeEpoch,
}
}
func provingPeriodStart(mi miner.MinerInfo, currEpoch abi.ChainEpoch) (period abi.ChainEpoch, nonNegative bool) {
return (&miner.State{Info: mi}).ProvingPeriodStart(currEpoch)
func deadlineInfo(mi miner.MinerInfo, new *types.TipSet) (*miner.DeadlineInfo, bool) {
return miner.ComputeProvingPeriodDeadline(mi.ProvingPeriodBoundary, new.Height())
}