private void CleanChain(Hash irreversibleBlockHash, long irreversibleBlockHeight) { _taskQueueManager.Enqueue(async() => { // Clean BlockStateSet var discardedBlockHashes = _chainBlockLinkService.GetCachedChainBlockLinks() .Where(b => b.Height <= irreversibleBlockHeight).Select(b => b.BlockHash).ToList(); await _blockchainStateService.RemoveBlockStateSetsAsync(discardedBlockHashes); // Clean chain branch var chain = await _blockchainService.GetChainAsync(); var discardedBranch = await _blockchainService.GetDiscardedBranchAsync(chain); _taskQueueManager.Enqueue( async() => { if (discardedBranch.BranchKeys.Count > 0 || discardedBranch.NotLinkedKeys.Count > 0) { await _blockchainService.CleanChainBranchAsync(discardedBranch); } await _forkCacheService.MergeAndCleanForkCacheAsync(irreversibleBlockHash, irreversibleBlockHeight); }, KernelConstants.UpdateChainQueueName); // Clean transaction block index cache await _transactionBlockIndexService.CleanTransactionBlockIndexCacheAsync(irreversibleBlockHeight); }, KernelConstants.ChainCleaningQueueName); }
public Task HandleEventAsync(NewIrreversibleBlockFoundEvent eventData) { _taskQueueManager.Enqueue(async() => { await _blockchainStateService.MergeBlockStateAsync(eventData.BlockHeight, eventData.BlockHash); }, KernelConstants.MergeBlockStateQueueName); _taskQueueManager.Enqueue(async() => { // Clean chain branch var chain = await _blockchainService.GetChainAsync(); var discardedBranch = await _blockchainService.GetDiscardedBranchAsync(chain); if (discardedBranch.BranchKeys.Count > 0 || discardedBranch.NotLinkedKeys.Count > 0) { _taskQueueManager.Enqueue( async() => { await _blockchainService.CleanChainBranchAsync(discardedBranch); }, KernelConstants.UpdateChainQueueName); } // Clean transaction block index cache await _transactionBlockIndexService.CleanTransactionBlockIndexCacheAsync(eventData.BlockHeight); }, KernelConstants.ChainCleaningQueueName); return(Task.CompletedTask); }