Skip to content

Conversation

golddydev
Copy link
Collaborator

@golddydev golddydev commented Sep 2, 2025

Enhanced SPO State Module with Historical Data Tracking and Aggregated State Management

Overview

This PR introduces enhancements to the SPO (Stake Pool Operator) state module, adding historical data tracking capabilities and a new aggregated state management system for active_stake and total_blocks_minted. The changes enable configurable storage of historical SPO data while maintaining backward compatibility and improving query performance.

Key Features Added

1. New Data Types (common/src/types.rs)

  • PoolUpdateAction: Enum for tracking pool registration/deregistration actions
  • PoolUpdateEvent: Structure for storing pool update events with transaction hash and certificate index

2. SPO State Refactor (modules/spo_state/src/state.rs)

  • Main State: Replace BlockState to State and remove State
  • History Management: Use history (for main State) in context runner.
  • Improved Rollback Handling: Implement roll back check for tx_certs message and check message synchronization.

3. Aggregated SPO State Management (modules/spo_state/src/aggregated_state.rs)

  • AggregatedSPOState: New state active_stake and total_blocks_minted till current epoch.
  • Active Stakes Tracking: Maintains active stakes per pool operator by epoch with automatic cleanup
  • Total Blocks Minted History: Volatile state tracking with security parameter-based pruning
  • State History Integration: Leverages existing state history infrastructure for rollback support for total_blocks_minted

4. Historical SPO State (modules/spo_state/src/historical_spo_state.rs)

  • HistoricalSPOState: Configurable structure for storing historical SPO data
  • Optional Fields: Registration, updates, delegators, and votes can be enabled/disabled via configuration

Configuration Options

The module now supports the following configuration flags:

  • store-epochs-history: Enable/disable epoch history storage
  • store-retired-pools: Enable/disable retired pools history
  • store-registration: Enable/disable pool registration history
  • store-updates: Enable/disable pool update events history
  • store-delegators: Enable/disable delegators history
  • store-votes: Enable/disable voting history
  • store-stake-addresses: Enable/disable stake addresses storage

Breaking Changes

None - This PR maintains full backward compatibility while adding new functionality.

- Added  struct to manage historical data for pool registrations, updates, and delegators.
- Implemented  to track active stakes and total blocks minted by epoch.
- Enhanced state management to handle new events related to pool updates and stake distributions.
- Updated store configuration to support new historical data options.
- Refactored existing state handling methods to integrate with the new structures.
@golddydev golddydev marked this pull request as ready for review September 2, 2025 15:01
@golddydev golddydev requested a review from whankinsiv September 2, 2025 15:01
Copy link
Collaborator

@whankinsiv whankinsiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking good. I would prefer there to be only 2 StateHistory's, one for the main state (block based) and one for epoch based state. My largest concern is regarding the duplication of StateAddressState which I don't understand the necessity for.

@golddydev golddydev requested a review from whankinsiv September 3, 2025 17:21
Copy link
Collaborator

@whankinsiv whankinsiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The feedback regarding total_blocks_minted will be implemented in #142

@sandtreader
Copy link
Collaborator

Sorry @golddydev there are now conflicts with Carla's relays (as we thought there might be). Happy to merge once fixed.

@golddydev
Copy link
Collaborator Author

Sorry @golddydev there are now conflicts with Carla's relays (as we thought there might be). Happy to merge once fixed.

Okay

@golddydev
Copy link
Collaborator Author

Sorry @golddydev there are now conflicts with Carla's relays (as we thought there might be). Happy to merge once fixed.

I fixed conflicts

@golddydev golddydev merged commit d1aaa5b into main Sep 4, 2025
2 checks passed
@golddydev golddydev deleted the golddydev/pool-delegators branch September 4, 2025 09:44
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.

3 participants