@bananapus/core-v6 0.0.6 → 0.0.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.
- package/README.md +1 -1
- package/SKILLS.md +1 -1
- package/package.json +1 -1
- package/src/JBRulesets.sol +21 -18
- package/src/interfaces/IJBRulesets.sol +4 -2
- package/test/TestWeightCacheStaleAfterRejection.sol +289 -0
- package/test/invariants/handlers/RulesetsHandler.sol +1 -1
- package/test/units/static/JBRulesets/TestRulesets.sol +2 -2
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +2 -2
package/README.md
CHANGED
package/SKILLS.md
CHANGED
package/package.json
CHANGED
package/src/JBRulesets.sol
CHANGED
|
@@ -840,50 +840,53 @@ contract JBRulesets is JBControlled, IJBRulesets {
|
|
|
840
840
|
return _getStructFor({projectId: projectId, rulesetId: rulesetId});
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
-
/// @notice Cache the value of the ruleset weight.
|
|
843
|
+
/// @notice Cache the value of the ruleset weight for a specific ruleset.
|
|
844
|
+
/// @dev The caller should pass the ruleset ID that `currentOf()` actually uses. When a queued ruleset is rejected
|
|
845
|
+
/// by an approval hook, `currentOf()` falls back to the base ruleset — callers should pass that base ruleset's
|
|
846
|
+
/// ID,
|
|
847
|
+
/// not the rejected latest.
|
|
844
848
|
/// @param projectId The ID of the project having its ruleset weight cached.
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
//
|
|
848
|
-
JBRuleset memory
|
|
849
|
-
_getStructFor({projectId: projectId, rulesetId: latestRulesetIdOf[projectId]});
|
|
849
|
+
/// @param rulesetId The ID of the ruleset to update the cache for.
|
|
850
|
+
function updateRulesetWeightCache(uint256 projectId, uint256 rulesetId) external override {
|
|
851
|
+
// Get the target ruleset.
|
|
852
|
+
JBRuleset memory targetRuleset = _getStructFor({projectId: projectId, rulesetId: rulesetId});
|
|
850
853
|
|
|
851
|
-
// Nothing to cache if the
|
|
854
|
+
// Nothing to cache if the target ruleset doesn't have a duration or a weight cut percent.
|
|
852
855
|
// slither-disable-next-line incorrect-equality
|
|
853
|
-
if (
|
|
856
|
+
if (targetRuleset.duration == 0 || targetRuleset.weightCutPercent == 0) return;
|
|
854
857
|
|
|
855
858
|
// Get a reference to the current cache.
|
|
856
|
-
JBRulesetWeightCache storage cache = _weightCacheOf[projectId][
|
|
859
|
+
JBRulesetWeightCache storage cache = _weightCacheOf[projectId][targetRuleset.id];
|
|
857
860
|
|
|
858
861
|
// Determine the largest start timestamp the cache can be filled to.
|
|
859
862
|
// Cap the advance to the cache lookup threshold per call to stay within the iteration limit in
|
|
860
863
|
// deriveWeightFrom.
|
|
861
864
|
// Multiple calls are needed to advance the cache for large cycle gaps.
|
|
862
|
-
uint256 maxStart =
|
|
863
|
-
|
|
865
|
+
uint256 maxStart = targetRuleset.start + (cache.weightCutMultiple + _WEIGHT_CUT_MULTIPLE_CACHE_LOOKUP_THRESHOLD)
|
|
866
|
+
* targetRuleset.duration;
|
|
864
867
|
|
|
865
868
|
// Determine the start timestamp to derive a weight from for the cache.
|
|
866
869
|
uint256 start = block.timestamp < maxStart ? block.timestamp : maxStart;
|
|
867
870
|
|
|
868
871
|
// The difference between the start of the latest queued ruleset and the start of the ruleset we're caching the
|
|
869
872
|
// weight of.
|
|
870
|
-
uint256 startDistance = start -
|
|
873
|
+
uint256 startDistance = start - targetRuleset.start;
|
|
871
874
|
|
|
872
875
|
// Calculate the weight cut multiple.
|
|
873
876
|
uint168 weightCutMultiple;
|
|
874
877
|
unchecked {
|
|
875
|
-
weightCutMultiple = uint168(startDistance /
|
|
878
|
+
weightCutMultiple = uint168(startDistance / targetRuleset.duration);
|
|
876
879
|
}
|
|
877
880
|
|
|
878
881
|
// Store the new values.
|
|
879
882
|
cache.weight = uint112(
|
|
880
883
|
deriveWeightFrom({
|
|
881
884
|
projectId: projectId,
|
|
882
|
-
baseRulesetStart:
|
|
883
|
-
baseRulesetDuration:
|
|
884
|
-
baseRulesetWeight:
|
|
885
|
-
baseRulesetWeightCutPercent:
|
|
886
|
-
baseRulesetCacheId:
|
|
885
|
+
baseRulesetStart: targetRuleset.start,
|
|
886
|
+
baseRulesetDuration: targetRuleset.duration,
|
|
887
|
+
baseRulesetWeight: targetRuleset.weight,
|
|
888
|
+
baseRulesetWeightCutPercent: targetRuleset.weightCutPercent,
|
|
889
|
+
baseRulesetCacheId: targetRuleset.id,
|
|
887
890
|
start: start
|
|
888
891
|
})
|
|
889
892
|
);
|
|
@@ -145,7 +145,9 @@ interface IJBRulesets {
|
|
|
145
145
|
external
|
|
146
146
|
returns (JBRuleset memory ruleset);
|
|
147
147
|
|
|
148
|
-
/// @notice Updates the weight cache for a
|
|
148
|
+
/// @notice Updates the weight cache for a specific ruleset to allow efficient weight derivation over many cycles.
|
|
149
149
|
/// @param projectId The ID of the project to update the weight cache for.
|
|
150
|
-
|
|
150
|
+
/// @param rulesetId The ID of the ruleset to update the cache for. This should be the ruleset that currentOf()
|
|
151
|
+
/// actually uses, which may differ from latestRulesetIdOf if the latest was rejected by an approval hook.
|
|
152
|
+
function updateRulesetWeightCache(uint256 projectId, uint256 rulesetId) external;
|
|
151
153
|
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.6;
|
|
3
|
+
|
|
4
|
+
import /* {*} from */ "./helpers/TestBaseWorkflow.sol";
|
|
5
|
+
|
|
6
|
+
/// @notice Mock approval hook that ALWAYS rejects queued rulesets.
|
|
7
|
+
contract AlwaysRejectApprovalHook is IJBRulesetApprovalHook {
|
|
8
|
+
function DURATION() external pure override returns (uint256) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function approvalStatusOf(uint256, JBRuleset memory) external pure override returns (JBApprovalStatus) {
|
|
13
|
+
return JBApprovalStatus.Failed;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
|
|
17
|
+
return interfaceId == type(IJBRulesetApprovalHook).interfaceId || interfaceId == type(IERC165).interfaceId;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// @notice Regression tests for the weight cache stale-after-rejection fix.
|
|
22
|
+
///
|
|
23
|
+
/// Before the fix, updateRulesetWeightCache() only updated the cache for latestRulesetIdOf.
|
|
24
|
+
/// When a queued ruleset was rejected by an approval hook, currentOf() would fall back to
|
|
25
|
+
/// the base ruleset, but that base ruleset's cache could never be updated — causing
|
|
26
|
+
/// deriveWeightFrom() to revert with WeightCacheRequired after >20,000 cycles.
|
|
27
|
+
///
|
|
28
|
+
/// The fix adds a rulesetId parameter to updateRulesetWeightCache() so callers can
|
|
29
|
+
/// specify exactly which ruleset's cache to update — typically the one currentOf() uses.
|
|
30
|
+
contract TestWeightCacheStaleAfterRejection is TestBaseWorkflow {
|
|
31
|
+
IJBController private _controller;
|
|
32
|
+
IJBRulesets private _rulesets;
|
|
33
|
+
address private _projectOwner;
|
|
34
|
+
AlwaysRejectApprovalHook private _rejectHook;
|
|
35
|
+
|
|
36
|
+
uint256 private _projectId;
|
|
37
|
+
|
|
38
|
+
function setUp() public override {
|
|
39
|
+
super.setUp();
|
|
40
|
+
_controller = jbController();
|
|
41
|
+
_rulesets = jbRulesets();
|
|
42
|
+
_projectOwner = multisig();
|
|
43
|
+
_rejectHook = new AlwaysRejectApprovalHook();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// @notice Launch a project with a 1-second duration ruleset, weight decay, and an always-reject approval hook.
|
|
47
|
+
function _launchProject() internal returns (uint256 projectId) {
|
|
48
|
+
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](1);
|
|
49
|
+
|
|
50
|
+
JBRulesetMetadata memory metadata = JBRulesetMetadata({
|
|
51
|
+
reservedPercent: 0,
|
|
52
|
+
cashOutTaxRate: 0,
|
|
53
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
54
|
+
pausePay: false,
|
|
55
|
+
pauseCreditTransfers: false,
|
|
56
|
+
allowOwnerMinting: false,
|
|
57
|
+
allowSetCustomToken: false,
|
|
58
|
+
allowTerminalMigration: false,
|
|
59
|
+
allowSetTerminals: false,
|
|
60
|
+
ownerMustSendPayouts: false,
|
|
61
|
+
allowSetController: false,
|
|
62
|
+
allowAddAccountingContext: true,
|
|
63
|
+
allowAddPriceFeed: false,
|
|
64
|
+
holdFees: false,
|
|
65
|
+
useTotalSurplusForCashOuts: true,
|
|
66
|
+
useDataHookForPay: false,
|
|
67
|
+
useDataHookForCashOut: false,
|
|
68
|
+
dataHook: address(0),
|
|
69
|
+
metadata: 0
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
rulesetConfigurations[0] = JBRulesetConfig({
|
|
73
|
+
mustStartAtOrAfter: 0,
|
|
74
|
+
duration: 1, // 1 second — cycles very fast
|
|
75
|
+
weight: 1000e18,
|
|
76
|
+
weightCutPercent: 1, // Non-zero so weight decays each cycle
|
|
77
|
+
approvalHook: _rejectHook, // Will reject all subsequent rulesets
|
|
78
|
+
metadata: metadata,
|
|
79
|
+
splitGroups: new JBSplitGroup[](0),
|
|
80
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
vm.prank(_projectOwner);
|
|
84
|
+
projectId = _controller.launchProjectFor({
|
|
85
|
+
owner: _projectOwner,
|
|
86
|
+
projectUri: "ipfs://test",
|
|
87
|
+
rulesetConfigurations: rulesetConfigurations,
|
|
88
|
+
terminalConfigurations: new JBTerminalConfig[](0),
|
|
89
|
+
memo: ""
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// @notice Helper to build a new ruleset config for queuing (will be rejected).
|
|
94
|
+
function _buildRejectedConfig() internal pure returns (JBRulesetConfig[] memory newConfigs) {
|
|
95
|
+
newConfigs = new JBRulesetConfig[](1);
|
|
96
|
+
newConfigs[0] = JBRulesetConfig({
|
|
97
|
+
mustStartAtOrAfter: 0,
|
|
98
|
+
duration: 1,
|
|
99
|
+
weight: 500e18, // Specific weight, not 1 (inherit), to avoid deriveWeightFrom during queuing
|
|
100
|
+
weightCutPercent: 1,
|
|
101
|
+
approvalHook: IJBRulesetApprovalHook(address(0)),
|
|
102
|
+
metadata: JBRulesetMetadata({
|
|
103
|
+
reservedPercent: 0,
|
|
104
|
+
cashOutTaxRate: 0,
|
|
105
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
106
|
+
pausePay: false,
|
|
107
|
+
pauseCreditTransfers: false,
|
|
108
|
+
allowOwnerMinting: false,
|
|
109
|
+
allowSetCustomToken: false,
|
|
110
|
+
allowTerminalMigration: false,
|
|
111
|
+
allowSetTerminals: false,
|
|
112
|
+
ownerMustSendPayouts: false,
|
|
113
|
+
allowSetController: false,
|
|
114
|
+
allowAddAccountingContext: true,
|
|
115
|
+
allowAddPriceFeed: false,
|
|
116
|
+
holdFees: false,
|
|
117
|
+
useTotalSurplusForCashOuts: true,
|
|
118
|
+
useDataHookForPay: false,
|
|
119
|
+
useDataHookForCashOut: false,
|
|
120
|
+
dataHook: address(0),
|
|
121
|
+
metadata: 0
|
|
122
|
+
}),
|
|
123
|
+
splitGroups: new JBSplitGroup[](0),
|
|
124
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// @notice REGRESSION: After queuing a rejected ruleset and warping >20k cycles,
|
|
129
|
+
/// updateRulesetWeightCache() should update the active base ruleset's cache (not just the
|
|
130
|
+
/// rejected latest), allowing currentOf() to succeed.
|
|
131
|
+
function test_weightCache_fixedAfterApprovalRejection() public {
|
|
132
|
+
_projectId = _launchProject();
|
|
133
|
+
|
|
134
|
+
// Verify the project works initially.
|
|
135
|
+
JBRuleset memory initial = _rulesets.currentOf(_projectId);
|
|
136
|
+
assertGt(initial.weight, 0, "Initial weight should be set");
|
|
137
|
+
|
|
138
|
+
// Queue a new ruleset (B). It will be rejected by A's approval hook.
|
|
139
|
+
vm.prank(_projectOwner);
|
|
140
|
+
_controller.queueRulesetsOf({projectId: _projectId, rulesetConfigurations: _buildRejectedConfig(), memo: ""});
|
|
141
|
+
|
|
142
|
+
// Verify B is now the latest but A is still the current (B is rejected).
|
|
143
|
+
uint256 latestId = _rulesets.latestRulesetIdOf(_projectId);
|
|
144
|
+
assertGt(latestId, initial.id, "Latest should be B");
|
|
145
|
+
JBRuleset memory afterQueue = _rulesets.currentOf(_projectId);
|
|
146
|
+
assertEq(afterQueue.id, initial.id, "Current should still be A (B is rejected)");
|
|
147
|
+
|
|
148
|
+
// Warp beyond the 20,000-cycle cache threshold.
|
|
149
|
+
vm.warp(block.timestamp + 20_001);
|
|
150
|
+
|
|
151
|
+
// Before the fix, updateRulesetWeightCache only accepted projectId and always updated
|
|
152
|
+
// latestRulesetIdOf — which is the rejected B. A's cache could never be updated.
|
|
153
|
+
// After the fix, the caller passes the rulesetId of the active base ruleset (A).
|
|
154
|
+
_rulesets.updateRulesetWeightCache(_projectId, initial.id);
|
|
155
|
+
|
|
156
|
+
// Now currentOf() should succeed because A's cache is populated.
|
|
157
|
+
JBRuleset memory afterFix = _rulesets.currentOf(_projectId);
|
|
158
|
+
assertEq(afterFix.id, initial.id, "Should still use ruleset A");
|
|
159
|
+
// Weight should be less than initial (decayed over 20k+ cycles).
|
|
160
|
+
assertLt(afterFix.weight, initial.weight, "Weight should have decayed");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// @notice Multiple cache updates work correctly when the latest is rejected.
|
|
164
|
+
/// Verifies that progressive caching (multiple updateRulesetWeightCache calls) also
|
|
165
|
+
/// works for the base ruleset, not just the latest.
|
|
166
|
+
function test_weightCache_progressiveCachingForRejectedLatest() public {
|
|
167
|
+
_projectId = _launchProject();
|
|
168
|
+
|
|
169
|
+
// Capture the base ruleset (A) ID before warping — after the warp, currentOf() would revert.
|
|
170
|
+
uint256 baseRulesetId = _rulesets.currentOf(_projectId).id;
|
|
171
|
+
|
|
172
|
+
// Queue a rejected ruleset.
|
|
173
|
+
vm.prank(_projectOwner);
|
|
174
|
+
_controller.queueRulesetsOf({projectId: _projectId, rulesetConfigurations: _buildRejectedConfig(), memo: ""});
|
|
175
|
+
|
|
176
|
+
// Warp far into the future (50k cycles — needs 3 cache update calls).
|
|
177
|
+
vm.warp(block.timestamp + 50_001);
|
|
178
|
+
|
|
179
|
+
// First cache update covers up to 20k cycles.
|
|
180
|
+
_rulesets.updateRulesetWeightCache(_projectId, baseRulesetId);
|
|
181
|
+
// Second covers up to 40k.
|
|
182
|
+
_rulesets.updateRulesetWeightCache(_projectId, baseRulesetId);
|
|
183
|
+
// Third covers up to 50k.
|
|
184
|
+
_rulesets.updateRulesetWeightCache(_projectId, baseRulesetId);
|
|
185
|
+
|
|
186
|
+
// currentOf() should now work.
|
|
187
|
+
JBRuleset memory current = _rulesets.currentOf(_projectId);
|
|
188
|
+
assertGt(current.cycleNumber, 50_000, "Should be past 50k cycles");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// @notice With the fix applied, payments and cashouts continue to work even after
|
|
192
|
+
/// a rejected ruleset + large cycle gap.
|
|
193
|
+
function test_weightCache_terminalOperationsWorkAfterFix() public {
|
|
194
|
+
// Set up terminal for the project.
|
|
195
|
+
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
196
|
+
accountingContexts[0] = JBAccountingContext({
|
|
197
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
|
|
201
|
+
terminalConfigs[0] =
|
|
202
|
+
JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: accountingContexts});
|
|
203
|
+
|
|
204
|
+
// Launch with terminals.
|
|
205
|
+
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](1);
|
|
206
|
+
rulesetConfigurations[0] = JBRulesetConfig({
|
|
207
|
+
mustStartAtOrAfter: 0,
|
|
208
|
+
duration: 1,
|
|
209
|
+
weight: 1000e18,
|
|
210
|
+
weightCutPercent: 1,
|
|
211
|
+
approvalHook: _rejectHook,
|
|
212
|
+
metadata: JBRulesetMetadata({
|
|
213
|
+
reservedPercent: 0,
|
|
214
|
+
cashOutTaxRate: 0,
|
|
215
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
216
|
+
pausePay: false,
|
|
217
|
+
pauseCreditTransfers: false,
|
|
218
|
+
allowOwnerMinting: false,
|
|
219
|
+
allowSetCustomToken: false,
|
|
220
|
+
allowTerminalMigration: false,
|
|
221
|
+
allowSetTerminals: false,
|
|
222
|
+
ownerMustSendPayouts: false,
|
|
223
|
+
allowSetController: false,
|
|
224
|
+
allowAddAccountingContext: true,
|
|
225
|
+
allowAddPriceFeed: false,
|
|
226
|
+
holdFees: false,
|
|
227
|
+
useTotalSurplusForCashOuts: true,
|
|
228
|
+
useDataHookForPay: false,
|
|
229
|
+
useDataHookForCashOut: false,
|
|
230
|
+
dataHook: address(0),
|
|
231
|
+
metadata: 0
|
|
232
|
+
}),
|
|
233
|
+
splitGroups: new JBSplitGroup[](0),
|
|
234
|
+
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
vm.prank(_projectOwner);
|
|
238
|
+
_projectId = _controller.launchProjectFor({
|
|
239
|
+
owner: _projectOwner,
|
|
240
|
+
projectUri: "ipfs://test",
|
|
241
|
+
rulesetConfigurations: rulesetConfigurations,
|
|
242
|
+
terminalConfigurations: terminalConfigs,
|
|
243
|
+
memo: ""
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Make a payment so there are funds in the terminal.
|
|
247
|
+
address payer = makeAddr("payer");
|
|
248
|
+
vm.deal(payer, 10 ether);
|
|
249
|
+
vm.prank(payer);
|
|
250
|
+
jbMultiTerminal().pay{value: 5 ether}({
|
|
251
|
+
projectId: _projectId,
|
|
252
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
253
|
+
amount: 5 ether,
|
|
254
|
+
beneficiary: payer,
|
|
255
|
+
minReturnedTokens: 0,
|
|
256
|
+
memo: "",
|
|
257
|
+
metadata: ""
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Capture the base ruleset (A) ID before queuing a rejected one.
|
|
261
|
+
uint256 baseRulesetId = _rulesets.currentOf(_projectId).id;
|
|
262
|
+
|
|
263
|
+
// Queue a rejected ruleset.
|
|
264
|
+
vm.prank(_projectOwner);
|
|
265
|
+
_controller.queueRulesetsOf({projectId: _projectId, rulesetConfigurations: _buildRejectedConfig(), memo: ""});
|
|
266
|
+
|
|
267
|
+
// Warp beyond 20k cycles.
|
|
268
|
+
vm.warp(block.timestamp + 20_001);
|
|
269
|
+
|
|
270
|
+
// Update the cache for the active base ruleset (A), not the rejected latest (B).
|
|
271
|
+
_rulesets.updateRulesetWeightCache(_projectId, baseRulesetId);
|
|
272
|
+
|
|
273
|
+
// Payments should succeed after cache update.
|
|
274
|
+
vm.deal(payer, 1 ether);
|
|
275
|
+
vm.prank(payer);
|
|
276
|
+
jbMultiTerminal().pay{value: 1 ether}({
|
|
277
|
+
projectId: _projectId,
|
|
278
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
279
|
+
amount: 1 ether,
|
|
280
|
+
beneficiary: payer,
|
|
281
|
+
minReturnedTokens: 0,
|
|
282
|
+
memo: "",
|
|
283
|
+
metadata: ""
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
uint256 tokenBalance = jbTokens().totalBalanceOf(payer, _projectId);
|
|
287
|
+
assertGt(tokenBalance, 0, "Payer should have tokens after fix");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -106,6 +106,6 @@ contract RulesetsHandler is Test {
|
|
|
106
106
|
|
|
107
107
|
/// @notice Update the weight cache for the project.
|
|
108
108
|
function updateWeightCache() public {
|
|
109
|
-
try rulesets.updateRulesetWeightCache(projectId) {} catch {}
|
|
109
|
+
try rulesets.updateRulesetWeightCache(projectId, rulesets.latestRulesetIdOf(projectId)) {} catch {}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -550,10 +550,10 @@ contract TestJBRulesetsUnits_Local is JBTest {
|
|
|
550
550
|
// Update the weight cache incrementally — each call advances by at most 20,000 cycles.
|
|
551
551
|
// With 20,000 cycles and 10% weight cut per cycle, weight reaches 0 well before 20,000 cycles.
|
|
552
552
|
// First call: advances cache by up to 20,000 cycles (weight decays to 0).
|
|
553
|
-
_rulesets.updateRulesetWeightCache(_projectId);
|
|
553
|
+
_rulesets.updateRulesetWeightCache(_projectId, _rulesets.latestRulesetIdOf(_projectId));
|
|
554
554
|
|
|
555
555
|
// Second call during the same block should mirror the previous (cache already covers current time).
|
|
556
|
-
_rulesets.updateRulesetWeightCache(_projectId);
|
|
556
|
+
_rulesets.updateRulesetWeightCache(_projectId, _rulesets.latestRulesetIdOf(_projectId));
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
function test_QueueForApprovalHookDNSupportInterface() external {
|
|
@@ -48,7 +48,7 @@ contract TestUpdateRulesetWeightCache_Local is JBRulesetsSetup {
|
|
|
48
48
|
function test_WhenLatestRulesetOfProjectDurationOrWeightCutPercentEQZero() external {
|
|
49
49
|
// it will return without updating
|
|
50
50
|
|
|
51
|
-
_rulesets.updateRulesetWeightCache(_projectId);
|
|
51
|
+
_rulesets.updateRulesetWeightCache(_projectId, _rulesets.latestRulesetIdOf(_projectId));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function test_WhenLatestRulesetHasProperDurationAndWeightCutPercent() external {
|
|
@@ -86,6 +86,6 @@ contract TestUpdateRulesetWeightCache_Local is JBRulesetsSetup {
|
|
|
86
86
|
mustStartAtOrAfter: _mustStartAt
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
_rulesets.updateRulesetWeightCache(_projectId);
|
|
89
|
+
_rulesets.updateRulesetWeightCache(_projectId, _rulesets.latestRulesetIdOf(_projectId));
|
|
90
90
|
}
|
|
91
91
|
}
|