diff --git a/chain/store/events.go b/chain/store/events.go index 1ac794fa0..12ac87088 100644 --- a/chain/store/events.go +++ b/chain/store/events.go @@ -28,21 +28,12 @@ type eventChainStore interface { } type Events struct { - cs eventChainStore - gcConfidence uint64 + cs eventChainStore tsc *tipSetCache lk sync.Mutex - ctr triggerId - - // ChainAt - - heightTriggers map[triggerId]*heightHandler - - htTriggerHeights map[triggerH][]triggerId - htHeights map[msgH][]triggerId - + heightEvents calledEvents } @@ -52,18 +43,23 @@ func NewEvents(cs eventChainStore) *Events { tsc := newTSCache(gcConfidence) e := &Events{ - cs: cs, - gcConfidence: uint64(gcConfidence), + cs: cs, tsc: tsc, - heightTriggers: map[uint64]*heightHandler{}, - htTriggerHeights: map[uint64][]uint64{}, - htHeights: map[uint64][]uint64{}, + heightEvents: heightEvents{ + tsc: tsc, + gcConfidence: uint64(gcConfidence), + + heightTriggers: map[uint64]*heightHandler{}, + htTriggerHeights: map[uint64][]uint64{}, + htHeights: map[uint64][]uint64{}, + }, calledEvents: calledEvents{ - cs: cs, - tsc: tsc, + cs: cs, + tsc: tsc, + gcConfidence: uint64(gcConfidence), confQueue: map[triggerH]map[msgH][]*queuedEvent{}, revertQueue: map[msgH][]triggerH{}, diff --git a/chain/store/events_called.go b/chain/store/events_called.go index 685a64f09..114a73cda 100644 --- a/chain/store/events_called.go +++ b/chain/store/events_called.go @@ -50,8 +50,9 @@ type queuedEvent struct { } type calledEvents struct { - cs eventChainStore - tsc *tipSetCache + cs eventChainStore + tsc *tipSetCache + gcConfidence uint64 lk sync.Mutex diff --git a/chain/store/events_height.go b/chain/store/events_height.go index 98ea1125e..62e3681ce 100644 --- a/chain/store/events_height.go +++ b/chain/store/events_height.go @@ -2,9 +2,26 @@ package store import ( "github.com/filecoin-project/go-lotus/chain/types" + "sync" ) -func (e *Events) headChangeAt(rev, app []*types.TipSet) error { +type heightEvents struct { + lk sync.Mutex + tsc *tipSetCache + gcConfidence uint64 + + ctr triggerId + + heightTriggers map[triggerId]*heightHandler + + htTriggerHeights map[triggerH][]triggerId + htHeights map[msgH][]triggerId +} + +func (e *heightEvents) headChangeAt(rev, app []*types.TipSet) error { + e.lk.Lock() + defer e.lk.Unlock() + // highest tipset is always the first (see cs.ReorgOps) newH := app[0].Height() @@ -55,7 +72,7 @@ func (e *Events) headChangeAt(rev, app []*types.TipSet) error { return nil } -func (e *Events) ChainAt(hnd HeightHandler, rev RevertHandler, confidence int, h uint64) error { +func (e *heightEvents) ChainAt(hnd HeightHandler, rev RevertHandler, confidence int, h uint64) error { e.lk.Lock() defer e.lk.Unlock()