perf(bifrost): remove redundant ECDSA recovery and pool-address scans from EVM scanning
🔎 Visual review: building it for69726735; the link appears here.
Summary
Behavior-preserving CPU and allocation cuts in bifrost's EVM scan path, based on a 120 s production profile from a validator. Every change is exactly equivalent: same outputs, same errors, same edge cases. Anything that couldn't be shown equivalent is listed under follow-ups instead.
| Commit | Change | Profile share addressed |
|---|---|---|
test(bifrost): benchmarks … |
benchmarks first (_test.go only) |
— |
perf(bifrost): cache EVM sender recovery … |
e.eipSigner.Sender(tx) → etypes.Sender(e.eipSigner, tx) in evm/, ethereum/, shared/evm/direct_erc20_transfer.go |
~1.7 s of 4.4 s ECDSA recovery |
perf(common): build GetAddress cache key by concatenation |
fmt.Sprintf("%s-%s", a, b) → a + "-" + b |
0.9 s Sprintf |
perf(bifrost): serve IsValidPoolAddress from the pool address cache |
use the existing poolAddressCache under an ASCII guard, falling back to the original loop otherwise |
1.67 s |
test(bifrost): benchmark FetchActiveNodes … + perf(bifrost): memoize FetchActiveNodes … |
remember the derived active pubkeys per cached node-accounts response slice | ~1.5 s of 1.80 s |
test(bifrost): benchmark contract-address checks … + perf(bifrost): compare contract addresses as lowercase hex … |
EVM + ETH isToValidContractAddress stop computing the EIP-55 checksum (a keccak256) per call, or per list entry on ETH |
0.31 s of Address.String's 0.41 s |
perf(bifrost): delay closeStream's Reset with a timer … |
time.AfterFunc instead of a goroutine sleeping 10 s |
2,321 of 3,177 goroutines (73 %) were parked in that sleep |
receiptToTxInItem overall (develop → this MR): −32 % to −59 % time, −77 % to −87 % bytes, −78 % to −85 % allocs. IsValidPoolAddress with 50 vaults: 18.6 µs → 0.1–0.3 µs.
Expected production effect: roughly 10 % of bifrost CPU (≈5 s of the 48.6 s sampled). That is from attributing each changed path's profile cost; it is not measured on a validator. Also ~12 % fewer allocated bytes, ~34 % fewer allocated objects, and ~2,300 fewer parked goroutines. The microbenchmarks show bigger percentages than that because they isolate the hot function. Most of the profile is RPC JSON decoding, which is left alone (see below).
Profile analysis
48.61 s of CPU samples over 120 s (cpu.pprof). Hot spots by cumulative time:
- ~28 %
encoding/json(13.5 s), almost all inside go-ethereum's RPC client:BlockByNumber6.3 s, block receipts(*Receipt).UnmarshalJSON3.2 s. Library-side; not touched. - 9.1 % ECDSA sender recovery (
types.recoverPlain, 4.41 s). By call site (-lines):evm_block_scanner.go:624,receiptToTxInItem: 2.76 s. This is the first recovery for every tx and is needed.evm_block_scanner.go:1109,getTxInFromSmartContract: 1.46 s. Redundant. Production runs the whitelist-disabled branch (EVMDisableContractWhitelist=1): line 624 recovers the sender, then every contract call reachesgetTxInFromSmartContractthroughIsSmartContractCall(L662) and recovers it again.getTxInFromFailedTransaction0.20 s, ETHfromTxToTxIn0.25 s, ETHgetTxInFromSmartContract0.09 s.- Correction to the original hypothesis: the profile does not show 2–3 recoveries for every tx. The duplicate only happens for txs that get dispatched (contract calls on the no-whitelist path, vault transfers). The removable share is ~1.5–1.7 s.
- 6.4 % cosmos
VerifySignatureon attestation gossip (3.13 s):handlePriceFeedAttestation2.49 s,AddAttestation0.64 s. Not changed; see follow-ups. - 3.7 %
FetchActiveNodes→GetNodeAccounts(1.80 s), a full JSON decode on everysendDeck. Not changed. - 3.4 %
PubKeyManager.IsValidPoolAddress(1.67 s):receiptToTxInItemL621/L627 1.28 s,filterObservations0.21 s, ETH 0.20 s. 97 % of it ismatchAddress→NewChainPoolInfo→GetAddress, and 0.91 s ofGetAddressisfmt.Sprintfbuilding the cache key. - 3.4 %
EthRPC.GetBlockHeightSafe(1.65 s), which decodes a full block viaBlockByNumberjust to read.Number(). Not changed; see follow-ups.
Equivalence arguments
etypes.Sender (go-ethereum → op-geth v1.101503.1, checked in the module cache)
types.Sender(signer, tx)returnstx.from's cached address only whensigCache.signer.Equal(signer). Otherwise it callssigner.Sender(tx)and caches the result only on success. On error it returnscommon.Address{}, err.- Every
Senderimplementation incore/types/transaction_signing.go(prague, isthmus, cancun, london incl. the OP deposit-tx branch, eip2930, EIP155, Homestead, Frontier,recoverPlain) returnscommon.Address{}on every error path. So the address and error fromtypes.Senderare identical tosigner.Sender. Errors are never cached, so a failing tx re-derives the same error each time, as before. pragueSigner.Equalcompares type and chain ID. ethclient'ssenderFromServerentry, stored whenBlockByNumberdecodes txs, never equals it, so the server-reported sender is never trusted. Recovery still happens locally once and then overwrites that entry. Nothing in bifrost callsethclient.TransactionSender, the only reader of that entry (client.go:451andethereum.go:391already usedetypes.Sender).tx.fromis anatomic.Pointer, so concurrent receipt goroutines are safe.
GetAddress key
fmt.Sprintf("%s-%s", s1, s2) with two string operands is byte-for-byte s1 + "-" + s2.
IsValidPoolAddress via cache
The old loop returns the first pubkey (in slice order, algo-filtered, inactive keys included, NewChainPoolInfo errors skipped) whose pool address satisfies strings.EqualFold(poolAddr, addr). buildPoolAddressCacheNoLock(chain, includeInactive=true) walks the same slice with the same algo filter and error skip, and keeps the first entry per strings.ToLower(poolAddr).
- For two ASCII strings,
EqualFoldis exactly ASCII-lowercase equality. The cache is used only whenaddris non-empty ASCII and every pool address in the set is ASCII. That second condition is a newallASCIIflag computed at build time. EqualFold also folds non-ASCII runes onto ASCII ones (Kelvin signK→k, long sſ→s), so any other input takes the original loop unchanged. - Empty
addralways takes the loop:GetAddressreturnsNoAddress, nilfor unsupported chains, so an empty addr matches there. The cache would agree too (it stores the""key), so this guard is conservative rather than load-bearing. - Every mutation of
pubkeysorInactive(add, add-node, remove, inactive toggle) already callsinvalidatePoolAddressCacheNoLock. A built set is never mutated, so reading it after releasing the lock is safe.IsActivePoolAddress(isPoolAddress) behavior is unchanged; it only moved onto the sharedpoolAddresseshelper. - New guard tests (
pubkey_manager_equiv_test.go):- A differential test against a verbatim copy of the old loop, over secp256k1 and ed25519 keys, inactive keys, and a key registered under the wrong algo. It covers 11 chains, including an empty chain and an unsupported chain. Inputs are lower/upper/alternating case, trailing space, truncated,
"", and Kelvin/ſ substitutions. It runs on cold and warm cache, and after remove (swap-delete reorders), inactive toggles and re-adds. - A fallback test for a non-ASCII set, and a
-racetest of reads during concurrent mutation. - Mutation check: removing the ASCII guard (or the whole guard), or dropping cache invalidation, makes the differential test fail.
- A differential test against a verbatim copy of the old loop, over secp256k1 and ed25519 keys, inactive keys, and a key registered under the wrong algo. It covers 11 chains, including an empty chain and an unsupported chain. Inputs are lower/upper/alternating case, trailing space, truncated,
FetchActiveNodes memo
sendDeck calls FetchActiveNodes every second (deckRefreshTime). The bridge's HTTP cache (thorchain.go get) returns the same body slice for one THORChain block (6 s), so about 5 of every 6 calls re-decoded identical bytes, including bech32-parsing every node's pubkeys.
- The memo stores the derived
[]common.PubKeytogether with the body slice it came from, and matches on slice identity (same first-element pointer and length, non-empty). Nothing writes to a cached body, so the same slice means the same bytes and the same result. Holding the slice keeps its array from being reused for a different response. A new or refreshed body, even one with identical bytes, decodes again. - Only successful decodes are stored. The error paths and their wrapped messages are unchanged.
- Callers receive a fresh copy, as before (still non-nil when empty).
GetNodeAccountsitself is untouched and still returns freshly decoded objects. The memo never outlives the HTTP cache entry, so freshness is unchanged. It is deliberately not keyed by THORChain height, which would change freshness. - Guard tests (
fetch_active_nodes_memo_test.go):- A differential test against the original implementation, for valid, 120-node, none-active,
[],null, empty, invalid-JSON and bad-pubkey bodies. - Cache refreshes with new and with identical bytes, mutation of the returned slice, errors not memoized, and 8 concurrent callers under
-race. - Mutation check: dropping the identity check or the defensive copy fails the tests.
- A differential test against the original implementation, for valid, 120-node, none-active,
Lowercase-hex contract comparisons (folded in from !5230 (closed))
- The lowercase hex and EIP-55 forms differ only in the ASCII case of
a–f.strings.EqualFoldcompares rune by rune under case folding, soEqualFold(x, lower) == EqualFold(x, checksum)for anyx, including non-ASCII strings. LowerHexAddress(a)is exactlystrings.ToLower(a.Hex()). That is fuzzed, and checked on 10k random addresses.- The router and whitelist lists are now looped in turn instead of being
appended into a new slice. The result is the same any-match. - ETH: the string is still derived only once there is something to compare. A nil
addrtherefore panics in exactly the same cases (tested), although production callers never pass nil. - Differential tests: both functions are compared against verbatim copies of the originals over 20k random cases each:
- list entries in checksum, lower and upper case, with the
0xprefix missing, padded, truncated, and with non-ASCII look-alikes; - whitelist on and off;
- nil
addr.
- list entries in checksum, lower and upper case, with the
- Mutation check: dropping the whitelist loop, or computing the ETH string eagerly, fails these tests.
closeStream timer (folded in from !5230 (closed))
time.AfterFunc(10s, f) runs the same Reset and the same error log on its own goroutine, no sooner than 10 s after the call. That is the same guarantee as the old goroutine's time.Sleep(10s), and nothing waited on that goroutine.
Benchmarks
AMD Ryzen Threadripper 3960X, -count 10, -tags mocknet.
BenchmarkReceiptToTxInItembuilds the scanner likeTestDirectERC20TransferFeatureFlag(testMimirBridge,evm.NewTokenManageron an httptest ethclient), with a realPubKeyManagerholding 50 vaults and the productionNewPragueSigner. Every iterationUnmarshalBinarys a fresh*Transaction, so the sender cache can't carry across iterations, just as each scanned block decodes new tx objects.DecodeOnlyshows that fixed decode cost.NativeToVault/whitelistis the requested target.ContractCall/nowhitelistmirrors the production branch seen in the profile.
1. etypes.Sender (receiptToTxInItem)
│ base │ sender │
│ sec/op │ sec/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 183.8µ ± 1% 126.1µ ± 3% -31.37% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 98.24µ ± 1% 99.11µ ± 2% ~ (p=0.089 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 170.6µ ± 2% 103.7µ ± 4% -39.19% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 1.941µ ± 1% 1.948µ ± 2% ~ (p=0.955 n=10)
geomean 49.44µ 39.87µ -19.37%
│ base │ sender │
│ B/op │ B/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 23.34Ki ± 0% 22.66Ki ± 0% -2.90% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 14.26Ki ± 0% 14.30Ki ± 0% +0.33% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 16.89Ki ± 0% 16.22Ki ± 0% -3.99% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 760.0 ± 0% 760.0 ± 0% ~ (p=1.000 n=10) ¹
geomean 8.037Ki 7.904Ki -1.66%
¹ all samples are equal
│ base │ sender │
│ allocs/op │ allocs/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 577.0 ± 0% 557.0 ± 0% -3.47% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 349.0 ± 0% 350.0 ± 0% +0.29% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 408.0 ± 0% 389.0 ± 0% -4.66% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 19.00 ± 0% 19.00 ± 0% ~ (p=1.000 n=10) ¹
geomean 198.8 194.8 -1.98%
¹ all samples are equal2. GetAddress concat
│ base │ concat │
│ sec/op │ sec/op vs base │
PubKeyGetAddress/ETH-48 392.2n ± 1% 169.0n ± 1% -56.92% (p=0.000 n=10)
PubKeyGetAddress/BTC-48 386.7n ± 5% 170.4n ± 3% -55.93% (p=0.000 n=10)
geomean 389.4n 169.7n -56.42%
│ base │ concat │
│ B/op │ B/op vs base │
PubKeyGetAddress/ETH-48 128.00 ± 0% 96.00 ± 0% -25.00% (p=0.000 n=10)
PubKeyGetAddress/BTC-48 128.00 ± 0% 96.00 ± 0% -25.00% (p=0.000 n=10)
geomean 128.0 96.00 -25.00%
│ base │ concat │
│ allocs/op │ allocs/op vs base │
PubKeyGetAddress/ETH-48 3.000 ± 0% 1.000 ± 0% -66.67% (p=0.000 n=10)
PubKeyGetAddress/BTC-48 3.000 ± 0% 1.000 ± 0% -66.67% (p=0.000 n=10)
geomean 3.000 1.000 -66.67%
│ base │ concat │
│ sec/op │ sec/op vs base │
IsValidPoolAddress/miss-48 18.56µ ± 3% 10.53µ ± 2% -43.28% (p=0.000 n=10)
IsValidPoolAddress/hit-lower-48 18.85µ ± 3% 10.85µ ± 3% -42.46% (p=0.000 n=10)
IsValidPoolAddress/hit-mixedcase-48 18.49µ ± 5% 10.84µ ± 2% -41.36% (p=0.000 n=10)
geomean 18.63µ 10.74µ -42.37%
│ sender │ concat │
│ sec/op │ sec/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 126.1µ ± 3% 102.4µ ± 3% -18.81% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 99.11µ ± 2% 82.99µ ± 2% -16.27% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 103.73µ ± 4% 90.48µ ± 3% -12.78% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 1.948µ ± 2% 1.918µ ± 4% ~ (p=0.617 n=10)
geomean 39.87µ 34.85µ -12.59%3. IsValidPoolAddress cache
│ concat │ cache │
│ sec/op │ sec/op vs base │
IsValidPoolAddress/miss-48 10526.5n ± 2% 264.0n ± 3% -97.49% (p=0.000 n=10)
IsValidPoolAddress/hit-lower-48 10847.5n ± 3% 105.2n ± 1% -99.03% (p=0.000 n=10)
IsValidPoolAddress/hit-mixedcase-48 10842.0n ± 2% 288.5n ± 3% -97.34% (p=0.000 n=10)
geomean 10.74µ 200.1n -98.14%
│ concat │ cache │
│ B/op │ B/op vs base │
IsValidPoolAddress/miss-48 4800.00 ± 0% 48.00 ± 0% -99.00% (p=0.000 n=10)
IsValidPoolAddress/hit-lower-48 4.688Ki ± 0% 0.000Ki ± 0% -100.00% (p=0.000 n=10)
IsValidPoolAddress/hit-mixedcase-48 4800.00 ± 0% 48.00 ± 0% -99.00% (p=0.000 n=10)
geomean 4.688Ki ? ¹ ²
│ concat │ cache │
│ allocs/op │ allocs/op vs base │
IsValidPoolAddress/miss-48 50.000 ± 0% 1.000 ± 0% -98.00% (p=0.000 n=10)
IsValidPoolAddress/hit-lower-48 50.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10)
IsValidPoolAddress/hit-mixedcase-48 50.000 ± 0% 1.000 ± 0% -98.00% (p=0.000 n=10)
geomean 50.00 ? ¹ ²
│ concat │ cache │
│ sec/op │ sec/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 102.40µ ± 3% 75.38µ ± 2% -26.39% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 82.99µ ± 2% 67.11µ ± 1% -19.13% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 90.48µ ± 3% 73.75µ ± 2% -18.48% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 1.918µ ± 4% 1.926µ ± 3% ~ (p=0.812 n=10)
geomean 34.85µ 29.11µ -16.46%4. FetchActiveNodes memo (cached-response case, 120 nodes)
│ base │ memo │
│ sec/op │ sec/op vs base │
FetchActiveNodes-48 1071898.5n ± 3% 626.6n ± 1% -99.94% (p=0.000 n=10)
│ base │ memo │
│ B/op │ B/op vs base │
FetchActiveNodes-48 140.539Ki ± 0% 1.062Ki ± 0% -99.24% (p=0.000 n=10)
│ base │ memo │
│ allocs/op │ allocs/op vs base │
FetchActiveNodes-48 1704.000 ± 0% 2.000 ± 0% -99.88% (p=0.000 n=10)5. Lowercase-hex contract comparisons
│ base │ new │
│ sec/op │ sec/op vs base │
IsToValidContractAddress/log/miss-48 688.5n ± 3% 148.9n ± 6% -78.37% (p=0.000 n=10)
IsToValidContractAddress/log/hit-router-48 723.7n ± 2% 187.7n ± 4% -74.07% (p=0.000 n=10)
IsToValidContractAddress/tx/miss-48 1013.9n ± 8% 225.3n ± 2% -77.78% (p=0.000 n=10)
IsToValidContractAddress/tx/hit-last-aggregator-48 1297.5n ± 4% 462.9n ± 4% -64.33% (p=0.000 n=10)
geomean 5.139µ 2.608µ -49.25%
│ base │ new │
│ B/op │ B/op vs base │
IsToValidContractAddress/log/miss-48 160.00 ± 0% 80.00 ± 0% -50.00% (p=0.000 n=10)
IsToValidContractAddress/log/hit-router-48 160.00 ± 0% 80.00 ± 0% -50.00% (p=0.000 n=10)
IsToValidContractAddress/tx/miss-48 480.00 ± 0% 80.00 ± 0% -83.33% (p=0.000 n=10)
IsToValidContractAddress/tx/hit-last-aggregator-48 480.00 ± 0% 80.00 ± 0% -83.33% (p=0.000 n=10)
geomean 779.7 413.5 -46.97%
│ base │ new │
│ allocs/op │ allocs/op vs base │
IsToValidContractAddress/log/miss-48 4.000 ± 0% 2.000 ± 0% -50.00% (p=0.000 n=10)
IsToValidContractAddress/log/hit-router-48 4.000 ± 0% 2.000 ± 0% -50.00% (p=0.000 n=10)
IsToValidContractAddress/tx/miss-48 5.000 ± 0% 2.000 ± 0% -60.00% (p=0.000 n=10)
IsToValidContractAddress/tx/hit-last-aggregator-48 5.000 ± 0% 2.000 ± 0% -60.00% (p=0.000 n=10)
geomean 15.80 10.43 -33.98%
│ base │ new │
│ sec/op │ sec/op vs base │
ETHIsToValidContractAddress/log/miss-48 1282.5n ± 4% 124.4n ± 7% -90.30% (p=0.000 n=10)
ETHIsToValidContractAddress/log/hit-router-48 1343.0n ± 6% 162.2n ± 4% -87.92% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/miss-48 15185.0n ± 2% 237.5n ± 2% -98.44% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/hit-last-whitelisted-48 15343.0n ± 3% 282.1n ± 3% -98.16% (p=0.000 n=10)
geomean 4.476µ 191.8n -95.72%
│ base │ new │
│ B/op │ B/op vs base │
ETHIsToValidContractAddress/log/miss-48 288.00 ± 0% 80.00 ± 0% -72.22% (p=0.000 n=10)
ETHIsToValidContractAddress/log/hit-router-48 288.00 ± 0% 80.00 ± 0% -72.22% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/miss-48 3488.00 ± 0% 80.00 ± 0% -97.71% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/hit-last-whitelisted-48 3488.00 ± 0% 80.00 ± 0% -97.71% (p=0.000 n=10)
geomean 1002.3 80.00 -92.02%
│ base │ new │
│ allocs/op │ allocs/op vs base │
ETHIsToValidContractAddress/log/miss-48 7.000 ± 0% 2.000 ± 0% -71.43% (p=0.000 n=10)
ETHIsToValidContractAddress/log/hit-router-48 7.000 ± 0% 2.000 ± 0% -71.43% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/miss-48 74.000 ± 0% 2.000 ± 0% -97.30% (p=0.000 n=10)
ETHIsToValidContractAddress/tx/hit-last-whitelisted-48 74.000 ± 0% 2.000 ± 0% -97.30% (p=0.000 n=10)
geomean 22.76 2.000 -91.21%6. closeStream timer (2,321 pending resets, the production count)
│ base │ new │
│ sec/op │ sec/op vs base │
GCWithPendingStreamResets-48 7.826m ± 1% 7.873m ± 2% ~ (p=0.481 n=10)
│ base │ new │
│ pending-B/stream │ pending-B/stream vs base │ReceiptToTxInItem's fixture registers no routers, so it doesn't exercise the contract comparisons. In the closeStream benchmark, GC time doesn't move measurably, because the test binary's own heap dominates it; the win is the memory held by the pending resets.
Overall: develop → this MR (receiptToTxInItem)
│ develop │ mr │
│ sec/op │ sec/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 183.76µ ± 1% 75.38µ ± 2% -58.98% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 98.24µ ± 1% 67.11µ ± 1% -31.69% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 170.59µ ± 2% 73.75µ ± 2% -56.76% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 1.941µ ± 1% 1.926µ ± 3% ~ (p=0.247 n=10)
geomean 49.44µ 29.11µ -41.12%
│ develop │ mr │
│ B/op │ B/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 23.339Ki ± 0% 4.041Ki ± 0% -82.69% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 14.258Ki ± 0% 1.845Ki ± 0% -87.06% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 16.893Ki ± 0% 3.807Ki ± 0% -77.47% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 760.0 ± 0% 760.0 ± 0% ~ (p=1.000 n=10) ¹
geomean 8.037Ki 2.142Ki -73.34%
¹ all samples are equal
│ develop │ mr │
│ allocs/op │ allocs/op vs base │
ReceiptToTxInItem/NativeToVault/whitelist-48 577.0 ± 0% 110.0 ± 0% -80.94% (p=0.000 n=10)
ReceiptToTxInItem/NativeNonVault/whitelist-48 349.00 ± 0% 51.00 ± 0% -85.39% (p=0.000 n=10)
ReceiptToTxInItem/ContractCall/nowhitelist-48 408.00 ± 0% 91.00 ± 0% -77.70% (p=0.000 n=10)
ReceiptToTxInItem/DecodeOnly-48 19.00 ± 0% 19.00 ± 0% ~ (p=1.000 n=10) ¹
geomean 198.8 55.81 -71.92%
¹ all samples are equalTesting
go test -tags mocknet(and without the tag forcommon,pubkeymanager,thorclient):common,bifrost/pubkeymanager(also-race),bifrost/thorclient(also-race),bifrost/observer,bifrost/p2p,bifrost/pkg/chainclients/{evm,ethereum,shared/...}. All pass, same as on clean develop.golangci-lint v1.63.4with the repo config on the touched packages: clean.gofumpt: clean.- The ethereum scanner's call sites got the same mechanical swap and are covered by its existing tests. There is no separate benchmark for them.
Follow-ups (not done: equivalence not provable, or out of scope)
EthRPC.GetBlockHeightSafe→HeaderByNumber(~3.4 % CPU): now !5225 (merged), separate because it is a deliberate behavior change. It would return the same number without decoding txs, but error behavior differs:BlockByNumberfails on undecodable txs or inconsistent bodies, andHeaderByNumberwouldn't. Needs a decision on whether the stricter check is wanted.- Price feed verify-before-staleness (
attestation_handlers_impl.gohandlePriceFeedAttestation). Read-only check result: no path verifies the same signature twice.AddAttestationdedups by exact signature before verifying, and the batcher only gossips the node's own attestations. But price feeds are verified before the cheapstate.Item.Time < apf.PriceFeed.Timecheck, so out-of-order or duplicate feeds pay a secp256k1 verify and are then dropped. Checking staleness first would only change the error log for stale-and-invalid feeds, but it reorders a signature check, so it is not done here. All verifies are kept. Done in this MR with an exactly equivalent memo (see above). Still open:FetchActiveNodes→GetNodeAccountssetActiveValidatorsre-derives peer IDs from every pubkey each second. That is not in the profile's 1.80 s, but it is the same kind of repeated work.- go-ethereum RPC JSON (~28 %): library-side. Options would be a faster decoder or fewer round-trips (e.g. reusing the block fetched for the height check), each with its own equivalence questions.
- Pre-existing data race, fixed separately in !5224 (merged): in
getTxInOptimizedthe per-receipt goroutines assigned the outererr. This is not just a-racereport: withconcurrency: 4(BASE, BSC) one goroutine can read another goroutine's error and drop its own valid inbound.