From 0ff334912bea294ae0773bbd32e2aee7a4b66e2e Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 9 Aug 2023 18:00:33 -0400 Subject: [PATCH] Address review --- chain/store/store.go | 8 ++++++-- chain/sync.go | 1 - chain/sync_manager.go | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chain/store/store.go b/chain/store/store.go index a83c2fda3..a7075f4cc 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -428,8 +428,12 @@ func (cs *ChainStore) RefreshHeaviestTipSet(ctx context.Context, newTsHeight abi // Equivocation has occurred! We need a new head NOW! if newHeaviest == nil || newHeaviestWeight.LessThan(heaviestWeight) { log.Warnf("chainstore heaviest tipset's weight SHRANK from %d (%s) to %d (%s) due to equivocation", heaviestWeight, cs.heaviest, newHeaviestWeight, newHeaviest) - // refresh heaviestWeight 10 times moving up and down - + // Unfortunately, we don't know what the right height to form a new heaviest tipset is. + // It is _probably_, but not _necessarily_, heaviestHeight. + // So, we need to explore a range of epochs, finding the heaviest tipset in that range. + // We thus try to form the heaviest tipset for 5 epochs above heaviestHeight (most of which will likely not exist), + // as well as for 5 below. + // This is slow, but we expect to almost-never be here (only if miners are equivocating, which carries a hefty penalty). for i := heaviestHeight + 5; i > heaviestHeight-5; i-- { possibleHeaviestTs, possibleHeaviestWeight, err := cs.FormHeaviestTipSetForHeight(ctx, i) if err != nil { diff --git a/chain/sync.go b/chain/sync.go index 5f9d16557..6341deeeb 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -247,7 +247,6 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) bool { return false } - // TODO: this method name is a lie syncer.syncmgr.SetPeerHead(ctx, from, fts.TipSet()) return true } diff --git a/chain/sync_manager.go b/chain/sync_manager.go index 94017c276..3369c3b5a 100644 --- a/chain/sync_manager.go +++ b/chain/sync_manager.go @@ -92,6 +92,7 @@ type syncManager struct { var _ SyncManager = (*syncManager)(nil) type peerHead struct { + // Note: this doesn't _necessarily_ mean that p's head is ts, just that ts is a tipset that p sent to us p peer.ID ts *types.TipSet }