Skip to content

Commit

Permalink
Feature/allow bridges between l2 networks (#669)
Browse files Browse the repository at this point in the history
* docker image + make + some other modifications

* Mutilpe rollup and L2-L2 bridges support

* gha tests

* linter

* minor refactor

* linter

* remove imports
  • Loading branch information
ARR552 authored Aug 21, 2024
1 parent ee44c7c commit 76f4ee6
Show file tree
Hide file tree
Showing 32 changed files with 3,040 additions and 116 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test-l2l2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test
on:
push:
branches:
- main
- master
- develop
- update-external-dependencies
pull_request:
jobs:
test-l2l2:
strategy:
matrix:
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
env:
GOARCH: ${{ matrix.goarch }}
- name: Test
run: make test-l2l2
27 changes: 27 additions & 0 deletions .github/workflows/test-multiplerollups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test
on:
push:
branches:
- main
- master
- develop
- update-external-dependencies
pull_request:
jobs:
test-multiplerollups:
strategy:
matrix:
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
env:
GOARCH: ${{ matrix.goarch }}
- name: Test
run: make test-multiplerollups
138 changes: 135 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,70 @@ include version.mk
DOCKER_COMPOSE := docker compose -f docker-compose.yml
DOCKER_COMPOSE_STATE_DB := zkevm-state-db
DOCKER_COMPOSE_POOL_DB := zkevm-pool-db
DOCKER_COMPOSE_RPC_DB := zkevm-rpc-db
DOCKER_COMPOSE_BRIDGE_DB := zkevm-bridge-db
DOCKER_COMPOSE_STATE_DB_2 := zkevm-state-db-2
DOCKER_COMPOSE_POOL_DB_2 := zkevm-pool-db-2
DOCKER_COMPOSE_BRIDGE_DB_2 := zkevm-bridge-db-2
DOCKER_COMPOSE_ZKEVM_NODE := zkevm-node
DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2 := zkevm-node-v1tov2
DOCKER_COMPOSE_ZKEVM_NODE_1 := zkevm-node-1
DOCKER_COMPOSE_ZKEVM_NODE_2 := zkevm-node-2
DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2 := zkevm-aggregator-v1tov2
DOCKER_COMPOSE_L1_NETWORK := zkevm-mock-l1-network
DOCKER_COMPOSE_L1_NETWORK_MULTI_ROLLUP := zkevm-mock-l1-network-multi-rollup
DOCKER_COMPOSE_L1_NETWORK_V1TOV2 := zkevm-v1tov2-l1-network
DOCKER_COMPOSE_ZKPROVER := zkevm-prover
DOCKER_COMPOSE_ZKPROVER_V1TOV2 := zkevm-prover-v1tov2
DOCKER_COMPOSE_ZKPROVER_1 := zkevm-prover-1
DOCKER_COMPOSE_ZKPROVER_2 := zkevm-prover-2
DOCKER_COMPOSE_BRIDGE := zkevm-bridge-service
DOCKER_COMPOSE_BRIDGE_V1TOV2 := zkevm-bridge-service-v1tov2
DOCKER_COMPOSE_BRIDGE_1 := zkevm-bridge-service-1
DOCKER_COMPOSE_BRIDGE_2 := zkevm-bridge-service-2

RUN_STATE_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_STATE_DB)
RUN_POOL_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_POOL_DB)
RUN_BRIDGE_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_DB)
RUN_STATE_DB_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_STATE_DB_2)
RUN_POOL_DB_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_POOL_DB_2)
RUN_BRIDGE_DB_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_DB_2)
RUN_DBS := ${RUN_BRIDGE_DB} && ${RUN_STATE_DB} && ${RUN_POOL_DB}
RUN_DBS_2 := ${RUN_BRIDGE_DB_2} && ${RUN_STATE_DB_2} && ${RUN_POOL_DB_2}
RUN_NODE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE)
RUN_NODE_1 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE_1)
RUN_NODE_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE_2)
RUN_NODE_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2)
RUN_AGGREGATOR_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2)
RUN_L1_NETWORK := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_L1_NETWORK)
RUN_L1_NETWORK_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2)
RUN_L1_NETWORK_MULTI_ROLLUP := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_L1_NETWORK_MULTI_ROLLUP)
RUN_ZKPROVER := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER)
RUN_ZKPROVER_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER_2)
RUN_ZKPROVER_1 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER_1)
RUN_ZKPROVER_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER_V1TOV2)
RUN_BRIDGE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE)
RUN_BRIDGE_1 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_1)
RUN_BRIDGE_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_2)
RUN_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_V1TOV2)

STOP_NODE_DB := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_NODE_DB) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_NODE_DB)
STOP_BRIDGE_DB := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_DB) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_DB)
STOP_DBS := ${STOP_NODE_DB} && ${STOP_BRIDGE_DB}
STOP_DBS := ${STOP_NODE_DB} && ${STOP_BRIDGE_DB} && ${STOP_NODE_DB_2} && ${STOP_BRIDGE_DB_2} && ${STOP_POOL_DB} && ${STOP_POOL_DB_2}
STOP_NODE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE)
STOP_NODE_1 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE_1) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE_1)
STOP_NODE_2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE_2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE_2)
STOP_NODE_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2)
STOP_AGGREGATOR_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2)
STOP_NETWORK := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_L1_NETWORK) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_L1_NETWORK)
STOP_NETWORK_MULTI_ROLLUP := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_L1_NETWORK_MULTI_ROLLUP) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_L1_NETWORK_MULTI_ROLLUP)
STOP_NETWORK_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2)
STOP_ZKPROVER := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER)
STOP_ZKPROVER_1 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER_1) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER_1)
STOP_ZKPROVER_2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER_2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER_2)
STOP_ZKPROVER_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER_V1TOV2)
STOP_BRIDGE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE)
STOP_BRIDGE_1 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_1) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_1)
STOP_BRIDGE_2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_2)
STOP_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_V1TOV2)
STOP := $(DOCKER_COMPOSE) down --remove-orphans

Expand Down Expand Up @@ -107,25 +134,51 @@ stop-db-bridge: ## Stops the node database
run-dbs: ## Runs the node database
$(RUN_DBS)

.PHONY: run-dbs-2
run-dbs-2: ## Runs the node database
$(RUN_DBS_2)

.PHONY: stop-dbs
stop-dbs: ## Stops the node database
$(STOP_DBS)
$(STOP_DBS_2)

.PHONY: run-node
run-node: ## Runs the node
$(RUN_NODE)

.PHONY: run-node-2
run-node-2: ## Runs the node
$(RUN_NODE_2)

.PHONY: run-node-1
run-node-1: ## Runs the node
$(RUN_NODE_1)

.PHONY: stop-node
stop-node: ## Stops the node
$(STOP_NODE)

.PHONY: stop-node-2
stop-node-2: ## Stops the node
$(STOP_NODE_2)

.PHONY: stop-node-1
stop-node-1: ## Stops the node
$(STOP_NODE_1)

.PHONY: run-network
run-network: ## Runs the l1 network
$(RUN_L1_NETWORK)

.PHONY: run-network-multi-rollup
run-network-multi-rollup: ## Runs the l1 network
$(RUN_L1_NETWORK_MULTI_ROLLUP)

.PHONY: stop-network
stop-network: ## Stops the l1 network
$(STOP_NETWORK)
$(STOP_NETWORK_MULTI_ROLLUP)

.PHONY: run-node-v1tov2
run-node-v1tov2: ## Runs the node
Expand Down Expand Up @@ -159,6 +212,22 @@ run-prover: ## Runs the zk prover
stop-prover: ## Stops the zk prover
$(STOP_ZKPROVER)

.PHONY: run-prover-1
run-prover-1: ## Runs the zk prover
$(RUN_ZKPROVER_1)

.PHONY: stop-prover-1
stop-prover-1: ## Stops the zk prover
$(STOP_ZKPROVER_1)

.PHONY: run-prover-2
run-prover-2: ## Runs the zk prover
$(RUN_ZKPROVER_2)

.PHONY: stop-prover-2
stop-prover-2: ## Stops the zk prover
$(STOP_ZKPROVER_2)

.PHONY: run-prover-v1tov2
run-prover-v1tov2: ## Runs the zk prover
$(RUN_ZKPROVER_V1TOV2)
Expand All @@ -175,6 +244,22 @@ run-bridge: ## Runs the bridge service
stop-bridge: ## Stops the bridge service
$(STOP_BRIDGE)

.PHONY: run-bridge-1
run-bridge-1: ## Runs the bridge service
$(RUN_BRIDGE_1)

.PHONY: stop-bridge-1
stop-bridge-1: ## Stops the bridge service
$(STOP_BRIDGE_1)

.PHONY: run-bridge-2
run-bridge-2: ## Runs the bridge service
$(RUN_BRIDGE_2)

.PHONY: stop-bridge-2
stop-bridge-2: ## Stops the bridge service
$(STOP_BRIDGE_2)

.PHONY: run-bridge-v1tov2
run-bridge-v1tov2: ## Runs the bridge service
$(RUN_BRIDGE_V1TOV2)
Expand All @@ -191,7 +276,7 @@ stop: ## Stops all services
restart: stop run ## Executes `make stop` and `make run` commands

.PHONY: run
run: stop ## runs all services
run: ## runs all services
$(RUN_DBS)
$(RUN_L1_NETWORK)
sleep 5
Expand All @@ -201,6 +286,43 @@ run: stop ## runs all services
sleep 7
$(RUN_BRIDGE)

.PHONY: run-1
run-1: ## runs all services
$(RUN_DBS)
$(RUN_L1_NETWORK_MULTI_ROLLUP)
sleep 5
$(RUN_ZKPROVER_1)
sleep 3
$(RUN_NODE_1)
sleep 7
$(RUN_BRIDGE_1)

.PHONY: run-2
run-2: ## runs all services
$(RUN_DBS_2)
$(RUN_L1_NETWORK_MULTI_ROLLUP)
sleep 5
$(RUN_ZKPROVER_2)
sleep 3
$(RUN_NODE_2)
sleep 7
$(RUN_BRIDGE_2)

.PHONY: run-multi
run-multi: ## runs all services
$(RUN_DBS)
$(RUN_DBS_2)
$(RUN_L1_NETWORK_MULTI_ROLLUP)
sleep 5
$(RUN_ZKPROVER_1)
$(RUN_ZKPROVER_2)
sleep 3
$(RUN_NODE_1)
$(RUN_NODE_2)
sleep 7
$(RUN_BRIDGE_1)
$(RUN_BRIDGE_2)

.PHONY: run-bridge-dependencies
run-bridge-dependencies: stop ## runs all services
$(RUN_DBS)
Expand Down Expand Up @@ -259,6 +381,16 @@ test-edge: build-docker stop run ## Runs all tests checking race conditions
sleep 3
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='edge'

.PHONY: test-multiplerollups
test-multiplerollups: build-docker stop run-multi ## Runs all tests checking race conditions
sleep 3
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='multiplerollups'

.PHONY: test-l2l2
test-l2l2: build-docker stop run-multi ## Runs all tests checking race conditions
sleep 3
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='l2l2'

.PHONY: test-e2ecompress
test-e2ecompress: build-docker stop run ## Runs all tests checking race conditions
sleep 3
Expand Down
3 changes: 2 additions & 1 deletion claimtxman/claimtxman.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (tm *ClaimTxManager) Start() {
for {
select {
case <-tm.ctx.Done():
ticker.Stop()
return
case netID := <-tm.chSynced:
if netID == tm.l2NetworkID && !tm.synced {
Expand Down Expand Up @@ -188,7 +189,7 @@ func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbT
continue
}

claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.DestinationNetwork)
claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.OriginalNetwork, deposit.DestinationNetwork)
if err != nil {
log.Errorf("error getting deposit status for deposit %d. Error: %v", deposit.DepositCount, err)
return err
Expand Down
2 changes: 1 addition & 1 deletion claimtxman/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type StorageInterface interface {

type bridgeServiceInterface interface {
GetClaimProofForCompressed(ger common.Hash, depositCnt, networkID uint, dbTx pgx.Tx) (*etherman.GlobalExitRoot, [][bridgectrl.KeyLen]byte, [][bridgectrl.KeyLen]byte, error)
GetDepositStatus(ctx context.Context, depositCount uint, destNetworkID uint) (string, error)
GetDepositStatus(ctx context.Context, depositCount, networkID, destNetworkID uint) (string, error)
}
9 changes: 9 additions & 0 deletions db/pgstorage/migrations/0011.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +migrate Up

ALTER TABLE sync.claim DROP CONSTRAINT claim_pkey;
ALTER TABLE sync.claim ADD PRIMARY KEY (index, rollup_index, network_id);

-- +migrate Down

ALTER TABLE sync.claim DROP CONSTRAINT claim_pkey;
ALTER TABLE sync.claim ADD PRIMARY KEY (network_id, index);
Loading

0 comments on commit 76f4ee6

Please sign in to comment.