diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 98a1b16951..361fed66b3 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -3009,7 +3009,7 @@ func TestStore_NoViableHead_Reboot_DoublyLinkedTree(t *testing.T) { // The node is optimistic now. optimistic, err := service.IsOptimistic(ctx) require.NoError(t, err) - require.Equal(t, true, optimistic) + require.Equal(t, false, optimistic) require.Equal(t, false, service.ForkChoicer().AllTipsAreInvalid()) // Check that the node's justified checkpoint does not agree with the @@ -3233,7 +3233,7 @@ func TestStore_NoViableHead_Reboot_Protoarray(t *testing.T) { // The node is optimistic now optimistic, err := service.IsOptimistic(ctx) require.NoError(t, err) - require.Equal(t, true, optimistic) + require.Equal(t, false, optimistic) require.Equal(t, false, service.ForkChoicer().AllTipsAreInvalid()) // Check that the node's justified checkpoint does not agree with the diff --git a/beacon-chain/forkchoice/doubly-linked-tree/node.go b/beacon-chain/forkchoice/doubly-linked-tree/node.go index bc2bf5f357..20be1226fe 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/node.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/node.go @@ -116,10 +116,13 @@ func (n *Node) setNodeAndParentValidated(ctx context.Context) error { return ctx.Err() } - if !n.optimistic || n.parent == nil { + if !n.optimistic { return nil } - n.optimistic = false + + if n.parent == nil { + return nil + } return n.parent.setNodeAndParentValidated(ctx) } diff --git a/beacon-chain/forkchoice/doubly-linked-tree/optimistic_sync_test.go b/beacon-chain/forkchoice/doubly-linked-tree/optimistic_sync_test.go index 5b10b529bf..f6c2fad2d1 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/optimistic_sync_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/optimistic_sync_test.go @@ -389,3 +389,14 @@ func TestSetOptimisticToInvalid_ForkAtMerge_bis(t *testing.T) { }) require.DeepEqual(t, roots, [][32]byte{{'b'}, {'c'}, {'d'}, {'e'}}) } + +func TestSetOptimisticToValid(t *testing.T) { + f := setup(1, 1) + op, err := f.IsOptimistic([32]byte{}) + require.NoError(t, err) + require.Equal(t, true, op) + require.NoError(t, f.SetOptimisticToValid(context.Background(), [32]byte{})) + op, err = f.IsOptimistic([32]byte{}) + require.NoError(t, err) + require.Equal(t, false, op) +}