-
Notifications
You must be signed in to change notification settings - Fork 5
feat: make historical epochs state #362
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
base: main
Are you sure you want to change the base?
Conversation
…t latest but number
… to common serde crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new historical_epochs_state module to track historical epoch information separately from the main epochs_state module, improving separation of concerns and enabling optional historical data storage. The refactoring moves epoch history storage from an in-memory DashMap to a persistent fjall database with proper volatile/immutable state separation.
Key Changes
- New
historical_epochs_statemodule with persistent storage using fjall database - Refactored
epochs_stateto remove history tracking and delegate to the new module - Updated REST handlers to query historical epochs from the new dedicated state module
- Added CBOR serialization support for
EpochActivityMessageand related types
Reviewed Changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
modules/historical_epochs_state/* |
New module implementing persistent historical epoch storage with volatile/immutable state separation |
modules/epochs_state/src/epochs_state.rs |
Removed epoch history logic and simplified to focus on current epoch tracking |
modules/epochs_state/src/state.rs |
Changed handle_mint to accept Option<&[u8]> for issuer_vkey |
modules/epochs_state/src/epochs_history.rs |
Deleted - functionality moved to new module |
modules/epochs_state/src/store_config.rs |
Deleted - no longer needed |
modules/rest_blockfrost/src/handlers/epochs.rs |
Updated to route historical queries to new module and validate epoch bounds |
modules/rest_blockfrost/src/handlers_config.rs |
Added historical epochs query topic configuration |
common/src/queries/epochs.rs |
Added DEFAULT_HISTORICAL_EPOCHS_QUERY_TOPIC constant |
common/src/messages.rs |
Added minicbor serialization derives to EpochActivityMessage |
common/src/protocol_params.rs |
Added minicbor serialization to Nonce types |
common/src/cbor.rs |
New module with custom u128 CBOR codec |
processes/omnibus/* |
Registered new module and added configuration section |
modules/accounts_state/src/accounts_state.rs |
Fixed log message from "subscriber" to "publisher" |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
modules/historical_epochs_state/src/immutable_historical_epochs_state.rs
Show resolved
Hide resolved
| for epoch in range { | ||
| let slice = self.epochs_history.get(Self::make_epoch_key(epoch))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fjall library has a range method which takes a range of keys and fetches everything in that range at once. Probably faster to use that and let fjall batch stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
6a951d1
| let db_path = if Path::new(&config.db_path).is_relative() { | ||
| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(&config.db_path) | ||
| } else { | ||
| PathBuf::from(&config.db_path) | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CARGO_MANIFEST_DIR is set at compile time, to a path on the compiling machine. It won't generally work to use it at runtime.
Honestly, we probably should just pass relative paths along unchanged. Filesystem APIs will treat them as relative to the PWD at runtime, which is probably the behavior we want for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing this out.
Now it uses relative path (both accounts and epochs historical state) and prefix default db path with fjall-* to add them .gitignore easily.
…ath with fjall and update gitignore files to ignore all db related files
whankinsiv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Could you please explain why this modules ready_to_prune logic is offset by one epoch compared to historical_accounts_state.
| pub fn new(path: impl AsRef<Path>) -> Result<Self> { | ||
| let cfg = fjall::Config::new(path) | ||
| // 4MB write buffer since EpochActivityMessage is not that big |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a clear-on-start config option.
lowhung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see the historical responsbility split out like this!
Description
This PR introduces a new dedicated
historical-epochs-statemodule for managing historical epoch data with persistent storage, refactors the existing epochs-state module to remove historical tracking responsibilities, and improves CBOR encoding forEpochActivityMessagewith customu128encoder/decoder.Changes
1. New historical-epochs-state Module
GetEpochInfo,GetNextEpochs,GetPreviousEpochs2. REST API Improvements
handle_epoch_info_blockfrostnow returns latest epoch when numeric param equals latestFixes
1. Epoch Activity Message Timing
2. Byron Block Mint Handling
Related Issue(s)
Related to #364
How was this tested?
historical_epochs_stateto testvolatile's prune, correctpersistentand reading from disk.minicborencode/decode foru128Checklist
Impact / Side effects
epochs_stateto servein-memoryepochs history.Reviewer notes / Areas to focus
historical_epochs_statemodule is the main changes of this PR.