Skip to content

Commit

Permalink
fix: is_new_chunk condition on block validation (#12782)
Browse files Browse the repository at this point in the history
`height_created` shouldn't be used to check that chunk is new, because
in the case of block skip block height will be strictly greater.
`height_included` must be used and that's what method `is_new_chunk`
does.

Also using `is_genesis` for genesis case check (`self.prev_block_hash()
== &CryptoHash::default()`) because it's equivalent and a little more
neat.
  • Loading branch information
Longarithm authored Jan 23, 2025
1 parent 3a584c2 commit 49384e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ impl Chain {

for (shard_index, chunk_header) in block.chunks().iter_deprecated().enumerate() {
let shard_id = shard_layout.get_shard_id(shard_index)?;
if chunk_header.height_created() == genesis_block.header().height() {
if chunk_header.is_genesis() {
// Special case: genesis chunks can be in non-genesis blocks and don't have a signature
// We must verify that content matches and signature is empty.
// TODO: this code will not work when genesis block has different number of chunks as the current block
Expand All @@ -873,7 +873,7 @@ impl Chain {
chunk_header.signature()
)));
}
} else if chunk_header.height_created() == block.header().height() {
} else if chunk_header.is_new_chunk(block.header().height()) {
if chunk_header.shard_id() != shard_id {
return Err(Error::InvalidShardId(chunk_header.shard_id()));
}
Expand Down

0 comments on commit 49384e1

Please sign in to comment.