Commit 9428137
committed
refactor: remove unnecessary transactionAsync calls from NoteStore and PrivateEventStore
First of a series of PRs that will aim at reducing the usage of `transactionAsync` in PXE to the minimum, if not completely.
This one removes a `transactionAsync` call from `NoteStore#applyNullifiers` and `PrivateEventStore#getPrivateEvents`.
It is safe to do so since `applyNullifiers` doesn't write to the DB, it just writes to the in-memory staged slice that the store keeps for the duration of job.
It is also safe to do so in `getPrivateEvents` because it also doesn't write to the DB, it just reads committed events.
Writes from both stores are issued on `commit`, which is still done in a `transactionAsync` wrapper (note that particular case will probably remain as one of the few legitimate usages of `transactionAsync`).
# Why we need to hunt down `transactionAsync`
The issue with `transactionAsync` is that it works as intended with LMDB stores, but it breaks assumptions in IndexedDB.
Browsers are free to auto-commit IndexedDB transactions whenever a micro-task resolves without adding a read or write request to it.
That browser behavior in practice makes it extremely hard to guarantee that what's run inside a `transactionAsync` wrapper will not be auto-committed.
`transactionAsync` is designed to make all operations across all store collections be routed through the same transactional context. We have to assume that whenever any code inside a `transactionAsync` resolves a promise without generating more work to the DB, the browser can and will commit the transaction, resulting in a `TransactionInactiveError` like the one in the screenshot.
This is especially tricky to deal with because while aztec-packages has a very thorough CI test harness, 99% of it runs on LMDB on Node. The issues discussed in this description affect only browser environments. I took some time to evaluate libs that simulate IndexedDB, but none seem to be reliable enough. That means we can only enhance coverage and regression testing of this by adding playwright headless browser tests, which are slow and heavy.
<img width="1172" height="258" alt="Screenshot 2026-01-27 at 13 15 21 (1)" src="https://github.com/user-attachments/assets/af093110-9a09-4f79-bbde-5c255d09d7d8" />1 parent 97643a6 commit 9428137
File tree
2 files changed
+85
-92
lines changed- yarn-project/pxe/src/storage
- note_store
- private_event_store
2 files changed
+85
-92
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| |||
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | | - | |
52 | 49 | | |
53 | 50 | | |
54 | 51 | | |
| |||
182 | 179 | | |
183 | 180 | | |
184 | 181 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
194 | 186 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
199 | 190 | | |
200 | | - | |
201 | | - | |
202 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
203 | 195 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
208 | 199 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
213 | 204 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
217 | 208 | | |
218 | 209 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
222 | 217 | | |
223 | 218 | | |
224 | 219 | | |
| |||
Lines changed: 57 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
161 | 144 | | |
162 | | - | |
| 145 | + | |
| 146 | + | |
163 | 147 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 148 | + | |
168 | 149 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 150 | + | |
| 151 | + | |
173 | 152 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
178 | 160 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
191 | 166 | | |
192 | 167 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
202 | 189 | | |
| 190 | + | |
203 | 191 | | |
204 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
205 | 201 | | |
| 202 | + | |
| 203 | + | |
206 | 204 | | |
207 | 205 | | |
208 | 206 | | |
| |||
0 commit comments