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

Use bridge time based events Read API in block production #12705

Open
taratorio opened this issue Nov 11, 2024 · 0 comments
Open

Use bridge time based events Read API in block production #12705

taratorio opened this issue Nov 11, 2024 · 0 comments
Labels
astrid imp2 Medium importance polygon

Comments

@taratorio
Copy link
Member

taratorio commented Nov 11, 2024

Currently, when running Astrid, the block mining flow uses the bridge to commit state sync events to the block. This is done inside FinalizeAndAssemble here.

The CommitStates function uses c.bridgeReader.Events(c.execCtx, blockNum) to fetch the events it needs to submit for the new block. This will not work when we are the block producer because the Bridge would have not seen a block with blockNum=X where X is the block we are currently mining.

Calling bridge.ProcessNewBlocks(blockX) would not work either, because calling that flow is the responsibility of the Block Consumer (in the sync package), not the Block Producer. E.g. failure scenario is we call ProcessNewBlocks(blockX), we mine the block, however our block is not the one that has higher difficulty so ends up being discarded. Then our Bridge will have inconsistent mappings. It is important that we do not call ProcessNewBlocks in Block Production. Think of Block Production as being read-only, never write.

A solution I propose to solve this is to introduce a new Read API on the Bridge and Bridge Reader:

EventsWithinTime(ctx, fromTime, toTime) []types.Message, error

Then, the block consumer will use bridge.Events(blockNum) as part of Finalize while the block producer will use bridge.EventsWithinTime(fromTime, toTime) as part of FinalizeAndAssemble.

In order to support such an API we will need to add a new table in the Bridge component which maps an event timestamp to its corresponding event id. Then the EventsWithinTime API can first collect the event ids that fall within the time window from this table and then fetch the corresponding events from the main events table using the ids.

Note this API needs to be supported only for hot state, so we can prune its data as part of the retirement flow in PruneAncientBlocks -> PruneHeimdall. No need to implement this lookup from snapshots.

The goal of this task is to:

  1. Implement bridge.EventsWithinTime
  2. Change the Bor consensus engine to use bridge.EventsWithinTime in FinalizeAndAssemble
@taratorio taratorio added this to the astrid-m3-standalone milestone Nov 11, 2024
@taratorio taratorio added imp2 Medium importance astrid polygon labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astrid imp2 Medium importance polygon
Projects
None yet
Development

No branches or pull requests

1 participant