Skip to content
Merged
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
23 changes: 15 additions & 8 deletions src/AElfScanServer.Worker.Core/Service/TransactionService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -171,7 +172,7 @@ private readonly IEntityMappingRepository<DailyMergeUniqueAddressCountIndex, str
private static long BpStakedAmount = 100000;
private static int BatchUpdateMaxSize = 1000;
private static object _lock = new object();
private static long PullLogEventTransactionInterval = 100 - 1;
private static ConcurrentDictionary<string, long> PullLogEventTransactionInterval = new ConcurrentDictionary<string, long>();
private static Timer timer;
private static long PullTransactioninterval = 500 - 1;

Expand Down Expand Up @@ -1003,18 +1004,24 @@ public virtual async Task BatchParseLogEventJob(string chainId)
await ConnectAsync();
var redisValue = RedisDatabase.StringGet(RedisKeyHelper.LogEventTransactionLastBlockHeight(chainId));
lastBlockHeight = redisValue.IsNullOrEmpty ? 2 : long.Parse(redisValue) + 1;
if (!PullLogEventTransactionInterval.TryGetValue(chainId, out var pullInterval))
{
pullInterval = 99; // 100 - 1
PullLogEventTransactionInterval[chainId] = pullInterval;
}
_logger.LogInformation(
"BatchParseLogEventJob {ChainId} lastBlockHeight {LastBlockHeight} PullLogEventTransactionInterval {PullLogEventTransactionInterval}",
chainId, lastBlockHeight, PullLogEventTransactionInterval);
chainId, lastBlockHeight, pullInterval);
while (true)
{

if (PullLogEventTransactionInterval != 0)
if (pullInterval != 0)
{
var latestBlocksAsync = await _aelfIndexerProvider.GetLatestSummariesAsync(chainId);
if (lastBlockHeight >= latestBlocksAsync.First().LatestBlockHeight)
{
PullLogEventTransactionInterval = 0;
pullInterval = 0;
PullLogEventTransactionInterval[chainId] = pullInterval;
}

_logger.LogInformation(
Expand All @@ -1024,7 +1031,7 @@ public virtual async Task BatchParseLogEventJob(string chainId)

var batchTransactionList =
await GetBatchTransactionList(chainId, lastBlockHeight,
lastBlockHeight + PullLogEventTransactionInterval);
lastBlockHeight + pullInterval);


if (batchTransactionList.IsNullOrEmpty())
Expand All @@ -1036,9 +1043,9 @@ await GetBatchTransactionList(chainId, lastBlockHeight,
_logger.LogInformation("BatchParseLogEventJob :{chainId},start:{startBlockHeight}", chainId,
lastBlockHeight);
await ParseLogEventList(batchTransactionList, chainId);
lastBlockHeight += PullLogEventTransactionInterval + 1;
lastBlockHeight += pullInterval + 1;
RedisDatabase.StringSet(RedisKeyHelper.LogEventTransactionLastBlockHeight(chainId),
lastBlockHeight + PullLogEventTransactionInterval);
lastBlockHeight + pullInterval);
await Task.Delay(1000 * 1);
}
}
Expand Down Expand Up @@ -2634,4 +2641,4 @@ public virtual async Task<double> GetElfPrice(string date)
return (double)res.Data.Price / 1e8;

}
}
}
Loading