@@ -3,6 +3,8 @@ use std::marker::PhantomData;
33use std:: sync:: LazyLock ;
44
55use async_trait:: async_trait;
6+ #[ cfg( feature = "os_input" ) ]
7+ use starknet_api:: block:: BlockNumber ;
68use starknet_api:: core:: { ContractAddress , PATRICIA_KEY_UPPER_BOUND_FELT } ;
79use starknet_api:: hash:: { HashOutput , StateRoots } ;
810use starknet_patricia:: db_layout:: { NodeLayout , NodeLayoutFor } ;
@@ -50,6 +52,7 @@ use crate::db::index_db::types::{
5052 IndexLayoutSubTree ,
5153 IndexNodeContext ,
5254} ;
55+ #[ cfg( feature = "os_input" ) ]
5356use crate :: db:: serde_db_utils:: DbBlockNumber ;
5457use crate :: forest:: deleted_nodes:: DeletedNodes ;
5558use crate :: forest:: filled_forest:: FilledForest ;
@@ -89,6 +92,26 @@ static STATE_ROOT_METADATA_PREFIX: LazyLock<[u8; 32]> = LazyLock::new(|| {
8992pub ( crate ) static ACCESSED_KEYS_DIGEST_METADATA_PREFIX : LazyLock < [ u8 ; 32 ] > =
9093 LazyLock :: new ( || ( Felt :: from_bytes_be ( & STATE_ROOT_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( ) ) ;
9194
95+ /// Prefix for Patricia proofs payload (per block).
96+ #[ allow( dead_code) ]
97+ pub ( crate ) static PATRICIA_PATHS_PREFIX : LazyLock < [ u8 ; 32 ] > = LazyLock :: new ( || {
98+ ( Felt :: from_bytes_be ( & ACCESSED_KEYS_DIGEST_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( )
99+ } ) ;
100+
101+ /// DB key for persisted merged Patricia proofs at `height`.
102+ ///
103+ /// Key structure: Prefix (32 bytes) || BlockNumber (8 bytes) || Padding (24 bytes).
104+ #[ cfg( feature = "os_input" ) ]
105+ #[ allow( dead_code) ]
106+ pub ( crate ) fn patricia_proofs_db_key ( height : BlockNumber ) -> DbKey {
107+ let mut key = Vec :: with_capacity ( 64 ) ;
108+ key. extend_from_slice ( & * PATRICIA_PATHS_PREFIX ) ;
109+ let block_number_bytes: [ u8 ; 8 ] = DbBlockNumber ( height) . serialize ( ) ;
110+ key. extend_from_slice ( & block_number_bytes) ;
111+ key. extend_from_slice ( & [ 0u8 ; 24 ] ) ;
112+ DbKey ( key)
113+ }
114+
92115pub struct IndexDb < S : Storage , H = TreeHashFunctionImpl > {
93116 storage : S ,
94117 phantom : PhantomData < H > ,
0 commit comments