diff --git a/src/Data/Repositories/ForwardingHtlcEventRepository.cs b/src/Data/Repositories/ForwardingHtlcEventRepository.cs index 00a5d923..b4412948 100644 --- a/src/Data/Repositories/ForwardingHtlcEventRepository.cs +++ b/src/Data/Repositories/ForwardingHtlcEventRepository.cs @@ -87,7 +87,11 @@ public ForwardingHtlcEventRepository(IDbContextFactory dbC } catch (DbUpdateException e) when (e.InnerException is PostgresException pg && pg.SqlState == PostgresErrorCodes.UniqueViolation) { - _logger.LogDebug("Skipping duplicated forwarding HTLC event for node {ManagedNodePubKey}", forwardingHtlcEvent.ManagedNodePubKey); + _logger.LogDebug( + "Skipping duplicate forwarding HTLC event for node {ManagedNodePubKey} (in {IncomingChannelId}:{IncomingHtlcId} -> out {OutgoingChannelId}:{OutgoingHtlcId})", + forwardingHtlcEvent.ManagedNodePubKey, + forwardingHtlcEvent.IncomingChannelId, forwardingHtlcEvent.IncomingHtlcId, + forwardingHtlcEvent.OutgoingChannelId, forwardingHtlcEvent.OutgoingHtlcId); return (true, null); } catch (Exception e) diff --git a/src/Program.cs b/src/Program.cs index d8e0cb2e..4832a2f6 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -33,6 +33,8 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Logging; using Quartz; using OpenTelemetry.Trace; using OpenTelemetry.Resources; @@ -204,8 +206,22 @@ public static async Task Main(string[] args) builder.Services.AddDbContextFactory( options => { - options.EnableSensitiveDataLogging(); - options.EnableDetailedErrors(); + // Sensitive-data logging dumps raw SQL parameter values (pubkeys, amounts, + // aliases) into logs, so keep it to dev only — never leak it in prod. + if (isDevEnvironment) + { + options.EnableSensitiveDataLogging(); + options.EnableDetailedErrors(); + } + + // Duplicate-key violations on inserts like ForwardingHtlcEvents are expected + // and handled by the repositories (deduped/skipped). EF logs the failed command + // and SaveChanges at Error regardless of our catch, which floods prod with + // benign, verbose stack traces — downgrade both to Debug so they stay quiet. + options.ConfigureWarnings(warnings => warnings + .Log((RelationalEventId.CommandError, LogLevel.Debug)) + .Log((CoreEventId.SaveChangesFailed, LogLevel.Debug))); + options.UseNpgsql(Constants.POSTGRES_CONNECTIONSTRING, options => { options.UseQuerySplittingBehavior(QuerySplittingBehavior