Skip to content

Commit

Permalink
Merge pull request #135 from Atralupus/reduce-delay
Browse files Browse the repository at this point in the history
Optimize transaction processing with dynamic batch limit
  • Loading branch information
Atralupus authored Feb 28, 2025
2 parents 1a2bc02 + 378938e commit aaac40c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ArenaService/Worker/BattleTxTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ CancellationToken stoppingToken
return;
}

var blockDiff = currentBlockIndex - startingBlock;
var limit = blockDiff switch
{
> 1000 => 300,
> 500 => 100,
> 100 => 30,
> 50 => 10,
> 30 => 5,
_ => 1
};

_logger.LogInformation(
$"Processing transactions from block {startingBlock} to {currentBlockIndex}"
);
Expand All @@ -107,7 +118,7 @@ CancellationToken stoppingToken
{
var response = await client.GetTxs.ExecuteAsync(
startingBlock,
1,
limit,
ACTION_TYPE,
[TxStatus.Success, TxStatus.Staging],
stoppingToken
Expand Down Expand Up @@ -180,10 +191,11 @@ out var payload
catch (Exception ex)
{
_logger.LogError(ex, $"Failed to process transaction {tx.Id}");
throw;
}
}

await SetLastProcessedBlockAsync(redis, startingBlock + 1);
await SetLastProcessedBlockAsync(redis, startingBlock + limit - 1);
}

private async Task<long> GetLastProcessedBlockAsync(IDatabase redis)
Expand Down

0 comments on commit aaac40c

Please sign in to comment.