fix(bifrost): receipt-error race, zero-concurrency hangs, and two logging bugs
🔎 Visual review: building it for4f8b4fad; the link appears here.
Four bifrost bug fixes found while profiling for !5222 (merged) and !5230 (closed). One commit each.
1. getTxInOptimized: goroutine-local receipt error (data race that could drop inbounds)
EVMScanner.getTxInOptimized (bifrost/pkg/chainclients/evm/evm_block_scanner.go) converts receipts in parallel goroutines, bounded by cfg.Concurrency. Each goroutine assigned the enclosing function's err:
var txInItem *stypes.TxInItem
txInItem, err = e.receiptToTxInItem(txForReceipt, receipt)
if err != nil { ...; return }BASE and BSC take this path (eth_getBlockReceipts) with concurrency: 4 in config/default.yaml. Besides being a data race, it can lose observations:
- Goroutine A gets a valid item and writes
err = nil. - Goroutine B writes
err = <its error>. - A reads B's error and returns without appending its item.
The inbound is then silently skipped, and the only trace is an error log attributed to the wrong tx.
Fix: declare err inside the goroutine (txInItem, err := ...). The sequential getTxIn path is unaffected.
Test: TestGetTxInOptimizedConcurrentReceipts converts a 32-tx BASE block (16 to a vault) with Concurrency = 4 and checks every inbound is observed. Before the fix it fails under -race (WARNING: DATA RACE at the err write/read).
2. Never hang on a zero or negative EVM concurrency setting
Four worker pools are sized straight from config, which nothing validates:
| Site | With 0 | With a negative value |
|---|---|---|
EVMScanner.getTxInOptimized (BASE/BSC/POL) |
unbuffered semaphore: the first receipt blocks forever and the scanner stalls | make(chan, -1) panics |
ETHScanner.extractTxs |
semaphore.NewWeighted(0) never grants Acquire(1): every tx worker waits forever |
same |
EVMClient / ETH Client.reconstructLiabilities |
the first send blocks forever, so signing never becomes ready | panics |
The shipped EVM chain configs set these to at least 1, but the shared default for reconstruct_liabilities_concurrency is 0, so a chain section without an override would hang at startup.
Fix: use at least one worker (max(x, 1)), the same convention signer/pipeline.go applies to its inactive-vault concurrency.
Tests: TestGetTxInOptimizedConcurrentReceipts now also runs with Concurrency 1, 0 and -1. There are new tests for ETH extractTxs and both reconstructLiabilities functions. All of them hang on the old code ("did not return").
3. Tron API request failures were never logged
TronApi.get and post (bifrost/pkg/chainclients/tron/api/tron_api.go) called api.logger.Err(err) without .Msg(), which builds a zerolog event and never sends it. They now log "failed to call tron api" with the method. A scan of bifrost/ for other zerolog events missing Msg/Send found no other instances.
Test: TestFailedCallsAreLogged captures the logger against a 503 server. It fails on the old code.
4. Batch receipt fetch tested the wrong error
In getTxIn's batched receipt fetch (the non-eth_getBlockReceipts path), errors.Is(err, ethereum.NotFound) checked the BatchCall error, which is always nil there, instead of elem.Error. It now checks elem.Error, as intended.
To be precise: this changes no log output today. geth's BatchCall never yields ethereum.NotFound. A null receipt surfaces as Receipt.UnmarshalJSON's "missing required field" error, so a missing receipt is still logged as an error. That is the safer outcome, because the tx is then skipped and that log is its only trace.
Testing
go test -tags mocknet(and-race) onbifrost/pkg/chainclients/{evm,ethereum,tron/...}: pass.- golangci-lint v1.63.4 (repo config) and gofumpt: clean.
go build ./...: passes.