From 9ef3ea5d4896e704748db3b1206429ccad6779c0 Mon Sep 17 00:00:00 2001 From: Ryan Quinn Ford Date: Wed, 11 Sep 2024 14:06:59 +0200 Subject: [PATCH] debugging storage.rs for jmt --- crates/common/src/hashchain.rs | 2 +- crates/prism/src/storage.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/common/src/hashchain.rs b/crates/common/src/hashchain.rs index f0ea9795..194dd836 100644 --- a/crates/common/src/hashchain.rs +++ b/crates/common/src/hashchain.rs @@ -86,7 +86,7 @@ impl Hashchain { } pub fn push(&mut self, operation: Operation) -> Result { - if let Operation::CreateAccount { .. } = operation { + if !self.is_empty() { bail!("Cannot CreateAccount on an already existing hashchain"); } if operation.id() != self.id { diff --git a/crates/prism/src/storage.rs b/crates/prism/src/storage.rs index cd820e44..8ea15bbf 100644 --- a/crates/prism/src/storage.rs +++ b/crates/prism/src/storage.rs @@ -95,7 +95,7 @@ impl TreeReader for RedisConnection { fn get_node_option(&self, node_key: &NodeKey) -> Result> { let mut con = self.lock_connection()?; let serialized_key = hex::encode(borsh::to_vec(node_key).unwrap()); - let node_data: Option> = con.get(format!("node:{}", serialized_key))?; + let node_data: Option> = con.get(dbg!(format!("node:{}", serialized_key)))?; match node_data { None => Ok(None), Some(data) => { @@ -146,12 +146,11 @@ impl TreeWriter for RedisConnection { fn write_node_batch(&self, node_batch: &NodeBatch) -> Result<()> { let mut con = self.lock_connection()?; let mut pipe = redis::pipe(); - for (node_key, node) in node_batch.nodes() { + let serialized_key = hex::encode(borsh::to_vec(node_key).unwrap()); let node_data = borsh::to_vec(node)?; - pipe.set(format!("node:{:?}", node_key), node_data); + pipe.set(format!("node:{}", serialized_key), node_data); } - for ((version, key_hash), value) in node_batch.values() { if let Some(v) = value { pipe.zadd(format!("value_history:{:?}", key_hash), v, *version as f64); @@ -163,7 +162,6 @@ impl TreeWriter for RedisConnection { ); } } - pipe.execute(&mut con); Ok(()) }