Skip to content

Conversation

golddydev
Copy link
Collaborator

@golddydev golddydev commented Sep 11, 2025

Module Refactoring: Epoch Activity Counter → Epochs State

Rename epoch_activity_counter to epochs_state since that module is not stateless and start storing state (e.g. block hashes).

Key Changes

Implemented BF Endpoints

  • /pools/{pool_id}/blocks: All block hashes minted by pool.
  • /pools/{pool_id}/updates: Pool's Update events (registered and deregistered)
  • /pools/{pool_id}/votes: History of Stake pool's votes.
  • /pools/{pool_id}: Pool's Detailed Information (only missing calidus_key against BF)

Fixes on several calculation

  • Pools Delegators: Updated it to only include (or sum) utxo_value of stake_keys.
  • DRep Delegators: Updated it to only include (or sum) utxo_value of stake_keys.

🆕 New Functionality & Data Structures

  • Pool Update Tracking: Added support for pool registration/retirement tracking with position information to spo_state (PoolRegistrationWithPos, PoolRetirementWithPos)
  • Pool Vote Tracking: Added support for pool's vote history tracking with position information to spo_state
  • Extended pool-related queries: Added new queries for:
    • Optimal pool sizing (For pool saturation calculation - From accounts_state)
    • Pool live stake information
    • Accounts UTXO values mapping & sum (this is used for live_pledge)

Refactor SPO State

  • "Remove Aggregated State": Remove AggregatedSPOState (which only stores active_stakes) and instead rely on epochs_history for active_stakes.

New Common Types

  • BlockHash: Introduce new BlockHash type as [u8; 32]

… state

- Replaced Vec<u8> with BlockHash type in BlockInfo for better type safety.
- Added BlockHash type definition and HashTraits implementation.
- Updated various modules to utilize the new BlockHash type, including state management and query responses.
- Enhanced StoreConfig to support block hash storage configuration.
- Adjusted tests to reflect changes in block hash handling.
- Removed unused GetPoolBlocks query from PoolsStateQuery.
- Enhanced get_block_hashes method to return an empty vector instead of an Option.
- Implemented pool blocks retrieval in handle_pool_blocks_blockfrost, including error handling for missing parameters and invalid pool IDs.
- Added support for querying pool information and block hashes in the SPOState module.
@golddydev golddydev changed the title feat: expand epochs state feat: expand epochs state; impl pool's historical endpoints Sep 11, 2025
@golddydev golddydev changed the base branch from main to golddydev/stake-addresses-in-spo-state September 11, 2025 15:37
…nance message

- Renamed and reorganized subscription topics for clarity and consistency.
- Introduced governance subscription handling in the SPOState module.
- Added support for retrieving pool updates and votes in the SPOState module.
- Updated PoolUpdates and PoolVotes structures to include relevant data.
- Enhance serde for PoolUpdateEvent and VoteRecord
Base automatically changed from golddydev/stake-addresses-in-spo-state to main September 15, 2025 12:34
- Added new queries for retrieving pool live stake information and optimal pool sizing.
- Implemented methods to get accounts' UTXO values and their sums.
- Refactored existing code to improve clarity and maintainability.
@golddydev golddydev marked this pull request as ready for review September 15, 2025 16:44
@golddydev golddydev linked an issue Sep 15, 2025 that may be closed by this pull request
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 good. I would prefer to see this PR broken up into 3 separate PRs with one for the epoch_state refactor, another for the expanded spo_state, and the third for the REST handling.


if let Some(block_hashes) = self.block_hashes.as_mut() {
let block_hash: Option<BlockHash> = block
.hash
Copy link
Collaborator

Choose a reason for hiding this comment

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

block.hash should be converted to the BlockHash type in mithril_snapshot_fetcher.


pub fn get_blocks_minted_data_by_pool(&self, vrf_key_hash: &KeyHash) -> (u64, u64) {
(
self.total_blocks_minted.get(vrf_key_hash).map(|v| *v as u64).unwrap_or(0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is v here not already u64?


let total_supply =
shelly_params.max_lovelace_supply - self.rewards_state.mark.pots.reserves;
let nopt = shelly_params.protocol_params.stake_pool_target_num as u64;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this not already u64?

slot,
number,
hash: block.hash().to_vec(),
hash: *block.hash(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Convert to BlockHash type here as mentioned above.

return None;
};
Some(delegators.insert(delegator.clone()))
Some(delegators.insert(delegator.clone()).is_some())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect, it should be

pub fn add_delegator(&mut self, delegator: &KeyHash) -> Option<bool> {
    self.delegators.as_mut().map(|d| d.insert(delegator.clone()))
}

return None;
};
Some(delegators.remove(delegator))
Some(delegators.remove(delegator).is_some())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing here, it should be

pub fn remove_delegator(&mut self, delegator: &KeyHash) -> Option<bool> {
    self.delegators.as_mut().map(|d| d.remove(delegator))
}

Comment on lines +207 to +216
pub fn get_pool_votes(&self, pool_id: &KeyHash) -> Option<Vec<VoteRecord>> {
let Some(historical_spos) = self.historical_spos.as_ref() else {
return None;
};

let votes: Option<Vec<VoteRecord>> =
historical_spos.get(pool_id).map(|s| s.votes.clone()).flatten();
votes
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be:

pub fn get_pool_votes(&self, pool_id: &KeyHash) -> Option<Vec<VoteRecord>> {
    self.historical_spos
        .as_ref()?
        .get(pool_id)
        .and_then(|s| s.votes.clone())
}

Comment on lines +195 to +204
/// Get Pool Updates
pub fn get_pool_updates(&self, pool_id: &KeyHash) -> Option<Vec<PoolUpdateEvent>> {
let Some(historical_spos) = self.historical_spos.as_ref() else {
return None;
};

let updates: Option<Vec<PoolUpdateEvent>> =
historical_spos.get(pool_id).map(|s| s.updates.clone()).flatten();
updates
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be:

pub fn get_pool_updates(&self, pool_id: &KeyHash) -> Option<Vec<PoolUpdateEvent>> {
    self.historical_spos
        .as_ref()?
        .get(pool_id)
        .and_then(|s| s.updates.clone())
}

block.slot, block.number
);
let point = Point::Specific(block.slot, block.hash.clone());
let point = Point::Specific(block.slot, block.hash.to_vec());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a fixed length type instead of a vec.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but this Point is from pallas

@golddydev golddydev marked this pull request as draft September 16, 2025 13:00
@golddydev
Copy link
Collaborator Author

Closing this PR favor of
#175
#177
#187

@golddydev golddydev closed this Sep 16, 2025
@golddydev golddydev deleted the golddydev/expand-epochs-state branch September 17, 2025 12:18
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.

Rename epoch_activity_counter to epochs_state Implement /pools/{pool_id}/blocks, updates, votes and /pools/{pool_id} endpoints
2 participants