Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several sync issues #583

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a79d440
Remove unused check
vcastellm Feb 16, 2024
a48ab4f
Fix the claim transaction
vcastellm Feb 16, 2024
edbac37
Fix wrong relation of claim_tx_hash
arnaubennassar Feb 19, 2024
355b9ab
WIP
arnaubennassar Feb 19, 2024
bcf26f3
looks to be working
arnaubennassar Feb 19, 2024
f2c1706
Merge pull request #585 from 0xPolygonHermez/abf/fix
vcastellm Feb 20, 2024
a3c1bdb
Remove commented Local Exit root existance check
vcastellm Feb 20, 2024
118699a
Restore previous
vcastellm Feb 20, 2024
7d63f89
typo
vcastellm Feb 20, 2024
bcba97f
Rename
vcastellm Feb 20, 2024
f04e8a6
Merge remote-tracking branch 'origin' into vcastellm/fix-sync
vcastellm Feb 20, 2024
fc9ff4b
Refactor logic
vcastellm Feb 20, 2024
ff6003f
Refactor claim.RollupIndex
vcastellm Feb 20, 2024
a7a1162
Fix test
vcastellm Feb 20, 2024
9921711
Pass ref
vcastellm Feb 20, 2024
726fed7
Fix UTs (#587)
arnaubennassar Feb 20, 2024
87db383
reverse negated logic for rollup id
arnaubennassar Feb 20, 2024
fd3b3ed
remove unused added field
arnaubennassar Feb 20, 2024
8426a6b
Fix linter
arnaubennassar Feb 20, 2024
c7ba4ff
Fix e2e tests
vcastellm Feb 20, 2024
c9660c3
Merge branch 'vcastellm/fix-sync' of github.com:0xPolygonHermez/zkevm…
vcastellm Feb 20, 2024
f989590
Remove test
vcastellm Feb 20, 2024
b6e663a
Test/multiple rollups (#591)
arnaubennassar Feb 29, 2024
4163e21
Remove _XXX from Makefile
arnaubennassar Feb 29, 2024
ac15bcc
Fix conflicts
arnaubennassar Feb 29, 2024
d60edb2
add migration test
arnaubennassar Feb 29, 2024
4eed41e
add migration test
arnaubennassar Feb 29, 2024
8b1a5d7
Fix linter
arnaubennassar Feb 29, 2024
7aa650c
Split migration file
arnaubennassar Mar 1, 2024
c00878c
TODOs for Monday :)
arnaubennassar Mar 1, 2024
1481244
Fix getting claims from deposits
arnaubennassar Mar 4, 2024
762ea6f
Fix UT
arnaubennassar Mar 4, 2024
7516f21
Fix e2e
arnaubennassar Mar 4, 2024
2e78d3c
Fix lint
arnaubennassar Mar 4, 2024
e7656e4
network_id is bigint
arnaubennassar Mar 6, 2024
e7eba0e
network_id is bigint
arnaubennassar Mar 6, 2024
21cf8cd
network_id is bigint
arnaubennassar Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
test: ["e2e", "edge", "multirollup"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -24,4 +25,4 @@ jobs:
env:
GOARCH: ${{ matrix.goarch }}
- name: Test
run: make test-full
run: make test-${{ matrix.test }}
27 changes: 0 additions & 27 deletions .github/workflows/test-edge.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

config/config.mainnet.toml
config/config.testnet.toml
**__debug**
116 changes: 56 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
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_ZKEVM_NODE := zkevm-node
DOCKER_COMPOSE_DB := zkevm-db
DOCKER_COMPOSE_ZKEVM_NODE-1 := zkevm-node-1
DOCKER_COMPOSE_ZKEVM_NODE-2 := zkevm-node-2
DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2 := zkevm-node-v1tov2
DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2 := zkevm-aggregator-v1tov2
DOCKER_COMPOSE_L1_NETWORK := zkevm-mock-l1-network
DOCKER_COMPOSE_L1_NETWORK_V1TOV2 := zkevm-v1tov2-l1-network
DOCKER_COMPOSE_ZKPROVER := zkevm-prover
DOCKER_COMPOSE_ZKPROVER-1 := zkevm-prover-1
DOCKER_COMPOSE_ZKPROVER-2 := zkevm-prover-2
DOCKER_COMPOSE_ZKPROVER_V1TOV2 := zkevm-prover-v1tov2
DOCKER_COMPOSE_BRIDGE := zkevm-bridge-service
DOCKER_COMPOSE_BRIDGE-1 := zkevm-bridge-service-1
DOCKER_COMPOSE_BRIDGE-2 := zkevm-bridge-service-2
DOCKER_COMPOSE_BRIDGE_V1TOV2 := zkevm-bridge-service-v1tov2

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_DBS := ${RUN_BRIDGE_DB} && ${RUN_STATE_DB} && ${RUN_POOL_DB}
RUN_NODE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE)
RUN_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_DB)
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_ZKPROVER := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER)
RUN_ZKPROVER_1 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER-1)
RUN_ZKPROVER_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER-2)
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_NODE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE)
STOP_DB := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_DB) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_DB)
STOP_NODE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE-1) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE-1)
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_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 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE-1) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE-1)
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 @@ -71,9 +70,9 @@ install-git-hooks: ## Moves hook files to the .git/hooks directory

.PHONY: test
test: ## Runs only short tests without checking race conditions
$(STOP_BRIDGE_DB) || true
$(RUN_BRIDGE_DB); sleep 3
trap '$(STOP_BRIDGE_DB)' EXIT; go test --cover -short -p 1 ./...
$(STOP_DB) || true
$(RUN_DB); sleep 3
trap '$(STOP_DB)' EXIT; go test --cover -short -p 1 ./...

.PHONY: install-linter
install-linter: ## Installs the linter
Expand All @@ -83,33 +82,17 @@ install-linter: ## Installs the linter
build-docker: ## Builds a docker image with the zkevm bridge binary
docker build -t zkevm-bridge-service -f ./Dockerfile .

.PHONY: run-db-node
run-db-node: ## Runs the node database
$(RUN_NODE_DB)
.PHONY: run-db
run-db: ## Runs the node database
$(RUN_DB)

.PHONY: stop-db-node
stop-db-node: ## Stops the node database
$(STOP_NODE_DB)

.PHONY: run-db-bridge
run-db-bridge: ## Runs the node database
$(RUN_BRIDGE_DB)

.PHONY: stop-db-bridge
stop-db-bridge: ## Stops the node database
$(STOP_BRIDGE_DB)

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

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

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

.PHONY: stop-node
stop-node: ## Stops the node
Expand Down Expand Up @@ -149,11 +132,11 @@ stop-network-v1tov2: ## Stops the l1 network

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

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

.PHONY: run-prover-v1tov2
run-prover-v1tov2: ## Runs the zk prover
Expand All @@ -165,7 +148,7 @@ stop-prover-v1tov2: ## Stops the zk prover

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

.PHONY: stop-bridge
stop-bridge: ## Stops the bridge service
Expand All @@ -188,18 +171,26 @@ restart: stop run ## Executes `make stop` and `make run` commands

.PHONY: run
run: stop ## runs all services
$(RUN_DBS)
$(RUN_DB)
$(RUN_L1_NETWORK)
sleep 5
$(RUN_ZKPROVER)
$(RUN_ZKPROVER_1)
sleep 3
$(RUN_NODE)
sleep 7
$(RUN_BRIDGE)
$(RUN_NODE_1)
sleep 25
$(RUN_BRIDGE_1)

.PHONY: run-2Rollups
run-2Rollups: run
$(RUN_ZKPROVER_2)
sleep 3
$(RUN_NODE_2)
sleep 25
$(RUN_BRIDGE_2)

.PHONY: run-v1tov2
run-v1tov2: stop ## runs all services
$(RUN_DBS)
$(RUN_DB)
$(RUN_L1_NETWORK_V1TOV2)
sleep 5
$(RUN_ZKPROVER_V1TOV2)
Expand All @@ -224,9 +215,9 @@ stop-mockserver: ## Stops the mock bridge service

.PHONY: bench
bench: ## benchmark test
$(STOP_BRIDGE_DB) || true
$(RUN_BRIDGE_DB); sleep 3
trap '$(STOP_BRIDGE_DB)' EXIT; go test -run=NOTEST -timeout=30m -bench=Small ./test/benchmark/...
$(STOP_DB) || true
$(RUN_DB); sleep 3
trap '$(STOP_DB)' EXIT; go test -run=NOTEST -timeout=30m -bench=Small ./test/benchmark/...

.PHONY: bench-full
bench-full: export ZKEVM_BRIDGE_DATABASE_PORT = 5432
Expand All @@ -236,8 +227,8 @@ bench-full: ## benchmark full test
go test -run=NOTEST -bench=Medium . && \
go test -run=NOTEST -timeout=30m -bench=Large .

.PHONY: test-full
test-full: build-docker stop run ## Runs all tests checking race conditions
.PHONY: test-e2e
test-e2e: 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='e2e'

Expand All @@ -246,6 +237,11 @@ 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-multirollup
test-multirollup: build-docker stop run-2Rollups ## 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='multirollup'

.PHONY: validate
validate: lint build test-full ## Validates the whole integrity of the code base

Expand Down
2 changes: 1 addition & 1 deletion bridgectrl/bridgectrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (bt *BridgeController) GetNetworkID(networkID uint) (uint8, error) {
// AddDeposit adds deposit information to the bridge tree.
func (bt *BridgeController) AddDeposit(ctx context.Context, deposit *etherman.Deposit, depositID uint64, dbTx pgx.Tx) error {
leaf := hashDeposit(deposit)
tID, err := bt.GetNetworkID(deposit.NetworkID)
tID, err := bt.GetNetworkID(deposit.OriginNetwork)
if err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions bridgectrl/bridgectrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func TestBridgeTree(t *testing.T) {
require.NoError(t, err)
amount, _ := new(big.Int).SetString(testVector.Amount, 0)
deposit := &etherman.Deposit{
LeafType: 0,
OriginalNetwork: testVector.OriginalNetwork,
OriginalAddress: common.HexToAddress(testVector.TokenAddress),
Amount: amount,
DestinationNetwork: testVector.DestinationNetwork,
DestinationAddress: common.HexToAddress(testVector.DestinationAddress),
BlockID: blockID,
DepositCount: uint(i),
Metadata: common.FromHex(testVector.Metadata),
LeafType: 0,
OriginalTokenNetwork: testVector.OriginalNetwork,
OriginalTokenAddress: common.HexToAddress(testVector.TokenAddress),
Amount: amount,
DestinationNetwork: testVector.DestinationNetwork,
DestinationAddress: common.HexToAddress(testVector.DestinationAddress),
BlockID: blockID,
DepositCount: uint(i),
Metadata: common.FromHex(testVector.Metadata),
}
leafHash := hashDeposit(deposit)
assert.Equal(t, testVector.ExpectedHash, hex.EncodeToString(leafHash[:]))
Expand All @@ -84,7 +84,7 @@ func TestBridgeTree(t *testing.T) {
// test reorg
orgRoot, err := bt.exitTrees[0].store.GetRoot(ctx, uint(i), 0, nil)
require.NoError(t, err)
require.NoError(t, store.Reset(ctx, uint64(i), deposit.NetworkID, nil))
require.NoError(t, store.Reset(ctx, uint64(i), deposit.OriginNetwork, nil))
err = bt.ReorgMT(ctx, uint(i), testVectors[i].OriginalNetwork, nil)
require.NoError(t, err)
blockID, err = store.AddBlock(context.TODO(), block, nil)
Expand Down
4 changes: 2 additions & 2 deletions bridgectrl/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func generateZeroHashes(height uint8) [][KeyLen]byte {
func hashDeposit(deposit *etherman.Deposit) [KeyLen]byte {
var res [KeyLen]byte
origNet := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(origNet, uint32(deposit.OriginalNetwork))
binary.BigEndian.PutUint32(origNet, uint32(deposit.OriginalTokenNetwork))
destNet := make([]byte, 4) //nolint:gomnd
binary.BigEndian.PutUint32(destNet, uint32(deposit.DestinationNetwork))
var buf [KeyLen]byte
metaHash := keccak256.Hash(deposit.Metadata)
copy(res[:], keccak256.Hash([]byte{deposit.LeafType}, origNet, deposit.OriginalAddress[:], destNet, deposit.DestinationAddress[:], deposit.Amount.FillBytes(buf[:]), metaHash))
copy(res[:], keccak256.Hash([]byte{deposit.LeafType}, origNet, deposit.OriginalTokenAddress[:], destNet, deposit.DestinationAddress[:], deposit.Amount.FillBytes(buf[:]), metaHash))
return res
}
Loading
Loading