@@ -21,7 +21,7 @@ use crate::manager::{ConfigManager, RevisionManager, RevisionManagerConfig};
2121use firewood_metrics:: firewood_counter;
2222use firewood_storage:: {
2323 CheckOpt , CheckerReport , Committed , FileBacked , FileIoError , HashedNodeReader ,
24- ImmutableProposal , NodeHashAlgorithm , NodeStore , Parentable , ReadableStorage ,
24+ ImmutableProposal , MutableProposal , NodeHashAlgorithm , NodeStore , Parentable , ReadableStorage ,
2525 Reconstructed as StorageReconstructed , TrieReader ,
2626} ;
2727use nonzero_ext:: nonzero;
@@ -488,9 +488,7 @@ impl api::Reconstructible for &NodeStore<Committed, FileBacked> {
488488 where
489489 Self : Sized ,
490490 {
491- let _ = batch. into_iter ( ) ;
492- let _ = self ;
493- todo ! ( "historical reconstruction pipeline is not implemented yet" )
491+ reconstruct_with_parent ( self , batch)
494492 }
495493}
496494
@@ -501,12 +499,41 @@ impl api::Reconstructible for Reconstructed {
501499 where
502500 Self : Sized ,
503501 {
504- let _ = batch. into_iter ( ) ;
505- let _ = self ;
506- todo ! ( "linear reconstructed->reconstructed pipeline is not implemented yet" )
502+ reconstruct_with_parent ( & * self . nodestore , batch)
507503 }
508504}
509505
506+ fn reconstruct_with_parent < P > (
507+ parent : & NodeStore < P , FileBacked > ,
508+ batch : impl IntoBatchIter ,
509+ ) -> Result < Reconstructed , api:: Error >
510+ where
511+ NodeStore < P , FileBacked > : TrieReader + HashedNodeReader ,
512+ {
513+ let proposal = NodeStore :: < MutableProposal , _ > :: new_for_reconstruction ( parent) ?;
514+ let mut merkle = Merkle :: from ( proposal) ;
515+
516+ for res in batch. into_iter ( ) . into_batch_iter :: < api:: Error > ( ) {
517+ match res? {
518+ BatchOp :: Put { key, value } => {
519+ merkle. insert ( key. as_ref ( ) , value. as_ref ( ) . into ( ) ) ?;
520+ }
521+ BatchOp :: Delete { key } => {
522+ merkle. remove ( key. as_ref ( ) ) ?;
523+ }
524+ BatchOp :: DeleteRange { prefix } => {
525+ merkle. remove_prefix ( prefix. as_ref ( ) ) ?;
526+ }
527+ }
528+ }
529+
530+ let nodestore = merkle. into_inner ( ) ;
531+ let reconstructed = Arc :: new ( nodestore. try_into ( ) ?) ;
532+ Ok ( Reconstructed {
533+ nodestore : reconstructed,
534+ } )
535+ }
536+
510537#[ cfg( test) ]
511538mod test {
512539 #![ expect( clippy:: unwrap_used) ]
0 commit comments