Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcoin chain fixes [not to merge] #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/Blockcore.Indexer/Sync/SyncTasks/BlockIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class BlockIndexer : TaskRunner
bool initialized;

long? inputCopyLastBlockHeight;
bool? inputAddressIndexCompleted;

public BlockIndexer(
IOptions<IndexerSettings> configuration,
Expand Down Expand Up @@ -200,11 +201,11 @@ await mongoData.InputTable.Indexes

}).ContinueWith(async task =>
{
log.LogDebug($"Creating indexes on {nameof(InputTable)}.{nameof(InputTable.Address)}");
//log.LogDebug($"Creating indexes on {nameof(InputTable)}.{nameof(InputTable.Address)}");

await mongoData.InputTable.Indexes
.CreateOneAsync(new CreateIndexModel<InputTable>(Builders<InputTable>
.IndexKeys.Ascending(trxBlk => trxBlk.Address)));
//await mongoData.InputTable.Indexes
// .CreateOneAsync(new CreateIndexModel<InputTable>(Builders<InputTable>
// .IndexKeys.Ascending(trxBlk => trxBlk.Address)));

}).ContinueWith(async task =>
{
Expand Down Expand Up @@ -255,7 +256,7 @@ await mongoData.Mempool.Indexes
{
if (indexingCompletTask != null && indexingCompletTask.IsCompleted)
{
if (inputCopyLastBlockHeight == null)
if (inputAddressIndexCompleted == null && inputCopyLastBlockHeight == null)
{
var addressNulls = mongoData.InputTable.AsQueryable()
.OrderBy(b => b.BlockIndex)
Expand Down Expand Up @@ -309,6 +310,29 @@ await mongoData.Mempool.Indexes
}
else
{
if (inputAddressIndexCompleted == null)
{
inputAddressIndexCompleted = false;

indexingCompletTask = Task.Run(async () =>
{
log.LogDebug($"Creating indexes on {nameof(InputTable)}.{nameof(InputTable.Address)}");

await mongoData.InputTable.Indexes
.CreateOneAsync(new CreateIndexModel<InputTable>(Builders<InputTable>
.IndexKeys.Ascending(trxBlk => trxBlk.Address)));

inputAddressIndexCompleted = true;
});

return true;
}

if (inputAddressIndexCompleted == false)
{
return true;
}

Runner.GlobalState.IndexMode = false;
Runner.GlobalState.IndexModeCompleted = true;

Expand Down
25 changes: 24 additions & 1 deletion src/Blockcore.Indexer/Sync/SyncTasks/BlockPuller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public override async Task<bool> OnExecute()
}

// fetch the next block form the fullnode
string nextHash = await client.GetblockHashAsync(Runner.GlobalState.PullingTip.Height + 1);
//string nextHash = await client.GetblockHashAsync(Runner.GlobalState.PullingTip.Height + 1);

string nextHash = await NextHashAsync(client, Runner.GlobalState.PullingTip.Height + 1);

if (string.IsNullOrEmpty(nextHash))
{
Expand Down Expand Up @@ -149,5 +151,26 @@ public override async Task<bool> OnExecute()

return await Task.FromResult(true);
}

private async Task<string> NextHashAsync(BitcoinClient client, long height)
{
// ugly hack for now

try
{
string nextHash = await client.GetblockHashAsync(height);

return nextHash;
}
catch (Exception e)
{
if (e.Message.Contains("Block height out of range"))
{
return null;
}

throw;
}
}
}
}