Skip to content

Commit

Permalink
gracefuly log exception when either LedgerExntenderService commits tr…
Browse files Browse the repository at this point in the history
…ansaction or resubmission service handles transaction before gateway finishes. (#579)
  • Loading branch information
PawelPawelec-RDX authored Dec 6, 2023
1 parent 73964e6 commit b3c35e9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Release Date: _unreleased_
- Fixed exception thrown on empty validator set in the `/state/validator/list` endpoint.
- `524` status code returned instead of `500` if request takes longer than configured timeout.
- Validate if addresses provided in requests to API belong to network it is running on.

- Fixed `500` status code returned from `/transaction/submit` when Transaction got committed before Gateway was able to store pending transaction node submission result. It'll return 200 status code from now on and log exception as information.

## 1.2.2
Release Date: 22.11.2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
*/

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Npgsql;
using RadixDlt.CoreApiSdk.Api;
using RadixDlt.NetworkGateway.Abstractions;
Expand All @@ -85,17 +86,20 @@ namespace RadixDlt.NetworkGateway.PostgresIntegration.Services;
internal class SubmissionTrackingService : ISubmissionTrackingService
{
private readonly ReadWriteDbContext _dbContext;
private readonly ILogger<SubmissionTrackingService> _logger;
private readonly IReadOnlyCollection<ISubmissionTrackingServiceObserver> _observers;
private readonly IClock _clock;

public SubmissionTrackingService(
ReadWriteDbContext dbContext,
IEnumerable<ISubmissionTrackingServiceObserver> observers,
IClock clock)
IClock clock,
ILogger<SubmissionTrackingService> logger)
{
_dbContext = dbContext;
_observers = observers.ToArray();
_clock = clock;
_logger = logger;
}

public async Task<SubmissionResult> ObserveSubmissionToGatewayAndSubmitToNetworkIfNew(
Expand Down Expand Up @@ -214,20 +218,34 @@ private async Task SubmitToNetworkAndUpdatePendingTransaction(
CancellationToken token
)
{
var nodeSubmissionResult = await TransactionSubmitter.Submit(
submitContext,
notarizedTransactionBytes,
_observers,
token
);
try
{
var nodeSubmissionResult = await TransactionSubmitter.Submit(
submitContext,
notarizedTransactionBytes,
_observers,
token
);

pendingTransaction.HandleNodeSubmissionResult(
handlingConfig,
nodeName,
nodeSubmissionResult,
_clock.UtcNow,
currentEpoch < 0 ? null : (ulong)currentEpoch);
pendingTransaction.HandleNodeSubmissionResult(
handlingConfig,
nodeName,
nodeSubmissionResult,
_clock.UtcNow,
currentEpoch < 0 ? null : (ulong)currentEpoch);

await _dbContext.SaveChangesAsync(token);
await _dbContext.SaveChangesAsync(token);
}
catch (DbUpdateConcurrencyException ex)
{
// We catch an error so that we can return a successful response to the user - which is correct
// because the submission to the Gateway, and indeed the network, was successful.
// The fact we couldn't persist this submission result doesn't matter particularly, as the system is
// designed to work even if the Gateway API crashes after persisting the pending transaction.
// A submission to the network will be retried by the PendingTransactionResubmissionWorker in due course
// if still required, because ResubmitFromTimestamp was set as part of creating the PendingTransaction.
// The only difference is that an extra re-submission will occur, because this initial submission was not tracked.
_logger.LogInformation(ex, "Gateway failed to store submission result. Other process already modified that transaction (it got either committed and processed by PostgresLedgerExtenderService or by PendingTransactionResubmissionWorker)");
}
}
}

0 comments on commit b3c35e9

Please sign in to comment.