Skip to content

Commit

Permalink
Merge pull request #26 from mangata-finance/feature/allign-sequencer-…
Browse files Browse the repository at this point in the history
…updater

Sequencer/Updater alignment
  • Loading branch information
mateuszaaa authored Feb 16, 2024
2 parents 46db609 + 1594f32 commit a43c196
Show file tree
Hide file tree
Showing 14 changed files with 1,050 additions and 404 deletions.
2 changes: 2 additions & 0 deletions rolldown-contract/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deploy:
forge script script/rolldown.s.sol:MyScript --fork-url http://localhost:8545 --broadcast -vvvv
22 changes: 13 additions & 9 deletions rolldown-contract/src/rolldown.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ contract RollDown {
}
oderCounter = inputArray.results[idx].requestId;
}

for (uint256 idx = 0; idx < inputArray.results.length; idx++) {
RequestResult calldata element = inputArray.results[idx];

Expand Down Expand Up @@ -202,21 +203,24 @@ contract RollDown {
} else {
revert("unknown request type");
}

}

// Create a new array with the correct size
uint256[] memory l2UpdatesToBeRemoved = new uint256[](
if(updatesToBeRemovedCounter > 0){
// Create a new array with the correct size
uint256[] memory l2UpdatesToBeRemoved = new uint256[](
updatesToBeRemovedCounter
);
);

// Copy values from temp array to final array
for (uint256 i = 0; i < updatesToBeRemovedCounter; i++) {
// Copy values from temp array to final array
for (uint256 i = 0; i < updatesToBeRemovedCounter; i++) {
l2UpdatesToBeRemoved[i] = l2UpdatesToBeRemovedTemp[i];
}
}

l2UpdatesToRemove[counter++].l2UpdatesToRemove = l2UpdatesToBeRemoved;// .push(l2UpdatesToBeRemoved[i]);
lastProcessedUpdate_origin_l1 += l2UpdatesToBeRemoved.length;
emit L2UpdatesToRemovedAcceptedIntoQueue(counter - 1, l2UpdatesToBeRemoved);
l2UpdatesToRemove[counter++].l2UpdatesToRemove = l2UpdatesToBeRemoved;// .push(l2UpdatesToBeRemoved[i]);
lastProcessedUpdate_origin_l1 += l2UpdatesToBeRemoved.length;
emit L2UpdatesToRemovedAcceptedIntoQueue(counter - 1, l2UpdatesToBeRemoved);
}
}

// Process functions
Expand Down
39 changes: 39 additions & 0 deletions rolldown-contract/test/rolldown.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,43 @@ import {Utilities, MyERC20} from "./utils/Utilities.sol";
assertEq(l1Update.lastProccessedRequestOnL1, 3);
assertEq(l1Update.lastAcceptedRequestOnL1, 4);
}

function testIgnoreDuplicatedUpdates() public {
// Arrange
uint256 amount = 1000;
address tokenAddress = 0xa7c534E6dF83C118A858Cb6fb4C1e8B92b03464b;
rollDown.withdraw(tokenAddress, amount);


RollDown.L2Update memory l2Update;
l2Update.cancles = new RollDown.Cancel[](0);
l2Update.results = new RollDown.RequestResult[](1);
l2Update.results[0] = RollDown.RequestResult({
requestId: 1,
updateType: RollDown.UpdateType.WITHDRAWAL,
status: false
});

// Act
// make sure that executing same request does not alter the state
rollDown.update_l1_from_l2(l2Update);
RollDown.L1Update memory update1 = rollDown.getUpdateForL2();
rollDown.update_l1_from_l2(l2Update);
rollDown.update_l1_from_l2(l2Update);
rollDown.update_l1_from_l2(l2Update);
rollDown.update_l1_from_l2(l2Update);
rollDown.update_l1_from_l2(l2Update);
RollDown.L1Update memory update2 = rollDown.getUpdateForL2();

// Assert
assertEq(update1.lastProccessedRequestOnL1, update2.lastProccessedRequestOnL1);
assertEq(update1.lastAcceptedRequestOnL1, update2.lastAcceptedRequestOnL1);
assertEq(update1.offset, update2.offset);
assertEq(update1.order.length, update2.order.length);
assertEq(update1.pendingDeposits.length, update2.pendingDeposits.length);
assertEq(update1.pendingWithdraws.length, update2.pendingWithdraws.length);
assertEq(update1.pendingCancelResultions.length, update2.pendingCancelResultions.length);
assertEq(update1.pendingL2UpdatesToRemove.length, update2.pendingL2UpdatesToRemove.length);

}
}
5 changes: 5 additions & 0 deletions rollup-sequencer/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export MNEMONIC="//Alice"
export MANGATA_CONTRACT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
export MANGATA_URL=ws://127.0.0.1:9946
export ETH_CHAIN_URL=ws://localhost:8545

Loading

0 comments on commit a43c196

Please sign in to comment.