From e68f69b63b51cf4bb44524be1f728967c09ade79 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 2 Nov 2020 22:56:26 +0100 Subject: [PATCH] Call GetHeaviestTipSet() only once when syncing Signed-off-by: Jakub Sztandera --- chain/sync.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 1410dd2a7..5813b939e 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -563,15 +563,16 @@ func (syncer *Syncer) Sync(ctx context.Context, maybeHead *types.TipSet) error { ) } - if syncer.store.GetHeaviestTipSet().ParentWeight().GreaterThan(maybeHead.ParentWeight()) { + hts := syncer.store.GetHeaviestTipSet() + + if hts.ParentWeight().GreaterThan(maybeHead.ParentWeight()) { + return nil + } + if syncer.Genesis.Equals(maybeHead) || hts.Equals(maybeHead) { return nil } - if syncer.Genesis.Equals(maybeHead) || syncer.store.GetHeaviestTipSet().Equals(maybeHead) { - return nil - } - - if err := syncer.collectChain(ctx, maybeHead); err != nil { + if err := syncer.collectChain(ctx, maybeHead, hts); err != nil { span.AddAttributes(trace.StringAttribute("col_error", err.Error())) span.SetStatus(trace.Status{ Code: 13, @@ -1684,14 +1685,14 @@ func persistMessages(ctx context.Context, bs bstore.Blockstore, bst *exchange.Co // // 3. StageMessages: having acquired the headers and found a common tipset, // we then move forward, requesting the full blocks, including the messages. -func (syncer *Syncer) collectChain(ctx context.Context, ts *types.TipSet) error { +func (syncer *Syncer) collectChain(ctx context.Context, ts *types.TipSet, hts *types.TipSet) error { ctx, span := trace.StartSpan(ctx, "collectChain") defer span.End() ss := extractSyncState(ctx) - ss.Init(syncer.store.GetHeaviestTipSet(), ts) + ss.Init(hts, ts) - headers, err := syncer.collectHeaders(ctx, ts, syncer.store.GetHeaviestTipSet()) + headers, err := syncer.collectHeaders(ctx, ts, hts) if err != nil { ss.Error(err) return err