Handle reverts in precommit more correctly

This commit is contained in:
Łukasz Magiera 2019-12-08 16:14:40 +01:00
parent dec458718f
commit 55c1432347
6 changed files with 71 additions and 55 deletions

View File

@ -26,6 +26,9 @@ const SlashablePowerDelay = 20
// Epochs // Epochs
const InteractivePoRepDelay = 2 const InteractivePoRepDelay = 2
// Epochs
const InteractivePoRepConfidence = 6
func init() { func init() {
os.Setenv("TRUST_PARAMS", "1") os.Setenv("TRUST_PARAMS", "1")
} }

View File

@ -28,3 +28,6 @@ const SlashablePowerDelay = 200
// Epochs // Epochs
const InteractivePoRepDelay = 8 const InteractivePoRepDelay = 8
// Epochs
const InteractivePoRepConfidence = 6

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"io" "io"
"math"
"mime" "mime"
"net/http" "net/http"
"os" "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 { 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) { func (sm *StorageMinerAPI) WorkerQueue(ctx context.Context, cfg sectorbuilder.WorkerCfg) (<-chan sectorbuilder.WorkerTask, error) {

View File

@ -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 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) 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 { err = m.events.ChainAt(func(ctx context.Context, ts *types.TipSet, curH uint64) error {
rand, err := m.api.ChainGetRandomness(ctx, ts.Key(), int64(randHeight)) rand, err := m.api.ChainGetRandomness(ctx, ts.Key(), int64(randHeight))
if err != nil { if err != nil {
@ -146,7 +148,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
return err 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{ info.Seed = SealSeed{
BlockHeight: randHeight, BlockHeight: randHeight,
TicketBytes: rand, TicketBytes: rand,
@ -158,7 +160,7 @@ func (m *Miner) handlePreCommitted(ctx context.Context, sector SectorInfo) *sect
log.Warn("revert in interactive commit sector step") log.Warn("revert in interactive commit sector step")
// TODO: need to cancel running process and restart... // TODO: need to cancel running process and restart...
return nil return nil
}, 3, mw.TipSet.Height()+build.InteractivePoRepDelay) }, build.InteractivePoRepConfidence, mw.TipSet.Height()+build.InteractivePoRepDelay)
if err != nil { if err != nil {
log.Warn("waitForPreCommitMessage ChainAt errored: ", err) log.Warn("waitForPreCommitMessage ChainAt errored: ", err)
} }

View File

@ -49,6 +49,7 @@ func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) {
type SectorInfo struct { type SectorInfo struct {
State api.SectorState State api.SectorState
SectorID uint64 SectorID uint64
Nonce uint64
// Packing // Packing
@ -75,7 +76,7 @@ type SectorInfo struct {
} }
func (t *SectorInfo) upd() *sectorUpdate { func (t *SectorInfo) upd() *sectorUpdate {
return &sectorUpdate{id: t.SectorID} return &sectorUpdate{id: t.SectorID, nonce: t.Nonce}
} }
func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo { func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"math"
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
@ -16,49 +17,41 @@ type sectorUpdate struct {
newState api.SectorState newState api.SectorState
id uint64 id uint64
err error err error
nonce uint64
mut func(*SectorInfo) mut func(*SectorInfo)
} }
func (u *sectorUpdate) fatal(err error) *sectorUpdate { func (u *sectorUpdate) fatal(err error) *sectorUpdate {
return &sectorUpdate{ u.newState = api.FailedUnrecoverable
newState: api.FailedUnrecoverable, u.err = err
id: u.id, return u
err: err,
mut: u.mut,
}
} }
func (u *sectorUpdate) error(err error) *sectorUpdate { func (u *sectorUpdate) error(err error) *sectorUpdate {
return &sectorUpdate{ u.err = err
newState: u.newState, return u
id: u.id,
err: err,
mut: u.mut,
}
} }
func (u *sectorUpdate) state(m func(*SectorInfo)) *sectorUpdate { func (u *sectorUpdate) state(m func(*SectorInfo)) *sectorUpdate {
return &sectorUpdate{ u.mut = m
newState: u.newState, return u
id: u.id,
err: u.err,
mut: m,
}
} }
func (u *sectorUpdate) to(newState api.SectorState) *sectorUpdate { func (u *sectorUpdate) to(newState api.SectorState) *sectorUpdate {
return &sectorUpdate{ u.nonce = newState
newState: newState, return u
id: u.id,
err: u.err,
mut: u.mut,
}
} }
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 { select {
case m.sectorUpdated <- sectorUpdate{ case m.sectorUpdated <- sectorUpdate{
newState: state, newState: state,
nonce: snonce,
id: sector, id: sector,
}: }:
return nil return nil
@ -78,6 +71,7 @@ func (m *Miner) sectorStateLoop(ctx context.Context) error {
select { select {
case m.sectorUpdated <- sectorUpdate{ case m.sectorUpdated <- sectorUpdate{
newState: si.State, newState: si.State,
nonce: si.Nonce,
id: si.SectorID, id: si.SectorID,
err: nil, err: nil,
mut: 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]) log.Infof("Sector %d updated state to %s", update.id, api.SectorStates[update.newState])
var sector SectorInfo var sector SectorInfo
err := m.sectors.Mutate(update.id, func(s *SectorInfo) error { 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 s.State = update.newState
if update.err != nil { if update.err != nil {
if s.LastErr != "" { if s.LastErr != "" {
@ -184,7 +187,7 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
log.Errorf("sector %d failed: %+v", update.id, update.err) log.Errorf("sector %d failed: %+v", update.id, update.err)
} }
if err != nil { if err != nil {
log.Errorf("sector %d error: %+v", update.id, err) log.Errorf("sector %d update error: %+v", update.id, err)
return return
} }
@ -203,10 +206,13 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
| | ^ | | ^
| v | | v |
*<- PreCommitted ------/ *<- PreCommitted ------/
| | | |||
| v v--> SealCommitFailed | vvv v--> SealCommitFailed
*<- Committing *<- Committing
| | ^--> CommitFailed | | ^--> CommitFailed
| v ^
*<- CommitWait ---/
| |
| v | v
*<- Proving *<- Proving
| |