@@ -811,24 +811,28 @@ where
811811 // stack is empty.
812812 //
813813 // We will use this `Available` cached branch as our next branch.
814- self . cached_branch_stack . push ( trie_cursor_state. take ( ) ) ;
815- trace ! ( target: TRACE_TARGET , cached=?self . cached_branch_stack. last( ) , "Pushed next trie node onto cached_branch_stack" ) ;
816-
817- let ( cached_path, _) = self . cached_branch_stack . last ( ) . expect ( "just pushed" ) ;
814+ let cached = trie_cursor_state. take ( ) ;
815+ trace ! ( target: TRACE_TARGET , cached=?cached, "Pushed next trie node onto cached_branch_stack" ) ;
818816
819817 // If the calculated range is not caught up to the next cached branch it means there
820818 // are portions of the trie prior to that branch which may need to be calculated;
821819 // return the uncalculated range up to that branch to make that happen.
822820 //
823821 // If the next cached branch's path is all zeros then we can skip this catch-up step,
824822 // because there cannot be any keys prior to that range.
823+ let cached_path = & cached. 0 ;
825824 if uncalculated_lower_bound < cached_path && !PATH_ALL_ZEROS . starts_with ( cached_path) {
826825 let range = ( * uncalculated_lower_bound, Some ( * cached_path) ) ;
827826 trace ! ( target: TRACE_TARGET , ?range, "Returning key range to calculate in order to catch up to cached branch" ) ;
827+
828+ // Push the cached branch onto the stack so it's available once the leaf range is done
829+ // being calculated.
830+ self . cached_branch_stack . push ( cached) ;
831+
828832 return Ok ( PopCachedBranchOutcome :: CalculateLeaves ( range) ) ;
829833 }
830834
831- Ok ( PopCachedBranchOutcome :: Popped ( self . cached_branch_stack . pop ( ) . expect ( "just pushed" ) ) )
835+ Ok ( PopCachedBranchOutcome :: Popped ( cached ) )
832836 }
833837
834838 /// Accepts the current state of both hashed and trie cursors, and determines the next range of
0 commit comments