2020-11-12 14:31:21 +00:00
|
|
|
package miner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/rand"
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-bitfield"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2021-12-08 17:11:19 +00:00
|
|
|
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
2020-11-12 14:31:21 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Miner) winPoStWarmup(ctx context.Context) error {
|
|
|
|
deadlines, err := m.api.StateMinerDeadlines(ctx, m.address, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting deadlines: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var sector abi.SectorNumber = math.MaxUint64
|
|
|
|
|
2020-11-18 01:03:52 +00:00
|
|
|
out:
|
2020-11-12 14:31:21 +00:00
|
|
|
for dlIdx := range deadlines {
|
|
|
|
partitions, err := m.api.StateMinerPartitions(ctx, m.address, uint64(dlIdx), types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting partitions for deadline %d: %w", dlIdx, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, partition := range partitions {
|
|
|
|
b, err := partition.ActiveSectors.First()
|
|
|
|
if err == bitfield.ErrNoBitsSet {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sector = abi.SectorNumber(b)
|
2020-11-16 09:51:02 +00:00
|
|
|
break out
|
2020-11-12 14:31:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if sector == math.MaxUint64 {
|
|
|
|
log.Info("skipping winning PoSt warmup, no sectors")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infow("starting winning PoSt warmup", "sector", sector)
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
var r abi.PoStRandomness = make([]byte, abi.RandomnessLength)
|
|
|
|
_, _ = rand.Read(r)
|
|
|
|
|
|
|
|
si, err := m.api.StateSectorGetInfo(ctx, m.address, sector, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting sector info: %w", err)
|
|
|
|
}
|
2022-12-12 15:44:08 +00:00
|
|
|
if si == nil {
|
|
|
|
return xerrors.Errorf("sector not found %d", sector)
|
|
|
|
}
|
2020-11-12 14:31:21 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
ts, err := m.api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting chain head")
|
|
|
|
}
|
|
|
|
nv, err := m.api.StateNetworkVersion(ctx, ts.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting network version")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = m.epp.ComputeProof(ctx, []proof7.ExtendedSectorInfo{
|
2020-11-12 14:31:21 +00:00
|
|
|
{
|
|
|
|
SealProof: si.SealProof,
|
|
|
|
SectorNumber: sector,
|
|
|
|
SealedCID: si.SealedCID,
|
2022-03-08 22:14:20 +00:00
|
|
|
SectorKey: si.SectorKeyCID,
|
2020-11-12 14:31:21 +00:00
|
|
|
},
|
2021-12-08 17:11:19 +00:00
|
|
|
}, r, ts.Height(), nv)
|
2020-11-12 14:31:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to compute proof: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infow("winning PoSt warmup successful", "took", time.Now().Sub(start))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Miner) doWinPoStWarmup(ctx context.Context) {
|
|
|
|
err := m.winPoStWarmup(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorw("winning PoSt warmup failed", "error", err)
|
|
|
|
}
|
|
|
|
}
|