Commit ec1b5fc
authored
feat(account-tree-controller): persist
## Explanation
We used to not persist the account-tree before and we were
re-constructing it "fresh" upon `init`. However, some other controllers
are dependent on the tree and have to wait for it to be built before
consuming it.
Since the tree should never really change between lock/unlock, that's ok
to have a on-disk copy of it to speedup consumers.
We will still try to re-construct it during `init` though (in case rules
have changed or that new accounts have appeared that went unnoticed).
## References
N/A
## Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Persists and rehydrates core controller state, which can affect
startup/lock-unlock behavior and introduce stale/mismatched tree data if
persisted state diverges from current accounts.
>
> **Overview**
> `AccountTreeController` now **persists `accountTree`** (state metadata
`persist: true`) instead of always recomputing it on `init`.
>
> The controller constructor now pre-initializes internal reverse lookup
maps from the persisted tree via `#initTreeContext`, allowing methods
like `getAccountContext`, `getAccountGroupObject`, and
`getAccountsFromSelectedAccountGroup` to work *before* `init()` runs.
>
> Tests and snapshots are updated to cover pre-populated persisted state
behavior and the new persisted-state surface, and the changelog
documents the new persistence behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
65dedea. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->accountTree (#8437)1 parent 6dc536e commit ec1b5fc
File tree
3 files changed
+140
-1
lines changed- packages/account-tree-controller
- src
3 files changed
+140
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
Lines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
238 | 278 | | |
239 | 279 | | |
240 | 280 | | |
| |||
877 | 917 | | |
878 | 918 | | |
879 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
880 | 925 | | |
881 | 926 | | |
882 | 927 | | |
| |||
902 | 947 | | |
903 | 948 | | |
904 | 949 | | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
905 | 955 | | |
906 | 956 | | |
907 | 957 | | |
| |||
1076 | 1126 | | |
1077 | 1127 | | |
1078 | 1128 | | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1079 | 1150 | | |
1080 | 1151 | | |
1081 | 1152 | | |
| |||
1147 | 1218 | | |
1148 | 1219 | | |
1149 | 1220 | | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
1150 | 1234 | | |
1151 | 1235 | | |
1152 | 1236 | | |
| |||
4863 | 4947 | | |
4864 | 4948 | | |
4865 | 4949 | | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
4866 | 4953 | | |
4867 | 4954 | | |
4868 | 4955 | | |
| |||
Lines changed: 50 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
238 | 244 | | |
239 | 245 | | |
240 | 246 | | |
| |||
275 | 281 | | |
276 | 282 | | |
277 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
278 | 327 | | |
279 | 328 | | |
280 | 329 | | |
| |||
0 commit comments