Only insert block in API cache if it's finalized
@@ -72,6 +72,15 @@ fn try_parse_hash(query: &str) -> Option<Vec<u8>> {
}
}
+/// Checks if block is finalized, meaning that
+/// both Verify operation is performed for it, and this
+/// operation is anchored on the Ethereum blockchain.
+fn block_verified(block: &BlockDetails) -> bool {
+ // We assume that it's not possible to have block that is
+ // verified and not committed.
+ block.verified_at.is_some() && block.verify_tx_hash.is_some()
+}
+
/// Caches used by REST API server.
#[derive(Debug, Clone)]
struct Caches {
@@ -267,7 +276,7 @@ impl AppState {
if let Ok(block_details) = storage.chain().block_schema().load_block_range(block_id, 1) {
// Unverified blocks can still change, so we can't cache them.
- if !block_details.is_empty() && block_details[0].verified_at.is_some() {
+ if !block_details.is_empty() && block_verified(&block_details[0]) {
self.caches
.block_executed_ops
.insert(block_id, executed_ops.clone());
@@ -302,7 +311,7 @@ impl AppState {
HttpResponse::InternalServerError().finish()
})?;
- if !blocks.is_empty() && blocks[0].verified_at.is_some() {
+ if !blocks.is_empty() && block_verified(&blocks[0]) {
self.caches.blocks_info.insert(block_id, blocks[0].clone());
}
@@ -324,7 +333,7 @@ impl AppState {
.find_block_by_height_or_hash(query.clone());
if let Some(block) = block.clone() {
- if block.verified_at.is_some() {
+ if block_verified(&block) {
self.caches.blocks_by_height_or_hash.insert(query, block);
}
}
