Skip to content

Commit

Permalink
#725 sovereign chains support (#728)
Browse files Browse the repository at this point in the history
* config

* Sovereign chains support

* linter

* fix config

* mocks + sync unit test

* remove l1Synced

* docker compose

* deploy sovereign contracts for testing

* aggoracle

* Working!

* linter + unit test

* e2e-sovereignchain

* linter
  • Loading branch information
ARR552 authored Jan 13, 2025
1 parent aaf15a3 commit c6f53d7
Show file tree
Hide file tree
Showing 35 changed files with 6,593 additions and 194 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test-sovereignchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test-sovereignchain
on:
push:
branches:
- main
- master
- develop
- update-external-dependencies
pull_request:
jobs:
test-sovereignchain:
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-sovereignchain
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN cd /src && make build
# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0
COPY --from=build /src/dist/zkevm-bridge /app/zkevm-bridge
COPY --from=build /src/dist/test-deploy-claimcompressor /app/test-deploy-claimcompressor
COPY --from=build /src/dist/test-deploy-tool /app/test-deploy-tool
COPY --from=build /src/dist/zkevm-autoclaimer /app/zkevm-autoclaimer
COPY --from=build /src/test/vectors /app/test/vectors
EXPOSE 8080
Expand Down
44 changes: 42 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ DOCKER_COMPOSE_BRIDGE_V1TOV2 := zkevm-bridge-service-v1tov2
DOCKER_COMPOSE_BRIDGE_1 := zkevm-bridge-service-1
DOCKER_COMPOSE_BRIDGE_2 := zkevm-bridge-service-2
DOCKER_COMPOSE_BRIDGE_3 := zkevm-bridge-service-3
DOCKER_COMPOSE_BRIDGE_SOVEREIGN_CHAIN := zkevm-bridge-service-sovereign-chain
DOCKER_COMPOSE_AGGORACLE := aggoracle

RUN_STATE_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_STATE_DB)
RUN_POOL_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_POOL_DB)
Expand All @@ -50,6 +52,8 @@ RUN_BRIDGE_1 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_1)
RUN_BRIDGE_2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_2)
RUN_BRIDGE_3 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_3)
RUN_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_V1TOV2)
RUN_BRIDGE_SOVEREIGN_CHAIN := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_SOVEREIGN_CHAIN)
RUN_AGGORACLE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_AGGORACLE)

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)
Expand All @@ -71,6 +75,8 @@ STOP_BRIDGE_1 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_1) && $(DOCKER_C
STOP_BRIDGE_2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_2)
STOP_BRIDGE_3 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_3) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_3)
STOP_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_V1TOV2)
STOP_BRIDGE_SOVEREIGN_CHAIN := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_SOVEREIGN_CHAIN) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_SOVEREIGN_CHAIN)
STOP_AGGORACLE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_AGGORACLE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_AGGORACLE)
STOP := $(DOCKER_COMPOSE) down --remove-orphans

LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.Version=$(VERSION)'
Expand All @@ -83,8 +89,8 @@ GO_BIN := $(GO_BASE)/dist
GO_ENV_VARS := GO_BIN=$(GO_BIN)
GO_BINARY := zkevm-bridge
GO_CMD := $(GO_BASE)/cmd
GO_DEPLOY_SCRIPT := $(GO_BASE)/test/scripts/deployclaimcompressor
GO_DEPLOY_SCRIPT_BINARY := test-deploy-claimcompressor
GO_DEPLOY_SCRIPT := $(GO_BASE)/test/scripts/deploytool
GO_DEPLOY_SCRIPT_BINARY := test-deploy-tool
GO_DEPLOY_AUTOCLAIMER := $(GO_BASE)/autoclaimservice
GO_DEPLOY_AUTOCLAIMER_BINARY := zkevm-autoclaimer

Expand Down Expand Up @@ -295,6 +301,22 @@ run-bridge-v1tov2: ## Runs the bridge service
stop-bridge-v1tov2: ## Stops the bridge service
$(STOP_BRIDGE_V1TOV2)

.PHONY: run-bridge-sovereign-chain
run-bridge-sovereign-chain: ## Runs the bridge service
$(RUN_BRIDGE_SOVEREIGN_CHAIN)

.PHONY: stop-bridge-sovereign-chain
stop-bridge-sovereign-chain: ## Stops the bridge service
$(STOP_BRIDGE_SOVEREIGN_CHAIN)

.PHONY: run-aggoracle
run-aggoracle: ## Runs the bridge service
$(RUN_AGGORACLE)

.PHONY: stop-aggoracle
stop-aggoracle: ## Stops the bridge service
$(STOP_AGGORACLE)

.PHONY: stop
stop: ## Stops all services
$(STOP)
Expand Down Expand Up @@ -386,6 +408,19 @@ run-v1tov2: stop ## runs all services
$(RUN_AGGREGATOR_V1TOV2)
$(RUN_BRIDGE_V1TOV2)

.PHONY: run-sovereign-chain
run-sovereign-chain: ## runs all services
$(RUN_DBS)
$(RUN_L1_NETWORK)
sleep 5
$(RUN_ZKPROVER)
sleep 3
$(RUN_NODE)
sleep 5
$(RUN_BRIDGE_SOVEREIGN_CHAIN)
sleep 30
$(RUN_AGGORACLE)

.PHONY: update-external-dependencies
update-external-dependencies: ## Updates external dependencies like images, test vectors or proto files
go run ./scripts/cmd/... updatedeps
Expand Down Expand Up @@ -443,6 +478,11 @@ test-e2ecompress: build-docker stop run-multi-single-bridge ## Runs all tests ch
sleep 3
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='e2ecompress'

.PHONY: test-sovereignchain
test-sovereignchain: build-docker stop run-multi-single-bridge ## 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='sovereignchain'

.PHONY: build-test-e2e-real_network
build-test-e2e-real_network: ## Build binary for e2e tests with real network
go test -c ./test/e2e/ -o dist/zkevm-bridge-e2e-real_network-erc20 -tags='e2e_real_network_erc20'
Expand Down
12 changes: 6 additions & 6 deletions claimtxman/claimtxman.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ClaimTxManager struct {
storage StorageInterface
auth *bind.TransactOpts
rollupID uint32
synced bool
l2Synced bool
nonceCache *NonceCache
monitorTxs types.TxMonitorer
}
Expand Down Expand Up @@ -104,12 +104,12 @@ func (tm *ClaimTxManager) Start() {
ticker.Stop()
return
case netID := <-tm.chSynced:
if netID == tm.l2NetworkID && !tm.synced {
if netID == tm.l2NetworkID && !tm.l2Synced {
log.Info("NetworkID synced: ", netID)
tm.synced = true
tm.l2Synced = true
}
case ger = <-tm.chExitRootEvent:
if tm.synced {
if tm.l2Synced {
log.Debugf("RollupID: %d UpdateDepositsStatus for ger: %s", tm.rollupID, ger.GlobalExitRoot.String())
if tm.cfg.GroupingClaims.Enabled {
log.Debugf("rollupID: %d, Ger value updated and ready to be processed...", tm.rollupID)
Expand All @@ -125,7 +125,7 @@ func (tm *ClaimTxManager) Start() {
log.Infof("Waiting for networkID %d to be synced before processing deposits", tm.l2NetworkID)
}
case <-compressorTicker.C:
if tm.synced && tm.cfg.GroupingClaims.Enabled && ger.GlobalExitRoot != latestProcessedGer {
if tm.l2Synced && tm.cfg.GroupingClaims.Enabled && ger.GlobalExitRoot != latestProcessedGer {
log.Infof("RollupID: %d,Processing deposits for ger: %s", tm.rollupID, ger.GlobalExitRoot.String())
go func() {
err := tm.updateDepositsStatus(ger)
Expand Down Expand Up @@ -178,7 +178,7 @@ func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbT
globalExitRoot = ger.GlobalExitRoot
err error
)
if ger.BlockID != 0 { // L2 exit root is updated
if ger.BlockID != 0 && ger.NetworkID == 0 { // L2 exit root is updated
log.Infof("RollupID: %d, Rollup exitroot %v is updated", tm.rollupID, ger.ExitRoots[1])
err = tm.storage.UpdateL2DepositsStatus(tm.ctx, ger.ExitRoots[1][:], tm.rollupID, tm.l2NetworkID, dbTx)
if err != nil {
Expand Down
125 changes: 125 additions & 0 deletions claimtxman/mocks/storage_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions claimtxman/monitortxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/jackc/pgx/v4"
)

type MonitorTxs struct {
Expand Down Expand Up @@ -81,7 +80,7 @@ func (tm *MonitorTxs) MonitorTxs(ctx context.Context) error {
// update monitored tx changes into storage
// if the tx was mined but failed, we continue to consider it was not mined
// and store the failed receipt to be used to check if nonce needs to be reviewed
hasFailedReceipts, allHistoryTxMined, receiptSuccessful := tm.checkTxHistory(ctx, mTx, mTxLog, dbTx)
hasFailedReceipts, allHistoryTxMined, receiptSuccessful := tm.checkTxHistory(ctx, mTx, mTxLog)

if receiptSuccessful {
//mTxLog.Infof("tx %s was mined successfully", txHash.String())
Expand Down Expand Up @@ -211,7 +210,7 @@ func (tm *MonitorTxs) MonitorTxs(ctx context.Context) error {
}

// returns hasFailedReceipts, allHistoryTxMined, receiptSuccessful
func (tm *MonitorTxs) checkTxHistory(ctx context.Context, mTx ctmtypes.MonitoredTx, mTxLog *log.Logger, dbTx pgx.Tx) (bool, bool, bool) {
func (tm *MonitorTxs) checkTxHistory(ctx context.Context, mTx ctmtypes.MonitoredTx, mTxLog *log.Logger) (bool, bool, bool) {
var receipt *types.Receipt
hasFailedReceipts := false
allHistoryTxMined := true
Expand Down
3 changes: 0 additions & 3 deletions claimtxman/nonce_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ func NewNonceCache(ctx context.Context, l2Node *utils.Client) (*NonceCache, erro
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
return &NonceCache{
ctx: ctx,
l2Node: l2Node,
Expand Down
Loading

0 comments on commit c6f53d7

Please sign in to comment.