Skip to content

Commit

Permalink
Reserve chainId already during initiation of fork (#134)
Browse files Browse the repository at this point in the history
It's better if we know the chainId already before, and not just in the moment of the creation of the forks
  • Loading branch information
josojo authored Dec 28, 2023
1 parent 5d9f881 commit bfdc1a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 10 additions & 4 deletions contracts/ForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ contract ForkingManager is IForkingManager, ForkableStructure {
uint256 public executionTimeForProposal;
uint256 public forkPreparationTime;

// variables to store the reserved chainIds for the forks
uint64 public reservedChainIdForFork1;
uint64 public reservedChainIdForFork2;

/// @inheritdoc IForkingManager
function initialize(
address _zkEVM,
Expand Down Expand Up @@ -103,6 +107,10 @@ contract ForkingManager is IForkingManager, ForkableStructure {
"Invalid new implementations"
);
proposedImplementations = _newImplementations;
reservedChainIdForFork1 = ChainIdManager(chainIdManager)
.getNextUsableChainId();
reservedChainIdForFork2 = ChainIdManager(chainIdManager)
.getNextUsableChainId();
// solhint-disable-next-line not-rely-on-time
executionTimeForProposal = (block.timestamp + forkPreparationTime);
}
Expand Down Expand Up @@ -214,8 +222,7 @@ contract ForkingManager is IForkingManager, ForkableStructure {
trustedAggregator: IPolygonZkEVM(zkEVM).trustedAggregator(),
trustedAggregatorTimeout: IPolygonZkEVM(zkEVM)
.trustedAggregatorTimeout(),
chainID: ChainIdManager(chainIdManager)
.getNextUsableChainId(),
chainID: reservedChainIdForFork1,
forkID: IPolygonZkEVM(zkEVM).forkID()
});
IForkableZkEVM(newInstances.zkEVM.one).initialize(
Expand Down Expand Up @@ -326,8 +333,7 @@ contract ForkingManager is IForkingManager, ForkableStructure {
trustedAggregator: IPolygonZkEVM(zkEVM).trustedAggregator(),
trustedAggregatorTimeout: IPolygonZkEVM(zkEVM)
.trustedAggregatorTimeout(),
chainID: ChainIdManager(chainIdManager)
.getNextUsableChainId(),
chainID: reservedChainIdForFork2,
forkID: newImplementations.forkID > 0
? newImplementations.forkID
: IPolygonZkEVM(zkEVM).forkID()
Expand Down
11 changes: 10 additions & 1 deletion test/ForkingManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ contract ForkingManagerTest is Test {
}
}

function testInitiateForkSetsDispuateDataAndExecutionTime() public {
function testInitiateForkSetsDisputeDataAndExecutionTimeAndReservesChainIds()
public
{
// Mint and approve the arbitration fee for the test contract
forkonomicToken.approve(address(forkmanager), arbitrationFee);
vm.prank(address(this));
Expand Down Expand Up @@ -691,6 +693,13 @@ contract ForkingManagerTest is Test {
receivedExecutionTime,
testTimestamp + forkmanager.forkPreparationTime()
);

uint64 reservedChainIdForFork1 = ForkingManager(forkmanager)
.reservedChainIdForFork1();
assertEq(reservedChainIdForFork1, firstChainId);
uint64 reservedChainIdForFork2 = ForkingManager(forkmanager)
.reservedChainIdForFork2();
assertEq(reservedChainIdForFork2, secondChainId);
}

function testExecuteForkRespectsTime() public {
Expand Down

0 comments on commit bfdc1a9

Please sign in to comment.