diff --git a/Core/Lyra.Core/BlockChain.cs b/Core/Lyra.Core/BlockChain.cs index 4ce344e95..88f1a4af9 100644 --- a/Core/Lyra.Core/BlockChain.cs +++ b/Core/Lyra.Core/BlockChain.cs @@ -218,6 +218,7 @@ private void CreateStateMachine() { while(true) { + _log.LogInformation($"Blockchain Startup... "); while (Neo.Network.P2P.LocalNode.Singleton.ConnectedCount < 2) { await Task.Delay(1000); @@ -232,6 +233,7 @@ private void CreateStateMachine() await Task.Delay(10000); + _log.LogInformation($"Querying billboard... "); var board = await _sys.Consensus.Ask(new AskForBillboard()); var q = from ns in _nodeStatus where board.PrimaryAuthorizers != null && board.PrimaryAuthorizers.Contains(ns.accountId) diff --git a/Core/Lyra.Core/Decentralize/ConsensusService.cs b/Core/Lyra.Core/Decentralize/ConsensusService.cs index f09c86fbe..0783bcca4 100644 --- a/Core/Lyra.Core/Decentralize/ConsensusService.cs +++ b/Core/Lyra.Core/Decentralize/ConsensusService.cs @@ -225,22 +225,26 @@ public ConsensusService(DagSystem sys, IActorRef localNode, IActorRef blockchain int count = 0; while (true) { - //var blockchainStatus = await blockchain.Ask(new BlockChain.QueryBlockchainStatus()); - //if (blockchainStatus.state == BlockChainState.Almighty) - //{ + try + { + _log.LogWarning("starting maintaince loop... "); await StateMaintainceAsync(); - //} - await Task.Delay(15000).ConfigureAwait(false); + await Task.Delay(15000).ConfigureAwait(false); - HeartBeat(); + HeartBeat(); - count++; + count++; - if (count > 4 * 5) // 5 minutes - { + if (count > 4 * 5) // 5 minutes + { - count = 0; + count = 0; + } + } + catch(Exception ex) + { + _log.LogWarning("In maintaince loop: " + ex.ToString()); } } }); @@ -385,14 +389,23 @@ private async Task StateMaintainceAsync() } //if necessary, insert a new ConsolidateBlock - if (IsThisNodeSeed0) + var blockchainStatus = await _blockchain.Ask(new BlockChain.QueryBlockchainStatus()); + if (IsThisNodeSeed0 && blockchainStatus.state == BlockChainState.Almighty) { //// test code //var livingPosNodeIds = _board.AllNodes.Keys.ToArray(); //_lastVotes = _sys.Storage.FindVotes(livingPosNodeIds); //// end test code - - if(await CheckPrimaryNodesStatus()) + bool allNodeSyncd = false; + try + { + allNodeSyncd = true;// await CheckPrimaryNodesStatus(); + } + catch(Exception ex) + { + _log.LogWarning("Exception in CheckPrimaryNodesStatus: " + ex.ToString()); + } + if(allNodeSyncd) { var unConsList = await _sys.Storage.GetAllUnConsolidatedBlockHashesAsync(); var lastConsBlock = await _sys.Storage.GetLastConsolidationBlockAsync();