Handle reverts in precommit more correctly
This commit is contained in:
parent
dec458718f
commit
55c1432347
@ -26,6 +26,9 @@ const SlashablePowerDelay = 20
|
||||
// Epochs
|
||||
const InteractivePoRepDelay = 2
|
||||
|
||||
// Epochs
|
||||
const InteractivePoRepConfidence = 6
|
||||
|
||||
func init() {
|
||||
os.Setenv("TRUST_PARAMS", "1")
|
||||
}
|
||||
|
@ -28,3 +28,6 @@ const SlashablePowerDelay = 200
|
||||
|
||||
// Epochs
|
||||
const InteractivePoRepDelay = 8
|
||||
|
||||
// Epochs
|
||||
const InteractivePoRepConfidence = 6
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"math"
|
||||
"mime"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -203,7 +204,7 @@ func (sm *StorageMinerAPI) SectorsRefs(context.Context) (map[string][]api.Sealed
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) SectorsUpdate(ctx context.Context, id uint64, state api.SectorState) error {
|
||||
return sm.Miner.UpdateSectorState(ctx, id, state)
|
||||
return sm.Miner.UpdateSectorState(ctx, id, math.MaxUint64, state)
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) WorkerQueue(ctx context.Context, cfg sectorbuilder.WorkerCfg) (<-chan sectorbuilder.WorkerTask, error) {
|
||||
|
@ -137,6 +137,8 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
|
||||
randHeight := mw.TipSet.Height() + build.InteractivePoRepDelay - 1 // -1 because of how the messages are applied
|
||||
log.Infof("precommit for sector %d made it on chain, will start proof computation at height %d", sector.SectorID, randHeight)
|
||||
|
||||
updateNonce := sector.Nonce
|
||||
|
||||
err = m.events.ChainAt(func(ctx context.Context, ts *types.TipSet, curH uint64) error {
|
||||
rand, err := m.api.ChainGetRandomness(ctx, ts.Key(), int64(randHeight))
|
||||
if err != nil {
|
||||
@ -146,7 +148,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
|
||||
return err
|
||||
}
|
||||
|
||||
m.sectorUpdated <- *sector.upd().to(api.Committing).state(func(info *SectorInfo) {
|
||||
m.sectorUpdated <- *sector.upd().to(api.Committing).setNonce(updateNonce).state(func(info *SectorInfo) {
|
||||
info.Seed = SealSeed{
|
||||
BlockHeight: randHeight,
|
||||
TicketBytes: rand,
|
||||
@ -158,7 +160,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
|
||||
log.Warn("revert in interactive commit sector step")
|
||||
// TODO: need to cancel running process and restart...
|
||||
return nil
|
||||
}, 3, mw.TipSet.Height()+build.InteractivePoRepDelay)
|
||||
}, build.InteractivePoRepConfidence, mw.TipSet.Height()+build.InteractivePoRepDelay)
|
||||
if err != nil {
|
||||
log.Warn("waitForPreCommitMessage ChainAt errored: ", err)
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) {
|
||||
type SectorInfo struct {
|
||||
State api.SectorState
|
||||
SectorID uint64
|
||||
Nonce uint64
|
||||
|
||||
// Packing
|
||||
|
||||
@ -75,7 +76,7 @@ type SectorInfo struct {
|
||||
}
|
||||
|
||||
func (t *SectorInfo) upd() *sectorUpdate {
|
||||
return §orUpdate{id: t.SectorID}
|
||||
return §orUpdate{id: t.SectorID, nonce: t.Nonce}
|
||||
}
|
||||
|
||||
func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
@ -16,49 +17,41 @@ type sectorUpdate struct {
|
||||
newState api.SectorState
|
||||
id uint64
|
||||
err error
|
||||
nonce uint64
|
||||
mut func(*SectorInfo)
|
||||
}
|
||||
|
||||
func (u *sectorUpdate) fatal(err error) *sectorUpdate {
|
||||
return §orUpdate{
|
||||
newState: api.FailedUnrecoverable,
|
||||
id: u.id,
|
||||
err: err,
|
||||
mut: u.mut,
|
||||
}
|
||||
u.newState = api.FailedUnrecoverable
|
||||
u.err = err
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *sectorUpdate) error(err error) *sectorUpdate {
|
||||
return §orUpdate{
|
||||
newState: u.newState,
|
||||
id: u.id,
|
||||
err: err,
|
||||
mut: u.mut,
|
||||
}
|
||||
u.err = err
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *sectorUpdate) state(m func(*SectorInfo)) *sectorUpdate {
|
||||
return §orUpdate{
|
||||
newState: u.newState,
|
||||
id: u.id,
|
||||
err: u.err,
|
||||
mut: m,
|
||||
}
|
||||
u.mut = m
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *sectorUpdate) to(newState api.SectorState) *sectorUpdate {
|
||||
return §orUpdate{
|
||||
newState: newState,
|
||||
id: u.id,
|
||||
err: u.err,
|
||||
mut: u.mut,
|
||||
}
|
||||
u.nonce = newState
|
||||
return u
|
||||
}
|
||||
|
||||
func (m *Miner) UpdateSectorState(ctx context.Context, sector uint64, state api.SectorState) error {
|
||||
func (u *sectorUpdate) setNonce(nc uint64) *sectorUpdate {
|
||||
u.nonce = nc
|
||||
return u
|
||||
}
|
||||
|
||||
func (m *Miner) UpdateSectorState(ctx context.Context, sector uint64, snonce uint64, state api.SectorState) error {
|
||||
select {
|
||||
case m.sectorUpdated <- sectorUpdate{
|
||||
newState: state,
|
||||
nonce: snonce,
|
||||
id: sector,
|
||||
}:
|
||||
return nil
|
||||
@ -78,6 +71,7 @@ func (m *Miner) sectorStateLoop(ctx context.Context) error {
|
||||
select {
|
||||
case m.sectorUpdated <- sectorUpdate{
|
||||
newState: si.State,
|
||||
nonce: si.Nonce,
|
||||
id: si.SectorID,
|
||||
err: nil,
|
||||
mut: nil,
|
||||
@ -166,6 +160,15 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
|
||||
log.Infof("Sector %d updated state to %s", update.id, api.SectorStates[update.newState])
|
||||
var sector SectorInfo
|
||||
err := m.sectors.Mutate(update.id, func(s *SectorInfo) error {
|
||||
if update.nonce < s.Nonce {
|
||||
return xerrors.Errorf("update nonce too low, ignoring (%d < %d)", update.nonce, s.Nonce)
|
||||
}
|
||||
|
||||
if update.nonce != math.MaxUint64 {
|
||||
s.Nonce = update.nonce
|
||||
} else {
|
||||
s.Nonce++ // forced update
|
||||
}
|
||||
s.State = update.newState
|
||||
if update.err != nil {
|
||||
if s.LastErr != "" {
|
||||
@ -184,38 +187,41 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
|
||||
log.Errorf("sector %d failed: %+v", update.id, update.err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("sector %d error: %+v", update.id, err)
|
||||
log.Errorf("sector %d update error: %+v", update.id, err)
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
* Empty
|
||||
| |
|
||||
| v
|
||||
*<- Packing <- incoming
|
||||
| |
|
||||
| v
|
||||
*<- Unsealed <--> SealFailed
|
||||
| |
|
||||
| v
|
||||
* PreCommitting <--> PreCommitFailed
|
||||
| | ^
|
||||
| v |
|
||||
*<- PreCommitted ------/
|
||||
| |
|
||||
| v v--> SealCommitFailed
|
||||
*<- Committing
|
||||
| | ^--> CommitFailed
|
||||
| v
|
||||
*<- Proving
|
||||
|
|
||||
v
|
||||
FailedUnrecoverable
|
||||
* Empty
|
||||
| |
|
||||
| v
|
||||
*<- Packing <- incoming
|
||||
| |
|
||||
| v
|
||||
*<- Unsealed <--> SealFailed
|
||||
| |
|
||||
| v
|
||||
* PreCommitting <--> PreCommitFailed
|
||||
| | ^
|
||||
| v |
|
||||
*<- PreCommitted ------/
|
||||
| |||
|
||||
| vvv v--> SealCommitFailed
|
||||
*<- Committing
|
||||
| | ^--> CommitFailed
|
||||
| v ^
|
||||
*<- CommitWait ---/
|
||||
| |
|
||||
| v
|
||||
*<- Proving
|
||||
|
|
||||
v
|
||||
FailedUnrecoverable
|
||||
|
||||
UndefinedSectorState <- ¯\_(ツ)_/¯
|
||||
| ^
|
||||
*---------------------/
|
||||
UndefinedSectorState <- ¯\_(ツ)_/¯
|
||||
| ^
|
||||
*---------------------/
|
||||
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user