Commit 708d702
authored
refactor: compression of config in gov to reduce costs. (#16603)
Spearbit suggested altering the `configuration` storage to use a map and
just have an id in the proposal. However, we can heavily compress the
values of the configuration that needs to actually go into the proposal.
So I believe a better option is to do that (we can get it down to 2
slots), as we then reduced the number of reads on more important
functions such as `vote` with only a minor added cost over the id for
the proposal itself.
- Ballots can be stored in a single `uint256` as they will never
meaningfully be size > `uint128`.
- All the timings in the configuration can be compressed to `uint32`
(the `CompressedTimestamp` that we already have).
- Altering the ordering in the `Proposal` allow us to more tightly pack
it for storage.
It is a bit more tricky to update some of the storage in tests, but we
can utilise a testonly wrapper that allow direct manipulation to address
that.
```solidity
struct CompressedConfiguration {
// Slot 1: Timing and percentages - 32*4 + 64*2 = 256 bits
CompressedTimestamp votingDelay;
CompressedTimestamp votingDuration;
CompressedTimestamp executionDelay;
CompressedTimestamp gracePeriod;
uint64 quorum;
uint64 requiredYeaMargin;
// Slot 2: Amounts and proposeConfig - 96 + 96 + 32 = 224 bits (32 bits unused)
uint96 minimumVotes;
uint96 lockAmount;
CompressedTimestamp lockDelay;
}
struct CompressedProposal {
// Slot 1: Core Identity (256 bits)
address proposer; // 160 bits
uint96 minimumVotes; // 96 bits - from config
// Slot 2: Timing (232 bits used, 24 bits padding)
ProposalState cachedState; // 8 bits
CompressedTimestamp creation; // 32 bits
CompressedTimestamp votingDelay; // 32 bits - from config
CompressedTimestamp votingDuration; // 32 bits - from config
CompressedTimestamp executionDelay; // 32 bits - from config
CompressedTimestamp gracePeriod; // 32 bits - from config
uint64 quorum; // 64 bits - from config
// Slot 3: Votes (256 bits)
CompressedBallot summedBallot; // 256 bits (128 yea + 128 nay)
// Slot 4: References (224 bits used, 32 bits padding)
IPayload payload; // 160 bits
uint64 requiredYeaMargin; // 64 bits - from config
}
```File tree
31 files changed
+761
-194
lines changed- l1-contracts
- script
- src
- core/libraries/rollup
- governance
- interfaces
- libraries
- compressed-data
- test
- builder
- compression
- delegation
- governance
- governance-proposer/scenario
- governance
- proposallib
- scenarios
- gse/gse
- helpers
- scenario
31 files changed
+761
-194
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
125 | | - | |
126 | 124 | | |
127 | 125 | | |
128 | 126 | | |
| |||
619 | 617 | | |
620 | 618 | | |
621 | 619 | | |
622 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
| |||
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
132 | | - | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
135 | 145 | | |
136 | 146 | | |
137 | 147 | | |
| |||
155 | 165 | | |
156 | 166 | | |
157 | 167 | | |
158 | | - | |
| 168 | + | |
159 | 169 | | |
160 | 170 | | |
161 | 171 | | |
162 | 172 | | |
163 | | - | |
| 173 | + | |
| 174 | + | |
164 | 175 | | |
165 | 176 | | |
166 | | - | |
| 177 | + | |
167 | 178 | | |
168 | 179 | | |
169 | 180 | | |
| |||
185 | 196 | | |
186 | 197 | | |
187 | 198 | | |
188 | | - | |
| 199 | + | |
189 | 200 | | |
190 | 201 | | |
191 | 202 | | |
| |||
237 | 248 | | |
238 | 249 | | |
239 | 250 | | |
240 | | - | |
241 | | - | |
| 251 | + | |
| 252 | + | |
242 | 253 | | |
243 | 254 | | |
244 | 255 | | |
| |||
296 | 307 | | |
297 | 308 | | |
298 | 309 | | |
299 | | - | |
| 310 | + | |
300 | 311 | | |
301 | 312 | | |
302 | 313 | | |
| |||
332 | 343 | | |
333 | 344 | | |
334 | 345 | | |
335 | | - | |
| 346 | + | |
336 | 347 | | |
337 | 348 | | |
338 | 349 | | |
339 | 350 | | |
340 | 351 | | |
341 | 352 | | |
342 | | - | |
| 353 | + | |
343 | 354 | | |
344 | 355 | | |
345 | 356 | | |
| |||
405 | 416 | | |
406 | 417 | | |
407 | 418 | | |
408 | | - | |
| 419 | + | |
| 420 | + | |
409 | 421 | | |
410 | 422 | | |
411 | 423 | | |
| |||
435 | 447 | | |
436 | 448 | | |
437 | 449 | | |
438 | | - | |
| 450 | + | |
439 | 451 | | |
440 | | - | |
| 452 | + | |
441 | 453 | | |
442 | 454 | | |
443 | | - | |
| 455 | + | |
444 | 456 | | |
445 | | - | |
446 | | - | |
| 457 | + | |
| 458 | + | |
447 | 459 | | |
448 | | - | |
449 | | - | |
| 460 | + | |
| 461 | + | |
450 | 462 | | |
451 | 463 | | |
452 | 464 | | |
| |||
470 | 482 | | |
471 | 483 | | |
472 | 484 | | |
473 | | - | |
| 485 | + | |
474 | 486 | | |
475 | 487 | | |
476 | 488 | | |
| |||
496 | 508 | | |
497 | 509 | | |
498 | 510 | | |
499 | | - | |
| 511 | + | |
500 | 512 | | |
501 | 513 | | |
502 | 514 | | |
| |||
577 | 589 | | |
578 | 590 | | |
579 | 591 | | |
580 | | - | |
| 592 | + | |
581 | 593 | | |
582 | 594 | | |
583 | 595 | | |
| |||
589 | 601 | | |
590 | 602 | | |
591 | 603 | | |
592 | | - | |
| 604 | + | |
593 | 605 | | |
594 | 606 | | |
595 | 607 | | |
| |||
604 | 616 | | |
605 | 617 | | |
606 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
607 | 632 | | |
608 | 633 | | |
609 | 634 | | |
| |||
648 | 673 | | |
649 | 674 | | |
650 | 675 | | |
651 | | - | |
| 676 | + | |
652 | 677 | | |
653 | 678 | | |
654 | 679 | | |
| |||
735 | 760 | | |
736 | 761 | | |
737 | 762 | | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
| 763 | + | |
| 764 | + | |
746 | 765 | | |
747 | 766 | | |
748 | 767 | | |
| |||
0 commit comments