panic recovery in MaybeRecordEvent; handle nil current tipsets in wdpost.

This commit is contained in:
Raúl Kripalani 2020-08-11 14:28:00 +01:00
parent 2ea5abdfb5
commit b534ab9d3c
5 changed files with 43 additions and 34 deletions

View File

@ -8,15 +8,12 @@ import (
"sync" "sync"
"time" "time"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
) )
var log = logging.Logger("journal")
// fsJournal is a basic journal backed by files on a filesystem. // fsJournal is a basic journal backed by files on a filesystem.
type fsJournal struct { type fsJournal struct {
EventTypeFactory EventTypeFactory

View File

@ -3,8 +3,12 @@ package journal
import ( import (
"sync" "sync"
"time" "time"
logging "github.com/ipfs/go-log"
) )
var log = logging.Logger("journal")
var ( var (
// DefaultDisabledEvents lists the journal events disabled by // DefaultDisabledEvents lists the journal events disabled by
// default, usually because they are considered noisy. // default, usually because they are considered noisy.
@ -30,6 +34,10 @@ type EventType struct {
safe bool safe bool
} }
func (et EventType) String() string {
return et.System + ":" + et.Event
}
// Enabled returns whether this event type is enabled in the journaling // Enabled returns whether this event type is enabled in the journaling
// subsystem. Users are advised to check this before actually attempting to // subsystem. Users are advised to check this before actually attempting to
// add a journal entry, as it helps bypass object construction for events that // add a journal entry, as it helps bypass object construction for events that
@ -84,9 +92,17 @@ type Event struct {
// enabled, and if so, it calls the supplier to create the event and // enabled, and if so, it calls the supplier to create the event and
// subsequently journal.RecordEvent on the provided journal to record it. // subsequently journal.RecordEvent on the provided journal to record it.
// //
// It also recovers from panics raised when calling the supplier function.
//
// This is safe to call with a nil Journal, either because the value is nil, // This is safe to call with a nil Journal, either because the value is nil,
// or because a journal obtained through NilJournal() is in use. // or because a journal obtained through NilJournal() is in use.
func MaybeRecordEvent(journal Journal, evtType EventType, supplier func() interface{}) { func MaybeRecordEvent(journal Journal, evtType EventType, supplier func() interface{}) {
defer func() {
if r := recover(); r != nil {
log.Warnf("recovered from panic while recording journal event; type=%s, err=%v", evtType, r)
}
}()
if journal == nil || journal == nilj { if journal == nil || journal == nilj {
return return
} }

View File

@ -1 +0,0 @@
package miner

View File

@ -27,13 +27,11 @@ var errNoPartitions = errors.New("no partitions")
func (s *WindowPoStScheduler) failPost(err error, deadline *miner.DeadlineInfo) { func (s *WindowPoStScheduler) failPost(err error, deadline *miner.DeadlineInfo) {
journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} { journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} {
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "failed", State: "failed",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(),
TipSet: s.cur.Cids(),
Error: err, Error: err,
} })
}) })
log.Errorf("TODO") log.Errorf("TODO")
@ -51,12 +49,10 @@ func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *miner.Deadli
s.activeDeadline = deadline s.activeDeadline = deadline
journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} { journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} {
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "started", State: "started",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(), })
TipSet: s.cur.Cids(),
}
}) })
go func() { go func() {
@ -82,12 +78,10 @@ func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *miner.Deadli
} }
journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} { journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} {
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "succeeded", State: "succeeded",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(), })
TipSet: s.cur.Cids(),
}
}) })
}() }()
} }
@ -153,16 +147,14 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin
mcid = sm.Cid() mcid = sm.Cid()
} }
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "recoveries_processed", State: "recoveries_processed",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(),
TipSet: s.cur.Cids(),
Recoveries: &WindowPoStEvt_Recoveries{ Recoveries: &WindowPoStEvt_Recoveries{
Declarations: params.Recoveries, Declarations: params.Recoveries,
MessageCID: mcid, MessageCID: mcid,
}, },
} })
}) })
for partIdx, partition := range partitions { for partIdx, partition := range partitions {
@ -260,16 +252,14 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64,
if sm != nil { if sm != nil {
mcid = sm.Cid() mcid = sm.Cid()
} }
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "faults_processed", State: "faults_processed",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(),
TipSet: s.cur.Cids(),
Faults: &WindowPoStEvt_Faults{ Faults: &WindowPoStEvt_Faults{
Declarations: params.Faults, Declarations: params.Faults,
MessageCID: mcid, MessageCID: mcid,
}, },
} })
}) })
for partIdx, partition := range partitions { for partIdx, partition := range partitions {
@ -517,16 +507,14 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi
mcid = sm.Cid() mcid = sm.Cid()
} }
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "proofs_processed", State: "proofs_processed",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(),
TipSet: s.cur.Cids(),
Proofs: &WindowPoStEvt_Proofs{ Proofs: &WindowPoStEvt_Proofs{
Partitions: proof.Partitions, Partitions: proof.Partitions,
MessageCID: mcid, MessageCID: mcid,
}, },
} })
}) })
enc, aerr := actors.SerializeParams(proof) enc, aerr := actors.SerializeParams(proof)

View File

@ -140,12 +140,13 @@ func (s *WindowPoStScheduler) Run(ctx context.Context) {
log.Errorf("expected first notif to have len = 1") log.Errorf("expected first notif to have len = 1")
continue continue
} }
if changes[0].Type != store.HCCurrent { chg := changes[0]
if chg.Type != store.HCCurrent {
log.Errorf("expected first notif to tell current ts") log.Errorf("expected first notif to tell current ts")
continue continue
} }
if err := s.update(ctx, changes[0].Val); err != nil { if err := s.update(ctx, chg.Val); err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
} }
@ -248,12 +249,10 @@ func (s *WindowPoStScheduler) abortActivePoSt() {
s.abort() s.abort()
journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} { journal.MaybeRecordEvent(s.jrnl, s.wdPoStEvtType, func() interface{} {
return WindowPoStEvt{ return s.enrichWithTipset(WindowPoStEvt{
State: "abort", State: "abort",
Deadline: s.activeDeadline, Deadline: s.activeDeadline,
Height: s.cur.Height(), })
TipSet: s.cur.Cids(),
}
}) })
log.Warnf("Aborting Window PoSt (Deadline: %+v)", s.activeDeadline) log.Warnf("Aborting Window PoSt (Deadline: %+v)", s.activeDeadline)
@ -262,3 +261,13 @@ func (s *WindowPoStScheduler) abortActivePoSt() {
s.activeDeadline = nil s.activeDeadline = nil
s.abort = nil s.abort = nil
} }
// enrichWithTipset enriches a WindowPoStEvt with tipset information,
// if available.
func (s *WindowPoStScheduler) enrichWithTipset(evt WindowPoStEvt) WindowPoStEvt {
if s.cur != nil {
evt.Height = s.cur.Height()
evt.TipSet = s.cur.Cids()
}
return evt
}