From 42a916f7496a9b3527cbbb621cf7389ff69ec6fe Mon Sep 17 00:00:00 2001 From: kant777 <61204489+kant777@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:32:45 -0700 Subject: [PATCH 1/4] Update postgres.go --- cl/singlenode/payloadstore/postgres.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cl/singlenode/payloadstore/postgres.go b/cl/singlenode/payloadstore/postgres.go index 5a34968cf..9afd736a6 100644 --- a/cl/singlenode/payloadstore/postgres.go +++ b/cl/singlenode/payloadstore/postgres.go @@ -27,9 +27,10 @@ func NewPostgresRepository(ctx context.Context, dsn string, logger *slog.Logger) return nil, fmt.Errorf("failed to open postgres connection: %w", err) } - db.SetMaxOpenConns(10) - db.SetMaxIdleConns(5) - db.SetConnMaxLifetime(5 * time.Minute) + db.SetMaxOpenConns(25) + db.SetMaxIdleConns(20) + db.SetConnMaxLifetime(0) + db.SetConnMaxIdleTime(0) pingCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() @@ -41,6 +42,16 @@ func NewPostgresRepository(ctx context.Context, dsn string, logger *slog.Logger) return nil, fmt.Errorf("failed to ping postgres: %w", err) } + go func() { + t := time.NewTicker(2 * time.Minute) + defer t.Stop() + for range t.C { + c, ccancel := context.WithTimeout(context.Background(), time.Second) + _ = db.PingContext(c) + ccancel() + } + }() + // Create table with enhanced schema for sequential access schemaCreationQuery := ` CREATE TABLE IF NOT EXISTS execution_payloads ( From 4155d7d35f1003bcfa2488602d29d8c607762c42 Mon Sep 17 00:00:00 2001 From: kant Date: Thu, 18 Sep 2025 19:42:06 -0700 Subject: [PATCH 2/4] formatting --- cl/singlenode/payloadstore/postgres.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cl/singlenode/payloadstore/postgres.go b/cl/singlenode/payloadstore/postgres.go index 9afd736a6..06a7aaeda 100644 --- a/cl/singlenode/payloadstore/postgres.go +++ b/cl/singlenode/payloadstore/postgres.go @@ -30,7 +30,7 @@ func NewPostgresRepository(ctx context.Context, dsn string, logger *slog.Logger) db.SetMaxOpenConns(25) db.SetMaxIdleConns(20) db.SetConnMaxLifetime(0) - db.SetConnMaxIdleTime(0) + db.SetConnMaxIdleTime(0) pingCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() @@ -42,7 +42,7 @@ func NewPostgresRepository(ctx context.Context, dsn string, logger *slog.Logger) return nil, fmt.Errorf("failed to ping postgres: %w", err) } - go func() { + go func() { t := time.NewTicker(2 * time.Minute) defer t.Stop() for range t.C { From 36fde9c6958524f49e4dabb7b54c76c0b8688640 Mon Sep 17 00:00:00 2001 From: kant Date: Thu, 18 Sep 2025 23:06:01 -0700 Subject: [PATCH 3/4] setting the timeout to 30 seconds since 5 seconds is not enought to auth, tls etc --- cl/singlenode/payloadstore/postgres.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cl/singlenode/payloadstore/postgres.go b/cl/singlenode/payloadstore/postgres.go index 06a7aaeda..6e827638c 100644 --- a/cl/singlenode/payloadstore/postgres.go +++ b/cl/singlenode/payloadstore/postgres.go @@ -112,7 +112,7 @@ func (r *PostgresRepository) SavePayload(ctx context.Context, info *types.Payloa inserted_at = NOW(); ` - insertCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + insertCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() result, err := r.db.ExecContext(insertCtx, query, info.PayloadID, info.ExecutionPayload, info.BlockHeight) @@ -216,7 +216,7 @@ func (r *PostgresRepository) GetPayloadByHeight(ctx context.Context, height uint WHERE block_height = $1; ` - queryCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() var payload types.PayloadInfo @@ -258,7 +258,7 @@ func (r *PostgresRepository) GetLatestPayload(ctx context.Context) (*types.Paylo LIMIT 1; ` - queryCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() var payload types.PayloadInfo @@ -297,7 +297,7 @@ func (r *PostgresRepository) GetLatestHeight(ctx context.Context) (uint64, error ORDER BY block_height DESC LIMIT 1; ` - queryCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() var h int64 From 0968fe534d215c5734536444de5121c14717644f Mon Sep 17 00:00:00 2001 From: kant Date: Fri, 19 Sep 2025 08:14:21 -0700 Subject: [PATCH 4/4] removing the ping logic --- cl/singlenode/payloadstore/postgres.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cl/singlenode/payloadstore/postgres.go b/cl/singlenode/payloadstore/postgres.go index 6e827638c..d31bd9a50 100644 --- a/cl/singlenode/payloadstore/postgres.go +++ b/cl/singlenode/payloadstore/postgres.go @@ -42,16 +42,6 @@ func NewPostgresRepository(ctx context.Context, dsn string, logger *slog.Logger) return nil, fmt.Errorf("failed to ping postgres: %w", err) } - go func() { - t := time.NewTicker(2 * time.Minute) - defer t.Stop() - for range t.C { - c, ccancel := context.WithTimeout(context.Background(), time.Second) - _ = db.PingContext(c) - ccancel() - } - }() - // Create table with enhanced schema for sequential access schemaCreationQuery := ` CREATE TABLE IF NOT EXISTS execution_payloads (