From 4d0d51b58c22ad77d94fb94867267b92b9d4eaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 3 Sep 2019 19:59:32 +0200 Subject: [PATCH] chain events: split headChange --- chain/store/events.go | 28 ++++++++++++++++++++++------ chain/store/events_test.go | 9 +++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/chain/store/events.go b/chain/store/events.go index 8a94332d0..bc82c2276 100644 --- a/chain/store/events.go +++ b/chain/store/events.go @@ -86,19 +86,27 @@ func NewEvents(cs eventChainStore) *Events { _ = e.tsc.add(cs.GetHeaviestTipSet()) cs.SubscribeHeadChanges(e.headChange) - // TODO: cleanup goroutine + // TODO: cleanup/gc goroutine return e } func (e *Events) headChange(rev, app []*types.TipSet) error { - e.lk.Lock() - defer e.lk.Unlock() - if len(app) == 0 { return xerrors.New("events.headChange expected at least one applied tipset") } + e.lk.Lock() + defer e.lk.Unlock() + + if err := e.headChangeAt(rev, app); err != nil { + return err + } + + return e.headChangeCalled(rev, app) +} + +func (e *Events) headChangeAt(rev, app []*types.TipSet) error { // highest tipset is always the first (see cs.ReorgOps) newH := app[0].Height() @@ -122,8 +130,6 @@ func (e *Events) headChange(rev, app []*types.TipSet) error { } } - // todo: called reverts - if err := e.tsc.revert(ts); err != nil { return err } @@ -158,7 +164,17 @@ func (e *Events) headChange(rev, app []*types.TipSet) error { } hnd.disable = hnd.msg != nil // special case for Called } + } + return nil +} + +func (e *Events) headChangeCalled(rev, app []*types.TipSet) error { + for _, ts := range rev { + _ = ts + } + + for _, ts := range app { // called triggers err := e.messagesForTs(ts, func(msg *types.Message) error { diff --git a/chain/store/events_test.go b/chain/store/events_test.go index 124a8060f..16a1342be 100644 --- a/chain/store/events_test.go +++ b/chain/store/events_test.go @@ -303,4 +303,13 @@ func TestCalled(t *testing.T) { require.Equal(t, t0123, appliedMsg.To) require.Equal(t, uint64(2), appliedMsg.Nonce) require.Equal(t, uint64(5), appliedMsg.Method) + + // call method again + + fcs.advance(0, 4, map[int]cid.Cid{ // msg at H=12; H=15 + 0: n2msg, + }) + + // require.Equal(t, false, applied) TODO: FIX! + require.Equal(t, false, reverted) }