Skip to content

Commit

Permalink
Feature/0xPolygonHermez#3549 reorgs improvement (0xPolygonHermez#3553)
Browse files Browse the repository at this point in the history
* New reorg function

* mocks

* linter

* Synchronizer tests

* new elderberry smc docker image

* new image

* logs

* fix json rpc

* fix

* Test sync from empty block

* Regular reorg case tested

* linter

* remove empty block + fix LatestSyncedBlockEmpty

* Improve check reorgs when no block is received during the call

* fix RPC error code for eth_estimateGas and eth_call for reverted tx and no return value; fix e2e test;

* fix test

* Extra unit test

* fix reorg until genesis

* disable parallel synchronization

---------

Co-authored-by: tclemos <[email protected]>
  • Loading branch information
2 people authored and Stefan-Ethernal committed May 21, 2024
1 parent 52e9667 commit d9ec8f0
Show file tree
Hide file tree
Showing 11 changed files with 1,489 additions and 150 deletions.
12 changes: 6 additions & 6 deletions config/environments/local/local.genesis.config.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/running_local.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ To configure your Metamask to use your local environment, follow these steps:
| Address | Description |
|---|---|
| 0x8dAF17A20c9DBA35f005b6324F493785D239719d | Polygon ZKEVM |
| 0x40E0576c0A7dff9dc460B29ba73e79aBf73dD2a9 | Polygon Bridge |
| 0xFe12ABaa190Ef0c8638Ee0ba9F828BF41368Ca0E | Polygon Bridge |
| 0x5FbDB2315678afecb367f032d93F642f64180aa3 | Pol token |
| 0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 | Polygon GlobalExitRootManager |
| 0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e | Polygon RollupManager |
Expand Down
4 changes: 2 additions & 2 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func NewClient(cfg Config, l1Config L1Config, da dataavailability.BatchDataProvi
rollupID, err := rollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr)
if err != nil {
log.Debugf("error rollupManager.RollupAddressToID(%s). Error: %w", l1Config.RollupManagerAddr, err)
// TODO return error after the upgrade
return nil, err
}
log.Debug("rollupID: ", rollupID)

Expand Down Expand Up @@ -1635,7 +1635,7 @@ func (etherMan *Client) forceSequencedBatchesEvent(ctx context.Context, vLog typ
if err != nil {
return err
}
// TODO completar los datos de forcedBlockHas, forcedGer y forcedTimestamp
// TODO complete data forcedBlockHash, forcedGer y forcedTimestamp

// Read the tx for this batch.
tx, err := etherMan.EthClient.TransactionInBlock(ctx, vLog.BlockHash, vLog.TxIndex)
Expand Down
8 changes: 6 additions & 2 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash
return e.txMan.NewDbTxScope(e.state, func(ctx context.Context, dbTx pgx.Tx) (interface{}, types.Error) {
if arg == nil {
return RPCErrorResponse(types.InvalidParamsErrorCode, "missing value for required argument 0", nil, false)
} else if blockArg == nil {
return RPCErrorResponse(types.InvalidParamsErrorCode, "missing value for required argument 1", nil, false)
}
block, respErr := e.getBlockByArg(ctx, blockArg, dbTx)
if respErr != nil {
Expand Down Expand Up @@ -113,6 +111,9 @@ func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash
if result.Reverted() {
data := make([]byte, len(result.ReturnValue))
copy(data, result.ReturnValue)
if len(data) == 0 {
return nil, types.NewRPCError(types.DefaultErrorCode, result.Err.Error())
}
return nil, types.NewRPCErrorWithData(types.RevertedErrorCode, result.Err.Error(), data)
} else if result.Failed() {
return nil, types.NewRPCError(types.DefaultErrorCode, result.Err.Error())
Expand Down Expand Up @@ -191,6 +192,9 @@ func (e *EthEndpoints) EstimateGas(arg *types.TxArgs, blockArg *types.BlockNumbe
if errors.Is(err, runtime.ErrExecutionReverted) {
data := make([]byte, len(returnValue))
copy(data, returnValue)
if len(data) == 0 {
return nil, types.NewRPCError(types.DefaultErrorCode, err.Error())
}
return nil, types.NewRPCErrorWithData(types.RevertedErrorCode, err.Error(), data)
} else if err != nil {
return nil, types.NewRPCError(types.DefaultErrorCode, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestCall(t *testing.T) {
latest,
},
expectedResult: nil,
expectedError: types.NewRPCError(types.RevertedErrorCode, "execution reverted"),
expectedError: types.NewRPCError(types.DefaultErrorCode, "execution reverted"),
setupMocks: func(c Config, m *mocksWrapper, testCase *testCase) {
nonce := uint64(7)
m.DbTx.On("Rollback", context.Background()).Return(nil).Once()
Expand Down
1 change: 1 addition & 0 deletions synchronizer/common/syncinterfaces/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type EthermanFullInterface interface {
GetTrustedSequencerURL() (string, error)
VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error)
GetLatestVerifiedBatchNum() (uint64, error)
GetFinalizedBlockNumber(ctx context.Context) (uint64, error)
}

type EthermanGetLatestBatchNumber interface {
Expand Down

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

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

Loading

0 comments on commit d9ec8f0

Please sign in to comment.