Skip to content

Commit

Permalink
Revert "return nullable long in MongoDbStore.GetLatestBlockIndex"
Browse files Browse the repository at this point in the history
This reverts commit 5bfbb75.
  • Loading branch information
boscohyun committed May 13, 2024
1 parent 1a12f70 commit 2c68397
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Mimir.Worker/BlockPoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public async Task RunAsync(CancellationToken cancellationToken)
var stateGetter = new StateGetter(stateService);
while (!cancellationToken.IsCancellationRequested)
{
var syncedBlockIndex = await mongoDbStore.GetLatestBlockIndex();
var currentBlockIndex = await stateService.GetLatestIndex();
var syncedBlockIndex = await mongoDbStore.GetLatestBlockIndex() ?? currentBlockIndex - 1;
var processBlockIndex = syncedBlockIndex + 1;
if (processBlockIndex > currentBlockIndex)
if (processBlockIndex >= currentBlockIndex)
{
await Task.Delay(TimeSpan.FromMilliseconds(3000), cancellationToken);
continue;
Expand Down
14 changes: 3 additions & 11 deletions Mimir.Worker/Services/MongoDbStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,11 @@ public async Task UpdateLatestBlockIndex(long blockIndex)
await MetadataCollection.BulkWriteAsync(new[] { updateModel });
}

public async Task<long?> GetLatestBlockIndex()
public async Task<long> GetLatestBlockIndex()
{
var filter = Builders<BsonDocument>.Filter.Eq("_id", "SyncContext");
try
{
var doc = await MetadataCollection.FindSync(filter).FirstAsync();
return doc.GetValue("LatestBlockIndex").AsInt64;
}
catch (InvalidOperationException e)
{
Console.WriteLine(e);
return null;
}
var doc = await MetadataCollection.FindSync(filter).FirstAsync();
return doc.GetValue("LatestBlockIndex").AsInt64;
}

public async Task BulkUpsertArenaDataAsync(List<ArenaData> arenaDatas)
Expand Down

0 comments on commit 2c68397

Please sign in to comment.