Skip to content

Commit 5c188b8

Browse files
committed
feat: rebase cache
1 parent a705739 commit 5c188b8

File tree

5 files changed

+16
-359
lines changed

5 files changed

+16
-359
lines changed

fendermint/vm/topdown/proof-service/src/bin/proof-cache-test.rs

Lines changed: 0 additions & 263 deletions
Original file line numberDiff line numberDiff line change
@@ -224,266 +224,3 @@ async fn run_service(
224224
println!("Press Ctrl+C to stop...");
225225
}
226226
}
227-
228-
fn inspect_cache(db_path: &PathBuf) -> anyhow::Result<()> {
229-
use fendermint_vm_topdown_proof_service::persistence::ProofCachePersistence;
230-
231-
println!("=== Cache Inspection ===");
232-
println!("Database: {}", db_path.display());
233-
println!();
234-
235-
let persistence = ProofCachePersistence::open(db_path)?;
236-
237-
// Load last committed
238-
let last_committed = persistence.load_last_committed()?;
239-
println!(
240-
"Last Committed Instance: {}",
241-
last_committed.map_or("None".to_string(), |i| i.to_string())
242-
);
243-
println!();
244-
245-
// Load all entries
246-
let entries = persistence.load_all_entries()?;
247-
println!("Total Entries: {}", entries.len());
248-
println!();
249-
250-
if entries.is_empty() {
251-
println!("Cache is empty.");
252-
return Ok(());
253-
}
254-
255-
println!("Entries:");
256-
println!(
257-
"{:<12} {:<20} {:<15} {:<15}",
258-
"Instance ID", "Epochs", "Proof Size", "Signers"
259-
);
260-
println!("{}", "-".repeat(70));
261-
262-
for entry in &entries {
263-
let epochs_str = format!("[{:?}]", entry.finalized_epochs);
264-
let epochs_display = if epochs_str.len() > 18 {
265-
format!("{}...", &epochs_str[..15])
266-
} else {
267-
epochs_str
268-
};
269-
270-
// Serialize proof bundle to get size
271-
let proof_bundle_size = fvm_ipld_encoding::to_vec(&entry.proof_bundle)
272-
.map(|v| v.len())
273-
.unwrap_or(0);
274-
275-
println!(
276-
"{:<12} {:<20} {:<15} {:<15}",
277-
entry.instance_id,
278-
epochs_display,
279-
format!("{} bytes", proof_bundle_size),
280-
format!("{} signers", entry.certificate.signers.len())
281-
);
282-
}
283-
284-
Ok(())
285-
}
286-
287-
fn show_stats(db_path: &PathBuf) -> anyhow::Result<()> {
288-
use fendermint_vm_topdown_proof_service::persistence::ProofCachePersistence;
289-
290-
println!("=== Cache Statistics ===");
291-
println!("Database: {}", db_path.display());
292-
println!();
293-
294-
let persistence = ProofCachePersistence::open(db_path)?;
295-
296-
let last_committed = persistence.load_last_committed()?;
297-
let entries = persistence.load_all_entries()?;
298-
299-
println!("General:");
300-
println!(
301-
" Last Committed: {}",
302-
last_committed.map_or("None".to_string(), |i| i.to_string())
303-
);
304-
println!(" Total Entries: {}", entries.len());
305-
println!();
306-
307-
if !entries.is_empty() {
308-
let min_instance = entries.iter().map(|e| e.instance_id).min().unwrap();
309-
let max_instance = entries.iter().map(|e| e.instance_id).max().unwrap();
310-
let total_proof_size: usize = entries
311-
.iter()
312-
.map(|e| {
313-
fvm_ipld_encoding::to_vec(&e.proof_bundle)
314-
.map(|v| v.len())
315-
.unwrap_or(0)
316-
})
317-
.sum();
318-
let avg_proof_size = total_proof_size / entries.len();
319-
320-
println!("Instances:");
321-
println!(" Min Instance ID: {}", min_instance);
322-
println!(" Max Instance ID: {}", max_instance);
323-
println!(" Range: {}", max_instance - min_instance + 1);
324-
println!();
325-
326-
println!("Proof Bundles:");
327-
println!(
328-
" Total Size: {} bytes ({:.2} KB)",
329-
total_proof_size,
330-
total_proof_size as f64 / 1024.0
331-
);
332-
println!(" Average Size: {} bytes", avg_proof_size);
333-
println!(
334-
" Min Size: {} bytes",
335-
entries
336-
.iter()
337-
.map(|e| fvm_ipld_encoding::to_vec(&e.proof_bundle)
338-
.map(|v| v.len())
339-
.unwrap_or(0))
340-
.min()
341-
.unwrap()
342-
);
343-
println!(
344-
" Max Size: {} bytes",
345-
entries
346-
.iter()
347-
.map(|e| fvm_ipld_encoding::to_vec(&e.proof_bundle)
348-
.map(|v| v.len())
349-
.unwrap_or(0))
350-
.max()
351-
.unwrap()
352-
);
353-
println!();
354-
355-
println!("Epochs:");
356-
let total_epochs: usize = entries.iter().map(|e| e.finalized_epochs.len()).sum();
357-
println!(" Total Finalized Epochs: {}", total_epochs);
358-
println!(
359-
" Avg Epochs per Instance: {:.1}",
360-
total_epochs as f64 / entries.len() as f64
361-
);
362-
}
363-
364-
Ok(())
365-
}
366-
367-
fn get_proof(db_path: &PathBuf, instance_id: u64) -> anyhow::Result<()> {
368-
use fendermint_vm_topdown_proof_service::config::CacheConfig;
369-
370-
println!("=== Get Proof ===");
371-
println!("Database: {}", db_path.display());
372-
println!("Instance ID: {}", instance_id);
373-
println!();
374-
375-
// Load cache with persistence
376-
let cache_config = CacheConfig {
377-
lookahead_instances: 10,
378-
retention_epochs: 2,
379-
};
380-
381-
let cache = ProofCache::new_with_persistence(cache_config, db_path, 0)?;
382-
383-
match cache.get(instance_id) {
384-
Some(entry) => {
385-
println!("Found proof for instance {}", instance_id);
386-
println!();
387-
println!("Details:");
388-
println!(" Instance ID: {}", entry.instance_id);
389-
println!(" Finalized Epochs: {:?}", entry.finalized_epochs);
390-
let proof_bundle_size = fvm_ipld_encoding::to_vec(&entry.proof_bundle)
391-
.map(|v| v.len())
392-
.unwrap_or(0);
393-
println!(" Proof Bundle Size: {} bytes", proof_bundle_size);
394-
println!(
395-
" - Storage Proofs: {}",
396-
entry.proof_bundle.storage_proofs.len()
397-
);
398-
println!(
399-
" - Event Proofs: {}",
400-
entry.proof_bundle.event_proofs.len()
401-
);
402-
println!(" - Witness Blocks: {}", entry.proof_bundle.blocks.len());
403-
println!(" Generated At: {:?}", entry.generated_at);
404-
println!(" Source RPC: {}", entry.source_rpc);
405-
println!();
406-
println!("Certificate:");
407-
println!(" Instance ID: {}", entry.certificate.instance_id);
408-
println!(
409-
" Finalized Epochs: {:?}",
410-
entry.certificate.finalized_epochs
411-
);
412-
println!(" Power Table CID: {}", entry.certificate.power_table_cid);
413-
println!(
414-
" BLS Signature: {} bytes",
415-
entry.certificate.signature.len()
416-
);
417-
println!(" Signers: {} validators", entry.certificate.signers.len());
418-
println!();
419-
420-
// Proof Bundle Summary
421-
println!("═══ Proof Bundle Summary ═══");
422-
let proof_bundle_size = fvm_ipld_encoding::to_vec(&entry.proof_bundle)
423-
.map(|v| v.len())
424-
.unwrap_or(0);
425-
println!(
426-
" Total Size: {} bytes ({:.2} KB)",
427-
proof_bundle_size,
428-
proof_bundle_size as f64 / 1024.0
429-
);
430-
println!(
431-
" Storage Proofs: {}",
432-
entry.proof_bundle.storage_proofs.len()
433-
);
434-
println!(" Event Proofs: {}", entry.proof_bundle.event_proofs.len());
435-
println!(" Witness Blocks: {}", entry.proof_bundle.blocks.len());
436-
println!();
437-
438-
// Proof Bundle Details - show structure
439-
println!("═══ Detailed Proof Structure ═══");
440-
println!(
441-
"Storage Proofs ({}):",
442-
entry.proof_bundle.storage_proofs.len()
443-
);
444-
for (i, sp) in entry.proof_bundle.storage_proofs.iter().enumerate() {
445-
println!(" [{}] {:?}", i, sp);
446-
}
447-
println!();
448-
449-
println!("Event Proofs ({}):", entry.proof_bundle.event_proofs.len());
450-
for (i, ep) in entry.proof_bundle.event_proofs.iter().enumerate() {
451-
println!(" [{}] {:?}", i, ep);
452-
}
453-
println!();
454-
455-
println!("Witness Blocks ({}):", entry.proof_bundle.blocks.len());
456-
println!(" (First and last blocks shown)");
457-
for (i, block) in entry.proof_bundle.blocks.iter().enumerate() {
458-
if i < 2 || i >= entry.proof_bundle.blocks.len() - 2 {
459-
println!(" [{}] {:?}", i, block);
460-
} else if i == 2 {
461-
println!(
462-
" ... ({} more blocks)",
463-
entry.proof_bundle.blocks.len() - 4
464-
);
465-
}
466-
}
467-
println!();
468-
469-
// Metadata
470-
println!("═══ Metadata ═══");
471-
println!(" Generated At: {:?}", entry.generated_at);
472-
println!(" Source RPC: {}", entry.source_rpc);
473-
println!();
474-
475-
// Full JSON dump
476-
println!("═══ Full Proof Bundle (JSON) ═══");
477-
if let Ok(json) = serde_json::to_string_pretty(&entry.proof_bundle) {
478-
println!("{}", json);
479-
}
480-
}
481-
None => {
482-
println!("No proof found for instance {}", instance_id);
483-
println!();
484-
println!("Available instances: {:?}", cache.cached_instances());
485-
}
486-
}
487-
488-
Ok(())
489-
}

fendermint/vm/topdown/proof-service/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
//! This avoids duplicating certificates when multiple epochs reference
1818
//! the same certificate.
1919
20-
// Re-export commonly used types
21-
pub use filecoin_f3_gpbft::powertable::{PowerEntries, PowerEntry};
22-
2320
pub mod assembler;
2421
pub mod cache;
2522
pub mod config;
@@ -28,6 +25,7 @@ pub mod observe;
2825
pub mod persistence;
2926
pub mod service;
3027
pub mod types;
28+
pub mod verifier;
3129

3230
// Re-export main types for convenience
3331
pub use cache::ProofCache;
@@ -55,7 +53,6 @@ use std::sync::Arc;
5553
/// * `initial_instance` - The last committed F3 instance (from F3CertManager actor)
5654
/// * `initial_power_table` - Initial power table (from F3CertManager actor)
5755
/// * `db_path` - Optional database path for persistence
58-
/// * `initial_committed_instance` - The last committed F3 instance (from actor)
5956
///
6057
/// # Returns
6158
/// * `Arc<ProofCache>` - Shared cache that proposers can query
@@ -154,6 +151,7 @@ mod tests {
154151
#[tokio::test]
155152
async fn test_launch_service_enabled() {
156153
use crate::config::GatewayId;
154+
use filecoin_f3_gpbft::PowerEntries;
157155

158156
let config = ProofServiceConfig {
159157
enabled: true,
@@ -171,8 +169,5 @@ mod tests {
171169

172170
let (_cache, handle) = result.unwrap().unwrap();
173171
handle.abort();
174-
175-
// Check cache state
176-
assert_eq!(cache.last_committed_instance(), 100);
177172
}
178173
}

0 commit comments

Comments
 (0)