Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code from starkware_utils #440

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,7 @@ where
ffc: &'a mut FactFetchingContext<S, H>,
indices: &'a [TreeIndex],
facts: &'a mut Option<BinaryFactDict>,
) -> impl std::future::Future<Output = Result<HashMap<TreeIndex, LF>, TreeError>> + Send {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you have removed this default implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason except it's never used. This trait is only implemented in virtual_patricia_node.rs, and it has it's own implementation of _get_leaves.

async move {
if indices.is_empty() {
return Ok(HashMap::default());
}

if self.is_leaf() {
return self._get_leaf(ffc, indices).await;
}

self._get_binary_node_leaves(ffc, indices, facts).await
}
.boxed()
}
) -> impl std::future::Future<Output = Result<HashMap<TreeIndex, LF>, TreeError>> + Send;

/// Returns the values of the leaves whose indices are given.
fn _get_binary_node_leaves<'a>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ pub trait Calculation<T, LF> {
/// (using their hash as the key).
fn calculate(&self, dependency_results: Vec<Box<dyn Any>>, fact_nodes: &mut NodeFactDict<LF>) -> T;

/// Same as calculate(), but return the facts.

fn calculate_new_fact_nodes(&self, dependency_results: Vec<Box<dyn Any>>) -> (T, NodeFactDict<LF>) {
let mut fact_nodes = NodeFactDict::default();
let result = self.calculate(dependency_results, &mut fact_nodes);

(result, fact_nodes)
}

/// Produces the result of this calculation.
///
/// Recursively calculates the result of the dependency calculations.
Expand All @@ -74,17 +65,6 @@ pub trait Calculation<T, LF> {

self.calculate(dependency_results, fact_nodes)
}

/// Produces the result of this calculation. Returns the result and a dict containing generated
/// facts.
///
/// Recursively calculates the result of the dependency calculations.
fn full_calculate_new_fact_nodes(&self) -> (T, NodeFactDict<LF>) {
let mut fact_nodes = NodeFactDict::default();
let result = self.full_calculate(&mut fact_nodes);

(result, fact_nodes)
}
}

pub(crate) struct DependencyWrapper<D, T, LF>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,6 @@ use crate::storage::storage::{DbObject, Fact, HashFunctionType, Storage, HASH_BY

const PATRICIA_NODE_PREFIX: &[u8] = "patricia_node".as_bytes();

/// Represents the root of an empty (all leaves are 0) full binary tree.
pub struct EmptyNodeFact;

impl EmptyNodeFact {
const PREIMAGE_LENGTH: usize = 0;
}

impl<S, H> InnerNodeFact<S, H> for EmptyNodeFact
where
H: HashFunctionType,
S: Storage,
{
fn to_tuple(&self) -> Vec<BigUint> {
vec![]
}
}

impl<S, H> Fact<S, H> for EmptyNodeFact
where
H: HashFunctionType,
S: Storage,
{
fn hash(&self) -> Hash {
Hash::empty()
}
}

impl DbObject for EmptyNodeFact {}

impl SerializationPrefix for EmptyNodeFact {
fn prefix() -> Vec<u8> {
PATRICIA_NODE_PREFIX.to_vec()
}
}

impl Serializable for EmptyNodeFact {
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
Ok("".as_bytes().to_vec())
}

fn deserialize(_data: &[u8]) -> Result<Self, DeserializeError> {
Ok(Self {})
}
}

#[derive(thiserror::Error, Debug)]
pub enum BinaryNodeError {
#[allow(unused)]
Expand Down Expand Up @@ -240,7 +195,6 @@ fn hash_edge<H: HashFunctionType>(bottom: &[u8], path: NodePath, length: Length)
}

pub enum PatriciaNodeFact {
Empty(EmptyNodeFact),
Binary(BinaryNodeFact),
Edge(EdgeNodeFact),
}
Expand All @@ -254,15 +208,13 @@ impl SerializationPrefix for PatriciaNodeFact {
impl Serializable for PatriciaNodeFact {
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
match self {
Self::Empty(empty) => empty.serialize(),
Self::Binary(binary) => binary.serialize(),
Self::Edge(edge) => edge.serialize(),
}
}

fn deserialize(data: &[u8]) -> Result<Self, DeserializeError> {
let node = match data.len() {
EmptyNodeFact::PREIMAGE_LENGTH => Self::Empty(EmptyNodeFact::deserialize(data)?),
BinaryNodeFact::PREIMAGE_LENGTH => Self::Binary(BinaryNodeFact::deserialize(data)?),
EdgeNodeFact::PREIMAGE_LENGTH => Self::Edge(EdgeNodeFact::deserialize(data)?),
other => {
Expand All @@ -280,7 +232,6 @@ where
{
fn hash(&self) -> Hash {
match self {
Self::Empty(empty) => <EmptyNodeFact as Fact<S, H>>::hash(empty),
Self::Binary(binary) => <BinaryNodeFact as Fact<S, H>>::hash(binary),
Self::Edge(edge) => <EdgeNodeFact as Fact<S, H>>::hash(edge),
}
Expand All @@ -296,7 +247,6 @@ where
{
fn to_tuple(&self) -> Vec<BigUint> {
match self {
Self::Empty(empty) => <EmptyNodeFact as InnerNodeFact<S, H>>::to_tuple(empty),
Self::Binary(binary) => <BinaryNodeFact as InnerNodeFact<S, H>>::to_tuple(binary),
Self::Edge(edge) => <EdgeNodeFact as InnerNodeFact<S, H>>::to_tuple(edge),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ where
Self::from_hash(binary_node_fact.left_node, children_height),
Self::from_hash(binary_node_fact.right_node, children_height),
)),
PatriciaNodeFact::Empty(_) => Err(TreeError::IsEmpty),
}
}
.boxed()
Expand Down
10 changes: 0 additions & 10 deletions crates/starknet-os/src/starkware_utils/serializable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ mod tests {

impl SerializationPrefix for MySerializable {}

impl Serializable for MySerializable {
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
panic!("Not implemented, on purpose");
}

fn deserialize(_data: &[u8]) -> Result<Self, DeserializeError> {
panic!("Not implemented, on purpose");
}
}

#[test]
fn test_class_name_prefix() {
assert_eq!(MySerializable::class_name_prefix(), "my_serializable".as_bytes());
Expand Down
Loading