Virtual Raindex event ingestion#2175
Open
hardyjosh wants to merge 3 commits into2025-09-26-virtual-raindexfrom
Open
Virtual Raindex event ingestion#2175hardyjosh wants to merge 3 commits into2025-09-26-virtual-raindexfrom
hardyjosh wants to merge 3 commits into2025-09-26-virtual-raindexfrom
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests
Comment |
… 2025-10-01-vr-event-stream
This was referenced Oct 3, 2025
rouzwelt
approved these changes
Oct 7, 2025
findolor
approved these changes
Oct 8, 2025
0xgleb
approved these changes
Oct 17, 2025
| fn u256_to_usize(value: &U256) -> Result<usize> { | ||
| value | ||
| .try_into() | ||
| .map_err(|_| RaindexError::Unimplemented("index too large for usize")) |
Collaborator
There was a problem hiding this comment.
Unimplemented doesn't seem like the best error variant to use here
Comment on lines
+237
to
+246
| /// Converts an iterator of [`OrderBookEvent`]s into a flat list of mutations. | ||
| pub fn orderbook_events_to_mutations<'a>( | ||
| events: impl IntoIterator<Item = OrderBookEvent<'a>>, | ||
| ) -> Result<Vec<RaindexMutation>> { | ||
| let mut mutations = Vec::new(); | ||
| for event in events { | ||
| mutations.extend(orderbook_event_to_mutations(event)?); | ||
| } | ||
| Ok(mutations) | ||
| } |
Collaborator
There was a problem hiding this comment.
nitpick: consider (.flatten_ok requires itertools)
Suggested change
| /// Converts an iterator of [`OrderBookEvent`]s into a flat list of mutations. | |
| pub fn orderbook_events_to_mutations<'a>( | |
| events: impl IntoIterator<Item = OrderBookEvent<'a>>, | |
| ) -> Result<Vec<RaindexMutation>> { | |
| let mut mutations = Vec::new(); | |
| for event in events { | |
| mutations.extend(orderbook_event_to_mutations(event)?); | |
| } | |
| Ok(mutations) | |
| } | |
| /// Converts an iterator of [`OrderBookEvent`]s into a flat list of mutations. | |
| pub fn orderbook_events_to_mutations<'a>( | |
| events: impl IntoIterator<Item = OrderBookEvent<'a>>, | |
| ) -> Result<Vec<RaindexMutation>> { | |
| events | |
| .into_iter() | |
| .map(orderbook_event_to_mutations) | |
| .flatten_ok() | |
| .collect() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Caution
Chained to #2167, merge first and update target for this to main
Motivation
We need the virtual raindex to replay on-chain activity without live RPC calls so we can fork mainnet orderbooks into an offline, deterministic sandbox. Before this work there was no log ingestion at all—virtual state could only be mutated directly—so parity checks, backfills, and event-driven simulations were impossible.
Solution
Introduce a dedicated events module that decodes OrderBook and Store logs into RaindexMutation batches (covering add/remove, deposit/withdraw, take orders, and clear/bounty flows), add complementary unit tests, and extend the integration harness to execute real takes/clears on an Anvil instance, replay the emitted logs, and assert the reconstructed snapshot matches the live virtual state.
The README now documents the ingestion pipeline so downstream callers can bootstrap virtual forks directly from recorded logs.
Checks
By submitting this for review, I'm confirming I've done the following: