M4 physical stock authority: exact tick overlay, owner-bucket mapping and migration performance

Open
#800 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start by locating WorldState, its stock and wallet fields, and the existing native tests and save/restore paths; the issue does not name specific files. Map allowed actor and bucket pairs from current state fields, then review the exact posting bridge and numeric authority decision before proposing changes. Done means the listed round-trip, rollback, determinism, corruption, stress, replay, and browser performance checks pass; implementation is explicitly blocked on those decisions.

Written by the indexing model from the issue text.

Description

area:simulation-core priority:normal status:blocked type:feature

Goal

If the exact-accounting representation is approved, implement an efficient, actor-owned stock storage adapter that does not copy every wallet and inventory on every trade and never conflates separate physical warehouses.

Evidence

  • Local unpublished R11 naive BigInt exact stock prototype cloned the entire book per transfer (~2000 transactions/s with ~5000 entries).
  • Local R12 switched to a per-tick touched-endpoint overlay and measured about 37x speedup (1200 transactions / 5002 entries, isolated Node benchmark, not real browser engine).
  • Local R13 uncovered unsafe restore of oversized BigInt values. R14/R15 exposed owner/bucket identity mistakes: HOUSEHOLD, PUBLIC, and ProductionUnit INPUT/OUTPUT/INVESTMENT are different real stocks, and not every actor may own every bucket.
  • Existing future #724 and #725 cover broad M10 performance/retention; this is a narrow prerequisite of an approved M4 precision change.

Scope

Stage only changed physical endpoints within a tick; commit atomically in canonical deterministic order, with snapshot/replay/historical saves explicit. Resolve each owner/bucket strictly against current WorldState fields and one owner per stock. Audit missing/extra inventory and wallet slots without expensive JSON serialization in hot path. Define appropriate benchmark budgets from empirical browser and Node runs.

Non-goals

No second mutable canonical stock source, no unauthorized new warehouse types, no silent migration of legacy saves or bypass of exact receipt contract, no broad M10 performance rewrite.

Acceptance criteria

  1. All allowed actor/bucket pairs round-trip with independent stock identity; unknown pairs rejected before any write.
  2. Rollback and readback of failed tick leave underlying world, ledger, staged overlay and IDs unchanged.
  3. Repeated same-asset transfers remain correct and deterministic across 240+ ticks.
  4. Measured performance remains useful for Pages runtime without O(total stock count) cloning per trade; browser gate recorded.

Verification

Targeted native WorldState tests + fixtures for each bucket and 5k-stock stress, save/restore corruption/overflow negative controls, deterministic replay, CI TypeScript/.NET/Pages and independent QA.

Depends on: numeric authority decision and exact posting bridge; no code promotion until these are approved.

Dominant language
TypeScript
Stars
4
Forks
0
Avg merge
7h 21m
Merged PRs (30d)
144

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from drevendev/trade_simulation

All issues in drevendev/trade_simulation

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.