diff --git a/src/index/block_index.rs b/src/index/block_index.rs index 8ab3e033cb..8f63cec17d 100644 --- a/src/index/block_index.rs +++ b/src/index/block_index.rs @@ -171,6 +171,15 @@ impl BlockIndex { index: &Index, block_height: u64, ) -> Result> { + if index.block_count()? + > self.lowest_blessed_by_block.len() as u64 + self.first_inscription_height + { + return Err(anyhow!( + "Block index not fully indexed ({} indexed of {})", + self.lowest_blessed_by_block.len() as u64 + self.first_inscription_height, + index.block_count()? + )); + } if block_height >= index.block_count()? || block_height < self.first_inscription_height { return Ok(Vec::new()); } diff --git a/src/templates/inscriptions_block.rs b/src/templates/inscriptions_block.rs index 9619934535..67d97e3962 100644 --- a/src/templates/inscriptions_block.rs +++ b/src/templates/inscriptions_block.rs @@ -17,9 +17,14 @@ impl InscriptionsBlockHtml { inscriptions: Vec, page_index: usize, ) -> Result { - let start = page_index * 100; - let end = start + 100; let num_inscriptions = inscriptions.len(); + + let start = page_index * 100; + let end = usize::min(start + 100, num_inscriptions); + + if start > num_inscriptions || start > end { + return Err(anyhow!("page index {page_index} exceeds inscription count")); + } let inscriptions = inscriptions[start..end].to_vec(); Ok(Self { @@ -36,7 +41,7 @@ impl InscriptionsBlockHtml { } else { None }, - next_page: if page_index * 100 <= num_inscriptions { + next_page: if (page_index + 1) * 100 <= num_inscriptions { Some(page_index + 1) } else { None