Commit c12bf49
authored
Respect ModuleCache max size (#5441)
## Motivation
`ModuleCache::insert()` never incremented `total_size` after inserting a
new entry. It only decremented during
eviction in `reduce_size_to()`. This meant:
- `total_size` was permanently 0
- The eviction check `if self.total_size + bytecode_size >
self.max_size` never triggered
- The cache grew unboundedly despite the 512 MiB limit
- `reduce_size_to()` would underflow on the subtraction `self.total_size
-= bytecode_size`
## Proposal
- Add `self.total_size += bytecode_size` after insertion, only when the
key wasn't already present (to avoid
double-counting on re-insertion of the same bytecode)
- Add an early return when a single bytecode exceeds `max_size`, which
prevents an underflow in the `self.max_size -
bytecode_size` computation passed to `reduce_size_to()`
- Add 4 unit tests covering: size tracking, eviction triggering,
oversized rejection, and duplicate key handling
## Test Plan
- CI + new tests pass
## Release Plan
- These changes should be backported to the latest `testnet` branch,
then
- be released in a validator hotfix.1 parent d461a29 commit c12bf49
File tree
5 files changed
+105
-33
lines changed- examples
- linera-execution/src/wasm
- linera-sdk/tests/fixtures
5 files changed
+105
-33
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
35 | 46 | | |
36 | 47 | | |
37 | 48 | | |
| |||
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
61 | 80 | | |
62 | 81 | | |
63 | 82 | | |
64 | 83 | | |
65 | 84 | | |
| 85 | + | |
66 | 86 | | |
67 | 87 | | |
68 | 88 | | |
| |||
79 | 99 | | |
80 | 100 | | |
81 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments