@@ -44,7 +44,6 @@ pub(crate) mod header;
4444pub ( crate ) mod persist;
4545pub ( crate ) mod primitives;
4646
47- use crate :: firewood_gauge;
4847use crate :: linear:: OffsetReader ;
4948use crate :: logger:: trace;
5049use crate :: node:: branch:: ReadSerializable as _;
@@ -53,7 +52,6 @@ use arc_swap::access::DynAccess;
5352use smallvec:: SmallVec ;
5453use std:: fmt:: Debug ;
5554use std:: io:: { Error , ErrorKind , Read } ;
56- use std:: sync:: atomic:: AtomicUsize ;
5755
5856// Re-export types from alloc module
5957pub use alloc:: NodeAllocator ;
@@ -125,7 +123,6 @@ impl<S: ReadableStorage> NodeStore<Committed, S> {
125123 deleted : Box :: default ( ) ,
126124 root_hash : None ,
127125 root : header. root_address ( ) . map ( Into :: into) ,
128- unwritten_nodes : AtomicUsize :: new ( 0 ) ,
129126 } ,
130127 storage,
131128 } ;
@@ -155,7 +152,6 @@ impl<S: ReadableStorage> NodeStore<Committed, S> {
155152 deleted : Box :: default ( ) ,
156153 root_hash : None ,
157154 root : None ,
158- unwritten_nodes : AtomicUsize :: new ( 0 ) ,
159155 } ,
160156 } )
161157 }
@@ -362,8 +358,6 @@ pub struct Committed {
362358 deleted : Box < [ MaybePersistedNode ] > ,
363359 root_hash : Option < TrieHash > ,
364360 root : Option < MaybePersistedNode > ,
365- /// TODO: No readers of this variable yet - will be used for tracking unwritten nodes in committed revisions
366- unwritten_nodes : AtomicUsize ,
367361}
368362
369363impl Clone for Committed {
@@ -372,10 +366,6 @@ impl Clone for Committed {
372366 deleted : self . deleted . clone ( ) ,
373367 root_hash : self . root_hash . clone ( ) ,
374368 root : self . root . clone ( ) ,
375- unwritten_nodes : AtomicUsize :: new (
376- self . unwritten_nodes
377- . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ,
378- ) ,
379369 }
380370 }
381371}
@@ -409,8 +399,6 @@ pub struct ImmutableProposal {
409399 root_hash : Option < TrieHash > ,
410400 /// The root node, either in memory or on disk
411401 root : Option < MaybePersistedNode > ,
412- /// The number of unwritten nodes in this proposal
413- unwritten_nodes : usize ,
414402}
415403
416404impl ImmutableProposal {
@@ -428,21 +416,6 @@ impl ImmutableProposal {
428416 }
429417}
430418
431- impl Drop for ImmutableProposal {
432- fn drop ( & mut self ) {
433- // When an immutable proposal is dropped without being committed,
434- // decrement the gauge to reflect that these nodes will never be written
435- if self . unwritten_nodes > 0 {
436- #[ allow( clippy:: cast_precision_loss) ]
437- firewood_gauge ! (
438- "firewood.nodes.unwritten" ,
439- "current number of unwritten nodes"
440- )
441- . decrement ( self . unwritten_nodes as f64 ) ;
442- }
443- }
444- }
445-
446419/// Contains the state of a revision of a merkle trie.
447420///
448421/// The first generic parameter is the type of the revision, which supports reading nodes from parent proposals.
@@ -505,23 +478,14 @@ impl<T: Into<NodeStoreParent>, S: ReadableStorage> From<NodeStore<T, S>>
505478/// Commit a proposal to a new revision of the trie
506479impl < S : WritableStorage > From < NodeStore < ImmutableProposal , S > > for NodeStore < Committed , S > {
507480 fn from ( val : NodeStore < ImmutableProposal , S > ) -> Self {
508- let NodeStore {
509- header,
510- kind,
511- storage,
512- } = val;
513- // Use ManuallyDrop to prevent the Drop impl from running since we're committing
514- let kind = std:: mem:: ManuallyDrop :: new ( kind) ;
515-
516481 NodeStore {
517- header,
482+ header : val . header ,
518483 kind : Committed {
519- deleted : kind. deleted . clone ( ) ,
520- root_hash : kind. root_hash . clone ( ) ,
521- root : kind. root . clone ( ) ,
522- unwritten_nodes : AtomicUsize :: new ( kind. unwritten_nodes ) ,
484+ deleted : val. kind . deleted . clone ( ) ,
485+ root_hash : val. kind . root_hash . clone ( ) ,
486+ root : val. kind . root . clone ( ) ,
523487 } ,
524- storage,
488+ storage : val . storage ,
525489 }
526490 }
527491}
@@ -548,7 +512,6 @@ impl<S: WritableStorage> NodeStore<Arc<ImmutableProposal>, S> {
548512 deleted : self . kind . deleted . clone ( ) ,
549513 root_hash : self . kind . root_hash . clone ( ) ,
550514 root : self . kind . root . clone ( ) ,
551- unwritten_nodes : AtomicUsize :: new ( self . kind . unwritten_nodes ) ,
552515 } ,
553516 storage : self . storage . clone ( ) ,
554517 }
@@ -574,7 +537,6 @@ impl<S: ReadableStorage> TryFrom<NodeStore<MutableProposal, S>>
574537 parent : Arc :: new ( ArcSwap :: new ( Arc :: new ( kind. parent ) ) ) ,
575538 root_hash : None ,
576539 root : None ,
577- unwritten_nodes : 0 ,
578540 } ) ,
579541 storage,
580542 } ;
@@ -587,31 +549,19 @@ impl<S: ReadableStorage> TryFrom<NodeStore<MutableProposal, S>>
587549
588550 // Hashes the trie and returns the address of the new root.
589551 #[ cfg( feature = "ethhash" ) ]
590- let ( root, root_hash, unwritten_count ) = nodestore. hash_helper ( root) ?;
552+ let ( root, root_hash) = nodestore. hash_helper ( root) ?;
591553 #[ cfg( not( feature = "ethhash" ) ) ]
592- let ( root, root_hash, unwritten_count) =
593- NodeStore :: < MutableProposal , S > :: hash_helper ( root) ?;
554+ let ( root, root_hash) = NodeStore :: < MutableProposal , S > :: hash_helper ( root) ?;
594555
595556 let immutable_proposal =
596557 Arc :: into_inner ( nodestore. kind ) . expect ( "no other references to the proposal" ) ;
597- // Use ManuallyDrop to prevent Drop from running since we're replacing the proposal
598- let immutable_proposal = std:: mem:: ManuallyDrop :: new ( immutable_proposal) ;
599558 nodestore. kind = Arc :: new ( ImmutableProposal {
600559 deleted : immutable_proposal. deleted . clone ( ) ,
601560 parent : immutable_proposal. parent . clone ( ) ,
602561 root_hash : Some ( root_hash. into_triehash ( ) ) ,
603562 root : Some ( root) ,
604- unwritten_nodes : unwritten_count,
605563 } ) ;
606564
607- // Track unwritten nodes in metrics
608- #[ allow( clippy:: cast_precision_loss) ]
609- firewood_gauge ! (
610- "firewood.nodes.unwritten" ,
611- "current number of unwritten nodes"
612- )
613- . increment ( unwritten_count as f64 ) ;
614-
615565 Ok ( nodestore)
616566 }
617567}
0 commit comments