wip changes for windowed post
This commit is contained in:
parent
f2dd0f046e
commit
e36f356908
@ -136,7 +136,7 @@ func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api lapi.FullNode, h
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ppt, _, err := ffiwrapper.ProofTypeFromSectorSize(sealer.SectorSize())
|
||||
ppt, _, err := ffiwrapper.ProofTypeFromSectorSize(sealer.SectorSize()) // TODO: this changes
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("bad sector size: %w", err)
|
||||
}
|
||||
|
@ -18,19 +18,20 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
func (s *WindowPoStScheduler) failPost(eps abi.ChainEpoch) {
|
||||
s.failLk.Lock()
|
||||
func (s *WindowPoStScheduler) failPost(deadline *Deadline) {
|
||||
log.Errorf("TODO")
|
||||
/*s.failLk.Lock()
|
||||
if eps > s.failed {
|
||||
s.failed = eps
|
||||
}
|
||||
s.failLk.Unlock()
|
||||
s.failLk.Unlock()*/
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) doPost(ctx context.Context, eps abi.ChainEpoch, ts *types.TipSet) {
|
||||
func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *Deadline, ts *types.TipSet) {
|
||||
ctx, abort := context.WithCancel(ctx)
|
||||
|
||||
s.abort = abort
|
||||
s.activeEPS = eps
|
||||
s.activeDeadline = deadline
|
||||
|
||||
go func() {
|
||||
defer abort()
|
||||
@ -38,16 +39,16 @@ func (s *WindowPoStScheduler) doPost(ctx context.Context, eps abi.ChainEpoch, ts
|
||||
ctx, span := trace.StartSpan(ctx, "WindowPoStScheduler.doPost")
|
||||
defer span.End()
|
||||
|
||||
proof, err := s.runPost(ctx, eps, ts)
|
||||
proof, err := s.runPost(ctx, deadline, ts)
|
||||
if err != nil {
|
||||
log.Errorf("runPost failed: %+v", err)
|
||||
s.failPost(eps)
|
||||
s.failPost(deadline)
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.submitPost(ctx, proof); err != nil {
|
||||
log.Errorf("submitPost failed: %+v", err)
|
||||
s.failPost(eps)
|
||||
s.failPost(deadline)
|
||||
return
|
||||
}
|
||||
|
||||
@ -91,7 +92,7 @@ func (s *WindowPoStScheduler) declareFaults(ctx context.Context, fc uint64, para
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorNumber) ([]abi.SectorNumber, error) {
|
||||
//faults := s.sb.Scrub(ssi)
|
||||
//faults := s.prover.Scrub(ssi)
|
||||
log.Warnf("Stub checkFaults")
|
||||
var faults []struct {
|
||||
SectorNum abi.SectorNumber
|
||||
@ -143,11 +144,11 @@ func (s *WindowPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorN
|
||||
return faultIDs, nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, ts *types.TipSet) (*abi.OnChainPoStVerifyInfo, error) {
|
||||
func (s *WindowPoStScheduler) runPost(ctx context.Context, deadline Deadline, ts *types.TipSet) (*abi.OnChainPoStVerifyInfo, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "storage.runPost")
|
||||
defer span.End()
|
||||
|
||||
challengeRound := eps
|
||||
challengeRound := deadline.start // TODO: check with spec
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
if err := s.actor.MarshalCBOR(buf); err != nil {
|
||||
@ -155,10 +156,15 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, t
|
||||
}
|
||||
rand, err := s.api.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_WindowedPoStChallengeSeed, challengeRound, buf.Bytes())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; eps=%d): %w", ts.Height(), eps, err)
|
||||
return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; deadline=%d): %w", ts.Height(), deadline, err)
|
||||
}
|
||||
|
||||
ssi, err := s.sortedSectorInfo(ctx, ts)
|
||||
partitions, err := s.getDeadlinePartitions(ts, deadline)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ssi, err := s.sortedSectorInfo(ctx, partitions, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting sorted sector info: %w", err)
|
||||
}
|
||||
@ -169,7 +175,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, t
|
||||
|
||||
log.Infow("running windowPost",
|
||||
"chain-random", rand,
|
||||
"eps", eps,
|
||||
"deadline", deadline,
|
||||
"height", ts.Height())
|
||||
|
||||
var snums []abi.SectorNumber
|
||||
@ -193,7 +199,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, t
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postOut, err := s.sb.GenerateFallbackPoSt(ctx, abi.ActorID(mid), ssi, abi.PoStRandomness(rand), faults)
|
||||
postOut, err := s.prover.GenerateFallbackPoSt(ctx, abi.ActorID(mid), ssi, abi.PoStRandomness(rand), faults)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("running post failed: %w", err)
|
||||
}
|
||||
@ -228,22 +234,18 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, t
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet) ([]abi.SectorInfo, error) {
|
||||
sset, err := s.api.StateMinerProvingSet(ctx, s.actor, ts.Key())
|
||||
func (s *WindowPoStScheduler) sortedSectorInfo(ctx context.Context, partitions []abiPartition, ts *types.TipSet) ([]abi.SectorInfo, error) {
|
||||
sset, err := s.getPartitionSectors(ts, partitions)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get proving set for miner (tsH: %d): %w", ts.Height(), err)
|
||||
}
|
||||
if len(sset) == 0 {
|
||||
log.Warn("empty proving set! (ts.H: %d)", ts.Height())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sbsi := make([]abi.SectorInfo, len(sset))
|
||||
for k, sector := range sset {
|
||||
|
||||
sbsi[k] = abi.SectorInfo{
|
||||
SectorNumber: sector.Info.Info.SectorNumber,
|
||||
SealedCID: sector.Info.Info.SealedCID,
|
||||
RegisteredProof: sector.Info.Info.RegisteredProof,
|
||||
SectorNumber: sector.SectorNumber,
|
||||
SealedCID: sector.SealedCID,
|
||||
RegisteredProof: sector.RegisteredProof,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opencensus.io/trace"
|
||||
@ -17,13 +16,11 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
const Inactive = 0
|
||||
|
||||
const StartConfidence = 4 // TODO: config
|
||||
|
||||
type WindowPoStScheduler struct {
|
||||
api storageMinerApi
|
||||
sb storage.Prover
|
||||
prover storage.Prover
|
||||
proofType abi.RegisteredProof
|
||||
|
||||
actor address.Address
|
||||
@ -32,15 +29,44 @@ type WindowPoStScheduler struct {
|
||||
cur *types.TipSet
|
||||
|
||||
// if a post is in progress, this indicates for which ElectionPeriodStart
|
||||
activeEPS abi.ChainEpoch
|
||||
activeDeadline *Deadline
|
||||
abort context.CancelFunc
|
||||
|
||||
failed abi.ChainEpoch // eps
|
||||
failLk sync.Mutex
|
||||
//failed abi.ChainEpoch // eps
|
||||
//failLk sync.Mutex
|
||||
}
|
||||
|
||||
func NewWindowedPoStScheduler(api storageMinerApi, sb storage.Prover, actor address.Address, worker address.Address, rt abi.RegisteredProof) *WindowPoStScheduler {
|
||||
return &WindowPoStScheduler{api: api, sb: sb, actor: actor, worker: worker, proofType: rt}
|
||||
return &WindowPoStScheduler{api: api, prover: sb, actor: actor, worker: worker, proofType: rt}
|
||||
}
|
||||
|
||||
const ProvingDeadlineEpochs = (30*60) / build.BlockDelay
|
||||
const ProvingPeriodDeadlines = 48
|
||||
const ProvingPeriodEpochs = ProvingDeadlineEpochs * ProvingDeadlineEpochs
|
||||
|
||||
type Deadline struct {
|
||||
// ID
|
||||
start abi.ChainEpoch
|
||||
|
||||
}
|
||||
|
||||
func (Deadline) Equals(other Deadline) bool {
|
||||
panic("maybe equal")
|
||||
}
|
||||
|
||||
type abiPartition uint64
|
||||
|
||||
func (s *WindowPoStScheduler) getCurrentDeadline(ts *types.TipSet) (Deadline, error) {
|
||||
return Deadline{}, nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) getDeadlinePartitions(ts *types.TipSet, d Deadline) ([]abiPartition, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) getPartitionSectors(ts *types.TipSet, partition []abiPartition) ([]abi.SectorInfo, error) {
|
||||
// TODO: maybe make this per partition
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) Run(ctx context.Context) {
|
||||
@ -126,12 +152,12 @@ func (s *WindowPoStScheduler) revert(ctx context.Context, newLowest *types.TipSe
|
||||
}
|
||||
s.cur = newLowest
|
||||
|
||||
newEPS, _, err := s.shouldFallbackPost(ctx, newLowest)
|
||||
newDeadline, err := s.getCurrentDeadline(newLowest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newEPS != s.activeEPS {
|
||||
if !s.activeDeadline.Equals(newDeadline) {
|
||||
s.abortActivePoSt()
|
||||
}
|
||||
|
||||
@ -142,33 +168,34 @@ func (s *WindowPoStScheduler) update(ctx context.Context, new *types.TipSet) err
|
||||
if new == nil {
|
||||
return xerrors.Errorf("no new tipset in WindowPoStScheduler.update")
|
||||
}
|
||||
newEPS, start, err := s.shouldFallbackPost(ctx, new)
|
||||
shouldPost, newDeadline, err := s.shouldPost(ctx, new)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !shouldPost {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.failLk.Lock()
|
||||
/*s.failLk.Lock()
|
||||
if s.failed > 0 {
|
||||
s.failed = 0
|
||||
s.activeEPS = 0
|
||||
}
|
||||
s.failLk.Unlock()
|
||||
s.failLk.Unlock()*/
|
||||
|
||||
|
||||
if newEPS == s.activeEPS {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.abortActivePoSt()
|
||||
|
||||
if newEPS != Inactive && start {
|
||||
s.doPost(ctx, newEPS, new)
|
||||
if newDeadline != nil {
|
||||
s.doPost(ctx, newDeadline, new)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) abortActivePoSt() {
|
||||
if s.activeEPS == Inactive {
|
||||
if s.activeDeadline == nil {
|
||||
return // noop
|
||||
}
|
||||
|
||||
@ -176,20 +203,14 @@ func (s *WindowPoStScheduler) abortActivePoSt() {
|
||||
s.abort()
|
||||
}
|
||||
|
||||
log.Warnf("Aborting Fallback PoSt (EPS: %d)", s.activeEPS)
|
||||
log.Warnf("Aborting Fallback PoSt (Deadline: %+v)", s.activeDeadline)
|
||||
|
||||
s.activeEPS = Inactive
|
||||
s.activeDeadline = nil
|
||||
s.abort = nil
|
||||
}
|
||||
|
||||
func (s *WindowPoStScheduler) shouldFallbackPost(ctx context.Context, ts *types.TipSet) (abi.ChainEpoch, bool, error) {
|
||||
ps, err := s.api.StateMinerPostState(ctx, s.actor, ts.Key())
|
||||
if err != nil {
|
||||
return 0, false, xerrors.Errorf("getting ElectionPeriodStart: %w", err)
|
||||
}
|
||||
|
||||
if ts.Height() >= ps.ProvingPeriodStart {
|
||||
return ps.ProvingPeriodStart, ts.Height() >= ps.ProvingPeriodStart+build.FallbackPoStConfidence, nil
|
||||
}
|
||||
return 0, false, nil
|
||||
func (s *WindowPoStScheduler) shouldPost(ctx context.Context, ts *types.TipSet) (bool, *Deadline, error) {
|
||||
// call getCurrentDeadline, set activeDeadline if needed
|
||||
panic("todo check actor state for post in the deadline")
|
||||
return true, nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user