Skip to content

Commit

Permalink
Fix timestamp stored in exit_root table (0xPolygonHermez#2811)
Browse files Browse the repository at this point in the history
* Fix timestamp stored in exit_root table

* json doc
  • Loading branch information
ARR552 authored Nov 23, 2023
1 parent 84ac067 commit 4bd8c1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,14 @@ func (etherMan *Client) updateGlobalExitRootEvent(ctx context.Context, vLog type
gExitRoot.BlockNumber = vLog.BlockNumber
gExitRoot.GlobalExitRoot = hash(globalExitRoot.MainnetExitRoot, globalExitRoot.RollupExitRoot)

fullBlock, err := etherMan.EthClient.BlockByHash(ctx, vLog.BlockHash)
if err != nil {
return fmt.Errorf("error getting hashParent. BlockNumber: %d. Error: %w", vLog.BlockNumber, err)
}
t := time.Unix(int64(fullBlock.Time()), 0)
gExitRoot.Timestamp = t

if len(*blocks) == 0 || ((*blocks)[len(*blocks)-1].BlockHash != vLog.BlockHash || (*blocks)[len(*blocks)-1].BlockNumber != vLog.BlockNumber) {
fullBlock, err := etherMan.EthClient.BlockByHash(ctx, vLog.BlockHash)
if err != nil {
return fmt.Errorf("error getting hashParent. BlockNumber: %d. Error: %w", vLog.BlockNumber, err)
}
t := time.Unix(int64(fullBlock.Time()), 0)
block := prepareBlock(vLog, t, fullBlock)
block.GlobalExitRoots = append(block.GlobalExitRoots, gExitRoot)
*blocks = append(*blocks, block)
Expand Down
1 change: 1 addition & 0 deletions etherman/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type GlobalExitRoot struct {
MainnetExitRoot common.Hash
RollupExitRoot common.Hash
GlobalExitRoot common.Hash
Timestamp time.Time
}

// SequencedBatch represents virtual batch
Expand Down
1 change: 1 addition & 0 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ func (s *ClientSynchronizer) processGlobalExitRoot(globalExitRoot etherman.Globa
MainnetExitRoot: globalExitRoot.MainnetExitRoot,
RollupExitRoot: globalExitRoot.RollupExitRoot,
GlobalExitRoot: globalExitRoot.GlobalExitRoot,
Timestamp: globalExitRoot.Timestamp,
}
err := s.state.AddGlobalExitRoot(s.ctx, &ger, dbTx)
if err != nil {
Expand Down

0 comments on commit 4bd8c1f

Please sign in to comment.