Skip to content

Commit

Permalink
fix(sync): mark blocks which diverge from checkpoint as bad (#12763)
Browse files Browse the repository at this point in the history
Resolves flake in `TestSyncCheckpointHead`

Fixes: #12758

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
  • Loading branch information
Kubuxu authored Dec 9, 2024
1 parent 6347eff commit e145ef5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions chain/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ loop:

if !ignoreCheckpoint {
if chkpt := syncer.store.GetCheckpoint(); chkpt != nil && base.Height() <= chkpt.Height() {
for _, b := range incoming.Blocks() {
syncer.bad.Add(b.Cid(), NewBadBlockReason(incoming.Cids(), "diverges from checkpoint"))
}
return nil, xerrors.Errorf("merge point affecting the checkpoing: %w", ErrForkCheckpoint)
}
}
Expand Down
8 changes: 5 additions & 3 deletions chain/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type syncTestUtil struct {

func prepSyncTest(t testing.TB, h int) *syncTestUtil {
_ = logging.SetLogLevel("*", "INFO")
_ = logging.SetLogLevel("fil-consensus", "ERROR")

g, err := gen.NewGenerator()
if err != nil {
Expand Down Expand Up @@ -956,7 +957,7 @@ func TestSyncCheckpointHead(t *testing.T) {
tu.loadChainToNode(p2)

base := tu.g.CurTipset
fmt.Println("Mining base: ", base.TipSet().Cids(), base.TipSet().Height())
t.Log("Mining base: ", base.TipSet().Cids(), base.TipSet().Height())

// The two nodes fork at this point into 'a' and 'b'
a1 := tu.mineOnBlock(base, p1, []int{0}, true, false, nil, 0, true)
Expand All @@ -973,14 +974,15 @@ func TestSyncCheckpointHead(t *testing.T) {
b = tu.mineOnBlock(b, p2, []int{1}, true, false, nil, 0, true)
b = tu.mineOnBlock(b, p2, []int{1}, true, false, nil, 0, true)

fmt.Println("A: ", a.Cids(), a.TipSet().Height())
fmt.Println("B: ", b.Cids(), b.TipSet().Height())
t.Log("A: ", a.Cids(), a.TipSet().Height())
t.Log("B: ", b.Cids(), b.TipSet().Height())

// Now for the fun part!! p1 should mark p2's head as BAD.

require.NoError(t, tu.mn.LinkAll())
tu.connect(p1, p2)
tu.waitUntilNodeHasTs(p1, b.TipSet().Key())

p1Head := tu.getHead(p1)
require.True(tu.t, p1Head.Equals(a.TipSet()))
tu.assertBad(p1, b.TipSet())
Expand Down

0 comments on commit e145ef5

Please sign in to comment.