Skip to content

Commit

Permalink
NDEV-2183: Make EthSyncing fields public
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniskore committed Sep 18, 2023
1 parent e672d8d commit db00beb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions evm_loader/lib/src/types/tracer_ch_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl EthSyncStatus {
#[derive(Row, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EthSyncing {
starting_block: u64,
current_block: u64,
highest_block: u64,
pub starting_block: u64,
pub current_block: u64,
pub highest_block: u64,
}
32 changes: 16 additions & 16 deletions evm_loader/lib/src/types/tracer_ch_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl ClickHouseDb {
}
}

pub async fn get_slot_by_blockhash(&self, blockhash: &str) -> ChResult<Option<u64>> {
pub async fn get_slot_by_blockhash(&self, blockhash: &str) -> ChResult<u64> {
let query = r#"SELECT slot
FROM events.notify_block_distributed
WHERE hash = ?
Expand All @@ -537,7 +537,12 @@ impl ClickHouseDb {
.await,
)?;

Ok(slot)
match slot {
Some(slot) => Ok(slot),
None => Err(ChError::Db(clickhouse::error::Error::Custom(
"get_slot_by_blockhash: no data available".to_string(),
))),
}
}

pub async fn get_sync_status(&self) -> ChResult<EthSyncStatus> {
Expand All @@ -557,9 +562,8 @@ impl ClickHouseDb {
.await,
)?;

if let Some(is_startup) = is_startup {
if is_startup {
let query = r#"SELECT slot
if let Some(true) = is_startup {
let query = r#"SELECT slot
FROM (
(SELECT MIN(slot) as slot FROM events.notify_block_distributed)
UNION ALL
Expand All @@ -570,18 +574,14 @@ impl ClickHouseDb {
ORDER BY slot ASC
"#;

let data = Self::row_opt(self.client.query(query).fetch_one::<EthSyncing>().await)?;
let data = Self::row_opt(self.client.query(query).fetch_one::<EthSyncing>().await)?;

match data {
Some(data) => return Ok(EthSyncStatus::new(Some(data))),
None => {
let err = clickhouse::error::Error::Custom(format!(
"get_sync_status: no data available",
));
return Err(ChError::Db(err));
}
}
}
return match data {
Some(data) => Ok(EthSyncStatus::new(Some(data))),
None => Err(ChError::Db(clickhouse::error::Error::Custom(
"get_sync_status: no data available".to_string(),
))),
};
}

Ok(EthSyncStatus::new(None))
Expand Down

0 comments on commit db00beb

Please sign in to comment.