From 4bc5c9bab54f2c0332cf9a428d7cbb42393d5b2f Mon Sep 17 00:00:00 2001 From: 0xMegie Date: Sun, 18 Oct 2026 13:54:55 +0100 Subject: [PATCH] Add realtime burst simulation and related functionality - Implemented a burst simulator for realtime feeds in `scripts/realtime-burst.mjs`. - Created batching functionality in `lib/realtime/batch.ts` to handle event coalescing. - Added burst detection and handling in `lib/realtime/burst.ts` and `lib/realtime/useBurst.ts`. - Developed a ring buffer implementation in `lib/realtime/ring.ts` for managing event history. - Introduced tests for batching, burst detection, and ring buffer in `lib/realtime/__tests__/`. - Enhanced event handling in `lib/stellar/events.ts` for trade events and added decoding logic. - Updated optimistic transaction handling in `lib/stellar/optimistic.ts` to manage provisional updates. - Modified transaction lifecycle management in `lib/stellar/tx-lifecycle.ts` to include ledger information. - Added utility functions for simulated transactions in `lib/stellar/typed-call.ts`. --- CONTRIBUTING.md | 14 + app/layout.tsx | 12 +- app/markets/page.tsx | 84 ++-- app/markets/quick-view/page.tsx | 40 +- app/notifications/page.tsx | 388 +++++++++++-------- app/page.tsx | 112 ++++-- components/layout/Navbar.tsx | 18 +- components/layout/WalletDropdown.tsx | 11 +- components/market/trade-tape.tsx | 159 ++++++++ docs/STATUS.md | 12 + docs/architecture.md | 20 + docs/manual-test.md | 15 + lib/hooks/__tests__/marketTrades.test.ts | 45 +++ lib/hooks/marketTrades.ts | 50 +++ lib/hooks/useMarketTrades.ts | 57 +++ lib/hooks/useStellar.ts | 295 +++++++++++++- lib/notifications/InboxProvider.tsx | 276 +++++++++++++ lib/notifications/__tests__/classify.test.ts | 65 ++++ lib/notifications/__tests__/store.test.ts | 62 +++ lib/notifications/classify.ts | 122 ++++++ lib/notifications/store.ts | 227 +++++++++++ lib/realtime/FeedProfiler.tsx | 45 +++ lib/realtime/RealtimeProvider.tsx | 104 +++++ lib/realtime/__tests__/batch.test.ts | 65 ++++ lib/realtime/__tests__/burst.test.ts | 27 ++ lib/realtime/__tests__/ring.test.ts | 22 ++ lib/realtime/batch.ts | 103 +++++ lib/realtime/burst.ts | 33 ++ lib/realtime/ring.ts | 47 +++ lib/realtime/useBurst.ts | 45 +++ lib/stellar/__tests__/events.test.ts | 90 +++++ lib/stellar/__tests__/optimistic.test.ts | 73 ++++ lib/stellar/events.ts | 286 ++++++++++++++ lib/stellar/optimistic.ts | 100 +++++ lib/stellar/tx-lifecycle.ts | 8 +- lib/stellar/typed-call.ts | 13 + scripts/realtime-burst.mjs | 71 ++++ 37 files changed, 2940 insertions(+), 276 deletions(-) create mode 100644 components/market/trade-tape.tsx create mode 100644 lib/hooks/__tests__/marketTrades.test.ts create mode 100644 lib/hooks/marketTrades.ts create mode 100644 lib/hooks/useMarketTrades.ts create mode 100644 lib/notifications/InboxProvider.tsx create mode 100644 lib/notifications/__tests__/classify.test.ts create mode 100644 lib/notifications/__tests__/store.test.ts create mode 100644 lib/notifications/classify.ts create mode 100644 lib/notifications/store.ts create mode 100644 lib/realtime/FeedProfiler.tsx create mode 100644 lib/realtime/RealtimeProvider.tsx create mode 100644 lib/realtime/__tests__/batch.test.ts create mode 100644 lib/realtime/__tests__/burst.test.ts create mode 100644 lib/realtime/__tests__/ring.test.ts create mode 100644 lib/realtime/batch.ts create mode 100644 lib/realtime/burst.ts create mode 100644 lib/realtime/ring.ts create mode 100644 lib/realtime/useBurst.ts create mode 100644 lib/stellar/__tests__/events.test.ts create mode 100644 lib/stellar/__tests__/optimistic.test.ts create mode 100644 lib/stellar/events.ts create mode 100644 lib/stellar/optimistic.ts create mode 100644 scripts/realtime-burst.mjs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9adb7df..630269c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,20 @@ npm run build `npm run e2e:testnet` is an optional, read-only check against a running backend and live testnet; see the header of `e2e/testnet.e2e.test.ts`. +## Realtime burst testing + +`scripts/realtime-burst.mjs` emits synthetic `TRADE_EXECUTED` events so you can +check that realtime feeds stay smooth under bursts (issue #41): + +```bash +npm i --no-save socket.io@4.8.1 # server package, not a project dependency +node scripts/realtime-burst.mjs --count 500 --rate 500 --port 4100 +NEXT_PUBLIC_API_URL=http://localhost:4100/api/v1 npm run dev +``` + +Open `/markets?profile=1` or `/?profile=1`: in development the feeds log commit +counts and render time per second to the console (`[profile] …`). + ## When the contracts change The contracts live in diff --git a/app/layout.tsx b/app/layout.tsx index 3204a21..533a546 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,6 +3,8 @@ import type { Metadata } from "next"; import Navbar from "@/components/layout/Navbar"; import { Footer } from "@/components/layout/Footer"; import { WalletProvider } from "@/lib/contexts/WalletContext"; +import { RealtimeProvider } from "@/lib/realtime/RealtimeProvider"; +import { InboxProvider } from "@/lib/notifications/InboxProvider"; import "./globals.css"; const geistSans = { @@ -40,9 +42,13 @@ export default function RootLayout({ - - {children} -