@@ -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,8 @@ use crate::db::index_db::types::{
5052 IndexLayoutSubTree ,
5153 IndexNodeContext ,
5254} ;
55+ #[ cfg( feature = "os_input" ) ]
56+ use crate :: db:: serde_db_utils:: DbBlockNumber ;
5357use crate :: forest:: deleted_nodes:: DeletedNodes ;
5458use crate :: forest:: filled_forest:: FilledForest ;
5559use crate :: forest:: forest_errors:: ForestResult ;
@@ -89,6 +93,25 @@ static STATE_ROOT_METADATA_PREFIX: LazyLock<[u8; 32]> = LazyLock::new(|| {
8993pub ( crate ) static ACCESSED_KEYS_DIGEST_METADATA_PREFIX : LazyLock < [ u8 ; 32 ] > =
9094 LazyLock :: new ( || ( Felt :: from_bytes_be ( & STATE_ROOT_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( ) ) ;
9195
96+ /// Prefix for Patricia proofs payload (per block).
97+ #[ cfg( feature = "os_input" ) ]
98+ pub ( crate ) static PATRICIA_PATHS_PREFIX : LazyLock < [ u8 ; 32 ] > = LazyLock :: new ( || {
99+ ( Felt :: from_bytes_be ( & ACCESSED_KEYS_DIGEST_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( )
100+ } ) ;
101+
102+ /// DB key for persisted merged Patricia proofs at `height`.
103+ ///
104+ /// Key structure: Prefix (32 bytes) || BlockNumber (8 bytes) || Padding (24 bytes).
105+ #[ cfg( feature = "os_input" ) ]
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