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.
This commit is contained in:
parent
aeee542fb9
commit
7162c656cc
@ -639,22 +639,10 @@ func (cs *ChainStore) reorgWorker(ctx context.Context, initialNotifees []ReorgNo
|
|||||||
func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet) error {
|
func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet) error {
|
||||||
_, span := trace.StartSpan(ctx, "takeHeaviestTipSet")
|
_, span := trace.StartSpan(ctx, "takeHeaviestTipSet")
|
||||||
defer span.End()
|
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))
|
span.AddAttributes(trace.BoolAttribute("newHead", true))
|
||||||
|
|
||||||
log.Infof("New heaviest tipset! %s (height=%d)", ts.Cids(), ts.Height())
|
log.Infof("New heaviest tipset! %s (height=%d)", ts.Cids(), ts.Height())
|
||||||
|
prevHeaviest := cs.heaviest
|
||||||
cs.heaviest = ts
|
cs.heaviest = ts
|
||||||
|
|
||||||
if err := cs.writeHead(ctx, ts); err != nil {
|
if err := cs.writeHead(ctx, ts); err != nil {
|
||||||
@ -662,6 +650,18 @@ func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet)
|
|||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user