perf(voting): bound reads and intent batches and remove measured query multiplication #47
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Scope and source
Priority: P2. Gap coverage: GAP-046. Derived from GAP_1791945837.md, reviewed code commit
f8dbe93df953a78b17cb3304b717dcf84c4cd517. Currente476a68da09645c2308cbf47b90211fcaffcb7afadds only the report, so implementation findings remain applicable. Report evidence is local reproduction/source inspection unless explicitly proposed; no production exploit or current live-readiness claim.Coverage and sequencing: gap backlog tracker. Workstream 15. Dependencies: 02, 04, 05, 08.
Current codebase
Lists fetch all proposals with bodies then tally per proposal; detail embeds all comments/analysis plus separate endpoints. Intents use fetch_all. Freeze calls balance functions for every active registration synchronously. Transfer legs repeat registration/balance/checkpoint queries; membership checks are linear and BSC repeatedly normalizes the registered set. No capacity baseline exists.
Why this implementation is needed
Large electorates/threads can exhaust memory or request latency, while query multiplication increases RPC/DB cost. Optimizations must preserve fixed accounting and atomic freeze visibility.
Relevant files
operator-voting/src/api.rsoperator-voting/src/db.rsoperator-voting/src/balance_query.rsledger/src/db.rsledger/src/register.rsledger/src/parser/cw20.rsledger/src/parser/bep20.rsfrontend/src/services/operatorVoting.tsfrontend/src/pages/VoteListPage.tsxdocs/OPERATOR_VOTING.mdRecommended solution
Add stable cursor pagination/maximum limits and lean list projections with grouped tallies. Separate bounded comments/analysis reads and fair indexed intent selection. Normalize membership into a HashSet once per batch, batch checkpoint persistence only after 02 correctness, and use EXPLAIN/benchmarks for indexes. Measure real-data-shaped freeze duration; if needed use a durable bounded freeze job with no partially visible open snapshot and explicit retry states. Keep integer arithmetic, revision approval and dual-chain state checks intact.
Constraints and guardrails
Preserve standalone offchain advisory voting, no new smart contracts or archive-node dependency, BSC as a core electorate, raw 18-decimal integer balances and separate Terra/BSC address identities. Keep Legal fail-closed transactional UI and the proven DEX Terra/Bridge EVM connectors; no browser BSC balance RPC, seed/key prompt or embedded admin/model credential. API must retain a restricted role separate from the ledger writer. Freeze at actual opening, never at draft creation or a client-supplied height. Agents own design, implementation, review and evidence under repository guidance; do not shift approvals/tests to the human or invent PASS evidence.
Acceptance criteria
Every public list/thread query has documented bounded size/order; pagination neither loses nor duplicates rows with concurrent inserts. Query counts stop scaling per proposal for tallies. Intent processing is fair and parser membership is reused. Agreed measured p95/soak budgets are met; opening remains all-or-nothing and immutable across optimized paths.
Test plan: supported paths, failure paths and concurrency
Empty/small/large datasets, max/default/invalid limits, equal timestamps and cursor boundary inserts/deletes, both-chain tallies and large threads. Fair queue under failures, normalization variants and repeated same-block events. Before/after EXPLAIN/query counts, concurrency load/soak and freeze at increasing electorate sizes; job crash/retry/cancel if introduced. Compare optimized balances/tallies to reference implementation.
Test plan: attack, hack and abuse vectors
Unbounded limit/cursor injection, expensive-search/large-thread floods, huge electorate freeze contention, skewed address normalization and batch replays. Verify SQL binding, bounded memory/DB occupancy, no starvation and no partial freeze or changed power under load.
Verification and completion criteria
Attach reproducible datasets, SQL/query plans and before/after latency/query-count/memory evidence with chosen budgets. Run accounting and approval regressions; no speculative index or throughput claim without measurements.
Record commit and pinned toolchain, commands/results and sanitized artifacts. Relevant Rust changes require
cargo test --workspace --libplus isolated Postgres integration (explicit guarded LEDGER_TEST_DATABASE_URL); frontend changes requirenpm testand production build plus relevant browser cases. Run secret scanning for new fixtures/config. Exercise fresh/upgrade migrations when schema/grants change; report skipped/live-only checks explicitly.