From ccfa03138d5ae510a0be8a030258e0fe0c266c31 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 18 Nov 2019 12:18:59 -0600 Subject: [PATCH 1/3] fix ordering of block applies in reorg ops --- chain/events/events_height.go | 3 +-- chain/store/store.go | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/chain/events/events_height.go b/chain/events/events_height.go index 524efd0d5..a05a3e1be 100644 --- a/chain/events/events_height.go +++ b/chain/events/events_height.go @@ -70,9 +70,8 @@ func (e *heightEvents) headChangeAt(rev, app []*types.TipSet) error { } } - tail := len(app) - 1 for i := range app { - ts := app[tail-i] + ts := app[i] if err := e.tsc.add(ts); err != nil { return err diff --git a/chain/store/store.go b/chain/store/store.go index 018b5bbc8..c2278add3 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -254,6 +254,13 @@ func (cs *ChainStore) reorgWorker(ctx context.Context) chan<- reorg { log.Error("computing reorg ops failed: ", err) continue } + + // reverse the apply array + for i := len(apply)/2 - 1; i >= 0; i-- { + opp := len(apply) - 1 - i + apply[i], apply[opp] = apply[opp], apply[i] + } + for _, hcf := range cs.headChangeNotifs { if err := hcf(revert, apply); err != nil { log.Error("head change func errored (BAD): ", err) From ba5effe1f6cde1255eb25cba5383c6189de35316 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 19 Nov 2019 15:54:39 -0600 Subject: [PATCH 2/3] don't swap order in tests anymore --- chain/events/events_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/chain/events/events_test.go b/chain/events/events_test.go index 4c5177e1e..af2795c89 100644 --- a/chain/events/events_test.go +++ b/chain/events/events_test.go @@ -173,10 +173,6 @@ func (fcs *fakeCS) advance(rev, app int, msgs map[int]cid.Cid, nulls ...int) { / apps = append(apps, ts) } - for i, j := 0, len(apps)-1; i < j; i, j = i+1, j-1 { - apps[i], apps[j] = apps[j], apps[i] - } - fcs.sub(revs, apps) time.Sleep(100 * time.Millisecond) // TODO: :c } From 582f8f9a1412abf913a47f0957911e683ec991c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 19 Nov 2019 23:07:58 +0100 Subject: [PATCH 3/3] events: Fix Called handler --- chain/events/events_called.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chain/events/events_called.go b/chain/events/events_called.go index 94368214e..81d4e7872 100644 --- a/chain/events/events_called.go +++ b/chain/events/events_called.go @@ -87,9 +87,7 @@ func (e *calledEvents) headChangeCalled(rev, app []*types.TipSet) error { e.handleReverts(ts) } - tail := len(app) - 1 - for i := range app { - ts := app[tail-i] + for _, ts := range app { // called triggers e.checkNewCalls(ts)