-
Notifications
You must be signed in to change notification settings - Fork 4
feat: expand epochs state; impl pool's historical endpoints #173
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
… 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.
…e tx_hash and cert_index
…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
…expand-epochs-state
- 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.
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.
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 |
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.
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), |
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.
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; |
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.
Is this not already u64?
slot, | ||
number, | ||
hash: block.hash().to_vec(), | ||
hash: *block.hash(), |
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.
Convert to BlockHash type here as mentioned above.
return None; | ||
}; | ||
Some(delegators.insert(delegator.clone())) | ||
Some(delegators.insert(delegator.clone()).is_some()) |
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.
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()) |
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.
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))
}
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 | ||
} | ||
|
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.
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())
}
/// 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 | ||
} |
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.
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()); |
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.
This should be a fixed length type instead of a vec.
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.
Yes, but this Point
is from pallas
Module Refactoring: Epoch Activity Counter → Epochs State
Rename
epoch_activity_counter
toepochs_state
since that module is not stateless and start storing state (e.g. block hashes).Key Changes
Implemented BF Endpoints
registered
andderegistered
)calidus_key
against BF)Fixes on several calculation
utxo_value
ofstake_keys
.utxo_value
ofstake_keys
.🆕 New Functionality & Data Structures
spo_state
(PoolRegistrationWithPos
,PoolRetirementWithPos
)spo_state
accounts_state
)live_pledge
)Refactor SPO State
AggregatedSPOState
(which only storesactive_stakes
) and instead rely onepochs_history
foractive_stakes
.New Common Types
BlockHash
type as[u8; 32]