@@ -153,7 +153,6 @@ public partial class RocksDBStore : BaseStore
153153 private readonly ReaderWriterLockSlim _rwBlockCommitLock ;
154154 private readonly ReaderWriterLockSlim _rwNextStateRootHashLock ;
155155 private readonly ReaderWriterLockSlim _rwEvidenceLock ;
156- private bool _pruned = false ;
157156 private bool _disposed = false ;
158157 private object _chainForkDeleteLock = new object ( ) ;
159158 private LruCache < Guid , LruCache < ( int , int ? ) , List < BlockHash > > > _indexCache ;
@@ -284,8 +283,6 @@ public RocksDBStore(
284283 new ReaderWriterLockSlim ( LockRecursionPolicy . SupportsRecursion ) ;
285284 _rwEvidenceLock = new ReaderWriterLockSlim ( LockRecursionPolicy . SupportsRecursion ) ;
286285
287- _pruned = ListChainIds ( ) . Count ( ) <= 1 ;
288-
289286 _blockDbCache = new LruCache < string , RocksDb > ( dbConnectionCacheSize ) ;
290287 _blockDbCache . SetPreRemoveDataMethod ( db =>
291288 {
@@ -300,6 +297,8 @@ public RocksDBStore(
300297 } ) ;
301298 }
302299
300+ private bool IsPruned => ListChainIds ( ) . Count ( ) <= 1 ;
301+
303302 public static bool MigrateChainDBFromColumnFamilies ( string path )
304303 {
305304 var opt = new DbOptions ( ) ;
@@ -1820,7 +1819,7 @@ private IEnumerable<BlockHash> IterateIndexes(
18201819 Guid chainId ,
18211820 long offset ,
18221821 long ? limit ,
1823- bool includeDeleted ) => _pruned
1822+ bool includeDeleted ) => IsPruned
18241823 ? IterateIndexesPruned ( chainId , offset , limit , includeDeleted )
18251824 : IterateIndexesUnpruned ( chainId , offset , limit , includeDeleted ) ;
18261825
@@ -1836,15 +1835,25 @@ private IEnumerable<BlockHash> IterateIndexesPruned(
18361835 }
18371836
18381837 long count = 0 ;
1838+ long limitUpperBound = CountIndex ( chainId ) - offset ;
1839+ long actualLimit = limit is { } l
1840+ ? Math . Min ( l , limitUpperBound )
1841+ : limitUpperBound ;
1842+
1843+ if ( actualLimit <= 0 )
1844+ {
1845+ yield break ;
1846+ }
1847+
18391848 foreach ( BlockHash hash in IterateIndexesInnerPruned ( chainId , offset ) )
18401849 {
1841- if ( count >= limit )
1850+ yield return hash ;
1851+ count += 1 ;
1852+
1853+ if ( count >= actualLimit )
18421854 {
18431855 yield break ;
18441856 }
1845-
1846- yield return hash ;
1847- count += 1 ;
18481857 }
18491858 }
18501859
0 commit comments