chore: merge main into release/rc.12 (RPC perf optimizations from #732)#759
Merged
Merged
Conversation
Three targeted optimizations that cut unnecessary JSON-RPC round-trips without changing any observable behavior: 1. Cache IdentityStorage, ConvictionStakingStorage, StakingStorage in init() alongside the other Hub-resolved contracts. Previously these were re-resolved from the Hub on every call to getIdentityId(), verifyACKIdentity(), verifySyncIdentity(), createChallenge(), and ensureOperationalWalletsRegistered() — each resolution is an extra eth_call to Hub.getContractAddress(). On relay nodes handling frequent peer ACKs, this alone eliminates dozens of redundant Hub reads per minute. A private getIdentityStorage() helper falls back to per-call resolution if the contract was not available at init. 2. Parallelize wallet balance reads in /api/wallets/balances: the sequential for-loop issued 2×N serial RPC calls (getBalance + balanceOf per wallet). Now fires all reads concurrently via Promise.all, reducing wall-clock latency from O(N) to O(1) round-trips. 3. Parallelize identity lookups in ensureOperationalWalletsRegistered: the sequential getIdentityId() loop is replaced with a single Promise.all batch, cutting startup identity-check time from O(keys) to O(1) round-trips. Co-authored-by: Cursor <cursoragent@cursor.com>
Address review feedback: init-time caching of IdentityStorage, ConvictionStakingStorage, StakingStorage had no invalidation path — a transient RPC failure at boot or a Hub rotation would leave stale or undefined handles for the lifetime of the process. Switch to lazy-cache-on-first-use: private getIdentityStorage(), getConvictionStakingStorage(), getStakingStorage() helpers resolve from Hub on the first call and cache the result. Removes init() pre-resolution entirely so boot-time RPC failures self-heal on next actual use. verifyACKIdentity() now uses the lazy helpers instead of reading this.contracts directly. Note: once rc.12 PR #689 (Hub rotation auto-recovery for all boot-bound contracts) lands, these cached references will be automatically invalidated on Hub.ContractChanged events via the BOUND_CONTRACT_INVALIDATORS map — the lazy-cache pattern is complementary to that approach. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
getIdentityStorage, getConvictionStakingStorage, getStakingStorage are TS-private helpers that survive into the prototype at runtime. They are not part of the ChainAdapter interface and don't need mirroring on MockChainAdapter — same treatment as nextSigner, walletKeyHash, resolveContract, etc. Co-authored-by: Cursor <cursoragent@cursor.com>
perf: reduce redundant RPC calls across hot paths
Brings in PR #732 — perf: reduce redundant RPC calls across hot paths, plus its 3 follow-up commits (lazy-cache refactor, CI retrigger, parity test exemption). Conflict resolution ------------------- `packages/chain/src/evm-adapter.ts` :: `verifyACKIdentity` — kept rc.12's delegation `(await this.verifyACKIdentityDetailed(...)).valid` because the structured variant added in PR #711 is the canonical ACK-signer gate now (operational-key purpose AND sharding-table membership, matching the on-chain `KnowledgeAssetsV10._verifyACKSignature` check). The legacy inline V10/V8 stake-fallback that lived here is superseded by the ST-membership check inside `verifyACKIdentityDetailed`, which StakingV10 updates atomically whenever a node crosses `minimumStake`. #732's lazy-cache perf optimization (`getIdentityStorage()` etc.) is unaffected — it's already applied to every other call site in the file via the auto-merge. `verifyACKIdentityDetailed` continues to use `resolveContract` directly; extending it to the lazy-cache helpers is a follow-up nicety, not a correctness requirement. Validation: `pnpm --filter @origintrail-official/dkg-chain test` → 449 tests pass. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings PR #732 (perf: reduce redundant RPC calls across hot paths) and its 3 follow-ups onto
release/rc.12:0dfe52f9perf: reduce redundant RPC calls across hot paths77289d02fix: use lazy-cache pattern instead of init-time cachingb1ae3da8chore: retrigger CIaaad35d7fix(test): exempt private lazy-cache helpers from parity check3f30100dMerge pull request perf: reduce redundant RPC calls across hot paths #732 from OriginTrail/fix/rpc-usage-optimizationsConflict resolution
packages/chain/src/evm-adapter.ts::verifyACKIdentity— kept rc.12's delegation(await this.verifyACKIdentityDetailed(...)).valid(PR #711). The legacy inline V10/V8 stake-fallback that lived here is superseded by the ST-membership check insideverifyACKIdentityDetailed, which matches the on-chainKnowledgeAssetsV10._verifyACKSignaturegate.#732's lazy-cache perf optimization (
getIdentityStorage(),getConvictionStakingStorage(),getStakingStorage()) is preserved everywhere via the auto-merge; the only spot it doesn't extend to is the newverifyACKIdentityDetailed(which still usesresolveContractdirectly). That's a follow-up nicety, not a correctness regression.Test plan
pnpm --filter @origintrail-official/dkg-chain test→ 449 passMade with Cursor