Skip to content

Commit

Permalink
Optimize transaction processing with dynamic batch limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus committed Feb 28, 2025
1 parent 1a2bc02 commit 378938e
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 378938e

Please sign in to comment.