@@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
12
12
use sov_rollup_interface:: da:: { BlockHeaderTrait as BlockHeader , CountedBufReader } ;
13
13
use sov_rollup_interface:: AddressTrait ;
14
14
pub use tendermint:: block:: Header as TendermintHeader ;
15
+ use tendermint:: block:: Height ;
15
16
use tendermint:: crypto:: default:: Sha256 ;
16
17
use tendermint:: merkle:: simple_hash_from_byte_vectors;
17
18
use tendermint:: Hash ;
@@ -21,6 +22,8 @@ use tracing::debug;
21
22
22
23
const NAMESPACED_HASH_LEN : usize = 48 ;
23
24
25
+ pub const GENESIS_PLACEHOLDER_HASH : & [ u8 ; 32 ] = & [ 255 ; 32 ] ;
26
+
24
27
use crate :: pfb:: { BlobTx , MsgPayForBlobs , Tx } ;
25
28
use crate :: shares:: { read_varint, BlobIterator , BlobRefIterator , NamespaceGroup } ;
26
29
use crate :: utils:: BoxError ;
@@ -270,6 +273,20 @@ impl BlockHeader for CelestiaHeader {
270
273
return hash. clone ( ) ;
271
274
}
272
275
276
+ // We special case the block following genesis, since genesis has a `None` hash, which
277
+ // we don't want to deal with. In this case, we return a specail placeholder for the
278
+ // block "hash"
279
+ if Height :: decode_vec ( & self . header . height )
280
+ . expect ( "header must be validly encoded" )
281
+ . value ( )
282
+ == 1
283
+ {
284
+ let prev_hash = TmHash ( tendermint:: Hash :: Sha256 ( * GENESIS_PLACEHOLDER_HASH ) ) ;
285
+ * cached_hash = Some ( prev_hash. clone ( ) ) ;
286
+ return prev_hash;
287
+ }
288
+
289
+ // In all other cases, we simply return the previous block hash parsed from the header
273
290
let hash =
274
291
<tendermint:: block:: Id as Protobuf < celestia_tm_version:: types:: BlockId > >:: decode (
275
292
self . header . last_block_id . as_ref ( ) ,
@@ -434,5 +451,12 @@ mod tests {
434
451
let compact_header: CompactHeader = original_header. header . into ( ) ;
435
452
436
453
assert_eq ! ( tm_header. hash( ) , compact_header. hash( ) ) ;
454
+ assert_eq ! (
455
+ hex:: decode( "32381A0B7262F15F081ACEF769EE59E6BB4C42C1013A3EEE23967FBF32B86AE6" )
456
+ . unwrap( ) ,
457
+ compact_header. hash( ) . as_bytes( )
458
+ ) ;
459
+
460
+ assert_eq ! ( tm_header. hash( ) , compact_header. hash( ) , ) ;
437
461
}
438
462
}
0 commit comments