fix: chainstore: do not get stuck in unhappy equivocation cases

This commit is contained in:
Aayush 2023-08-11 16:46:56 -04:00
parent 7b43f90a3b
commit 12e076e9ea
2 changed files with 12 additions and 9 deletions

View File

@ -446,14 +446,16 @@ func (cs *ChainStore) RefreshHeaviestTipSet(ctx context.Context, newTsHeight abi
} }
} }
if newHeaviest == nil { // if we've found something, we know it's the heaviest equivocation-free head, take it IMMEDIATELY
return xerrors.Errorf("failed to refresh to a new valid tipset") if newHeaviest != nil {
}
errTake := cs.takeHeaviestTipSet(ctx, newHeaviest) errTake := cs.takeHeaviestTipSet(ctx, newHeaviest)
if errTake != nil { if errTake != nil {
return xerrors.Errorf("failed to take newHeaviest tipset as head: %w", err) return xerrors.Errorf("failed to take newHeaviest tipset as head: %w", err)
} }
} else {
// if we haven't found something, just stay with our equivocation-y head
newHeaviest = cs.heaviest
}
} }
// if the new height we were notified about isn't what we just refreshed at, see if we have a heavier tipset there // if the new height we were notified about isn't what we just refreshed at, see if we have a heavier tipset there

View File

@ -396,8 +396,9 @@ func TestEquivocations(t *testing.T) {
require.Nil(t, tryTs2) require.Nil(t, tryTs2)
require.True(t, tryTsWeight2.IsZero()) require.True(t, tryTsWeight2.IsZero())
// now we "notify" at this height -- it should fail, because we cannot refresh our head due to equivocation and nulls // now we "notify" at this height -- it should lead to no head change because there's no formable head in near epochs
require.ErrorContains(t, cg.ChainStore().RefreshHeaviestTipSet(ctx, blkAfterNulls.Height), "failed to refresh to a new valid tipset") require.NoError(t, cg.ChainStore().RefreshHeaviestTipSet(ctx, blkAfterNulls.Height))
require.True(t, headAfterNulls.TipSet.TipSet().Equals(cg.ChainStore().GetHeaviestTipSet()))
} }
func addBlockToTracker(t *testing.T, cs *store.ChainStore, blk *types.BlockHeader) { func addBlockToTracker(t *testing.T, cs *store.ChainStore, blk *types.BlockHeader) {