Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wizd committed Aug 7, 2020
1 parent 1b41380 commit 2ae34e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Core/Lyra.Core/BlockChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -232,6 +233,7 @@ private void CreateStateMachine()
await Task.Delay(10000);
_log.LogInformation($"Querying billboard... ");
var board = await _sys.Consensus.Ask<BillBoard>(new AskForBillboard());
var q = from ns in _nodeStatus
where board.PrimaryAuthorizers != null && board.PrimaryAuthorizers.Contains(ns.accountId)
Expand Down
39 changes: 26 additions & 13 deletions Core/Lyra.Core/Decentralize/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,26 @@ public ConsensusService(DagSystem sys, IActorRef localNode, IActorRef blockchain
int count = 0;
while (true)
{
//var blockchainStatus = await blockchain.Ask<NodeStatus>(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());
}
}
});
Expand Down Expand Up @@ -385,14 +389,23 @@ private async Task StateMaintainceAsync()
}

//if necessary, insert a new ConsolidateBlock
if (IsThisNodeSeed0)
var blockchainStatus = await _blockchain.Ask<NodeStatus>(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();
Expand Down

0 comments on commit 2ae34e5

Please sign in to comment.