Skip to content

Do not block when informing the view changer of a new view - #713

Merged
pfi79 merged 2 commits into
hyperledger:mainfrom
HagarMeir:fix/inform-new-view-nonblocking
Oct 19, 2026
Merged

pfi79 merged 2 commits into
hyperledger:mainfrom
HagarMeir:fix/inform-new-view-nonblocking

Conversation

@HagarMeir

Copy link
Copy Markdown
Contributor

Written by Claude (Anthropic's AI assistant) on behalf of Hagar Meir.

Fixes #712.

The controller informs the view changer of a new view after a sync, from its run loop. InformNewView sent on a channel with a buffer of one. So if the view changer hadn't yet processed the previous view, the controller's run loop blocked until it did.

Changes

  • InformNewView never blocks. If a view is already pending, it keeps only the higher of the two, so the view changer still moves to the latest view.
  • TestInformNewViewDoesNotBlock informs a view changer that isn't running yet of three views. It checks that no call blocks, and that the view changer ends up in the latest view. On main the second call blocks.
  • TestInformViewChanger used to call InformNewView twice, relying on the second call blocking to know the first was processed. It now waits for the view changer to restart the request timers, which it does once it processes the view.

🤖 Generated with Claude Code

The controller informs the view changer of a new view after a sync,
from its run loop. InformNewView sent on a channel with a buffer of one,
so if the view changer had not processed the previous view yet, the
controller's run loop blocked until it did.

Keep only the highest pending view instead, so InformNewView never
blocks and the view changer still moves to the latest view.
TestInformViewChanger relied on the second call blocking to know the
first was processed; it now waits for the timers to be restarted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
@pfi79

pfi79 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor
  1. Is the “max pending view” write race-free, or is the single-threaded invariant documented?
    Please point to the field/update in InformNewView and confirm it is mutex/atomic-protected, or that a comment explicitly states it is only called from the controller run loop.

  2. Does TestInformViewChanger avoid time.Sleep-based synchronization?
    Please point to the channel/Eventually/signal the test uses to wait for timer restart — not a sleep.

  3. Is there a comment explaining “don’t block, keep the max”?
    Please point to the comment near the pending-view logic that documents why we keep only the highest view instead of blocking.

Document that InformNewView is called from the controller's run loop,
why keeping only the higher pending view loses nothing, and that the
pending view is held only in informChan so concurrent calls are safe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
@HagarMeir

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

  1. There's no shared field: the pending view is held only in informChan (buffer of one), and view is local to the call, so the channel operations are the only synchronization needed and concurrent calls are safe. The only caller today is Controller.sync on the controller's run loop, but the code doesn't rely on it. I've added this to the comment.
  2. Yes, no sleeps. Both tests wait on the informed channel, which the RestartTimers mock signals once the view changer processes the view (time.After is only used as a failure timeout).
  3. Expanded the comment on InformNewView to explain why it must not block and why keeping only the highest view loses nothing (1799c74).

(Written by Claude on behalf of Hagar Meir.)

@pfi79
pfi79 merged commit e65e57d into hyperledger:main Oct 19, 2026
6 checks passed
@HagarMeir
HagarMeir deleted the fix/inform-new-view-nonblocking branch October 19, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Informing the view changer of a new view can block the controller's run loop

2 participants