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

Add new chainsync package #542

Open
wants to merge 1 commit into
base: ezdac/01-remove-optimism
Choose a base branch
from

Conversation

ezdac
Copy link
Collaborator

@ezdac ezdac commented Oct 18, 2024

2/4 - Add new chainsync package

This is part of a series of 4 Pull Requests that all aim to refactor our old
chainsync mechanism. The reason to split this up is to provide more digestible
and grouped parts of the refactoring effort. I am aware this is a big change,
but especially for refactoring an integral part of the system, and designing
it at the same time, at least for me it is impossible to provide smaller
increments of work that don't leave the code in an uncompilable,
non-functional state.

This adds a new chainsync package that receives new latest-block updates from
an Ethereum JSON RPC server and backtracks a locally cached chain-segment of
previous blocks in comparison with the updated header information. It does this
in order to recognize reorgs and being able to invalidate all chain-state that
was inserted for a reorged-away chain-segment. The information of the difference
of old chain and new chain in case of reorgs is omitted by Ethereum JSON RPC
servers, since it is possible that only the new latest header is received by the
client, and intermediary sections of the new reorg chain are not passively
received. Therefore the client itself has to keep track of the most recent chain
and what gaps between the last common block of a potential new chain segment and
it's old chain-state's segment have to be filled.

In addition to this active syncing mechanism, the chainsync package provides
an easy way to register handler implementations that retrieve specific
contract-event updates for the newly received chain-segments and the context of
newly "reorged away" chain-segments are available in the same handler. That way,
each handler can define behavior on how to remove old state-updates due to newly
removed events and how to insert new state updates due to newly emitted events.

There is also the possibility to define and execute "chain-update" handler.
Those will not only receive updates for when the newly synced to chain-segment
contains a certain contract event, but they will be executed for every new chain
update and will provide the same chain-update context as the contract-event
handler.

@ezdac ezdac changed the base branch from main to ezdac/01-remove-optimism October 18, 2024 22:39
@ezdac ezdac marked this pull request as ready for review October 25, 2024 23:50
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.

1 participant