Skip to content

Commit

Permalink
fix (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 authored Sep 3, 2024
1 parent 9395322 commit 8b7867f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ func start(ctx *cli.Context) error {
chSyncedL2 := make(chan uint)
chsExitRootEvent = append(chsExitRootEvent, chExitRootEventL2)
chsSyncedL2 = append(chsSyncedL2, chSyncedL2)
go runSynchronizer(ctx.Context, 0, bridgeController, l2EthermanClient, c.Synchronizer, storage, zkEVMClient, chExitRootEventL2, nil, chSyncedL2)
go runSynchronizer(ctx.Context, 0, bridgeController, l2EthermanClient, c.Synchronizer, storage, zkEVMClient, chExitRootEventL2, nil, chSyncedL2, []uint{})
}
chSynced := make(chan uint)
go runSynchronizer(ctx.Context, c.NetworkConfig.GenBlockNumber, bridgeController, l1Etherman, c.Synchronizer, storage, nil, nil, chsExitRootEvent, chSynced)
go runSynchronizer(ctx.Context, c.NetworkConfig.GenBlockNumber, bridgeController, l1Etherman, c.Synchronizer, storage, nil, nil, chsExitRootEvent, chSynced, networkIDs)
go func() {
for {
select {
Expand Down Expand Up @@ -203,8 +203,8 @@ func newEthermans(c *config.Config) (*etherman.Client, []*etherman.Client, error
return l1Etherman, l2Ethermans, nil
}

func runSynchronizer(ctx context.Context, genBlockNumber uint64, brdigeCtrl *bridgectrl.BridgeController, etherman *etherman.Client, cfg synchronizer.Config, storage db.Storage, zkEVMClient *client.Client, chExitRootEventL2 chan *etherman.GlobalExitRoot, chsExitRootEvent []chan *etherman.GlobalExitRoot, chSynced chan uint) {
sy, err := synchronizer.NewSynchronizer(ctx, storage, brdigeCtrl, etherman, zkEVMClient, genBlockNumber, chExitRootEventL2, chsExitRootEvent, chSynced, cfg)
func runSynchronizer(ctx context.Context, genBlockNumber uint64, brdigeCtrl *bridgectrl.BridgeController, etherman *etherman.Client, cfg synchronizer.Config, storage db.Storage, zkEVMClient *client.Client, chExitRootEventL2 chan *etherman.GlobalExitRoot, chsExitRootEvent []chan *etherman.GlobalExitRoot, chSynced chan uint, allNetworkIDs []uint) {
sy, err := synchronizer.NewSynchronizer(ctx, storage, brdigeCtrl, etherman, zkEVMClient, genBlockNumber, chExitRootEventL2, chsExitRootEvent, chSynced, cfg, allNetworkIDs)
if err != nil {
log.Fatal(err)
}
Expand Down
51 changes: 31 additions & 20 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ClientSynchronizer struct {
zkEVMClient zkEVMClientInterface
synced bool
l1RollupExitRoot common.Hash
allNetworkIDs []uint
}

// NewSynchronizer creates and initializes an instance of Synchronizer
Expand All @@ -49,7 +50,8 @@ func NewSynchronizer(
chExitRootEventL2 chan *etherman.GlobalExitRoot,
chsExitRootEvent []chan *etherman.GlobalExitRoot,
chSynced chan uint,
cfg Config) (Synchronizer, error) {
cfg Config,
allNetworkIDs []uint) (Synchronizer, error) {
ctx, cancel := context.WithCancel(parentCtx)
networkID := ethMan.GetNetworkID()
ger, err := storage.(storageInterface).GetLatestL1SyncedExitRoot(ctx, nil)
Expand All @@ -74,6 +76,7 @@ func NewSynchronizer(
chSynced: chSynced,
chsExitRootEvent: chsExitRootEvent,
l1RollupExitRoot: ger.ExitRoots[1],
allNetworkIDs: allNetworkIDs,
}, nil
}
return &ClientSynchronizer{
Expand Down Expand Up @@ -593,35 +596,43 @@ func (s *ClientSynchronizer) processVerifyBatch(verifyBatch etherman.VerifiedBat
log.Debugf("networkID: %d, skipping empty local exit root in verifyBatch event. VerifyBatch: %+v", s.networkID, verifyBatch)
return nil
}
// Just check that the calculated RollupExitRoot is fine
ok, err := s.storage.CheckIfRootExists(s.ctx, verifyBatch.LocalExitRoot.Bytes(), uint8(verifyBatch.RollupID), dbTx)
if err != nil {
log.Errorf("networkID: %d, error Checking if root exists. Error: %v", s.networkID, err)
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
if rollbackErr != nil {
log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v, error : %s",
s.networkID, verifyBatch.BlockNumber, rollbackErr, err.Error())
return rollbackErr
var isRollupSyncing bool
for _, n := range s.allNetworkIDs {
if verifyBatch.RollupID == n {
isRollupSyncing = true
}
return err
}
if !ok {
log.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String())
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
if rollbackErr != nil {
log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v, error : %s",
s.networkID, verifyBatch.BlockNumber, rollbackErr, err.Error())
return rollbackErr
if isRollupSyncing {
// Just check that the calculated RollupExitRoot is fine
ok, err := s.storage.CheckIfRootExists(s.ctx, verifyBatch.LocalExitRoot.Bytes(), uint8(verifyBatch.RollupID), dbTx)
if err != nil {
log.Errorf("networkID: %d, error Checking if root exists. Error: %v", s.networkID, err)
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
if rollbackErr != nil {
log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v, error : %s",
s.networkID, verifyBatch.BlockNumber, rollbackErr, err.Error())
return rollbackErr
}
return err
}
if !ok {
log.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String())
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
if rollbackErr != nil {
log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v, error : %s",
s.networkID, verifyBatch.BlockNumber, rollbackErr, err.Error())
return rollbackErr
}
return fmt.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String())
}
return fmt.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String())
}
rollupLeaf := etherman.RollupExitLeaf{
BlockID: blockID,
Leaf: verifyBatch.LocalExitRoot,
RollupId: verifyBatch.RollupID,
}
// Update rollupExitRoot
err = s.bridgeCtrl.AddRollupExitLeaf(s.ctx, rollupLeaf, dbTx)
err := s.bridgeCtrl.AddRollupExitLeaf(s.ctx, rollupLeaf, dbTx)
if err != nil {
log.Errorf("networkID: %d, error adding rollup exit leaf. Error: %v", s.networkID, err)
rollbackErr := s.storage.Rollback(s.ctx, dbTx)
Expand Down

0 comments on commit 8b7867f

Please sign in to comment.