@bsv/overlay 2.2.0 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE.txt +57 -27
  2. package/README.md +102 -266
  3. package/dist/cjs/mod.d.ts +15 -0
  4. package/dist/cjs/mod.d.ts.map +1 -0
  5. package/dist/cjs/mod.js +4 -1
  6. package/dist/cjs/mod.js.map +1 -1
  7. package/dist/cjs/package.json +46 -18
  8. package/dist/cjs/src/Advertisement.d.ts +9 -0
  9. package/dist/cjs/src/Advertisement.d.ts.map +1 -0
  10. package/dist/cjs/src/Advertiser.d.ts +36 -0
  11. package/dist/cjs/src/Advertiser.d.ts.map +1 -0
  12. package/dist/cjs/src/BASM.d.ts +110 -0
  13. package/dist/cjs/src/BASM.d.ts.map +1 -0
  14. package/dist/cjs/src/BASM.js.map +1 -1
  15. package/dist/cjs/src/BASMRemote.d.ts +14 -0
  16. package/dist/cjs/src/BASMRemote.d.ts.map +1 -0
  17. package/dist/cjs/src/BASMRemote.js.map +1 -1
  18. package/dist/cjs/src/Engine.d.ts +377 -0
  19. package/dist/cjs/src/Engine.d.ts.map +1 -0
  20. package/dist/cjs/src/Engine.js +430 -436
  21. package/dist/cjs/src/Engine.js.map +1 -1
  22. package/dist/cjs/src/GASP/OverlayGASPRemote.d.ts +24 -0
  23. package/dist/cjs/src/GASP/OverlayGASPRemote.d.ts.map +1 -0
  24. package/dist/cjs/src/GASP/OverlayGASPRemote.js +7 -10
  25. package/dist/cjs/src/GASP/OverlayGASPRemote.js.map +1 -1
  26. package/dist/cjs/src/GASP/OverlayGASPStorage.d.ts +103 -0
  27. package/dist/cjs/src/GASP/OverlayGASPStorage.d.ts.map +1 -0
  28. package/dist/cjs/src/GASP/OverlayGASPStorage.js +34 -31
  29. package/dist/cjs/src/GASP/OverlayGASPStorage.js.map +1 -1
  30. package/dist/cjs/src/LookupFormula.d.ts +29 -0
  31. package/dist/cjs/src/LookupFormula.d.ts.map +1 -0
  32. package/dist/cjs/src/LookupService.d.ts +85 -0
  33. package/dist/cjs/src/LookupService.d.ts.map +1 -0
  34. package/dist/cjs/src/Output.d.ts +32 -0
  35. package/dist/cjs/src/Output.d.ts.map +1 -0
  36. package/dist/cjs/src/SafeLog.d.ts +14 -0
  37. package/dist/cjs/src/SafeLog.d.ts.map +1 -0
  38. package/dist/cjs/src/SafeLog.js +44 -0
  39. package/dist/cjs/src/SafeLog.js.map +1 -0
  40. package/{src/SyncConfiguration.ts → dist/cjs/src/SyncConfiguration.d.ts} +2 -1
  41. package/dist/cjs/src/SyncConfiguration.d.ts.map +1 -0
  42. package/dist/cjs/src/TopicManager.d.ts +35 -0
  43. package/dist/cjs/src/TopicManager.d.ts.map +1 -0
  44. package/dist/cjs/src/storage/Storage.d.ts +237 -0
  45. package/dist/cjs/src/storage/Storage.d.ts.map +1 -0
  46. package/dist/cjs/src/storage/knex/KnexStorage.d.ts +69 -0
  47. package/dist/cjs/src/storage/knex/KnexStorage.d.ts.map +1 -0
  48. package/dist/cjs/src/storage/knex/KnexStorage.js +7 -10
  49. package/dist/cjs/src/storage/knex/KnexStorage.js.map +1 -1
  50. package/dist/cjs/src/storage/knex/all-migrations.d.ts +11 -0
  51. package/dist/cjs/src/storage/knex/all-migrations.d.ts.map +1 -0
  52. package/dist/cjs/src/storage/knex/all-migrations.js.map +1 -1
  53. package/dist/cjs/src/storage/knex/migrations/2024-05-18-001-initial.d.ts +4 -0
  54. package/dist/cjs/src/storage/knex/migrations/2024-05-18-001-initial.d.ts.map +1 -0
  55. package/dist/cjs/src/storage/knex/migrations/2024-05-18-001-initial.js.map +1 -1
  56. package/dist/cjs/src/storage/knex/migrations/2024-07-10-001-block-height.d.ts +4 -0
  57. package/dist/cjs/src/storage/knex/migrations/2024-07-10-001-block-height.d.ts.map +1 -0
  58. package/dist/cjs/src/storage/knex/migrations/2024-07-10-001-block-height.js.map +1 -1
  59. package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.d.ts +4 -0
  60. package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.d.ts.map +1 -0
  61. package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.js +36 -12
  62. package/dist/cjs/src/storage/knex/migrations/2024-07-17-001-transactions.js.map +1 -1
  63. package/dist/cjs/src/storage/knex/migrations/2024-07-18-001-indexes.d.ts +4 -0
  64. package/dist/cjs/src/storage/knex/migrations/2024-07-18-001-indexes.d.ts.map +1 -0
  65. package/dist/cjs/src/storage/knex/migrations/2024-07-18-001-indexes.js.map +1 -1
  66. package/dist/cjs/src/storage/knex/migrations/2025-05-28-001-enlarge.d.ts +4 -0
  67. package/dist/cjs/src/storage/knex/migrations/2025-05-28-001-enlarge.d.ts.map +1 -0
  68. package/dist/cjs/src/storage/knex/migrations/2025-05-28-001-enlarge.js.map +1 -1
  69. package/dist/cjs/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.d.ts +4 -0
  70. package/dist/cjs/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.d.ts.map +1 -0
  71. package/dist/cjs/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.js.map +1 -1
  72. package/dist/cjs/src/storage/knex/migrations/2025-07-22-001-fix-score-column-type.d.ts +4 -0
  73. package/dist/cjs/src/storage/knex/migrations/2025-07-22-001-fix-score-column-type.d.ts.map +1 -0
  74. package/dist/cjs/src/storage/knex/migrations/2025-07-22-001-fix-score-column-type.js.map +1 -1
  75. package/dist/cjs/src/storage/knex/migrations/2025-11-11-001-utxo-lookup-index.d.ts +9 -0
  76. package/dist/cjs/src/storage/knex/migrations/2025-11-11-001-utxo-lookup-index.d.ts.map +1 -0
  77. package/dist/cjs/src/storage/knex/migrations/2025-11-11-001-utxo-lookup-index.js.map +1 -1
  78. package/dist/cjs/src/storage/knex/migrations/2026-05-29-001-brc136-basm.d.ts +4 -0
  79. package/dist/cjs/src/storage/knex/migrations/2026-05-29-001-brc136-basm.d.ts.map +1 -0
  80. package/dist/cjs/src/storage/knex/migrations/2026-05-29-001-brc136-basm.js.map +1 -1
  81. package/dist/esm/mod.js +2 -1
  82. package/dist/esm/mod.js.map +1 -1
  83. package/dist/esm/src/BASMRemote.js.map +1 -1
  84. package/dist/esm/src/Engine.js +408 -414
  85. package/dist/esm/src/Engine.js.map +1 -1
  86. package/dist/esm/src/GASP/OverlayGASPRemote.js +2 -2
  87. package/dist/esm/src/GASP/OverlayGASPRemote.js.map +1 -1
  88. package/dist/esm/src/GASP/OverlayGASPStorage.js +23 -19
  89. package/dist/esm/src/GASP/OverlayGASPStorage.js.map +1 -1
  90. package/dist/esm/src/SafeLog.js +40 -0
  91. package/dist/esm/src/SafeLog.js.map +1 -0
  92. package/dist/esm/src/storage/knex/KnexStorage.js.map +1 -1
  93. package/dist/esm/src/storage/knex/migrations/2024-07-17-001-transactions.js +36 -12
  94. package/dist/esm/src/storage/knex/migrations/2024-07-17-001-transactions.js.map +1 -1
  95. package/dist/types/mod.d.ts +5 -4
  96. package/dist/types/mod.d.ts.map +1 -1
  97. package/dist/types/src/BASMRemote.d.ts.map +1 -1
  98. package/dist/types/src/Engine.d.ts +15 -0
  99. package/dist/types/src/Engine.d.ts.map +1 -1
  100. package/dist/types/src/GASP/OverlayGASPRemote.d.ts +2 -2
  101. package/dist/types/src/GASP/OverlayGASPRemote.d.ts.map +1 -1
  102. package/dist/types/src/GASP/OverlayGASPStorage.d.ts +3 -1
  103. package/dist/types/src/GASP/OverlayGASPStorage.d.ts.map +1 -1
  104. package/dist/types/src/SafeLog.d.ts +14 -0
  105. package/dist/types/src/SafeLog.d.ts.map +1 -0
  106. package/dist/types/src/storage/knex/KnexStorage.d.ts.map +1 -1
  107. package/dist/types/src/storage/knex/all-migrations.d.ts.map +1 -1
  108. package/dist/types/src/storage/knex/migrations/2024-07-17-001-transactions.d.ts.map +1 -1
  109. package/package.json +87 -30
  110. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  111. package/dist/esm/tsconfig.esm.tsbuildinfo +0 -1
  112. package/dist/types/tsconfig.types.tsbuildinfo +0 -1
  113. package/docs/API.md +0 -944
  114. package/docs/BRC-136-BASM.md +0 -327
  115. package/docs/README.md +0 -16
  116. package/docs/Synchronization.md +0 -212
  117. package/docs/concepts/00-overview.md +0 -85
  118. package/docs/concepts/01-best-practices.md +0 -202
  119. package/docs/concepts/02-query-performance.md +0 -345
  120. package/docs/concepts/03-database-monitoring.md +0 -211
  121. package/docs/concepts/04-pagination-example.md +0 -186
  122. package/docs/concepts/05-recommendations-summary.md +0 -158
  123. package/docs/concepts/README.md +0 -20
  124. package/docs/examples/README.md +0 -15
  125. package/docs/examples/gs-wip.md +0 -111
  126. package/docs/internal/README.md +0 -11
  127. package/mod.ts +0 -40
  128. package/src/Advertisement.ts +0 -8
  129. package/src/Advertiser.ts +0 -41
  130. package/src/BASM.ts +0 -208
  131. package/src/BASMRemote.ts +0 -54
  132. package/src/Engine.ts +0 -2199
  133. package/src/GASP/OverlayGASPRemote.ts +0 -108
  134. package/src/GASP/OverlayGASPStorage.ts +0 -383
  135. package/src/LookupFormula.ts +0 -31
  136. package/src/LookupService.ts +0 -136
  137. package/src/Output.ts +0 -31
  138. package/src/TopicManager.ts +0 -40
  139. package/src/__tests/BASM.test.ts +0 -44
  140. package/src/__tests/BASMChain.test.ts +0 -290
  141. package/src/__tests/Engine.test.ts +0 -1345
  142. package/src/__tests/OverlayGASPRemote.test.ts +0 -135
  143. package/src/__tests/OverlayGASPStorage.test.ts +0 -171
  144. package/src/storage/Storage.ts +0 -260
  145. package/src/storage/knex/KnexStorage.ts +0 -651
  146. package/src/storage/knex/all-migrations.ts +0 -32
  147. package/src/storage/knex/migrations/2024-05-18-001-initial.ts +0 -30
  148. package/src/storage/knex/migrations/2024-07-10-001-block-height.ts +0 -15
  149. package/src/storage/knex/migrations/2024-07-17-001-transactions.ts +0 -40
  150. package/src/storage/knex/migrations/2024-07-18-001-indexes.ts +0 -30
  151. package/src/storage/knex/migrations/2025-05-28-001-enlarge.ts +0 -42
  152. package/src/storage/knex/migrations/2025-06-25-001-gasp-pagination-support.ts +0 -46
  153. package/src/storage/knex/migrations/2025-07-22-001-fix-score-column-type.ts +0 -24
  154. package/src/storage/knex/migrations/2025-11-11-001-utxo-lookup-index.ts +0 -18
  155. package/src/storage/knex/migrations/2026-05-29-001-brc136-basm.ts +0 -123
@@ -1,211 +0,0 @@
1
- # Overlay Database Monitoring and Debugging
2
-
3
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](./README.md) | [📖 Examples](../examples/README.md) | [⚙️ Internal](../internal/README.md)
4
-
5
- **Navigation:** [Overview](./00-overview.md) | [Best Practices](./01-best-practices.md) | [Query Performance](./02-query-performance.md) | [Database Monitoring](./03-database-monitoring.md) | [Pagination Example](./04-pagination-example.md) | [Recommendations Summary](./05-recommendations-summary.md)
6
-
7
- ---
8
-
9
- ## Overview
10
-
11
- Monitoring and debugging overlay databases helps ensure reliability, correctness, and predictable performance.
12
- As overlays grow, developers benefit from having ways to inspect what their Lookup Service is storing and validate that Topic Manager admission logic is working as intended.
13
-
14
- This document outlines optional strategies for:
15
-
16
- * Providing **safe, read-only** inspection of Lookup data
17
- * Building **debugging workflows** during overlay development
18
- * Tracking **basic performance and health metrics**
19
- * Ensuring correctness without exposing sensitive data or modifying overlay protocols
20
-
21
- These recommendations are intended for **overlay developers**, not system administrators of BSVA infrastructure.
22
-
23
- ---
24
-
25
- ## 1. Goals
26
-
27
- Overlay authors may want to:
28
-
29
- * Verify what data is stored after Topic Manager admission
30
- * Inspect the parsed documents produced by PushDrop decoding
31
- * Measure lookup latency or query efficiency
32
- * Debug message ingestion, reactions, or thread activity during development
33
- * Provide trusted team members with read-only visibility in test or staging environments
34
-
35
- All monitoring discussed here is optional and applies only to the overlay developer’s own deployment.
36
-
37
- ---
38
-
39
- ## 2. Read-Only Access for Debugging
40
-
41
- ### 2.1 Purpose
42
-
43
- Read-only visibility is useful during development or internal debugging because it allows developers to:
44
-
45
- * Confirm that the Lookup Service stored the expected metadata
46
- * Inspect whether fields such as `threadId`, `createdAt`, or `parentMessageId` were parsed correctly
47
- * Understand why a transaction may not appear in query results
48
-
49
- ### 2.2 Implementation Options
50
-
51
- Overlay authors can choose from several approaches depending on their internal workflow.
52
-
53
- #### Option A: MongoDB Read-Only Role
54
-
55
- MongoDB allows creation of roles that grant read-only access to specific collections:
56
-
57
- ```js
58
- db.createUser({
59
- user: "overlayReader",
60
- pwd: "strongpassword",
61
- roles: [
62
- { role: "read", db: "overlaydb" }
63
- ]
64
- });
65
- ```
66
-
67
- This is useful for:
68
-
69
- * Internal developers
70
- * Debugging in staging environments
71
- * Letting trusted team members inspect lookup data
72
-
73
- #### Option B: Internal Read-Only Endpoint
74
-
75
- Some teams choose to expose a controlled debug route during development:
76
-
77
- ```typescript
78
- router.get('/debug/messages', async (req, res) => {
79
- const threadId = req.query.threadId;
80
- const results = await storage.listThreadMessages(threadId, 0, 25);
81
- res.json(results);
82
- });
83
- ```
84
-
85
- **Important:**
86
- Such endpoints must not be exposed publicly. They should be protected with:
87
-
88
- * API keys
89
- * Admin tokens
90
- * IP allowlists
91
- * Or disabled entirely in production
92
-
93
- This is entirely optional and depends on each developer’s debugging workflow.
94
-
95
- ---
96
-
97
- ## 3. Health and Performance Metrics
98
-
99
- These metrics are optional but useful during development or debugging.
100
-
101
- ### 3.1 Basic Metrics
102
-
103
- Overlay authors may choose to track:
104
-
105
- * Collection size and document count
106
- * Index size and index efficiency
107
- * Average query execution time for common lookups
108
- * Latency from Topic Manager admission to Lookup write
109
- * Count of decode or parse failures
110
-
111
- These can be logged periodically or exported to monitoring tools like Prometheus or Grafana if desired.
112
-
113
- Example minimal metric:
114
-
115
- ```typescript
116
- app.get('/metrics', async (req, res) => {
117
- const stats = await db.collection('convoMessages').stats();
118
- res.send(`convo_messages_bytes ${stats.size}\n`);
119
- });
120
- ```
121
-
122
- ### 3.2 Transaction Admission Tracking
123
-
124
- During development, Topic Managers can log admission decisions:
125
-
126
- ```typescript
127
- console.log(`[tm_convo] admitted output ${txid}:${vout}`);
128
- ```
129
-
130
- This helps correlate:
131
-
132
- * The BEEF transaction
133
- * Decoded PushDrop fields
134
- * The resulting Lookup Service document
135
-
136
- This logging is optional and purely for debugging the overlay’s own ingestion logic.
137
-
138
- ---
139
-
140
- ## 4. Debugging Workflow Example
141
-
142
- A typical overlay debugging workflow might look like:
143
-
144
- 1. Identify the txid of a message that should appear in the UI
145
- 2. Query the Lookup data (using read-only DB access or internal endpoint)
146
- 3. Verify that the Topic Manager correctly decoded the PushDrop fields
147
- 4. Ensure Lookups return expected results (e.g., thread messages, replies, reactions)
148
- 5. If performance issues appear, check index usage via `explain("executionStats")`
149
- 6. If admission issues appear, review Topic Manager logs
150
-
151
- This workflow helps developers confirm correctness without modifying protocol-level logic.
152
-
153
- ---
154
-
155
- ## 5. Optional Tools and Enhancements
156
-
157
- These tools are optional and useful only in development environments.
158
-
159
- ### 5.1 Overlay Health Dashboard
160
-
161
- A lightweight web interface integrated into Overlay Express that would:
162
-
163
- * Display real-time query performance (e.g., avg lookup latency)
164
- * Show admission rates per Topic Manager
165
- * Track DB growth and index efficiency
166
- * Provide a query console for authorized users
167
-
168
- This is helpful for overlay teams during debugging or feature development.
169
-
170
- ### 5.2 Integration With Existing Mongo Tooling
171
-
172
- Developers can use existing Mongo tools with read-only credentials:
173
-
174
- * Mongo Express
175
- * MongoDB Compass
176
- * Atlas Monitoring
177
-
178
- This allows safe browsing of Lookup documents without risk of modification.
179
-
180
- ---
181
-
182
- ## 6. Security Considerations
183
-
184
- To avoid security risks:
185
-
186
- * Restrict read-only access to internal team members
187
- * Do not expose debugging endpoints publicly
188
- * Use authentication (API keys, tokens) for any admin routes
189
- * Avoid logging user data such as:
190
- * CurvePoint headers
191
- * Encrypted payloads
192
- * Identity certificates
193
- * Private metadata
194
-
195
- Logs should focus on metadata only, such as txid, threadId, and timestamps.
196
-
197
- ---
198
-
199
- ## 7. Summary of Recommendations
200
-
201
- | Area | Recommendation |
202
- | ----------- | ------------------------------------------------------------------ |
203
- | Read Access | Provide secure read-only access for overlay and CARS admins. |
204
- | Metrics | Track query latency, DB size, and failed transactions. |
205
- | Logging | Record admission flow from Topic Manager to Lookup. |
206
- | Tools | Use Mongo Express or Compass with read-only roles. |
207
- | Security | Restrict debugging endpoints and sanitize data. |
208
-
209
- ---
210
-
211
- Next file: [`04-pagination-example.md`](./04-pagination-example.md) — Demonstrates performance improvements from pagination in Convo Messenger overlay queries.
@@ -1,186 +0,0 @@
1
- # Pagination in Overlay Queries: Convo Messenger Example
2
-
3
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](./README.md) | [📖 Examples](../examples/README.md) | [⚙️ Internal](../internal/README.md)
4
-
5
- **Navigation:** [Overview](./00-overview.md) | [Best Practices](./01-best-practices.md) | [Query Performance](./02-query-performance.md) | [Database Monitoring](./03-database-monitoring.md) | [Pagination Example](./04-pagination-example.md) | [Recommendations Summary](./05-recommendations-summary.md)
6
-
7
- ---
8
-
9
- ## Overview
10
-
11
- Pagination is one of the simplest and most effective techniques for ensuring overlay lookup performance remains stable as datasets grow.
12
- Without pagination, queries that return lists—messages, reactions, or other records—can become increasingly slow and resource-intensive.
13
-
14
- This document illustrates why pagination matters and uses Convo Messenger as a real example of how it improves performance.
15
- It does not prescribe a required pattern or mandate changes; it simply shows how one overlay benefits from predictable, bounded queries.
16
-
17
- ---
18
-
19
- ## 1. Why Pagination Matters
20
-
21
- Overlay datasets grow continuously. Without pagination:
22
-
23
- * A lookup endpoint may return thousands of documents at once
24
- * Memory usage spikes on both the server and the client
25
- * Query latency increases as more documents accumulate
26
- * Sorting happens in memory instead of using indexes
27
-
28
- Pagination ensures each lookup returns only a small, fixed-size window of results.
29
-
30
- **Benefits**
31
-
32
- * Consistent performance regardless of dataset size
33
- * Lower memory pressure
34
- * Index-friendly access patterns
35
- * Improved UX in applications that display messages or lists
36
-
37
- ---
38
-
39
- ## 2. How Convo Messenger Uses Pagination (Example)
40
-
41
- Convo Messenger added pagination to all Lookup queries that return lists, including:
42
-
43
- * listThreadMessages
44
- * listLatestMessages
45
- * listReplies
46
- * listThreadReactions
47
-
48
- Below is one example from Convo’s Lookup Service showing how `skip` and `limit` values are interpreted when provided:
49
-
50
- ```typescript
51
- if (query.type === 'listThreadMessages') {
52
- const threadId = query.threadId ?? query.value?.threadId;
53
- if (!threadId) throw new Error("threadId required");
54
-
55
- const skip = query.skip ?? query.value?.skip ?? 0;
56
- const limit = query.limit ?? query.value?.limit ?? 50;
57
-
58
- const messages = await this.storage.listThreadMessages(threadId, skip, limit);
59
- return this.formatAsLookupAnswers(messages);
60
- }
61
- ```
62
-
63
- **Storage Layer Example (Convo)**
64
-
65
- Convo’s storage layer performs an indexed and paginated fetch:
66
-
67
- ```typescript
68
- async listThreadMessages(threadId: string, skip = 0, limit = 50) {
69
- const results = await this.messages
70
- .aggregate([
71
- { $match: { threadId } },
72
- { $sort: { createdAt: -1 } }, // newest → oldest (indexed)
73
- { $skip: skip },
74
- { $limit: limit }
75
- ])
76
- .toArray();
77
-
78
- return results.reverse(); // oldest → newest for UI ordering
79
- }
80
- ```
81
-
82
- This matches Convo’s existing index:
83
-
84
- ```typescript
85
- db.convoMessages.createIndex({ threadId: 1, createdAt: -1 });
86
- ```
87
-
88
- **Client-Side Integration**
89
-
90
- In the frontend (React), pagination can be managed by maintaining a `page` or `offset` variable:
91
-
92
- ```typescript
93
- const [messages, setMessages] = useState([]);
94
- const [page, setPage] = useState(0);
95
- const pageSize = 50;
96
-
97
- async function loadNextPage() {
98
- const result = await lookup.query({
99
- service: 'convo_lookup',
100
- query: {
101
- type: 'listThreadMessages',
102
- threadId,
103
- skip: page * pageSize,
104
- limit: pageSize,
105
- }
106
- });
107
-
108
- setMessages([...messages, ...result]);
109
- setPage(page + 1);
110
- }
111
- ```
112
-
113
- This simple approach allows seamless infinite scrolling or “Load More” functionality.
114
-
115
- Again, this is not a prescription—it simply demonstrates how Convo uses indexed pagination to maintain predictable performance.
116
-
117
- ---
118
-
119
- ## 3. Performance Impact (Convo Example)
120
-
121
- After adding pagination to its lookup queries, Convo observed substantial performance improvements.
122
-
123
- | Metric | Before Pagination | After Pagination |
124
- | -------------------------- | -----------------: | ---------------------: |
125
- | Average Query Time | ~420 ms | **< 70 ms** |
126
- | Memory Usage (per request) | ~75 MB | **< 8 MB** |
127
- | CPU Load (peak) | Very High | **Much Lower** |
128
- | UI Latency | Noticeable stutter | **Instantaneous load** |
129
-
130
- **Takeaways**
131
- * Avoiding unbounded queries dramatically stabilizes performance
132
- * Server resource usage becomes predictable
133
- * Larger threads no longer degrade lookup time
134
- * User experience improves without changing overlay protocols
135
-
136
- ---
137
-
138
- ## 4. Developer Notes (General Guidance)
139
-
140
- ### 4.1 Recommended Defaults
141
-
142
- | Parameter | Recommended Value | Notes |
143
- | --------- | ------------------- | ---------------------------------------------------------- |
144
- | `limit` | 50 | Reasonable for message lists; tweak based on dataset size. |
145
- | `skip` | 0 | Always provide, even if zero. |
146
- | sort | `{ createdAt: -1 }` | Ensures chronological consistency. |
147
-
148
- ### 4.2 Index Alignment
149
-
150
- For overlays that paginate ordered data, an index on the sort field is essential:
151
-
152
- ```js
153
- { threadId: 1, createdAt: -1 }
154
- ```
155
- This avoids expensive in-memory sorts.
156
-
157
- ### 4.3 Cursor-Based Pagination (Optional)
158
-
159
- Some overlays may use cursor-based pagination (e.g., createdAt > X) for large-scale workloads.
160
- ---
161
-
162
- ## 5. Visual Results (Convo Example)
163
-
164
- Pagination allowed Convo to:
165
- * Avoid returning entire threads at once
166
- * Use MongoDB indexes effectively
167
- * Keep lookup latency stable as message volume grew
168
- * Implement infinite scroll UX without heavy data loads
169
-
170
- This demonstrates how pagination helps overlays scale smoothly without requiring complicated architecture.
171
-
172
- ---
173
-
174
- ## 6. Recommendations Summary
175
-
176
- | Area | Recommendation |
177
- | ------------------ | ---------------------------------------------------- |
178
- | Implementation | Always bound list queries with pagination parameters |
179
- | Client Integration | Incremental loading improves UX and stability |
180
- | Indexing | Align indexes with sort and filter fields |
181
- | Optimization | Cursor-based pagination can help for very large sets |
182
- | Benchmarking | Measure latency and memory before/after deployment |
183
-
184
- ---
185
-
186
- Next file: [`05-recommendations-summary.md`](./05-recommendations-summary.md) — Summarizes all proposed overlay improvements for BSVA documentation and Overlay Express feature suggestions.
@@ -1,158 +0,0 @@
1
- # Overlay Recommendations Summary
2
-
3
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](./README.md) | [📖 Examples](../examples/README.md) | [⚙️ Internal](../internal/README.md)
4
-
5
- **Navigation:** [Overview](./00-overview.md) | [Best Practices](./01-best-practices.md) | [Query Performance](./02-query-performance.md) | [Database Monitoring](./03-database-monitoring.md) | [Pagination Example](./04-pagination-example.md) | [Recommendations Summary](./05-recommendations-summary.md)
6
-
7
- ---
8
-
9
- ## Overview
10
-
11
- This document summarizes the key recommendations from the overlay optimization series.
12
- These best practices help developers build overlays that remain efficient, stable, and easy to debug as datasets grow.
13
- The recommendations also highlight future opportunities for improvements to Overlay Express and related tooling.
14
-
15
- This summary is written for overlay authors and maintainers. It does not prescribe protocol-level changes.
16
-
17
- ---
18
-
19
- ## 1. General Design Recommendations
20
-
21
- | Area | Recommendation | Description |
22
- | ---------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
23
- | **Lookup Data Structure** | Store only indexable metadata | Keep Lookup Services lightweight by storing only the fields needed for indexing and filtering. Store large data (media, payloads) externally. |
24
- | **Topic Manager Validation** | Enforce schema and idempotency | Ensure each admitted transaction matches the expected structure and avoid duplicate writes. |
25
- | **Retention Policy** | Implement periodic cleanup | Schedule jobs to prune stale data and rebuild indexes to maintain predictable performance. |
26
- | **Security** | Restrict admin/debug access | Provide safe read-only views only to trusted admins (e.g., CARS admins or overlay maintainers). |
27
-
28
- ---
29
-
30
- ## 2. Query and Indexing Recommendations
31
-
32
- ### 2.1 Query Design
33
-
34
- * Always filter on indexed fields (e.g., `threadId`, `parentMessageId`, `createdAt`).
35
- * Avoid unbounded queries (`find({})`, no limit, no filter).
36
- * Do not use regex or `$text` queries—they prevent index usage.
37
- * Prefer range queries `($gte, $lte)` when filtering by time.
38
-
39
- ### 2.2 Indexing Strategy
40
-
41
- * Add indexes that match your overlay’s most common query patterns:
42
- * Example from Convo: `{ threadId: 1, createdAt: -1 }`
43
- * Example for replies: `{ parentMessageId: 1, createdAt: -1 }`
44
- * Use MongoDB’s explain("executionStats") to confirm index usage.
45
- * Rebuild indexes periodically for overlays that experience frequent writes/deletes.
46
-
47
- ### 2.3 Pagination
48
-
49
- * Implement skip/limit pagination on all list endpoints.
50
- * Align pagination with indexed sorting to avoid in-memory sorts.
51
- * For large-scale overlays, consider cursor-based pagination (e.g., createdAt > X).
52
-
53
- ---
54
-
55
- ## 3. Monitoring and Debugging
56
-
57
- ### 3.1 Read-Only Admin Access
58
-
59
- Provide safe ways for overlay and CARS admins to inspect stored data:
60
- * Read-only database credentials
61
- * Or a protected REST endpoint for paginated inspection
62
-
63
- These allow debugging without risking data mutation.
64
-
65
- ### 3.2 Health Metrics
66
-
67
- Track operational metrics such as:
68
- * Query latency (per lookup type)
69
- * Failed or rejected transactions
70
- * Topic Manager ingestion delay
71
- * Database and index size
72
- * Slow query counts
73
-
74
- Visualize these with Prometheus, Grafana, or MongoDB tools.
75
-
76
- ### 3.3 Logging Standards
77
-
78
- * Log Topic Manager admissions and Lookup Service query timings.
79
- * Use consistent log tags (e.g., `[tm_convo]`, `[ls_market]`, `[overlay]`).
80
- * Avoid logging sensitive or encrypted data.
81
-
82
- ---
83
-
84
- ## 4. Performance Enhancements Verified in Convo Messenger
85
-
86
- | Optimization | Result |
87
- | --------------------------------- | --------------------------------------------- |
88
- | Added pagination (`skip`/`limit`) | Reduced avg query time from 420ms → 70ms |
89
- | Indexed `(threadId, createdAt)` | Reduced CPU load and consistent scaling |
90
- | Range Based queries | More predictable performance |
91
- | MongoDB profiler + timing logs | Identified slow or unindexed queries |
92
-
93
- These tests confirm that even small backend changes yield **major end-user improvements** in message loading and overlay stability.
94
-
95
- ---
96
-
97
- ## 5. Proposed Overlay Express Enhancements
98
-
99
- ### 5.1 Built-In Query Monitor (Future Proposal)
100
-
101
- A lightweight module that tracks and displays:
102
- * Average execution time per query type
103
- * Query counts
104
- * Slow query alerts
105
- * Index usage indicators
106
-
107
- ### 5.2 Health Endpoint Standardization
108
-
109
- A recommended addition:
110
-
111
- ```bash
112
- /health → basic liveness
113
- /metrics → Prometheus-compatible performance stats
114
- ```
115
-
116
- ### 5.3 Admin Console Integration
117
-
118
- A browser-based console for authorized users to:
119
- * Inspect Lookup data (read-only)
120
- * View recent admissions
121
- * Inspect slow queries
122
- * Monitor index statistics
123
-
124
- ### 5.4 SDK Convenience Utilities
125
-
126
- Potential optional helpers:
127
- * `lookup.paginate()` wrapper
128
- * Standardized pagination response format
129
- * Typed client helpers for common query shapes
130
-
131
- These features would reduce boilerplate for overlay developers.
132
- ---
133
-
134
- ## 6. Next Steps for BSVA Integration
135
-
136
- 1. Add these best practices to BSVA documentation and onboarding materials.
137
- 2. Update example overlays (e.g., in Metanet Academy) to demonstrate pagination and indexing.
138
- 3. Create an example overlay dashboard (Prometheus/Grafana) for developers.
139
- 4. Review potential Overlay Express enhancements with maintainers.
140
-
141
- ---
142
-
143
- ## 7. Summary Table
144
-
145
- | Category | Key Action | Impact |
146
- | --------------- | ------------------------------- | --------------------------------------- |
147
- | Lookup Design | Store metadata only | Lower storage load and faster queries |
148
- | Indexing | Add indexes based on query usage| Lower latency and predictable behavior |
149
- | Pagination | Apply universally | Stable performance as data grows |
150
- | Monitoring | Add metrics + profiling | Early detection of issues |
151
- | Admin Tools | Provide safe, read-only access | Easier debugging and transparency |
152
- | Overlay Express | Consider Query Monitor tooling | Unified visibility across overlays |
153
-
154
- ---
155
-
156
- **Conclusion:**
157
- These recommendations form a solid baseline for building fast, scalable, and maintainable overlays.
158
- They are intentionally lightweight and compatible with existing designs—no protocol changes required.
@@ -1,20 +0,0 @@
1
- # Conceptual Topics
2
-
3
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](./README.md) | [📖 Examples](../examples/README.md) | [⚙️ Internal](../internal/README.md)
4
-
5
- ---
6
-
7
- These documents cover high-level conceptual information that will augment developers' understanding of the code-level Overlay Services Engine documentation:
8
-
9
- ## Available Topics
10
-
11
- - [Overview](./00-overview.md) — Introduction to Overlay Use and Optimization in the BSV Ecosystem
12
- - [Best Practices](./01-best-practices.md) — Best practices for overlay design and implementation
13
- - [Query Performance](./02-query-performance.md) — Query optimization and performance considerations
14
- - [Database Monitoring](./03-database-monitoring.md) — Monitoring and debugging overlays
15
- - [Pagination Example](./04-pagination-example.md) — Pagination and practical examples
16
- - [Recommendations Summary](./05-recommendations-summary.md) — Quick reference of best practices
17
-
18
- ---
19
-
20
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](./README.md) | [📖 Examples](../examples/README.md) | [⚙️ Internal](../internal/README.md)
@@ -1,15 +0,0 @@
1
- # Examples
2
-
3
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](../concepts/README.md) | [📖 Examples](./README.md) | [⚙️ Internal](../internal/README.md)
4
-
5
- ---
6
-
7
- Here, you will find documentation for common example usages of the Overlay Services Engine.
8
-
9
- ## Available Examples
10
-
11
- - [Getting Started (WIP)](./gs-wip.md) — Introduction and getting started guide
12
-
13
- ---
14
-
15
- [🏠 Home](../README.md) | [📚 API](../API.md) | [💡 Concepts](../concepts/README.md) | [📖 Examples](./README.md) | [⚙️ Internal](../internal/README.md)