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

transaction: Optimize MMR hash for HistoricTransaction #2630

Merged
merged 2 commits into from
Jun 17, 2024
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
7 changes: 4 additions & 3 deletions keys/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl FromDatabaseValue for Address {
mod serde_derive {
use std::borrow::Cow;

use nimiq_serde::SerializedSize;
use nimiq_serde::{FixedSizeByteArray, SerializedSize};
use serde::{
de::{Deserialize, Deserializer, Error},
ser::{Serialize, Serializer},
Expand All @@ -247,7 +247,7 @@ mod serde_derive {
if serializer.is_human_readable() {
serializer.serialize_str(&self.to_user_friendly_address())
} else {
Serialize::serialize(&self.0, serializer)
FixedSizeByteArray::from(self.0).serialize(serializer)
}
}
}
Expand All @@ -261,7 +261,8 @@ mod serde_derive {
let s: Cow<'de, str> = Deserialize::deserialize(deserializer)?;
Address::from_any_str(&s).map_err(Error::custom)
} else {
let data: [u8; Self::SIZE] = Deserialize::deserialize(deserializer)?;
let data: [u8; Self::SIZE] =
FixedSizeByteArray::deserialize(deserializer)?.into_inner();
Ok(Address(data))
}
}
Expand Down
7 changes: 4 additions & 3 deletions primitives/transaction/src/historic_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ impl MMRHash<Blake2bHash> for HistoricTransaction {
/// to include it into the History Tree.
/// This returns the executed transaction hash prefixed with 'prefix' number of leaves.
fn hash(&self, prefix: u64) -> Blake2bHash {
let mut message = prefix.to_be_bytes().to_vec();
message.append(&mut self.serialize_to_vec());
message.hash()
let mut hasher = Blake2bHasher::new();
hasher.write_all(&prefix.to_be_bytes()).unwrap();
self.serialize_to_writer(&mut hasher).unwrap();
hasher.finish()
}
}

Expand Down
Loading