Exemple #1
0
        // forward api. should have more control here.
        //public ServiceAccount ServiceAccount => _serviceAccount;
        public async Task <bool> AddBlockAsync(TransactionBlock block)
        {
            var result = await _store.AddBlockAsync(block);

            if (result)
            {
                LyraSystem.Singleton.Consensus.Tell(new BlockAdded {
                    hash = block.Hash
                });
            }
            return(result);
        }
Exemple #2
0
        private async Task <bool> AddBlockImplAsync(Block block)
        {
            var result = await _store.AddBlockAsync(block);

            if (result)
            {
                LyraSystem.Singleton.Consensus.Tell(new BlockAdded {
                    hash = block.Hash
                });
            }

            if (block is ConsolidationBlock)
            {
                var consBlock = block as ConsolidationBlock;
                // we need to update the consolidation flag
                foreach (var hash in consBlock.blockHashes)
                {
                    if (!await _store.ConsolidateBlock(hash) && _stateMachine.State != BlockChainState.Engaging)
                    {
                        _log.LogCritical($"BlockChain Not consolidate block properly: {hash}");
                    }
                }

                // debug
                var blockCountInDb = await _store.GetBlockCountAsync();

                if (consBlock.totalBlockCount + 1 > blockCountInDb)
                {
                    _log.LogCritical($"Consolidation block miscalculate!! total: {blockCountInDb} calculated: {consBlock.totalBlockCount}");
                }
            }
            return(result);
        }
        private async Task <bool> AddBlockImplAsync(Block block)
        {
            var result = await _store.AddBlockAsync(block);

            if (result)
            {
                LyraSystem.Singleton.Consensus.Tell(new BlockAdded {
                    hash = block.Hash
                });
            }

            if (block is ConsolidationBlock)
            {
                // we need to update the consolidation flag
                foreach (var hash in (block as ConsolidationBlock).blockHashes)
                {
                    if (!await _store.ConsolidateBlock(hash) && _stateMachine.State != BlockChainState.Engaging)
                    {
                        _log.LogCritical($"BlockChain Not consolidate block properly: {hash}");
                    }
                }
            }
            return(result);
        }
Exemple #4
0
        public async Task <ServiceBlock> GetLastServiceBlockAsync() => await StopWatcher.TrackAsync(() => _store.GetLastServiceBlockAsync(), StopWatcher.GetCurrentMethod());                   //_store.GetLastServiceBlockAsync();

        // forward api. should have more control here.
        public async Task <bool> AddBlockAsync(Block block) => await StopWatcher.TrackAsync(() => _store.AddBlockAsync(block), StopWatcher.GetCurrentMethod());