From 519eed929045204926d087c7e1e19cab7ea178e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 5 Sep 2019 09:31:16 +0200 Subject: [PATCH] chain events: Annotate types for readability --- chain/store/events.go | 18 +++++++-------- chain/store/events_called.go | 45 +++++++++++++++--------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/chain/store/events.go b/chain/store/events.go index 4b85aaa98..1ac794fa0 100644 --- a/chain/store/events.go +++ b/chain/store/events.go @@ -34,14 +34,14 @@ type Events struct { tsc *tipSetCache lk sync.Mutex - ctr uint64 + ctr triggerId // ChainAt - heightTriggers map[uint64]*heightHandler + heightTriggers map[triggerId]*heightHandler - htTriggerHeights map[uint64][]uint64 - htHeights map[uint64][]uint64 + htTriggerHeights map[triggerH][]triggerId + htHeights map[msgH][]triggerId calledEvents } @@ -65,11 +65,11 @@ func NewEvents(cs eventChainStore) *Events { cs: cs, tsc: tsc, - confQueue: map[uint64]map[uint64][]*queuedEvent{}, - revertQueue: map[uint64][]uint64{}, - triggers: map[uint64]*callHandler{}, - callTuples: map[callTuple][]uint64{}, - timeouts: map[uint64]map[uint64]int{}, + confQueue: map[triggerH]map[msgH][]*queuedEvent{}, + revertQueue: map[msgH][]triggerH{}, + triggers: map[triggerId]*callHandler{}, + callTuples: map[callTuple][]triggerId{}, + timeouts: map[uint64]map[triggerId]int{}, }, } diff --git a/chain/store/events_called.go b/chain/store/events_called.go index 1503c7ccf..685a64f09 100644 --- a/chain/store/events_called.go +++ b/chain/store/events_called.go @@ -9,9 +9,14 @@ import ( "github.com/filecoin-project/go-lotus/chain/types" ) -// continous -// with reverts -// no timout +type triggerId = uint64 + +// msgH is the block height at which a message was present / event has happened +type msgH = uint64 + +// triggerH is the block height at which the listener will be notified about the +// message (msgH+confidence) +type triggerH = uint64 // `ts` is the tipset, in which the `msg` is included. // `curH`-`ts.Height` = `confidence` @@ -36,7 +41,7 @@ type callHandler struct { } type queuedEvent struct { - trigger uint64 + trigger triggerId h uint64 msg *types.Message @@ -50,20 +55,20 @@ type calledEvents struct { lk sync.Mutex - ctr uint64 + ctr triggerId - triggers map[uint64]*callHandler - callTuples map[callTuple][]uint64 + triggers map[triggerId]*callHandler + callTuples map[callTuple][]triggerId // maps block heights to events // [triggerH][msgH][event] - confQueue map[uint64]map[uint64][]*queuedEvent + confQueue map[triggerH]map[msgH][]*queuedEvent // [msgH][triggerH] - revertQueue map[uint64][]uint64 + revertQueue map[msgH][]triggerH // [timeoutH+confidence][triggerId]{calls} - timeouts map[uint64]map[uint64]int + timeouts map[uint64]map[triggerId]int } type callTuple struct { @@ -72,6 +77,9 @@ type callTuple struct { } func (e *calledEvents) headChangeCalled(rev, app []*types.TipSet) error { + e.lk.Lock() + defer e.lk.Unlock() + for _, ts := range rev { e.handleReverts(ts) } @@ -290,20 +298,3 @@ func (e *calledEvents) Called(check CheckFunc, hnd CalledHandler, rev RevertHand return nil } - -/*func (e *calledEvents) debugInfo() { - fmt.Println("vvv") - fmt.Println("@", e.tsc.best().Height()) - - for k, v := range e.revertQueue { - fmt.Println("revert (msgH->trigH)", k, v) - } - for triggerH, v := range e.confQueue { - for msgh, e := range v { - for _, evt := range e { - fmt.Printf("T@ %d, M@ %d, EH %d, T %d, called %t\n", triggerH, msgh, evt.h, evt.trigger, evt.called) - } - } - } - fmt.Println("^^^") -}*/