Skip to content

chore: merge main into release/rc.12 (RPC perf optimizations from #732)#759

Merged
branarakic merged 6 commits into
release/rc.12from
chore/merge-main-pr732-rpc-perf
May 27, 2026
Merged

chore: merge main into release/rc.12 (RPC perf optimizations from #732)#759
branarakic merged 6 commits into
release/rc.12from
chore/merge-main-pr732-rpc-perf

Conversation

@branarakic
Copy link
Copy Markdown
Contributor

Summary

Brings PR #732 (perf: reduce redundant RPC calls across hot paths) and its 3 follow-ups onto release/rc.12:

  • 0dfe52f9 perf: reduce redundant RPC calls across hot paths
  • 77289d02 fix: use lazy-cache pattern instead of init-time caching
  • b1ae3da8 chore: retrigger CI
  • aaad35d7 fix(test): exempt private lazy-cache helpers from parity check
  • 3f30100d Merge pull request perf: reduce redundant RPC calls across hot paths #732 from OriginTrail/fix/rpc-usage-optimizations

Conflict 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 inside verifyACKIdentityDetailed, which matches the on-chain KnowledgeAssetsV10._verifyACKSignature gate.

#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 new verifyACKIdentityDetailed (which still uses resolveContract directly). That's a follow-up nicety, not a correctness regression.

Test plan

  • pnpm --filter @origintrail-official/dkg-chain test449 pass
  • The chain package contains all the auto-merged surfaces (mock-adapter-parity, evm-adapter, status route)

Made with Cursor

Niks988 and others added 6 commits May 27, 2026 12:00
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>
@branarakic branarakic merged commit 4a77bb8 into release/rc.12 May 27, 2026
2 of 3 checks passed
@branarakic branarakic deleted the chore/merge-main-pr732-rpc-perf branch May 27, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants