chain events: Separate heightEvents from main struct

This commit is contained in:
Łukasz Magiera 2019-09-05 09:36:11 +02:00
parent 519eed9290
commit 50960b3f8c
3 changed files with 36 additions and 22 deletions

View File

@ -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{},

View File

@ -50,8 +50,9 @@ type queuedEvent struct {
}
type calledEvents struct {
cs eventChainStore
tsc *tipSetCache
cs eventChainStore
tsc *tipSetCache
gcConfidence uint64
lk sync.Mutex

View File

@ -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()