diff --git a/common/src/messages.rs b/common/src/messages.rs index 5f8cdbf2..09f98164 100644 --- a/common/src/messages.rs +++ b/common/src/messages.rs @@ -148,17 +148,25 @@ pub struct EpochActivityMessage { pub epoch: u64, /// Epoch start time + /// UNIX timestamp pub epoch_start_time: u64, /// Epoch end time + /// UNIX timestamp pub epoch_end_time: u64, - /// First block time + /// When first block of this epoch was created pub first_block_time: u64, - /// Last block time + /// Block height of first block of this epoch + pub first_block_height: u64, + + /// When last block of this epoch was created pub last_block_time: u64, + /// Block height of last block of this epoch + pub last_block_height: u64, + /// Total blocks in this epoch pub total_blocks: usize, diff --git a/common/src/queries/epochs.rs b/common/src/queries/epochs.rs index 62b04109..42e2eba9 100644 --- a/common/src/queries/epochs.rs +++ b/common/src/queries/epochs.rs @@ -11,8 +11,6 @@ pub enum EpochsStateQuery { GetPreviousEpochs { epoch_number: u64 }, GetEpochStakeDistribution { epoch_number: u64 }, GetEpochStakeDistributionByPool { epoch_number: u64 }, - GetEpochBlockDistribution { epoch_number: u64 }, - GetEpochBlockDistributionByPool { epoch_number: u64 }, GetLatestEpochBlocksMintedByPool { vrf_key_hash: KeyHash }, } @@ -24,8 +22,6 @@ pub enum EpochsStateQueryResponse { PreviousEpochs(PreviousEpochs), EpochStakeDistribution(EpochStakeDistribution), EpochStakeDistributionByPool(EpochStakeDistributionByPool), - EpochBlockDistribution(EpochBlockDistribution), - EpochBlockDistributionByPool(EpochBlockDistributionByPool), LatestEpochBlocksMintedByPool(u64), NotFound, @@ -62,9 +58,3 @@ pub struct EpochStakeDistribution {} #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct EpochStakeDistributionByPool {} - -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct EpochBlockDistribution {} - -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] -pub struct EpochBlockDistributionByPool {} diff --git a/common/src/queries/pools.rs b/common/src/queries/pools.rs index 6608cf45..0cf53e78 100644 --- a/common/src/queries/pools.rs +++ b/common/src/queries/pools.rs @@ -1,6 +1,6 @@ use crate::{ - queries::governance::VoteRecord, rational_number::RationalNumber, BlockHash, KeyHash, - PoolEpochState, PoolMetadata, PoolRegistration, PoolRetirement, PoolUpdateEvent, Relay, + queries::governance::VoteRecord, rational_number::RationalNumber, KeyHash, PoolEpochState, + PoolMetadata, PoolRegistration, PoolRetirement, PoolUpdateEvent, Relay, }; pub const DEFAULT_POOLS_QUERY_TOPIC: (&str, &str) = @@ -41,9 +41,13 @@ pub enum PoolsStateQuery { GetPoolTotalBlocksMinted { pool_id: KeyHash, }, - GetPoolBlockHashes { + GetBlocksByPool { pool_id: KeyHash, }, + GetBlocksByPoolAndEpoch { + pool_id: KeyHash, + epoch: u64, + }, GetPoolUpdates { pool_id: KeyHash, }, @@ -67,7 +71,10 @@ pub enum PoolsStateQueryResponse { PoolRelays(Vec), PoolDelegators(PoolDelegators), PoolTotalBlocksMinted(u64), - PoolBlockHashes(Vec), + // Vector of Block Heights + BlocksByPool(Vec), + // Vector of Block Heights + BlocksByPoolAndEpoch(Vec), PoolUpdates(Vec), PoolVotes(Vec), NotFound, diff --git a/modules/epochs_state/src/epochs_history.rs b/modules/epochs_state/src/epochs_history.rs index 23ee3078..ee2d67bf 100644 --- a/modules/epochs_state/src/epochs_history.rs +++ b/modules/epochs_state/src/epochs_history.rs @@ -117,7 +117,9 @@ mod tests { epoch_start_time: 0, epoch_end_time: 0, first_block_time: 0, + first_block_height: 0, last_block_time: 0, + last_block_height: 0, total_blocks: 1, total_txs: 1, total_outputs: 100, @@ -147,7 +149,9 @@ mod tests { epoch_start_time: 0, epoch_end_time: 0, first_block_time: 0, + first_block_height: 0, last_block_time: 0, + last_block_height: 0, total_blocks: 1, total_txs: 1, total_outputs: 100, @@ -165,7 +169,9 @@ mod tests { epoch_start_time: 0, epoch_end_time: 0, first_block_time: 0, + first_block_height: 0, last_block_time: 0, + last_block_height: 0, total_blocks: 1, total_txs: 1, total_outputs: 100, diff --git a/modules/epochs_state/src/state.rs b/modules/epochs_state/src/state.rs index a443eb8e..7e2d3120 100644 --- a/modules/epochs_state/src/state.rs +++ b/modules/epochs_state/src/state.rs @@ -29,10 +29,16 @@ pub struct State { // UNIX timestamp first_block_time: u64, + // first block height + first_block_height: u64, + // last block time // UNIX timestamp last_block_time: u64, + // last block height + last_block_height: u64, + // Map of counts by VRF key hashes blocks_minted: HashMap, @@ -63,7 +69,9 @@ impl State { epoch: 0, epoch_start_time: genesis.byron_timestamp, first_block_time: genesis.byron_timestamp, + first_block_height: 0, last_block_time: 0, + last_block_height: 0, blocks_minted: HashMap::new(), epoch_blocks: 0, epoch_txs: 0, @@ -178,6 +186,7 @@ impl State { // This will update last block time pub fn handle_mint(&mut self, block_info: &BlockInfo, vrf_vkey: Option<&[u8]>) { self.last_block_time = block_info.timestamp; + self.last_block_height = block_info.number; self.epoch_blocks += 1; if let Some(vrf_vkey) = vrf_vkey { @@ -215,7 +224,9 @@ impl State { self.epoch = block_info.epoch; self.epoch_start_time = block_info.timestamp; self.first_block_time = block_info.timestamp; + self.first_block_height = block_info.number; self.last_block_time = block_info.timestamp; + self.last_block_height = block_info.number; self.blocks_minted.clear(); self.epoch_blocks = 0; self.epoch_txs = 0; @@ -231,7 +242,9 @@ impl State { epoch_start_time: self.epoch_start_time, epoch_end_time: self.epoch_start_time + EPOCH_LENGTH, first_block_time: self.first_block_time, + first_block_height: self.first_block_height, last_block_time: self.last_block_time, + last_block_height: self.last_block_height, // NOTE: // total_blocks will be missing one // This is only because we now ignore EBBs @@ -422,7 +435,9 @@ mod tests { assert!(state.blocks_minted.is_empty()); assert_eq!(state.epoch_start_time, block.timestamp); assert_eq!(state.first_block_time, block.timestamp); + assert_eq!(state.first_block_height, block.number); assert_eq!(state.last_block_time, block.timestamp); + assert_eq!(state.last_block_height, block.number); let blocks_minted = state.get_latest_epoch_blocks_minted_by_pool(&keyhash(b"vrf_1")); assert_eq!(blocks_minted, 0); diff --git a/modules/rest_blockfrost/src/handlers/epochs.rs b/modules/rest_blockfrost/src/handlers/epochs.rs index 3d0cd071..4486fadb 100644 --- a/modules/rest_blockfrost/src/handlers/epochs.rs +++ b/modules/rest_blockfrost/src/handlers/epochs.rs @@ -8,9 +8,11 @@ use acropolis_common::{ accounts::{AccountsStateQuery, AccountsStateQueryResponse}, epochs::{EpochsStateQuery, EpochsStateQueryResponse}, parameters::{ParametersStateQuery, ParametersStateQueryResponse}, + pools::{PoolsStateQuery, PoolsStateQueryResponse}, spdd::{SPDDStateQuery, SPDDStateQueryResponse}, utils::query_state, }, + serialization::Bech32WithHrp, }; use anyhow::{anyhow, Result}; use caryatid_sdk::Context; @@ -417,9 +419,71 @@ pub async fn handle_epoch_total_blocks_blockfrost( } pub async fn handle_epoch_pool_blocks_blockfrost( - _context: Arc>, - _params: Vec, - _handlers_config: Arc, + context: Arc>, + params: Vec, + handlers_config: Arc, ) -> Result { - Ok(RESTResponse::with_text(501, "Not implemented")) + if params.len() != 2 { + return Ok(RESTResponse::with_text( + 400, + "Expected two parameters: an epoch number and a pool ID", + )); + } + let epoch_number_param = ¶ms[0]; + let pool_id_param = ¶ms[1]; + + let epoch_number = match epoch_number_param.parse::() { + Ok(num) => num, + Err(_) => { + return Ok(RESTResponse::with_text( + 400, + "Invalid epoch number parameter", + )); + } + }; + + let Ok(spo) = Vec::::from_bech32_with_hrp(pool_id_param, "pool") else { + return Ok(RESTResponse::with_text( + 400, + &format!("Invalid Bech32 stake pool ID: {pool_id_param}"), + )); + }; + + // query Pool's Blocks by epoch from spo-state + let msg = Arc::new(Message::StateQuery(StateQuery::Pools( + PoolsStateQuery::GetBlocksByPoolAndEpoch { + pool_id: spo.clone(), + epoch: epoch_number, + }, + ))); + + let blocks = query_state( + &context, + &handlers_config.pools_query_topic, + msg, + |message| match message { + Message::StateQueryResponse(StateQueryResponse::Pools( + PoolsStateQueryResponse::BlocksByPoolAndEpoch(blocks), + )) => Ok(blocks), + Message::StateQueryResponse(StateQueryResponse::Pools( + PoolsStateQueryResponse::Error(e), + )) => Err(anyhow::anyhow!( + "Internal server error while retrieving pool block hashes by epoch: {e}" + )), + _ => Err(anyhow::anyhow!("Unexpected message type")), + }, + ) + .await?; + + // NOTE: + // Need to query chain_store + // to get block_hash for each block height + + match serde_json::to_string_pretty(&blocks) { + Ok(json) => Ok(RESTResponse::with_json(200, &json)), + Err(e) => Ok(RESTResponse::with_text( + 500, + &format!("Internal server error while retrieving pool block hashes by epoch: {e}"), + )), + } } diff --git a/modules/rest_blockfrost/src/handlers/pools.rs b/modules/rest_blockfrost/src/handlers/pools.rs index 4c28f897..d5bf5771 100644 --- a/modules/rest_blockfrost/src/handlers/pools.rs +++ b/modules/rest_blockfrost/src/handlers/pools.rs @@ -1062,9 +1062,9 @@ pub async fn handle_pool_blocks_blockfrost( )); }; - // Get block hashes by pool_id from spo_state + // Get blocks by pool_id from spo_state let pool_blocks_msg = Arc::new(Message::StateQuery(StateQuery::Pools( - PoolsStateQuery::GetPoolBlockHashes { + PoolsStateQuery::GetBlocksByPool { pool_id: spo.clone(), }, ))); @@ -1075,18 +1075,21 @@ pub async fn handle_pool_blocks_blockfrost( pool_blocks_msg, |message| match message { Message::StateQueryResponse(StateQueryResponse::Pools( - PoolsStateQueryResponse::PoolBlockHashes(pool_blocks), + PoolsStateQueryResponse::BlocksByPool(pool_blocks), )) => Ok(pool_blocks), Message::StateQueryResponse(StateQueryResponse::Pools( PoolsStateQueryResponse::Error(_), - )) => Err(anyhow::anyhow!("Block hashes are not enabled")), + )) => Err(anyhow::anyhow!("Blocks are not enabled")), _ => Err(anyhow::anyhow!("Unexpected message type")), }, ) .await?; - let pool_blocks_rest = pool_blocks.into_iter().map(|b| hex::encode(b)).collect::>(); - match serde_json::to_string(&pool_blocks_rest) { + // NOTE: + // Need to query chain_store + // to get block_hash for each block height + + match serde_json::to_string_pretty(&pool_blocks) { Ok(json) => Ok(RESTResponse::with_json(200, &json)), Err(e) => Ok(RESTResponse::with_text( 500, diff --git a/modules/spo_state/src/historical_spo_state.rs b/modules/spo_state/src/historical_spo_state.rs index 609684d9..51c63ddc 100644 --- a/modules/spo_state/src/historical_spo_state.rs +++ b/modules/spo_state/src/historical_spo_state.rs @@ -1,7 +1,7 @@ use acropolis_common::{ queries::governance::VoteRecord, KeyHash, PoolRegistration, PoolUpdateEvent, }; -use imbl::HashSet; +use imbl::{HashSet, OrdMap, Vector}; use serde::{Deserialize, Serialize}; use crate::store_config::StoreConfig; @@ -17,6 +17,10 @@ pub struct HistoricalSPOState { pub delegators: Option>, // SPO's votes pub votes: Option>, + + // blocks + // + pub blocks: Option>>, } impl HistoricalSPOState { @@ -27,6 +31,7 @@ impl HistoricalSPOState { updates: store_config.store_updates.then(Vec::new), delegators: store_config.store_delegators.then(HashSet::new), votes: store_config.store_votes.then(Vec::new), + blocks: store_config.store_blocks.then(OrdMap::new), } } @@ -55,4 +60,21 @@ impl HistoricalSPOState { pub fn remove_delegator(&mut self, delegator: &KeyHash) -> Option { self.delegators.as_mut().and_then(|delegators| Some(delegators.remove(delegator).is_some())) } + + pub fn get_all_blocks(&self) -> Option> { + self.blocks.as_ref().map(|blocks| blocks.values().flatten().cloned().collect()) + } + + pub fn get_blocks_by_epoch(&self, epoch: u64) -> Option> { + self.blocks + .as_ref() + .and_then(|blocks| blocks.get(&epoch).map(|blocks| blocks.iter().cloned().collect())) + } + + pub fn add_block(&mut self, epoch: u64, block_number: u64) -> Option<()> { + self.blocks.as_mut().and_then(|blocks| { + blocks.entry(epoch).or_insert_with(Vector::new).push_back(block_number); + Some(()) + }) + } } diff --git a/modules/spo_state/src/spo_state.rs b/modules/spo_state/src/spo_state.rs index 757f3c30..70de4850 100644 --- a/modules/spo_state/src/spo_state.rs +++ b/modules/spo_state/src/spo_state.rs @@ -634,12 +634,19 @@ impl SPOState { PoolsStateQueryResponse::PoolTotalBlocksMinted(state.get_total_blocks_minted_by_pool(&pool_id)) } - PoolsStateQuery::GetPoolBlockHashes { pool_id } => { - if state.is_block_hashes_enabled() { - PoolsStateQueryResponse::PoolBlockHashes(state.get_pool_block_hashes(pool_id).unwrap_or_default()) - } else { - PoolsStateQueryResponse::Error("Block hashes are not enabled".into()) - } + PoolsStateQuery::GetBlocksByPool { pool_id } => { + state + .is_historical_blocks_enabled() + .then(|| PoolsStateQueryResponse::BlocksByPool(state.get_blocks_by_pool(pool_id).unwrap_or_default())) + .unwrap_or(PoolsStateQueryResponse::Error("Blocks are not enabled".into())) + } + + PoolsStateQuery::GetBlocksByPoolAndEpoch { pool_id, epoch } => { + state + .is_historical_blocks_enabled() + .then(|| PoolsStateQueryResponse::BlocksByPoolAndEpoch(state.get_blocks_by_pool_and_epoch(pool_id, *epoch) + .unwrap_or_default())) + .unwrap_or(PoolsStateQueryResponse::Error("Blocks are not enabled".into())) } PoolsStateQuery::GetPoolUpdates { pool_id } => { diff --git a/modules/spo_state/src/state.rs b/modules/spo_state/src/state.rs index 976faf15..931ad608 100644 --- a/modules/spo_state/src/state.rs +++ b/modules/spo_state/src/state.rs @@ -10,12 +10,12 @@ use acropolis_common::{ params::TECHNICAL_PARAMETER_POOL_RETIRE_MAX_EPOCH, queries::governance::VoteRecord, stake_addresses::StakeAddressMap, - BlockHash, BlockInfo, KeyHash, PoolMetadata, PoolRegistration, PoolRegistrationWithPos, - PoolRetirement, PoolRetirementWithPos, PoolUpdateEvent, Relay, StakeCredential, TxCertificate, - TxHash, Voter, VotingProcedures, + BlockInfo, KeyHash, PoolMetadata, PoolRegistration, PoolRegistrationWithPos, PoolRetirement, + PoolRetirementWithPos, PoolUpdateEvent, Relay, StakeCredential, TxCertificate, TxHash, Voter, + VotingProcedures, }; use anyhow::Result; -use imbl::{HashMap, Vector}; +use imbl::HashMap; use std::sync::{Arc, Mutex}; use tracing::{debug, error, info}; @@ -41,9 +41,6 @@ pub struct State { // Keyed by pool_id total_blocks_minted: HashMap, - /// block hashes keyed pool id - block_hashes: Option>>, - /// historical spo state /// keyed by pool operator id historical_spos: Option>, @@ -67,11 +64,6 @@ impl State { } else { None }, - block_hashes: if config.store_block_hashes { - Some(HashMap::new()) - } else { - None - }, stake_addresses: if config.store_stake_addresses { Some(Arc::new(Mutex::new(StakeAddressMap::new()))) } else { @@ -96,8 +88,8 @@ impl State { self.store_config.store_votes } - pub fn is_block_hashes_enabled(&self) -> bool { - self.store_config.store_block_hashes + pub fn is_historical_blocks_enabled(&self) -> bool { + self.store_config.store_blocks } pub fn is_stake_address_enabled(&self) -> bool { @@ -124,7 +116,6 @@ impl From for State { vrf_key_hash_to_pool_id_map, total_blocks_minted: HashMap::new(), historical_spos: None, - block_hashes: None, stake_addresses: None, } } @@ -219,9 +210,23 @@ impl State { delegators_map.map(|map| map.into_iter().collect()) } - /// Get Pool Blocks - pub fn get_pool_block_hashes(&self, pool_id: &KeyHash) -> Option> { - self.block_hashes.as_ref()?.get(pool_id).map(|blocks| blocks.clone().into_iter().collect()) + /// Get Blocks by Pool + /// Return Vector of block heights + /// Return None when store_blocks not enabled + pub fn get_blocks_by_pool(&self, pool_id: &KeyHash) -> Option> { + let Some(historical_spos) = self.historical_spos.as_ref() else { + return None; + }; + historical_spos.get(pool_id).and_then(|s| s.get_all_blocks()) + } + + /// Get Blocks by Pool and Epoch + /// Return None when store_blocks not enabled + pub fn get_blocks_by_pool_and_epoch(&self, pool_id: &KeyHash, epoch: u64) -> Option> { + let Some(historical_spos) = self.historical_spos.as_ref() else { + return None; + }; + historical_spos.get(pool_id).and_then(|s| s.get_blocks_by_epoch(epoch)) } /// Get Pool Updates @@ -268,20 +273,23 @@ impl State { } // Handle block's minting. - // Returns None if block_hashes is not enabled - // Return Some(false) if pool_id for vrf_vkey is not found - pub fn handle_mint(&mut self, block_info: &BlockInfo, vrf_vkey: &[u8]) -> Option { + // Returns false if vrf_vkey_hash is not mapped to any pool_id + pub fn handle_mint(&mut self, block_info: &BlockInfo, vrf_vkey: &[u8]) -> bool { let vrf_key_hash = keyhash(vrf_vkey); let Some(pool_id) = self.vrf_key_hash_to_pool_id_map.get(&vrf_key_hash).cloned() else { - return Some(false); + return false; }; *(self.total_blocks_minted.entry(pool_id.clone()).or_insert(0)) += 1; - // if block_hashes are enabled - if let Some(block_hashes) = self.block_hashes.as_mut() { - block_hashes.entry(pool_id).or_insert_with(Vector::new).push_back(block_info.hash); - }; - Some(true) + // if store_blocks is enabled + if self.is_historical_blocks_enabled() { + if let Some(historical_spos) = self.historical_spos.as_mut() { + if let Some(historical_spo) = historical_spos.get_mut(&pool_id) { + historical_spo.add_block(block_info.epoch, block_info.number); + } + } + } + true } fn handle_new_epoch(&mut self, block: &BlockInfo) -> Arc { @@ -1019,7 +1027,7 @@ mod tests { #[test] fn get_total_blocks_minted_returns_after_handle_mint() { - let mut state = State::new(&save_block_hashes_store_config()); + let mut state = State::new(&save_blocks_store_config()); let mut block = new_block(0); let mut msg = new_certs_msg(); msg.certificates.push(TxCertificate::PoolRegistrationWithPos( @@ -1045,30 +1053,30 @@ mod tests { assert!(state.handle_tx_certs(&block, &msg).is_ok()); block = new_block(2); - assert_eq!(Some(true), state.handle_mint(&block, &vec![0])); + assert_eq!(true, state.handle_mint(&block, &vec![0])); assert_eq!(1, state.get_total_blocks_minted_by_pool(&vec![1])); block = new_block(3); - assert_eq!(Some(true), state.handle_mint(&block, &vec![0])); + assert_eq!(true, state.handle_mint(&block, &vec![0])); assert_eq!(2, state.get_total_blocks_minted_by_pools(&vec![vec![1]])[0]); } #[test] - fn get_block_hashes_returns_none_when_state_is_new() { + fn get_blocks_returns_none_when_blocks_not_enabled() { let state = State::default(); - assert!(state.get_pool_block_hashes(&vec![0]).is_none()); + assert!(state.get_blocks_by_pool(&vec![0]).is_none()); } #[test] fn handle_mint_returns_false_if_pool_not_found() { - let mut state = State::new(&save_block_hashes_store_config()); + let mut state = State::new(&save_blocks_store_config()); let block = new_block(0); - assert_eq!(Some(false), state.handle_mint(&block, &vec![0])); + assert_eq!(false, state.handle_mint(&block, &vec![0])); } #[test] - fn get_block_hashes_return_data_after_handle_mint() { - let mut state = State::new(&save_block_hashes_store_config()); + fn get_blocks_return_data_after_handle_mint() { + let mut state = State::new(&save_blocks_store_config()); let mut block = new_block(0); let mut msg = new_certs_msg(); msg.certificates.push(TxCertificate::PoolRegistrationWithPos( @@ -1093,9 +1101,15 @@ mod tests { )); assert!(state.handle_tx_certs(&block, &msg).is_ok()); block = new_block(2); - assert_eq!(Some(true), state.handle_mint(&block, &vec![0])); - let block_hashes = state.get_pool_block_hashes(&vec![1]).unwrap(); - assert_eq!(block_hashes.len(), 1); - assert_eq!(block_hashes[0], block.hash); + assert_eq!(true, state.handle_mint(&block, &vec![0])); + let blocks = state.get_blocks_by_pool(&vec![1]).unwrap(); + assert_eq!(blocks.len(), 1); + assert_eq!(blocks[0], block.number); + + let blocks = state.get_blocks_by_pool_and_epoch(&vec![1], 2).unwrap(); + assert_eq!(blocks.len(), 1); + assert_eq!(blocks[0], block.number); + + assert!(state.get_blocks_by_pool_and_epoch(&vec![1], 3).is_none()); } } diff --git a/modules/spo_state/src/store_config.rs b/modules/spo_state/src/store_config.rs index 97a294a5..a89c15d6 100644 --- a/modules/spo_state/src/store_config.rs +++ b/modules/spo_state/src/store_config.rs @@ -9,7 +9,7 @@ const DEFAULT_STORE_REGISTRATION: (&str, bool) = ("store-registration", false); const DEFAULT_STORE_UPDATES: (&str, bool) = ("store-updates", false); const DEFAULT_STORE_DELEGATORS: (&str, bool) = ("store-delegators", false); const DEFAULT_STORE_VOTES: (&str, bool) = ("store-votes", false); -const DEFAULT_STORE_BLOCK_HASHES: (&str, bool) = ("store-block-hashes", false); +const DEFAULT_STORE_BLOCKS: (&str, bool) = ("store-blocks", false); const DEFAULT_STORE_STAKE_ADDRESSES: (&str, bool) = ("store-stake-addresses", false); #[derive(Default, Debug, Clone, Serialize)] @@ -20,7 +20,7 @@ pub struct StoreConfig { pub store_updates: bool, pub store_delegators: bool, pub store_votes: bool, - pub store_block_hashes: bool, + pub store_blocks: bool, pub store_stake_addresses: bool, } @@ -32,7 +32,7 @@ impl StoreConfig { store_updates: bool, store_delegators: bool, store_votes: bool, - store_block_hashes: bool, + store_blocks: bool, store_stake_addresses: bool, ) -> Self { Self { @@ -42,13 +42,17 @@ impl StoreConfig { store_updates, store_delegators, store_votes, - store_block_hashes, + store_blocks, store_stake_addresses, } } pub fn store_historical_state(&self) -> bool { - self.store_registration || self.store_updates || self.store_delegators || self.store_votes + self.store_registration + || self.store_updates + || self.store_delegators + || self.store_votes + || self.store_blocks } } @@ -71,9 +75,7 @@ impl From> for StoreConfig { .get_bool(DEFAULT_STORE_DELEGATORS.0) .unwrap_or(DEFAULT_STORE_DELEGATORS.1), store_votes: config.get_bool(DEFAULT_STORE_VOTES.0).unwrap_or(DEFAULT_STORE_VOTES.1), - store_block_hashes: config - .get_bool(DEFAULT_STORE_BLOCK_HASHES.0) - .unwrap_or(DEFAULT_STORE_BLOCK_HASHES.1), + store_blocks: config.get_bool(DEFAULT_STORE_BLOCKS.0).unwrap_or(DEFAULT_STORE_BLOCKS.1), store_stake_addresses: config .get_bool(DEFAULT_STORE_STAKE_ADDRESSES.0) .unwrap_or(DEFAULT_STORE_STAKE_ADDRESSES.1), diff --git a/modules/spo_state/src/test_utils.rs b/modules/spo_state/src/test_utils.rs index 920eb2c1..ce257135 100644 --- a/modules/spo_state/src/test_utils.rs +++ b/modules/spo_state/src/test_utils.rs @@ -15,7 +15,7 @@ pub fn default_store_config() -> StoreConfig { store_updates: false, store_delegators: false, store_votes: false, - store_block_hashes: false, + store_blocks: false, store_stake_addresses: false, } } @@ -28,7 +28,7 @@ pub fn save_history_store_config() -> StoreConfig { store_updates: false, store_delegators: false, store_votes: false, - store_block_hashes: false, + store_blocks: false, store_stake_addresses: false, } } @@ -41,12 +41,12 @@ pub fn save_retired_pools_store_config() -> StoreConfig { store_updates: false, store_delegators: false, store_votes: false, - store_block_hashes: false, + store_blocks: false, store_stake_addresses: false, } } -pub fn save_block_hashes_store_config() -> StoreConfig { +pub fn save_blocks_store_config() -> StoreConfig { StoreConfig { store_epochs_history: false, store_retired_pools: false, @@ -54,7 +54,7 @@ pub fn save_block_hashes_store_config() -> StoreConfig { store_updates: false, store_delegators: false, store_votes: false, - store_block_hashes: true, + store_blocks: true, store_stake_addresses: false, } } @@ -92,7 +92,9 @@ pub fn new_epoch_activity_message(epoch: u64) -> EpochActivityMessage { epoch_start_time: 0, epoch_end_time: 0, first_block_time: 0, + first_block_height: 0, last_block_time: 0, + last_block_height: 0, total_blocks: 0, total_txs: 0, total_outputs: 0, diff --git a/processes/omnibus/omnibus.toml b/processes/omnibus/omnibus.toml index 12b9954c..c44f9449 100644 --- a/processes/omnibus/omnibus.toml +++ b/processes/omnibus/omnibus.toml @@ -44,13 +44,14 @@ store-updates = false store-delegators = false # Enables /pools/{pool_id}/votes endpoint store-votes = false -# Store block hashes, enables /pools/{pool_id}/blocks endpoints -store-block-hashes = false +# Store blocks, enables /pools/{pool_id}/blocks, /epochs/{number}/blocks/{pool_id} +store-blocks = false # Store stake_addresses store-stake-addresses = false [module.spdd-state] # Enables active_stakes in /epochs/latest | {number} endpoints +# Enables /epochs/{number}/{next | previous} store-spdd = false [module.drep-state]