Skip to content

Commit 99c87bd

Browse files
committed
starknet_committer: db keys for proofs and accessed keys digest
1 parent c1d1d19 commit 99c87bd

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • crates/starknet_committer/src/db/index_db

crates/starknet_committer/src/db/index_db/db.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::marker::PhantomData;
33
use std::sync::LazyLock;
44

55
use async_trait::async_trait;
6+
#[cfg(feature = "os_input")]
7+
use starknet_api::block::BlockNumber;
68
use starknet_api::core::{ContractAddress, PATRICIA_KEY_UPPER_BOUND_FELT};
79
use starknet_api::hash::{HashOutput, StateRoots};
810
use 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")]
5356
use crate::db::serde_db_utils::DbBlockNumber;
5457
use crate::forest::deleted_nodes::DeletedNodes;
5558
use crate::forest::filled_forest::FilledForest;
@@ -89,6 +92,26 @@ static STATE_ROOT_METADATA_PREFIX: LazyLock<[u8; 32]> = LazyLock::new(|| {
8992
pub(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+
92115
pub struct IndexDb<S: Storage, H = TreeHashFunctionImpl> {
93116
storage: S,
94117
phantom: PhantomData<H>,

0 commit comments

Comments
 (0)