Skip to content

Commit

Permalink
Sync old network compatibility (0xPolygonHermez#3166)
Browse files Browse the repository at this point in the history
* Sync old network compatibility

* logs
  • Loading branch information
ARR552 authored Jan 30, 2024
1 parent 87bb731 commit 18a75ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 3 additions & 2 deletions config/mainnetgenesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const MainnetNetworkConfigJSON = `
{
"l1Config" : {
"chainId": 1,
"polygonZkEVMAddress": "0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2",
"polTokenAddress": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
"polygonZkEVMAddress": "0x519E42c24163192Dca44CD3fBDCEBF6be9130987",
"polygonRollupManagerAddress": "0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2",
"polTokenAddress": "0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6",
"polygonZkEVMGlobalExitRootAddress": "0x580bda1e7A0CFAe92Fa7F6c20A3794F169CE3CFb"
},
"root": "0x3f86b09b43e3e49a41fc20a07579b79eba044253367817d5c241d23c0e2bc5c9",
Expand Down
34 changes: 28 additions & 6 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ func NewClient(cfg Config, l1Config L1Config) (*Client, error) {
// Get RollupID
rollupID, err := rollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr)
if err != nil {
log.Errorf("error rollupManager.cRollupAddressToID(%s). Error: %w", l1Config.RollupManagerAddr, err)
return nil, err
log.Debugf("error rollupManager.RollupAddressToID(%s). Error: %w", l1Config.RollupManagerAddr, err)
// TODO return error after the upgrade
}
log.Debug("rollupID: ", rollupID)

Expand Down Expand Up @@ -667,6 +667,14 @@ func (etherMan *Client) addExistingRollup(ctx context.Context, vLog types.Log, b
if etherMan.RollupID != addExistingRollup.RollupID {
return nil
}
// TODO Delete after upgrade Get RollupID
rollupID, err := etherMan.RollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, etherMan.SCAddresses[0])
if err != nil {
log.Error("error getting rollupID. Error: ", err)
return err
}
log.Debug("rollupID: ", rollupID)

return etherMan.updateForkId(ctx, vLog, blocks, blocksOrder, addExistingRollup.LastVerifiedBatchBeforeUpgrade, addExistingRollup.ForkID, "")
}

Expand Down Expand Up @@ -1553,11 +1561,18 @@ func (etherMan *Client) EthBlockByNumber(ctx context.Context, blockNumber uint64

// GetLatestBatchNumber function allows to retrieve the latest proposed batch in the smc
func (etherMan *Client) GetLatestBatchNumber() (uint64, error) {
var latestBatchNum uint64
rollupData, err := etherMan.RollupManager.RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID)
if err != nil {
return 0, err
log.Debug("error getting latestBatchNum from rollupManager. Trying old zkevm smc... Error: ", err)
latestBatchNum, err = etherMan.OldZkEVM.LastBatchSequenced(&bind.CallOpts{Pending: false})
if err != nil {
return latestBatchNum, err
}
} else {
latestBatchNum = rollupData.LastBatchSequenced
}
return rollupData.LastBatchSequenced, nil
return latestBatchNum, nil
}

// GetLatestBlockNumber gets the latest block number from the ethereum
Expand Down Expand Up @@ -1595,11 +1610,18 @@ func (etherMan *Client) GetLatestBlockTimestamp(ctx context.Context) (uint64, er

// GetLatestVerifiedBatchNum gets latest verified batch from ethereum
func (etherMan *Client) GetLatestVerifiedBatchNum() (uint64, error) {
var lastVerifiedBatchNum uint64
rollupData, err := etherMan.RollupManager.RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID)
if err != nil {
return 0, err
log.Debug("error getting lastVerifiedBatchNum from rollupManager. Trying old zkevm smc... Error: ", err)
lastVerifiedBatchNum, err = etherMan.OldZkEVM.LastVerifiedBatch(&bind.CallOpts{Pending: false})
if err != nil {
return lastVerifiedBatchNum, err
}
} else {
lastVerifiedBatchNum = rollupData.LastVerifiedBatch
}
return rollupData.LastVerifiedBatch, nil
return lastVerifiedBatchNum, nil
}

// GetTx function get ethereum tx
Expand Down

0 comments on commit 18a75ff

Please sign in to comment.