@ -49,12 +49,9 @@ public class AtStatesPruner implements Runnable {
if ( Controller . getInstance ( ) . isSynchronizing ( ) )
if ( Controller . getInstance ( ) . isSynchronizing ( ) )
continue ;
continue ;
long currentPrunableTimestamp = NTP . getTime ( ) - Settings . getInstance ( ) . getAtStatesMaxLifetime ( ) ;
// Prune AT states for all blocks up until our latest minus pruneBlockLimit
// We want to keep AT states near the tip of our copy of blockchain so we can process/orphan nearby blocks
final int ourLatestHeight = chainTip . getHeight ( ) ;
long chainPrunableTimestamp = chainTip . getTimestamp ( ) - Settings . getInstance ( ) . getAtStatesMaxLifetime ( ) ;
final int upperPrunableHeight = ourLatestHeight - Settings . getInstance ( ) . getPruneBlockLimit ( ) ;
long upperPrunableTimestamp = Math . min ( currentPrunableTimestamp , chainPrunableTimestamp ) ;
int upperPrunableHeight = repository . getBlockRepository ( ) . getHeightFromTimestamp ( upperPrunableTimestamp ) ;
int upperBatchHeight = pruneStartHeight + Settings . getInstance ( ) . getAtStatesPruneBatchSize ( ) ;
int upperBatchHeight = pruneStartHeight + Settings . getInstance ( ) . getAtStatesPruneBatchSize ( ) ;
int upperPruneHeight = Math . min ( upperBatchHeight , upperPrunableHeight ) ;
int upperPruneHeight = Math . min ( upperBatchHeight , upperPrunableHeight ) ;