Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/starknet_committer/src/db/facts_db/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ impl<S: Storage> ForestMetadata for FactsDb<S> {
match metadata_type {
ForestMetadataType::CommitmentOffset => DbKey(Self::COMMITMENT_OFFSET_KEY.to_vec()),
ForestMetadataType::StateDiffHash(block_number) => {
let state_diff_hash_key_prefix = DbKeyPrefix::new(Self::STATE_DIFF_HASH_PREFIX);
let state_diff_hash_key_prefix =
DbKeyPrefix::new(Self::STATE_DIFF_HASH_PREFIX.into());
create_db_key(state_diff_hash_key_prefix, &block_number.0.to_be_bytes())
}
ForestMetadataType::StateRoot(block_number) => {
let state_root_key_prefix = DbKeyPrefix::new(Self::STATE_ROOT_PREFIX);
let state_root_key_prefix = DbKeyPrefix::new(Self::STATE_ROOT_PREFIX.into());
create_db_key(state_root_key_prefix, &block_number.0.to_be_bytes())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub enum CommitterLeafPrefix {
impl From<CommitterLeafPrefix> for DbKeyPrefix {
fn from(value: CommitterLeafPrefix) -> Self {
match value {
CommitterLeafPrefix::StorageLeaf => Self::new(b"starknet_storage_leaf"),
CommitterLeafPrefix::StateTreeLeaf => Self::new(b"contract_state"),
CommitterLeafPrefix::CompiledClassLeaf => Self::new(b"contract_class_leaf"),
CommitterLeafPrefix::StorageLeaf => Self::new(b"starknet_storage_leaf".into()),
CommitterLeafPrefix::StateTreeLeaf => Self::new(b"contract_state".into()),
CommitterLeafPrefix::CompiledClassLeaf => Self::new(b"contract_class_leaf".into()),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ use crate::patricia_merkle_tree::errors::TypesError;
use crate::patricia_merkle_tree::node_data::errors::{LeafError, LeafResult};
use crate::patricia_merkle_tree::original_skeleton_tree::config::OriginalSkeletonTreeConfig;

pub(crate) const TEST_PREFIX: &[u8] = &[0];

#[derive(Debug, PartialEq, Clone, Copy, Default, Eq)]
pub struct MockLeaf(pub Felt);

impl HasStaticPrefix for MockLeaf {
type KeyContext = EmptyKeyContext;
fn get_static_prefix(_key_context: &Self::KeyContext) -> DbKeyPrefix {
DbKeyPrefix::new(&[0])
DbKeyPrefix::new(TEST_PREFIX.into())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum PatriciaPrefix {
impl From<PatriciaPrefix> for DbKeyPrefix {
fn from(value: PatriciaPrefix) -> Self {
match value {
PatriciaPrefix::InnerNode => Self::new(b"patricia_node"),
PatriciaPrefix::InnerNode => Self::new(b"patricia_node".into()),
PatriciaPrefix::Leaf(prefix) => prefix,
}
}
Expand All @@ -60,10 +60,10 @@ impl<L: Leaf> HasDynamicPrefix for FilledNode<L, HashOutput> {
// Inherit the KeyContext from the HasStaticPrefix implementation of the leaf.
type KeyContext = <L as HasStaticPrefix>::KeyContext;

fn get_prefix(&self, _key_context: &Self::KeyContext) -> DbKeyPrefix {
fn get_prefix(&self, key_context: &Self::KeyContext) -> DbKeyPrefix {
match &self.data {
NodeData::Binary(_) | NodeData::Edge(_) => PatriciaPrefix::InnerNode,
NodeData::Leaf(_) => PatriciaPrefix::Leaf(L::get_static_prefix(_key_context)),
NodeData::Leaf(_) => PatriciaPrefix::Leaf(L::get_static_prefix(key_context)),
}
.into()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rstest::rstest;
use starknet_patricia_storage::db_object::HasStaticPrefix;
use starknet_patricia_storage::storage_trait::DbKeyPrefix;

use crate::patricia_merkle_tree::external_test_utils::small_tree_index_to_full;
use crate::patricia_merkle_tree::external_test_utils::{small_tree_index_to_full, TEST_PREFIX};
use crate::patricia_merkle_tree::node_data::inner_node::{EdgePath, EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::leaf::Leaf;
use crate::patricia_merkle_tree::traversal::{SubTreeTrait, UnmodifiedChildTraversal};
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<'a> SubTreeTrait<'a> for TestSubTree<'a> {
_key_context: &<L as HasStaticPrefix>::KeyContext,
) -> DbKeyPrefix {
// Dummy prefix for testing purposes (we only need a prefix when interacting with storage).
DbKeyPrefix::new(&[0])
DbKeyPrefix::new(TEST_PREFIX.into())
}

fn get_root_suffix(&self) -> Vec<u8> {
Expand Down
9 changes: 5 additions & 4 deletions crates/starknet_patricia_storage/src/storage_trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Display;
use std::future::Future;
Expand Down Expand Up @@ -172,15 +173,15 @@ impl Storage for NullStorage {
}

#[derive(Debug)]
pub struct DbKeyPrefix(&'static [u8]);
pub struct DbKeyPrefix(Cow<'static, [u8]>);

impl DbKeyPrefix {
pub fn new(prefix: &'static [u8]) -> Self {
pub fn new(prefix: Cow<'static, [u8]>) -> Self {
Self(prefix)
}

pub fn to_bytes(&self) -> &'static [u8] {
self.0
pub fn to_bytes(&self) -> &[u8] {
self.0.as_ref()
}
}

Expand Down
Loading