chain events: split headChange
This commit is contained in:
parent
5f88ceb965
commit
4d0d51b58c
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user