Exemplo n.º 1
0
        private async Task ProcessLogEventAsync(Block block, IrreversibleBlockFound irreversibleBlockFound)
        {
            try
            {
                var chain = await _blockchainService.GetChainAsync();

                if (chain.LastIrreversibleBlockHeight > irreversibleBlockFound.IrreversibleBlockHeight)
                {
                    return;
                }

                var libBlockHash = await _blockchainService.GetBlockHashByHeightAsync(chain,
                                                                                      irreversibleBlockFound.IrreversibleBlockHeight, block.GetHash());

                if (libBlockHash == null)
                {
                    return;
                }

                // enable transaction packing
                _transactionPackingService.EnableTransactionPacking();
                if (chain.LastIrreversibleBlockHeight == irreversibleBlockFound.IrreversibleBlockHeight)
                {
                    return;
                }

                if (chain.LastIrreversibleBlockHeight == irreversibleBlockFound.IrreversibleBlockHeight)
                {
                    return;
                }

                var blockIndex = new BlockIndex(libBlockHash, irreversibleBlockFound.IrreversibleBlockHeight);
                Logger.LogDebug($"About to set new lib height: {blockIndex.BlockHeight} " +
                                $"Event: {irreversibleBlockFound} " +
                                $"BlockIndex: {blockIndex.BlockHash} - {blockIndex.BlockHeight}");
                _taskQueueManager.Enqueue(
                    async() =>
                {
                    var currentChain = await _blockchainService.GetChainAsync();
                    if (currentChain.LastIrreversibleBlockHeight < blockIndex.BlockHeight)
                    {
                        await _blockchainService.SetIrreversibleBlockAsync(currentChain, blockIndex.BlockHeight,
                                                                           blockIndex.BlockHash);
                    }
                }, KernelConstants.UpdateChainQueueName);
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Failed to resolve IrreversibleBlockFound event.");
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task HandleAsync(Block block, TransactionResult transactionResult, LogEvent logEvent)
        {
            var distanceToLib = new IrreversibleBlockHeightUnacceptable();

            distanceToLib.MergeFrom(logEvent);

            if (distanceToLib.DistanceToIrreversibleBlockHeight > 0)
            {
                Logger.LogDebug($"Distance to lib height: {distanceToLib.DistanceToIrreversibleBlockHeight}");
                _transactionPackingService.DisableTransactionPacking();
            }
            else
            {
                _transactionPackingService.EnableTransactionPacking();
            }

            await Task.CompletedTask;
        }