From 7162c656ccf246be20ded423cd0b889dafbd24be Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 25 Apr 2023 11:56:26 -0700 Subject: [PATCH] fix: chain: record heaviest tipset before notifying (#10694) Clearly this hasn't caused any issues, but I'm pretty sure we should be updating the current head _before_ notifying about it. --- chain/store/store.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/chain/store/store.go b/chain/store/store.go index b34ddb266..dc9dc6484 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -639,22 +639,10 @@ func (cs *ChainStore) reorgWorker(ctx context.Context, initialNotifees []ReorgNo func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet) error { _, span := trace.StartSpan(ctx, "takeHeaviestTipSet") defer span.End() - - if cs.heaviest != nil { // buf - if len(cs.reorgCh) > 0 { - log.Warnf("Reorg channel running behind, %d reorgs buffered", len(cs.reorgCh)) - } - cs.reorgCh <- reorg{ - old: cs.heaviest, - new: ts, - } - } else { - log.Warnf("no heaviest tipset found, using %s", ts.Cids()) - } - span.AddAttributes(trace.BoolAttribute("newHead", true)) log.Infof("New heaviest tipset! %s (height=%d)", ts.Cids(), ts.Height()) + prevHeaviest := cs.heaviest cs.heaviest = ts if err := cs.writeHead(ctx, ts); err != nil { @@ -662,6 +650,18 @@ func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet) return err } + if prevHeaviest != nil { // buf + if len(cs.reorgCh) > 0 { + log.Warnf("Reorg channel running behind, %d reorgs buffered", len(cs.reorgCh)) + } + cs.reorgCh <- reorg{ + old: prevHeaviest, + new: ts, + } + } else { + log.Warnf("no previous heaviest tipset found, using %s", ts.Cids()) + } + return nil }