Skip to content

Commit 1ada715

Browse files
ycscalyclaude
andcommitted
Patch inkrypto with Arc-wrapped SetupParameters to fix memory issue
This commit adds a local patch to use a modified version of inkrypto that wraps SetupParameters in Arc to prevent expensive deep clones during reconfiguration. The reconfiguration protocol's PublicInput contained 7 SetupParameters directly (each ~8MB with accelerator tables). With 80 validators and multiple protocol rounds, cloning caused memory usage to grow to tens of GB. Changes: - Add patch section in Cargo.toml to use local inkrypto with fix - Add memory stats logging to MPC manager for debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b6f785c commit 1ada715

4 files changed

Lines changed: 53 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,14 @@ ika-archival = { path = "crates/ika-archival" }
334334

335335
[patch.crates-io]
336336
crypto-bigint = { git = "https://github.com/ycscaly/crypto-bigint.git", rev = "8aabcee5" }
337-
rfc6979 = { git = "https://github.com/RustCrypto/signatures", tag = "rfc6979/v0.5.0-rc.1" }
337+
rfc6979 = { git = "https://github.com/RustCrypto/signatures", tag = "rfc6979/v0.5.0-rc.1" }
338+
339+
# Patch inkrypto to use local version with Arc-wrapped SetupParameters (memory fix)
340+
[patch."https://github.com/dwallet-labs/inkrypto"]
341+
mpc = { path = "/mnt/nvme0n1p1/inkrypto/mpc" }
342+
proof = { path = "/mnt/nvme0n1p1/inkrypto/proof" }
343+
class_groups = { path = "/mnt/nvme0n1p1/inkrypto/class-groups" }
344+
commitment = { path = "/mnt/nvme0n1p1/inkrypto/commitment" }
345+
twopc_mpc = { path = "/mnt/nvme0n1p1/inkrypto/2pc-mpc" }
346+
group = { path = "/mnt/nvme0n1p1/inkrypto/group" }
347+
homomorphic_encryption = { path = "/mnt/nvme0n1p1/inkrypto/homomorphic-encryption" }

crates/ika-core/src/dwallet_mpc/dwallet_mpc_service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ impl DWalletMPCService {
259259

260260
pub(crate) async fn run_service_loop_iteration(&mut self) {
261261
debug!("Running DWalletMPCService loop");
262+
// Log memory stats for debugging
263+
self.dwallet_mpc_manager.log_memory_stats();
262264
self.sync_last_session_to_complete_in_current_epoch().await;
263265

264266
// Receive **new** dWallet MPC events and save them in the local DB.

crates/ika-core/src/dwallet_mpc/mpc_manager.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,46 @@ impl DWalletMPCManager {
169169
})
170170
}
171171

172+
/// Log memory statistics for debugging memory issues.
173+
/// Call this periodically to track memory usage patterns.
174+
pub(crate) fn log_memory_stats(&self) {
175+
let total_sessions = self.sessions.len();
176+
let active_sessions = self
177+
.sessions
178+
.values()
179+
.filter(|s| matches!(&s.status, SessionStatus::Active { .. }))
180+
.count();
181+
let completed_sessions = self
182+
.sessions
183+
.values()
184+
.filter(|s| matches!(&s.status, SessionStatus::Completed))
185+
.count();
186+
let computation_completed_sessions = self
187+
.sessions
188+
.values()
189+
.filter(|s| matches!(&s.status, SessionStatus::ComputationCompleted))
190+
.count();
191+
192+
let network_keys_count = self.network_keys.network_encryption_keys.len();
193+
let pending_for_network_key_count: usize = self
194+
.requests_pending_for_network_key
195+
.values()
196+
.map(|v| v.len())
197+
.sum();
198+
let pending_for_committee_count = self.requests_pending_for_next_active_committee.len();
199+
200+
info!(
201+
total_sessions,
202+
active_sessions,
203+
completed_sessions,
204+
computation_completed_sessions,
205+
network_keys_count,
206+
pending_for_network_key_count,
207+
pending_for_committee_count,
208+
"MPC Manager Memory Stats"
209+
);
210+
}
211+
172212
pub(crate) fn sync_last_session_to_complete_in_current_epoch(
173213
&mut self,
174214
previous_value_for_last_session_to_complete_in_current_epoch: u64,

0 commit comments

Comments
 (0)