Skip to content

Conversation

@mejango
Copy link
Contributor

@mejango mejango commented Aug 21, 2023

  • multiple FC's per block (fc.configuration gets incremented if made during same block)
  • can't override Approved reconfiguration if it has a ballot

@mejango mejango marked this pull request as ready for review September 11, 2023 22:18
@simplemachine92
Copy link
Member

Reviewing this and debugging the failed test.

@simplemachine92
Copy link
Member

simplemachine92 commented Sep 15, 2023

For the failed test here, it looks like before that configurations would be overwritten during a rolled-over cycle. Now that isn't the case, so I've rewritten testMultipleReconfigurationOnRolledOver() to follow the new logic

(also, please tell me if there is a better way to propose changes to a file outside the scope of a PR.. I feel like I would have to push changes over your branch, no?)

function testMultipleReconfigurationOnRolledOver() public {
uint256 weightFirstReconfiguration = 1234 * 10 ** 18;
uint256 weightSecondReconfiguration = 6969 * 10 ** 18;
uint256 projectId = controller.launchProjectFor(
multisig(),
_projectMetadata,
_data,
_metadata,
0, // Start asap
_groupedSplits,
_fundAccessConstraints,
_terminals,
""
);
JBFundingCycle memory fundingCycle = jbFundingCycleStore().currentOf(projectId);
// Initial funding cycle data
assertEq(fundingCycle.number, 1);
assertEq(fundingCycle.weight, _data.weight);
uint256 currentConfiguration = fundingCycle.configuration;
// Jump to FC+1, rolled over
vm.warp(block.timestamp + fundingCycle.duration);
// First reconfiguration
vm.prank(multisig());
controller.reconfigureFundingCyclesOf(
projectId,
JBFundingCycleData({duration: 6 days, weight: weightFirstReconfiguration, discountRate: 0, ballot: _ballot}), // 3days ballot
_metadata,
0, // Start asap
_groupedSplits,
_fundAccessConstraints,
""
);
vm.warp(block.timestamp + 1); // Avoid overwrite
// Second reconfiguration (different configuration)
vm.prank(multisig());
controller.reconfigureFundingCyclesOf(
projectId,
JBFundingCycleData({duration: 6 days, weight: weightSecondReconfiguration, discountRate: 0, ballot: _ballot}), // 3days ballot
_metadata,
0, // Start asap
_groupedSplits,
_fundAccessConstraints,
""
);
uint256 secondReconfiguration = block.timestamp;
// Shouldn't have changed, still in FC#2, rolled over from FC#1
fundingCycle = jbFundingCycleStore().currentOf(projectId);
assertEq(fundingCycle.number, 2);
assertEq(fundingCycle.configuration, currentConfiguration);
assertEq(fundingCycle.weight, _data.weight);
// Jump to after the ballot passed, but before the next FC
vm.warp(fundingCycle.start + fundingCycle.duration - 1);
// Queued should be the second reconfiguration
JBFundingCycle memory queuedFundingCycle = jbFundingCycleStore().queuedOf(projectId);
assertEq(queuedFundingCycle.number, 3);
assertEq(queuedFundingCycle.configuration, secondReconfiguration);
assertEq(queuedFundingCycle.weight, weightSecondReconfiguration);
vm.warp(fundingCycle.start + fundingCycle.duration);
// Second reconfiguration should be now the current one
JBFundingCycle memory newFundingCycle = jbFundingCycleStore().currentOf(projectId);
assertEq(newFundingCycle.number, 3);
assertEq(newFundingCycle.configuration, secondReconfiguration);
assertEq(newFundingCycle.weight, weightSecondReconfiguration);
}

Becomes

function testMultipleReconfigurationOnRolledOver() public {
        uint256 weightFirstReconfiguration = 1234 * 10 ** 18;
        uint256 weightSecondReconfiguration = 6969 * 10 ** 18;

        uint256 projectId = controller.launchProjectFor(
            multisig(),
            _projectMetadata,
            _data,
            _metadata,
            0, // Start asap
            _groupedSplits,
            _fundAccessConstraints,
            _terminals,
            ""
        );

        JBFundingCycle memory fundingCycle = jbFundingCycleStore().currentOf(projectId);

        // Initial funding cycle data
        assertEq(fundingCycle.number, 1);
        assertEq(fundingCycle.weight, _data.weight);

        uint256 currentConfiguration = fundingCycle.configuration;

        // Jump to FC+1, rolled over
        vm.warp(block.timestamp + fundingCycle.duration);

        // First reconfiguration
        vm.prank(multisig());
        controller.reconfigureFundingCyclesOf(
            projectId,
            JBFundingCycleData({duration: 6 days, weight: weightFirstReconfiguration, discountRate: 0, ballot: _ballot}), // 3days ballot
            _metadata,
            0, // Start asap
            _groupedSplits,
            _fundAccessConstraints,
            ""
        );

        uint256 firstReconfiguration = block.timestamp;

        vm.warp(block.timestamp + 1); // Avoid overwrite

        // Second reconfiguration (different configuration)
        vm.prank(multisig());
        controller.reconfigureFundingCyclesOf(
            projectId,
            JBFundingCycleData({duration: 6 days, weight: weightSecondReconfiguration, discountRate: 0, ballot: _ballot}), // 3days ballot
            _metadata,
            0, // Start asap
            _groupedSplits,
            _fundAccessConstraints,
            ""
        );
        uint256 secondReconfiguration = block.timestamp;

        // Shouldn't have changed, still in FC#2, rolled over from FC#1
        fundingCycle = jbFundingCycleStore().currentOf(projectId);
        assertEq(fundingCycle.number, 2);
        assertEq(fundingCycle.configuration, currentConfiguration);
        assertEq(fundingCycle.weight, _data.weight);

        // Jump to after the ballot passed, but before the next FC
        vm.warp(fundingCycle.start + fundingCycle.duration - 1);

        // Queued should be the first reconfiguration
        JBFundingCycle memory queuedFirstReconfigFundingCycle = jbFundingCycleStore().queuedOf(projectId);
        assertEq(queuedFirstReconfigFundingCycle.number, 3);
        assertEq(queuedFirstReconfigFundingCycle.configuration, firstReconfiguration);
        assertEq(queuedFirstReconfigFundingCycle.weight, weightFirstReconfiguration);

        vm.warp(fundingCycle.start + fundingCycle.duration);

        // First reconfiguration should now be the current one
        JBFundingCycle memory newlyActiveFirstReconfigFundingCycle = jbFundingCycleStore().currentOf(projectId);
        assertEq(newlyActiveFirstReconfigFundingCycle.number, 3);
        assertEq(newlyActiveFirstReconfigFundingCycle.configuration, firstReconfiguration);
        assertEq(newlyActiveFirstReconfigFundingCycle.weight, weightFirstReconfiguration);

        // Queued should now be the second reconfiguration
        JBFundingCycle memory queuedSecondReconfigFundingCycle = jbFundingCycleStore().queuedOf(projectId);
        assertEq(queuedSecondReconfigFundingCycle.configuration, secondReconfiguration);
        assertEq(queuedSecondReconfigFundingCycle.weight, weightSecondReconfiguration);

        // Warp to when second reconfig becomes active
        vm.warp(queuedSecondReconfigFundingCycle.start + fundingCycle.duration);

        // currentOf and queuedOf should match here as it will use the last configured base cycle
        JBFundingCycle memory newlyActiveSecondReconfigFundingCycle = jbFundingCycleStore().currentOf(projectId);
        assertEq(newlyActiveSecondReconfigFundingCycle.configuration, secondReconfiguration);
        assertEq(newlyActiveSecondReconfigFundingCycle.weight, weightSecondReconfiguration);

        // Queued should be the last base cycle carried over
        JBFundingCycle memory queuedBaseFCFromSecondReconfig = jbFundingCycleStore().queuedOf(projectId);
        assertEq(queuedBaseFCFromSecondReconfig.configuration, secondReconfiguration);
        assertEq(queuedBaseFCFromSecondReconfig.weight, weightSecondReconfiguration);
    }

@mejango
Copy link
Contributor Author

mejango commented Sep 15, 2023

A PR against this PR would be ideal, unless you want write access directly to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants