Skip to content

Commit

Permalink
Merge pull request #11159 from filecoin-project/asr/fix-frc-0051
Browse files Browse the repository at this point in the history
fix: chainstore: do not get stuck in unhappy equivocation cases
  • Loading branch information
arajasek authored Aug 15, 2023
2 parents 3318296 + 12e076e commit b226a7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 9 additions & 7 deletions chain/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,15 @@ func (cs *ChainStore) RefreshHeaviestTipSet(ctx context.Context, newTsHeight abi
}
}

if newHeaviest == nil {
return xerrors.Errorf("failed to refresh to a new valid tipset")
}

errTake := cs.takeHeaviestTipSet(ctx, newHeaviest)
if errTake != nil {
return xerrors.Errorf("failed to take newHeaviest tipset as head: %w", err)
// if we've found something, we know it's the heaviest equivocation-free head, take it IMMEDIATELY
if newHeaviest != nil {
errTake := cs.takeHeaviestTipSet(ctx, newHeaviest)
if errTake != nil {
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
}
}

Expand Down
5 changes: 3 additions & 2 deletions chain/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,9 @@ func TestEquivocations(t *testing.T) {
require.Nil(t, tryTs2)
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
require.ErrorContains(t, cg.ChainStore().RefreshHeaviestTipSet(ctx, blkAfterNulls.Height), "failed to refresh to a new valid tipset")
// now we "notify" at this height -- it should lead to no head change because there's no formable head in near epochs
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) {
Expand Down

0 comments on commit b226a7d

Please sign in to comment.