Skip to content

Commit

Permalink
Working!
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed Jan 10, 2025
1 parent 7f228e7 commit 41cc68d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ run-sovereign-chain: ## runs all services
$(RUN_NODE)
sleep 5
$(RUN_BRIDGE_SOVEREIGN_CHAIN)
sleep 20
sleep 30
$(RUN_AGGORACLE)

.PHONY: update-external-dependencies
Expand Down
10 changes: 9 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ func monitorChannel(ctx context.Context, chExitRootEvent chan *etherman.GlobalEx
log.Error("networkId: %d, error creating dbTx. Error: %v", networkID, err)
continue
}
if ger.BlockID != 0 { // L2 exit root is updated
if ger.BlockID != 0 && ger.NetworkID == 0 { // L2 exit root is updated
if len(ger.ExitRoots) == 0 {
log.Debug("Skipping the ready for claim update until the synchronization is completed")
continue
}
if err := s.UpdateL2DepositsStatus(ctx, ger.ExitRoots[1][:], networkID, networkID, dbTx); err != nil {
log.Errorf("networkId: %d, error updating L2DepositsStatus. Error: %v", networkID, err)
rollbackErr := s.Rollback(ctx, dbTx)
Expand All @@ -186,6 +190,10 @@ func monitorChannel(ctx context.Context, chExitRootEvent chan *etherman.GlobalEx
continue
}
} else { // L1 exit root is updated in the trusted state
if len(ger.ExitRoots) == 0 {
log.Debug("Skipping the ready for claim update until the synchronization is completed")
continue
}
_, err := s.UpdateL1DepositsStatus(ctx, ger.ExitRoots[0][:], networkID, dbTx)
if err != nil {
log.Errorf("networkId: %d, error getting and updating L1DepositsStatus. Error: %v", networkID, err)
Expand Down
10 changes: 7 additions & 3 deletions db/pgstorage/pgstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ func (p *PostgresStorage) AddBlock(ctx context.Context, block *etherman.Block, d

// AddGlobalExitRoot adds a new ExitRoot to the db.
func (p *PostgresStorage) AddGlobalExitRoot(ctx context.Context, exitRoot *etherman.GlobalExitRoot, dbTx pgx.Tx) error {
const addExitRootSQL = "INSERT INTO sync.exit_root (block_id, global_exit_root, exit_roots) VALUES ($1, $2, $3)"
const addExitRootSQL = "INSERT INTO sync.exit_root (block_id, global_exit_root, exit_roots, network_id) VALUES ($1, $2, $3, $4)"
exitRoots := [][]byte{}
if len(exitRoot.ExitRoots) != 0 {
exitRoots = [][]byte{exitRoot.ExitRoots[0][:], exitRoot.ExitRoots[1][:]}
}
e := p.getExecQuerier(dbTx)
_, err := e.Exec(ctx, addExitRootSQL, exitRoot.BlockID, exitRoot.GlobalExitRoot, pq.Array([][]byte{exitRoot.ExitRoots[0][:], exitRoot.ExitRoots[1][:]}))
_, err := e.Exec(ctx, addExitRootSQL, exitRoot.BlockID, exitRoot.GlobalExitRoot, pq.Array(exitRoots), exitRoot.NetworkID)
return err
}

Expand Down Expand Up @@ -314,7 +318,7 @@ func (p *PostgresStorage) GetL2ExitRootsByGER(ctx context.Context, ger common.Ha

for rows.Next() {
var gerData etherman.GlobalExitRoot
err = rows.Scan(&gerData.BlockID, &gerData.GlobalExitRoot, gerData.NetworkID, &gerData.ID)
err = rows.Scan(&gerData.BlockID, &gerData.GlobalExitRoot, &gerData.NetworkID, &gerData.ID)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ services:
- "-c"
- "/app/test-deploy-tool deployClaimCompressor --url \"http://zkevm-node:8123\" --bridgeAddress \"0xFe12ABaa190Ef0c8638Ee0ba9F828BF41368Ca0E\" --walletFile /pk/keystore.claimtxmanager --password \"testonly\" &&
/app/test-deploy-tool sendETH --url \"http://zkevm-node:8123\" --destAddress \"0x70997970c51812dc3a010c7d01b50e0d17dc79c8\" --walletFile /pk/keystore.claimtxmanager --password \"testonly\" &&
/app/test-deploy-tool sendETH --url \"http://zkevm-node:8123\" --destAddress \"0x71C95911E9a5D330f4D621842EC243EE1343292e\" --walletFile /pk/keystore.claimtxmanager --password \"testonly\" &&
/app/test-deploy-tool deploySovereignChainSMC --url \"http://zkevm-node:8123\" --walletFile /pk/keystore.aggregator --password \"testonly\" &&
/app/zkevm-bridge run --cfg /app/config.toml"

Expand Down
4 changes: 2 additions & 2 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func (s *ClientSynchronizer) processGlobalExitRoot(globalExitRoot etherman.Globa
log.Debugf("networkID: %d, Storing L1 Ger: ", s.networkID, globalExitRoot.GlobalExitRoot)
// Check if there is some globalExitRoot in L2. If so, it must be incompleted. It must be updated.
// A race condition between dbTxs (L1 dbTx and L2 dbTxs) is very unlikely because L1 sync takes usually takes more time than L2 sync.
gers, err := s.storage.GetL2ExitRootsByGER(s.ctx, globalExitRoot.GlobalExitRoot, dbTx)
gers, err := s.storage.GetL2ExitRootsByGER(s.ctx, globalExitRoot.GlobalExitRoot, nil)
if err != nil && !errors.Is(err, gerror.ErrStorageNotFound) {
log.Errorf("networkID: %d, error storing the GlobalExitRoot in processGlobalExitRoot. BlockNumber: %d. Error: %v", s.networkID, globalExitRoot.BlockNumber, err)
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
Expand Down Expand Up @@ -703,7 +703,7 @@ func (s *ClientSynchronizer) processGlobalExitRoot(globalExitRoot etherman.Globa
} else if len(globalExitRoot.ExitRoots) == 0 {
log.Debugf("networkID: %d, Storing L2 Ger: %s", s.networkID, globalExitRoot.GlobalExitRoot)
// First read the mainnetExitRoot and rollupsExitRoot to store all the information in the db.
ger, err := s.storage.GetExitRootByGER(s.ctx, globalExitRoot.GlobalExitRoot, dbTx)
ger, err := s.storage.GetExitRootByGER(s.ctx, globalExitRoot.GlobalExitRoot, nil)
if errors.Is(err, gerror.ErrStorageNotFound) {
log.Warnf("networkID: %d, L1Ger entry not found in the database. GER: %s", s.networkID, globalExitRoot.GlobalExitRoot.String())
} else if err != nil {
Expand Down

0 comments on commit 41cc68d

Please sign in to comment.