Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions block/internal/executing/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ func (e *Executor) produceBlock() error {
return fmt.Errorf("failed to save block: %w", err)
}

if err := e.store.SetHeight(e.ctx, newHeight); err != nil {
// Once the SaveBlockData has been saved we must update the height and the state.
// context.TODO() should be reverted to the real context (e.ctx) once https://github.com/evstack/ev-node/issues/2274 has been implemented, this prevents context cancellation
if err := e.store.SetHeight(context.TODO(), newHeight); err != nil {
return fmt.Errorf("failed to update store height: %w", err)
}

if err := e.updateState(e.ctx, newState); err != nil {
if err := e.updateState(context.TODO(), newState); err != nil {
return fmt.Errorf("failed to update state: %w", err)
}
Comment on lines +384 to 392
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While context.TODO() works, context.Background() is more idiomatic for creating a non-cancellable context. It more clearly communicates the intent to run a critical operation that must not be cancelled.

I've updated the code to use context.Background() and improved the comment to clarify the rationale.

Suggested change
// Once the SaveBlockData has been saved we must update the height and the state.
// context.TODO() should be reverted to the real context (e.ctx) once https://github.com/evstack/ev-node/issues/2274 has been implemented, this prevents context cancellation
if err := e.store.SetHeight(context.TODO(), newHeight); err != nil {
return fmt.Errorf("failed to update store height: %w", err)
}
if err := e.updateState(e.ctx, newState); err != nil {
if err := e.updateState(context.TODO(), newState); err != nil {
return fmt.Errorf("failed to update state: %w", err)
}
// Once block data is saved, height and state must be updated even if the context is cancelled.
// Using context.Background() prevents inconsistent state. See issue #2274.
if err := e.store.SetHeight(context.Background(), newHeight); err != nil {
return fmt.Errorf("failed to update store height: %w", err)
}
if err := e.updateState(context.Background(), newState); err != nil {
return fmt.Errorf("failed to update state: %w", err)
}


Expand Down
Loading