Skip to content

Commit 22ea4b4

Browse files
authored
fix: activate dataset and persist clearing account config in demo compose (#1250)
* fix: wire deposit/withdrawal saga orchestration in unified binary The unified binary's wireCurrentAccount used the basic NewService() constructor which creates a Service without deposit/withdrawal orchestrators, causing nil pointer panics on ExecuteDeposit calls. Switch to NewServiceWithExistingClients() with loopback gRPC clients for position-keeping and financial-accounting, enabling full Starlark saga orchestration within the unified binary. Also: - Copy saga script assets into Docker image (SAGA_ASSET_DIR=/app) - Fix init-databases.sql: meridian_internal_account → meridian_internal_bank_account * fix: load clearing account config from env for deposit double-entry Without a clearing account, the deposit saga only creates a CREDIT posting (to customer). FA rejects the unbalanced booking log. Load AccountConfig from DEPOSIT_CLEARING_ACCOUNT_ID env var so the saga creates both DEBIT (clearing) and CREDIT (customer) postings. Gracefully falls back to nil when env var is unset. * fix: fail fast on invalid clearing account config Differentiate "env var not set" (graceful skip) from "env var set but invalid" (hard error) to avoid silently falling back to single-sided postings when config is misconfigured. * fix: use account_id for PK position logs in deposit and withdrawal sagas The Starlark deposit and withdrawal scripts were passing external_identifier (e.g. VE-GBP-010) as the position_id to position_keeping.initiate_log, but the post-deposit balance query uses account_id (e.g. ACC-xxx). This mismatch caused PK balance lookups to fail with "no position logs found for account". * fix: add required CEL expressions to seed-demo dataset registration RegisterDataSet now requires validation_expression and resolution_key_expression fields. Add appropriate CEL expressions for the wholesale energy price dataset. * fix: activate dataset before recording observations and persist clearing account config - seed-demo: call ActivateDataSet after RegisterDataSet to transition from DRAFT to ACTIVE before recording observations - docker-compose: add DEPOSIT_CLEARING_ACCOUNT_ID env var passthrough so it persists across deployments - .env.demo.example: document the clearing account config --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 313ab35 commit 22ea4b4

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

cmd/seed-demo/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ func seedMarketData(ctx context.Context, conn *grpc.ClientConn) error {
471471
fmt.Println(" Registered dataset: WHOLESALE_ENERGY_GBP_KWH")
472472
}
473473

474+
// Activate dataset so observations can be recorded
475+
_, err = client.ActivateDataSet(ctx, &marketv1.ActivateDataSetRequest{
476+
Code: "WHOLESALE_ENERGY_GBP_KWH",
477+
})
478+
if err == nil {
479+
fmt.Println(" Activated dataset: WHOLESALE_ENERGY_GBP_KWH")
480+
} else if st, ok := status.FromError(err); !ok || st.Code() != codes.FailedPrecondition {
481+
return fmt.Errorf("activate dataset: %w", err)
482+
}
483+
474484
// Seed 30 days of wholesale prices.
475485
// UK wholesale prices vary between 15-35p/kWh with daily volatility.
476486
rng := rand.New(rand.NewSource(42)) //nolint:gosec

deploy/demo/.env.demo.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ KAFKA_ENABLED=false
148148
# [OPTIONAL] Internal master tenant identifier used by the market-information service.
149149
MASTER_TENANT_ID=meridian_master
150150

151+
# [OPTIONAL] Clearing account ID for deposit double-entry postings.
152+
# When set, deposits create both a DEBIT posting to this clearing account
153+
# and a CREDIT posting to the customer account.
154+
DEPOSIT_CLEARING_ACCOUNT_ID=CLEARING-GBP-001
155+
151156
# ---------------------------------------------------------------------------
152157
# Observability (OpenTelemetry)
153158
# ---------------------------------------------------------------------------

deploy/demo/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ services:
9898
# --- Multi-tenancy ---
9999
MASTER_TENANT_ID: ${MASTER_TENANT_ID:-meridian_master}
100100

101+
# --- Clearing accounts ---
102+
DEPOSIT_CLEARING_ACCOUNT_ID: ${DEPOSIT_CLEARING_ACCOUNT_ID:-}
103+
101104
# --- Connection pool ---
102105
DB_MAX_OPEN_CONNS: ${DB_MAX_OPEN_CONNS:-25}
103106
DB_MAX_IDLE_CONNS: ${DB_MAX_IDLE_CONNS:-5}

0 commit comments

Comments
 (0)