Ejemplo n.º 1
0
        public async Task SetIrreversibleBlockAsync(Chain chain, long irreversibleBlockHeight,
                                                    Hash irreversibleBlockHash)
        {
            // Create before IChainManager.SetIrreversibleBlockAsync so that we can correctly get the previous LIB info
            var eventDataToPublish = new NewIrreversibleBlockFoundEvent()
            {
                PreviousIrreversibleBlockHash   = chain.LastIrreversibleBlockHash,
                PreviousIrreversibleBlockHeight = chain.LastIrreversibleBlockHeight,
                BlockHash   = irreversibleBlockHash,
                BlockHeight = irreversibleBlockHeight
            };

            var success = await _chainManager.SetIrreversibleBlockAsync(chain, irreversibleBlockHash);

            if (!success)
            {
                return;
            }
            // TODO: move to background job, it will slow down our system
            // Clean last branches and not linked
            var toCleanBlocks = await _chainManager.CleanBranchesAsync(chain, eventDataToPublish.PreviousIrreversibleBlockHash,
                                                                       eventDataToPublish.PreviousIrreversibleBlockHeight);

            await RemoveBlocksAsync(toCleanBlocks);

            await LocalEventBus.PublishAsync(eventDataToPublish);
        }