Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed May 15, 2024
1 parent efac007 commit 34ac5e5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub trait Backend<Block: BlockT>: Send + Sync {
self.log_indexer().is_indexed()
}

/// Get the latest substrate block hash in the sql database.
async fn best_hash(&self) -> Result<Block::Hash, String>;
/// Get the hash of the latest substrate block fully indexed by the backend.
async fn latest_block_hash(&self) -> Result<Block::Hash, String>;
}

#[derive(Debug, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion client/db/src/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<Block: BlockT, C: HeaderBackend<Block>> fc_api::Backend<Block> for Backend<
&self.log_indexer
}

async fn best_hash(&self) -> Result<Block::Hash, String> {
async fn latest_block_hash(&self) -> Result<Block::Hash, String> {
Ok(self.client.info().best_hash)
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/db/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,8 @@ impl<Block: BlockT<Hash = H256>> fc_api::Backend<Block> for Backend<Block> {
self
}

async fn best_hash(&self) -> Result<Block::Hash, String> {
// Retrieves the block hash for the latest indexed block, maybe it's not canon.
async fn latest_block_hash(&self) -> Result<Block::Hash, String> {
// Retrieves the block hash for the latestindexed block, maybe it's not canon.
sqlx::query("SELECT substrate_block_hash FROM blocks ORDER BY block_number DESC LIMIT 1")
.fetch_one(self.pool())
.await
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ pub mod frontier_backend_client {
BlockNumberOrHash::Num(number) => {
Ok(Some(BlockId::Number(number.unique_saturated_into())))
}
BlockNumberOrHash::Latest => match backend.best_hash().await {
BlockNumberOrHash::Latest => match backend.latest_block_hash().await {
Ok(hash) => Ok(Some(BlockId::Hash(hash))),
Err(e) => {
log::warn!(target: "rpc", "Failed to get best hash from the sql db: {:?}", e);
log::warn!(target: "rpc", "Failed to get latest block hash from the sql db: {:?}", e);
Ok(Some(BlockId::Hash(client.info().best_hash)))
}
},
Expand Down

0 comments on commit 34ac5e5

Please sign in to comment.