-
Notifications
You must be signed in to change notification settings - Fork 5
feat: implement SPDD history storage, add serde_as for Bech32 #248
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
Conversation
…counts state module - Added SPDDStore to store Stake Pool Delegation Distribution data using fjall. - Introduced methods to store and query SPDD by epoch and pool ID. - Updated AccountsState to handle new SPDD queries. - Enhanced REST API to support fetching SPDD data by epoch and pool. - Added configuration option to enable SPDD history storage. - Add serialize as functions for Bech32. - Included tests for SPDDStore functionality.
…nitialization - Removed existing data deletion logic from SPDDStore initialization.
- Introduced query to enum. - Use network from instead of hard-coded, in epochs spdd endpoints
- Introduced a new configuration option for SPDD retention epochs in accounts state. - Updated SPDDStore to support retention logic, allowing automatic pruning of old epochs. - Enhanced logging to provide information on retention settings and pruning actions. - Added tests to verify the pruning functionality for stored epochs.
- Updated SPDDStore to track the latest stored epoch and added logic to check if an epoch is stored based on retention settings. - Modified AccountsState to utilize the new epoch checking logic when querying SPDD data. - Adjusted omnibus.toml to enable SPDD history storage and set retention epochs for better management of stored data.
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.
Had some questions re: comments being left in the code. Would be curious to hear what others think about this too.
- Refactored to streamline epoch data management, including methods for checking epoch completion and removing epoch data. - Updated query methods to utilize the new type and improved error handling for incomplete epochs. - Enhanced test cases to reflect changes in data structures and ensure correctness of epoch operations. - Introduced a new type in for better clarity.
Overall comment - the description says it's a new SPDDStore module (which is ideal) but there are changes to AccountsState to do it. I'm worried AccountsState is already too big, so if it could be moved out into an SPDDStore which just tracks the SPDD output from AccountsState, that would be better. (Actually just checked, we already have an SPDDState module which tracks this - this needs to go as an extension to that) |
Hi @sandtreader. Golddy and I discussed this; the main reason we placed per-pool SPDD in |
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.
Needs to move to SPDDState as per comment
Ah, does it go down into individual delegators? Of course it does, that's why it's so huge. Understood - apologies and objection withdrawn! |
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.
Looks great! Merging.
feat: add historical SPDD storage and query capabilities
Summary
This PR implements persistent storage and querying of historical Stake Pool Delegation Distribution (SPDD) data using the
fjall
embedded key-value database. This enables querying stake distribution snapshots by epoch and pool ID.Changes
New Features
SPDDStore
module to persist SPDD state per epoch with retention configuration.GetSPDDByEpoch
: Query all delegations for a specific epochGetSPDDByEpochAndPool
: Query delegations for a specific pool in an epochstore-spdd-history
flag (default:false
) to enable/disable SPDD persistenceCore Implementation
Database Layer (
spo_distribution_store.rs
):epoch (8 bytes) + pool_id (28 bytes) + stake_key (28 bytes)
State Integration:
dump_spdd_state()
method added to extract current SPDD stateepoch + 1
- because this is active stakes)accounts_state
moduleRetention Epochs:
spdd-retention-epochs
: Set this configuration tou64
or"none"
to store only lastX
epochs spdd history or all history.Network Support:
GetNetworkName
query toparameters-state
modulemainnet/testnet
)Developer Experience
DisplayFromBech32<PREFIX>
with HRP prefix support for cleaner Bech32 serialization/deserializationOther
.gitignore
entry for*_db
database directoriesTesting
Notes
mainnet
when we convert stake key hash to bech32 stake address.spdd_db/
path (gitignored)Storage Estimation Per Epoch
Data Structure
Per delegation record:
Cardano Network Statistics (current mainnet):
Estimated on-disk size per epoch:
≈ 115-125 MB per epoch
Long-term Storage Projections