Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay handler execution till after state update #1353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

td202
Copy link
Contributor

@td202 td202 commented Mar 19, 2025

Purpose

Closes #1352

This defers the execution of on-block and on-finalization handlers until after the consensus state has been committed. This in particular ensures that in the case of a protocol update, the consensus state is committed before the protocol update occurs (as this is part of the on-finalization handling). Consequently, a GetBlockInfo that queries the genesis block of a new consensus (created in the protocol update) will always be able to see the terminal block (which is available once the consensus state is committed).

This also ensures that if gRPC clients are notified of block arrivals, queries about those blocks will not fail, which was previously a theoretical possibility.

Changes

  • The SkovT implementation uses the MonadWriter aspect to produce a sequence of HandlerEvents rather than directly invoking a handler callback.
  • The handlers onBlockHandler, onFinalizationHandler and onPendingLiveHandler are removed from the HandlerContext, as the events will be used instead. (onPendingLiveHandler was not used anyway.)
  • The handler implementations are promoted from being part of the HandlerContext implementation to separate functions skovV1BlockHandler and skovV1FinalizeHandler.
  • These handlers are called as part of liftSkovV1Update, and are run after updating the state.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

@td202 td202 marked this pull request as ready for review March 19, 2025 16:39
@td202 td202 requested review from eb-concordium and drsk0 March 19, 2025 16:40
update ([#1352](https://github.com/Concordium/concordium-node/issues/1352)). The fix delays
executing the on-block and on-finalization handlers until after the state update has been
committed. This also should also result in better consistency in the gRPC API (i.e. if a client
is notified that a block has arrived, `GetBlockInfo` should not result in `NOT_FOUND` for thatb
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
is notified that a block has arrived, `GetBlockInfo` should not result in `NOT_FOUND` for thatb
is notified that a block has arrived, `GetBlockInfo` should not result in `NOT_FOUND` for that

- Fix a bug that can occasionally result in a crash if `GetBlockInfo` is invoked during a protocol
update ([#1352](https://github.com/Concordium/concordium-node/issues/1352)). The fix delays
executing the on-block and on-finalization handlers until after the state update has been
committed. This also should also result in better consistency in the gRPC API (i.e. if a client
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: "This also should also ... "

bufferedSendCatchUpStatus
forM_ finalizedBlocks $ \bp -> do
let height = localToAbsoluteBlockHeight genHeight (SkovV1.blockHeight bp)
let isHomeBaked = case nodeBakerIdMaybe of
Copy link
Contributor

Choose a reason for hiding this comment

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

could we factor this out and reuse in skovV1BlockHandler

@drsk0
Copy link
Contributor

drsk0 commented Mar 25, 2025

@td202 are there tests for this?

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.

BUG: Data race can lead to crash from GetBlockInfo
3 participants