diff --git a/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/CoinviewTests.cs b/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/CoinviewTests.cs index 02a7e88324..c84edca8c5 100644 --- a/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/CoinviewTests.cs +++ b/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/CoinviewTests.cs @@ -49,7 +49,7 @@ public CoinviewTests() this.stakeChainStore = new StakeChainStore(this.network, this.chainIndexer, (IStakedb)this.coindb, this.loggerFactory); this.stakeChainStore.Load(); - this.rewindDataIndexCache = new RewindDataIndexCache(this.dateTimeProvider, this.network, new FinalizedBlockInfoRepository(new HashHeightPair()), new Checkpoints()); + this.rewindDataIndexCache = new RewindDataIndexCache(this.dateTimeProvider, this.network); this.cachedCoinView = new CachedCoinView(this.network, this.coindb, this.dateTimeProvider, this.loggerFactory, this.nodeStats, new ConsensusSettings(new NodeSettings(this.network)), this.chainIndexer, this.stakeChainStore, this.rewindDataIndexCache); diff --git a/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/RewindDataIndexCacheTest.cs b/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/RewindDataIndexCacheTest.cs index 9b98519897..4bd13d2109 100644 --- a/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/RewindDataIndexCacheTest.cs +++ b/src/Stratis.Bitcoin.Features.Consensus.Tests/CoinViews/RewindDataIndexCacheTest.cs @@ -34,7 +34,7 @@ public void RewindDataIndex_InitialiseCache_BelowMaxReorg() var finalizedBlockInfoRepositoryMock = new Mock(); finalizedBlockInfoRepositoryMock.Setup(s => s.GetFinalizedBlockInfo()).Returns(new HashHeightPair()); - var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network, finalizedBlockInfoRepositoryMock.Object, new Checkpoints()); + var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network); rewindDataIndexCache.Initialize(5, coinViewMock.Object); @@ -54,7 +54,7 @@ public void RewindDataIndex_InitialiseCache() var finalizedBlockInfoRepositoryMock = new Mock(); finalizedBlockInfoRepositoryMock.Setup(s => s.GetFinalizedBlockInfo()).Returns(new HashHeightPair()); - var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network, finalizedBlockInfoRepositoryMock.Object, new Checkpoints()); + var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network); rewindDataIndexCache.Initialize(20, coinViewMock.Object); @@ -74,7 +74,7 @@ public void RewindDataIndex_Save() var finalizedBlockInfoRepositoryMock = new Mock(); finalizedBlockInfoRepositoryMock.Setup(s => s.GetFinalizedBlockInfo()).Returns(new HashHeightPair()); - var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network, finalizedBlockInfoRepositoryMock.Object, new Checkpoints()); + var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network); rewindDataIndexCache.Initialize(20, coinViewMock.Object); @@ -95,7 +95,7 @@ public void RewindDataIndex_Flush() var finalizedBlockInfoRepositoryMock = new Mock(); finalizedBlockInfoRepositoryMock.Setup(s => s.GetFinalizedBlockInfo()).Returns(new HashHeightPair()); - var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network, finalizedBlockInfoRepositoryMock.Object, new Checkpoints()); + var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network); rewindDataIndexCache.Initialize(20, coinViewMock.Object); @@ -116,7 +116,7 @@ public void RewindDataIndex_Remove() var finalizedBlockInfoRepositoryMock = new Mock(); finalizedBlockInfoRepositoryMock.Setup(s => s.GetFinalizedBlockInfo()).Returns(new HashHeightPair()); - var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network, finalizedBlockInfoRepositoryMock.Object, new Checkpoints()); + var rewindDataIndexCache = new RewindDataIndexCache(dateTimeProviderMock.Object, this.Network); rewindDataIndexCache.Initialize(20, coinViewMock.Object); diff --git a/src/Stratis.Bitcoin.Features.Consensus/ProvenBlockHeaders/RewindDataIndexCache.cs b/src/Stratis.Bitcoin.Features.Consensus/ProvenBlockHeaders/RewindDataIndexCache.cs index c72161187c..4e1d858f87 100644 --- a/src/Stratis.Bitcoin.Features.Consensus/ProvenBlockHeaders/RewindDataIndexCache.cs +++ b/src/Stratis.Bitcoin.Features.Consensus/ProvenBlockHeaders/RewindDataIndexCache.cs @@ -12,8 +12,6 @@ namespace Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders public class RewindDataIndexCache : IRewindDataIndexCache { private readonly Network network; - private readonly IFinalizedBlockInfoRepository finalizedBlockInfoRepository; - private readonly ICheckpoints checkpoints; /// /// Internal cache for rewind data index. Key is a TxId + N (N is an index of output in a transaction) @@ -26,22 +24,18 @@ public class RewindDataIndexCache : IRewindDataIndexCache /// The number of items stored in cache is the sum of inputs used in every transaction in each of those blocks. /// private int numberOfBlocksToKeep; - private int lastCheckpoint; /// /// Performance counter to measure performance of the save and get operations. /// private readonly BackendPerformanceCounter performanceCounter; - public RewindDataIndexCache(IDateTimeProvider dateTimeProvider, Network network, IFinalizedBlockInfoRepository finalizedBlockInfoRepository, ICheckpoints checkpoints) + public RewindDataIndexCache(IDateTimeProvider dateTimeProvider, Network network) { Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider)); this.network = network; - this.finalizedBlockInfoRepository = finalizedBlockInfoRepository; - this.checkpoints = checkpoints; this.items = new ConcurrentDictionary(); - this.lastCheckpoint = this.checkpoints.GetLastCheckpointHeight(); this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider); } @@ -51,24 +45,10 @@ public void Initialize(int tipHeight, ICoinView coinView) { this.items.Clear(); - if (this.lastCheckpoint > tipHeight) - return; - - HashHeightPair finalBlock = this.finalizedBlockInfoRepository.GetFinalizedBlockInfo(); - this.numberOfBlocksToKeep = (int)this.network.Consensus.MaxReorgLength; int heightToSyncTo = tipHeight > this.numberOfBlocksToKeep ? tipHeight - this.numberOfBlocksToKeep : 1; - if (tipHeight < finalBlock.Height) - throw new ConsensusException($"Violation of finality on height { tipHeight } for RewindDataIndex."); - - if (heightToSyncTo < finalBlock.Height) - heightToSyncTo = finalBlock.Height; - - if (heightToSyncTo < this.lastCheckpoint) - heightToSyncTo = this.lastCheckpoint; - for (int rewindHeight = tipHeight; rewindHeight >= heightToSyncTo; rewindHeight--) { RewindData rewindData = coinView.GetRewindData(rewindHeight); @@ -104,9 +84,6 @@ private void AddRewindData(int rewindHeight, RewindData rewindData) /// public void Remove(int tipHeight, ICoinView coinView) { - if (this.lastCheckpoint > tipHeight) - return; - this.SaveAndEvict(tipHeight, null); int bottomHeight = tipHeight > this.numberOfBlocksToKeep ? tipHeight - this.numberOfBlocksToKeep : 1; @@ -118,9 +95,6 @@ public void Remove(int tipHeight, ICoinView coinView) /// public void SaveAndEvict(int tipHeight, Dictionary indexData) { - if (this.lastCheckpoint > tipHeight) - return; - if (indexData != null) { using (new StopwatchDisposable(o => this.performanceCounter.AddInsertTime(o))) diff --git a/src/Stratis.Bitcoin.Features.MemoryPool.Tests/TestChainFactory.cs b/src/Stratis.Bitcoin.Features.MemoryPool.Tests/TestChainFactory.cs index b588aeaf41..d0c83b73a8 100644 --- a/src/Stratis.Bitcoin.Features.MemoryPool.Tests/TestChainFactory.cs +++ b/src/Stratis.Bitcoin.Features.MemoryPool.Tests/TestChainFactory.cs @@ -117,7 +117,7 @@ public static async Task CreatePosAsync(Network network, Scri var stakeChain = new StakeChainStore(network, chain, null, loggerFactory); ConsensusRuleEngine consensusRules = new PosConsensusRuleEngine(network, loggerFactory, dateTimeProvider, chain, deployments, consensusSettings, new Checkpoints(), inMemoryCoinView, stakeChain, new StakeValidator(network, stakeChain, chain, inMemoryCoinView, loggerFactory), chainState, new InvalidBlockHashStore(dateTimeProvider), - new NodeStats(dateTimeProvider, NodeSettings.Default(network), new Mock().Object), new RewindDataIndexCache(dateTimeProvider, network, finalizedBlockInfoRepository, new Checkpoints()), asyncProvider, consensusRulesContainer).SetupRulesEngineParent(); + new NodeStats(dateTimeProvider, NodeSettings.Default(network), new Mock().Object), new RewindDataIndexCache(dateTimeProvider, network), asyncProvider, consensusRulesContainer).SetupRulesEngineParent(); IConsensusManager consensus = ConsensusManagerHelper.CreateConsensusManager(network, dataDir, chainState, chainIndexer: chain, consensusRules: consensusRules, inMemoryCoinView: inMemoryCoinView);