From e23bfbdfcdf1f30b90e01c36eeb9e7195d49f573 Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Tue, 17 Mar 2026 07:53:45 +0100 Subject: [PATCH] ci/cd: both suffix & infix archive fallback mechanism --- build/tools/templates.go | 14 +++++++-- build/tools/templates_test.go | 53 +++++++++++++++++++++++++++++++++++ docs/build.md | 5 ++-- docs/env.md | 5 ++-- 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 build/tools/templates_test.go diff --git a/build/tools/templates.go b/build/tools/templates.go index 2148f9ec..15882830 100644 --- a/build/tools/templates.go +++ b/build/tools/templates.go @@ -366,9 +366,19 @@ func lookupEnvWithArchiveFallback(prefix, alias string) (string, bool) { func aliasCandidates(alias string) []string { candidates := []string{alias} - if !strings.HasSuffix(alias, archiveSuffix) { - candidates = append(candidates, alias+archiveSuffix) + if strings.Contains(alias, archiveSuffix) { + return candidates } + + candidates = append(candidates, alias+archiveSuffix) + + if idx := strings.Index(alias, "_"); idx != -1 { + infix := alias[:idx] + archiveSuffix + alias[idx:] + if infix != alias && infix != alias+archiveSuffix { + candidates = append(candidates, infix) + } + } + return candidates } diff --git a/build/tools/templates_test.go b/build/tools/templates_test.go new file mode 100644 index 00000000..64a9524c --- /dev/null +++ b/build/tools/templates_test.go @@ -0,0 +1,53 @@ +package build + +import "testing" + +func TestLookupEnvWithArchiveFallback_PrefersExactAlias(t *testing.T) { + const prefix = "TEST_LOOKUP_PREFIX_" + t.Setenv(prefix+"base", "https://base") + t.Setenv(prefix+"base_archive", "https://base-archive") + + got, ok := lookupEnvWithArchiveFallback(prefix, "base") + if !ok { + t.Fatal("expected exact alias lookup to succeed") + } + if got != "https://base" { + t.Fatalf("expected exact alias to win, got %q", got) + } +} + +func TestLookupEnvWithArchiveFallback_UsesArchiveSuffixFallback(t *testing.T) { + const prefix = "TEST_LOOKUP_PREFIX_" + t.Setenv(prefix+"base_archive", "https://base-archive") + + got, ok := lookupEnvWithArchiveFallback(prefix, "base") + if !ok { + t.Fatal("expected suffix archive fallback to succeed") + } + if got != "https://base-archive" { + t.Fatalf("unexpected suffix fallback value %q", got) + } +} + +func TestLookupEnvWithArchiveFallback_UsesArchiveInfixFallback(t *testing.T) { + const prefix = "TEST_LOOKUP_PREFIX_" + t.Setenv(prefix+"polygon_archive_bor", "https://polygon-archive") + + got, ok := lookupEnvWithArchiveFallback(prefix, "polygon_bor") + if !ok { + t.Fatal("expected infix archive fallback to succeed") + } + if got != "https://polygon-archive" { + t.Fatalf("unexpected infix fallback value %q", got) + } +} + +func TestLookupEnvWithArchiveFallback_DoesNotDoubleArchive(t *testing.T) { + const prefix = "TEST_LOOKUP_PREFIX_" + t.Setenv(prefix+"polygon_archive_archive_bor", "https://invalid") + t.Setenv(prefix+"polygon_archive_bor_archive", "https://invalid") + + if _, ok := lookupEnvWithArchiveFallback(prefix, "polygon_archive_bor"); ok { + t.Fatal("unexpected lookup success for duplicate archive alias variants") + } +} diff --git a/docs/build.md b/docs/build.md index f74a9419..8856d0c6 100644 --- a/docs/build.md +++ b/docs/build.md @@ -90,10 +90,11 @@ command: `make NO_CACHE=true all-bitcoin`. `BB_RPC_URL_HTTP_`: Overrides `ipc.rpc_url_template` while generating package definitions so you can target hosted HTTP RPC endpoints without editing coin JSON. The root `Makefile` forwards any `BB_RPC_URL_HTTP_*` variables into the -Docker build/test containers. +Docker build/test containers. Resolution prefers the exact alias and also accepts archive variants such as `_archive` +and, for names like Polygon, `_archive_`. `BB_RPC_URL_WS_`: Overrides `ipc.rpc_url_ws_template` for WebSocket subscriptions. It should point to the -same host as `BB_RPC_URL_HTTP_`. +same host as `BB_RPC_URL_HTTP_` and follows the same fallback resolution. Example: `BB_RPC_URL_HTTP_ethereum=http://backend_hostname:1234 BB_RPC_URL_WS_ethereum_archive=ws://backend_hostname:1234 make deb-ethereum_archive`. diff --git a/docs/env.md b/docs/env.md index 4abd081c..6a6b3234 100644 --- a/docs/env.md +++ b/docs/env.md @@ -21,9 +21,10 @@ Some behavior of Blockbook can be modified by environment variables. The variabl ## Build-time variables - `BB_RPC_URL_HTTP_` - Overrides `ipc.rpc_url_template` during package/config generation so build and - integration-test tooling can target hosted HTTP RPC endpoints without editing coin JSON. + integration-test tooling can target hosted HTTP RPC endpoints without editing coin JSON. Lookup prefers the exact alias + and also accepts archive variants like `_archive` and `_archive_`. - `BB_RPC_URL_WS_` - Overrides `ipc.rpc_url_ws_template` for WebSocket subscriptions; should point to - the same host as `BB_RPC_URL_HTTP_`. + the same host as `BB_RPC_URL_HTTP_` and follows the same fallback resolution. - `BB_RPC_BIND_HOST_` - Overrides backend RPC bind host during package/config generation; when set to `0.0.0.0`, RPC stays restricted unless `BB_RPC_ALLOW_IP_` is set. - `BB_RPC_ALLOW_IP_` - Overrides backend RPC allow list for UTXO configs (e.g. `rpcallowip`), defaulting