Skip to content

Commit

Permalink
[MGX-1410] Ferry deposit service (#261)
Browse files Browse the repository at this point in the history
* Ferry service - ethereum only

* make aware of different chains (ethereum/arbitrum)

* apply lints

* fix minor bugs

* fix unit tests

* throw when not enought funds to cover tx fee

* fix formatting

* rework env variables

* move deposits to separate file

* extract L1Interface

* export L2Interface

* move L1 & L2 interfaces to separate files

* clenup

* add docker ignore

* default configs for ferry

* ferry deposit enabled in docker compose

* rename test files

* add delay parameter

* align tests

* align sequencer to contract changes

* fixing automatic cancellation
  • Loading branch information
mateuszaaa authored Oct 8, 2024
1 parent 4607ac7 commit 73f6a6f
Show file tree
Hide file tree
Showing 27 changed files with 39,479 additions and 46 deletions.
16 changes: 15 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ROLLUP_SEQUENCER_MNEMONIC_ETH="0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd2
ROLLUP_SEQUENCER_L1_CHAIN_ETH="Ethereum"

ROLLUP_SEQUENCER_ETH_CHAIN_URL_ARB=ws://arbitrum-stub:8546
ROLLUP_SEQUENCER_MNEMONIC_ARB="0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b"
ROLLUP_SEQUENCER_L1_CHAIN_ARB="Arbitrum"
ROLLUP_SEQUENCER_MNEMONIC_ARB="0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b"

ROLLUP_SEQUENCER_BLOCK_NUMBER_DELAY=0

Expand All @@ -23,3 +23,17 @@ ROLLUP_UPDATER_FINALIZATION_SOURCE="relay"
# AGGREGATOR
SUBSTRATE_RPC_URL=ws://node-alice:9944
MANGATA_NODE_VERSION=eth-rollup-develop-fast

# Ferry deposit
ETH_FERRY_DEPOSIT_MANGATA_NODE_URL=ws://node-alice:9944
ETH_FERRY_DEPOSIT_CHAIN_URL=ws://eth-stub:8545
# Address: 0xc5Ec35873Bf8cE5BC4AC8E2349e489213A3C560F
ETH_FERRY_DEPOSIT_MNEMONIC=0x4871c416bd9404c9dade584c9188a4c56f64c38a7d83048684e70fc065c31e44
ETH_FERRY_DEPOSIT_L1_CHAIN=Ethereum
ETH_FERRY_MANGATA_CONTRACT_ADDRESS=0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc
ETH_FERRY_DEPOSIT_TX_COST=1000000000000000000000
#1k GASP
ETH_FERRY_DEPOSIT_TX_COST=1000000000000000000000
#10k GASP
ETH_FERRY_DEPOSIT_MIN_PROFIT=10000000000000000000000
ETH_FERRY_DEPOSIT_BLOCK_DELAY=0
10 changes: 5 additions & 5 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ include:
- path: ./avs-aggregator/compose.yml
- path: ./avs-finalizer/compose.yml
- path: ./rollup-sequencer/compose.yml
# - path: ./rollup-updater/compose.yml
- path: ./contracts/compose.yml
- path: ./gasp-syncer/compose.yml
- path: ./ferry-deposit/compose.yml

services:
eth-stub:
Expand Down Expand Up @@ -34,11 +34,11 @@ services:
interval: 2s
timeout: 10s
retries: 3

node-alice:
image: mangatasolutions/rollup-node:${MANGATA_NODE_VERSION:-eth-rollup-develop}
platform: linux/amd64
command:
command:
- --alith
- --chain=rollup-local-seq
- --base-path=/data
Expand All @@ -49,11 +49,11 @@ services:
ports:
- 9944:9944
- 30333:30333

node-bob:
image: mangatasolutions/rollup-node:${MANGATA_NODE_VERSION:-eth-rollup-develop}
platform: linux/amd64
command:
command:
- --baltathar
- --chain=rollup-local-seq
- --base-path=/data
Expand Down
21 changes: 17 additions & 4 deletions contracts/src/Rolldown.sol
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,24 @@ contract Rolldown is
}

function process_l2_update_cancels(Cancel calldata cancel) private {
L1Update memory pending = getPendingRequests(
bool cancelJustified = false;

if (cancel.range.end > counter - 1 ){
cancelJustified = true;
}else{
L1Update memory pending = getPendingRequests(
cancel.range.start,
cancel.range.end
);
bytes32 correct_hash = keccak256(abi.encode(pending));
);
bytes32 correct_hash = keccak256(abi.encode(pending));
cancelJustified = correct_hash != cancel.hash;
}
uint256 timeStamp = block.timestamp;

CancelResolution memory resolution = CancelResolution({
requestId: RequestId({origin: Origin.L1, id: counter++}),
l2RequestId: cancel.requestId.id,
cancelJustified: correct_hash != cancel.hash,
cancelJustified: cancelJustified,
timeStamp: timeStamp
});

Expand Down Expand Up @@ -383,11 +390,17 @@ contract Rolldown is
uint256 depositsCounter = 0;
uint256 cancelsCounter = 0;

if (start == 0 && end == 0){
return result;
}

for (uint256 requestId = start; requestId <= end; requestId++) {
if (deposits[requestId].requestId.id != 0) {
depositsCounter++;
} else if (cancelResolutions[requestId].requestId.id != 0) {
cancelsCounter++;
}else {
revert("Invalid range");
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/RolldownStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract contract RolldownStorage is IRolldown {
// NOTE: PR DESC
// mapping(uint256 => WithdrawalResolution) public withdrawalResolutions;
mapping(uint256 => CancelResolution) public cancelResolutions;
mapping(uint256 => Deposit) internal deposits;
mapping(uint256 => Deposit) public deposits;
// NOTE: PR DESC
// mapping(uint256 => L2UpdatesToRemove) internal l2UpdatesToRemove;
// NOTE: PR DESC
Expand Down
12 changes: 4 additions & 8 deletions contracts/test/rolldown.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ contract RolldownTest is Test, IRolldownPrimitives {
rolldown.update_l1_from_l2(merkle_root, range);
vm.stopPrank();

L1Update memory l1UpdateBefore = rolldown.getPendingRequests(1,2);
L1Update memory l1UpdateBefore = rolldown.getPendingRequests(1,1);
assertEq(l1UpdateBefore.pendingDeposits.length, 1);
assertEq(l1UpdateBefore.pendingCancelResolutions.length, 0);

Expand Down Expand Up @@ -446,7 +446,7 @@ contract RolldownTest is Test, IRolldownPrimitives {
rolldown.update_l1_from_l2(merkle_root, range);
vm.stopPrank();

L1Update memory l1UpdateBefore = rolldown.getPendingRequests(1,2);
L1Update memory l1UpdateBefore = rolldown.getPendingRequests(1,1);
assertEq(l1UpdateBefore.pendingDeposits.length, 1);
assertEq(l1UpdateBefore.pendingCancelResolutions.length, 0);

Expand All @@ -455,7 +455,7 @@ contract RolldownTest is Test, IRolldownPrimitives {
emit IRolldownPrimitives.DisputeResolutionAcceptedIntoQueue(1, false);
rolldown.close_cancel(cancel, merkle_root, proofs);
vm.stopPrank();

//validate pendingL2requests
L1Update memory l1UpdateAfter = rolldown.getPendingRequests(1,2);
assertEq(l1UpdateAfter.pendingDeposits.length, 1);
Expand Down Expand Up @@ -495,14 +495,10 @@ contract RolldownTest is Test, IRolldownPrimitives {
rolldown.close_withdrawal(withdrawal, merkle_root, proofs);
vm.stopPrank();
assertEq(token.balanceOf(recipient), 0);

assertEq(rolldown.lastProcessedUpdate_origin_l2(), 1 );
address status = rolldown.processedL2Requests(merkle_root);
assertTrue(status != rolldown.CLOSED());
L1Update memory l1UpdateBefore = rolldown.getPendingRequests(1,2);
assertEq(l1UpdateBefore.pendingDeposits.length, 0);
assertEq(l1UpdateBefore.pendingCancelResolutions.length, 0);

}

function testAcceptOnlyConsecutiveUpdatesWithoutGaps() public {
Expand Down
14 changes: 14 additions & 0 deletions ferry-deposit/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.git
node_modules
.env*
.vscode
.github
**/Dockerfile
**/build/
**/dist/
**/test-results/
ops
skaffold.yml
README.md
docker-compose*
.gitignore
25 changes: 25 additions & 0 deletions ferry-deposit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:18.20.4 AS build

WORKDIR /app

COPY package.json package-lock.json /app/
RUN npm ci

COPY . .
RUN npm run build && npm prune --production

FROM node:18.19-slim

# Add Tini, according to: https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
RUN apt-get update && apt-get install -y tini && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/usr/bin/tini", "--"]

ENV NODE_ENV=production

WORKDIR /app

COPY package*.json ./
COPY --from=build /app/build /app/build
COPY --from=build /app/node_modules /app/node_modules

CMD ["node", "build/src/index.js"]
23 changes: 23 additions & 0 deletions ferry-deposit/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"style": {
"noNonNullAssertion": "off"
},
"correctness": {
"noConstantCondition": "off"
},
"complexity": {
"noForEach": "off"
}
}
}
}
20 changes: 20 additions & 0 deletions ferry-deposit/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
eth-ferry-deposit:
restart: unless-stopped
platform: linux/amd64
image: mangatasolutions/ferry-deposit:local-eth
depends_on:
eth-contracts-deployment:
condition: service_completed_successfully
node-alice:
condition: service_started
build: .
environment:
MANGATA_NODE_URL: ${ETH_FERRY_DEPOSIT_MANGATA_NODE_URL:-wss://collator-01-ws-rococo.mangata.online}
ETH_CHAIN_URL: ${ETH_FERRY_DEPOSIT_CHAIN_URL:-wss://ethereum.publicnode.com}
MANGATA_CONTRACT_ADDRESS: ${ETH_FERRY_MANGATA_CONTRACT_ADDRESS:-0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc}
MNEMONIC: ${ETH_FERRY_DEPOSIT_MNEMONIC}
L1_CHAIN: ${ETH_FERRY_DEPOSIT_L1_CHAIN}
MIN_PROFIT: ${ETH_FERRY_DEPOSIT_MIN_PROFIT}
TX_COST: ${ETH_FERRY_DEPOSIT_TX_COST}
BLOCK_DELAY: ${ETH_FERRY_DEPOSIT_BLOCK_DELAY}
9 changes: 9 additions & 0 deletions ferry-deposit/env-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

export MANGATA_NODE_URL=ws://127.0.0.1:9944
export ETH_CHAIN_URL=http://127.0.0.1:8545
export MANGATA_CONTRACT_ADDRESS=0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc
export MNEMONIC=0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b
export L1_CHAIN="Ethereum"
export MIN_PROFIT=1000000000000000000000
export TX_COST=1000000000000000000000
export BLOCK_DELAY=0
Loading

0 comments on commit 73f6a6f

Please sign in to comment.