Skip to content
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
16 changes: 12 additions & 4 deletions apps/hermes/server/src/state/aggregate/wormhole_merkle.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 Version bump not included for hermes server

Per REVIEW.md guidelines on version bumps: the hermes server crate (apps/hermes/server/Cargo.toml) version is 0.12.0 and was not bumped in this PR. Since this is an internal memory optimization with no public API change and no behavioral change, a version bump is arguably not required — but the reviewer should confirm whether the project's release process expects a bump for internal-only changes.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
v1::{AccumulatorUpdateData, MerklePriceUpdate, Proof, WormholeMerkleRoot},
},
},
std::sync::Arc,
};

// The number of messages in a single update data is defined as a
Expand All @@ -31,7 +32,10 @@ pub struct WormholeMerkleState {
#[derive(Clone, PartialEq, Debug)]
pub struct WormholeMerkleMessageProof {
pub proof: MerklePath<Keccak160>,
pub vaa: VaaBytes,
/// Shared VAA for the message's slot. All messages in a slot share the same
/// VAA, so we store it behind an `Arc` to avoid cloning the (~1-2KB) bytes
/// once per feed (which, across ~6000 feeds × cache depth, dominated memory).
pub vaa: Arc<VaaBytes>,
}

#[derive(Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -83,12 +87,16 @@ pub fn construct_message_states_proofs(
return Err(anyhow!("Invalid merkle root"));
}

// Clone the VAA bytes once for the whole slot; every message proof shares it
// via the `Arc` (refcount bump only), instead of duplicating the bytes per feed.
let shared_vaa = Arc::new(wormhole_merkle_state.vaa.clone());

accumulator_messages
.raw_messages
.iter()
.map(|m| {
Ok(WormholeMerkleMessageProof {
vaa: wormhole_merkle_state.vaa.clone(),
vaa: shared_vaa.clone(),
proof: merkle_acc
.prove(m.as_ref())
.ok_or(anyhow!("Failed to prove message"))?,
Expand All @@ -107,7 +115,7 @@ pub fn construct_update_data(mut messages: Vec<RawMessageWithMerkleProof>) -> Re

while let Some(message) = iter.next() {
let slot = message.slot;
let vaa = message.proof.vaa;
let vaa: VaaBytes = (*message.proof.vaa).clone();
let mut updates = vec![MerklePriceUpdate {
message: message.raw_message.into(),
proof: message.proof.proof,
Expand Down Expand Up @@ -174,7 +182,7 @@ mod test {
RawMessageWithMerkleProof {
slot: slot_and_pubtime,
proof: WormholeMerkleMessageProof {
vaa: vec![],
vaa: std::sync::Arc::new(vec![]),
proof: MerklePath::default(),
},
raw_message: to_vec::<_, byteorder::BE>(&price_feed_message).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion apps/hermes/server/src/state/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ mod test {
received_at: publish_time,
proof_set: ProofSet {
wormhole_merkle_proof: WormholeMerkleMessageProof {
vaa: vec![],
vaa: std::sync::Arc::new(vec![]),
proof: MerklePath::<Keccak160>::new(vec![]),
},
},
Expand Down