Skip to content

Commit

Permalink
small bug fixes (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangershony authored May 16, 2023
1 parent bfffdea commit 5b8cce9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Blockcore.Indexer.Core/Handlers/StatsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public async Task<CoinInfo> CoinInformation()

public async Task<Statistics> Statistics()
{
if (globalState.StoreTip?.BlockHash == null)
{
return new Statistics { Symbol = syncConnection.Symbol, Error = "node is not ready"};
}

var cachedStats = cache.Get<Statistics>(Key);

if (cachedStats != null &&
Expand Down
21 changes: 20 additions & 1 deletion src/Blockcore.Indexer.Core/Sync/SyncTasks/BlockStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override async Task OnExecute()
Runner.GlobalState.StoreTip = storageOperations.PushStorageBatch(genesisBatch);
}

BlockInfo fetchedBlock = await client.GetBlockAsync(Runner.GlobalState.StoreTip.BlockHash);
BlockInfo fetchedBlock = await GetBlockOrNullAsync(client, Runner.GlobalState.StoreTip.BlockHash);
if (fetchedBlock == null)
{
// check if the fullnode is ahead of the indexer height
Expand All @@ -117,5 +117,24 @@ public override async Task OnExecute()
// update the chains tip
Runner.GlobalState.ChainTipHeight = syncOperations.GetBlockCount(client);
}

private static async Task<BlockInfo> GetBlockOrNullAsync(IBlockchainClient client, string blockHash)
{
try
{
BlockInfo blockInfo = await client.GetBlockAsync(blockHash);

return blockInfo;
}
catch (Exception e)
{
if (e.Message.Contains("Block not found"))
{
return null;
}

throw;
}
}
}
}

0 comments on commit 5b8cce9

Please sign in to comment.