This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 724
Feature/3518 use generic eth client for l2 #3519
Merged
joanestebanr
merged 6 commits into
release/v0.6.5
from
feature/3518-use_generic_eth_client_for_l2
Apr 4, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70c772e
#3518 compatibility with ethereum-API L2 node
joanestebanr 4d2c48f
remove unused code
joanestebanr 4490897
migrate docker-compose to v2 because ubuntu:latest have deprecated it
joanestebanr 3a4fa3f
fix docker-compose
joanestebanr 7443e41
fix unittest
joanestebanr 39a489c
fix case trusted URL is not set
joanestebanr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"math/big" | ||
"testing" | ||
|
||
rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"github.com/0xPolygonHermez/zkevm-node/state" | ||
"github.com/0xPolygonHermez/zkevm-node/synchronizer/actions" | ||
mock_syncinterfaces "github.com/0xPolygonHermez/zkevm-node/synchronizer/common/syncinterfaces/mocks" | ||
|
@@ -19,7 +18,7 @@ import ( | |
type CheckL2BlocksTestData struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. } |
||
sut *actions.CheckL2BlockHash | ||
mockState *mock_syncinterfaces.StateFullInterface | ||
zKEVMClient *mock_syncinterfaces.ZKEVMClientInterface | ||
zKEVMClient *mock_syncinterfaces.ZKEVMClientEthereumCompatibleInterface | ||
} | ||
|
||
func TestCheckL2BlockHash_GetMinimumL2BlockToCheck(t *testing.T) { | ||
|
@@ -57,7 +56,7 @@ func TestCheckL2BlockHashNotEnoughBlocksToCheck(t *testing.T) { | |
func newCheckL2BlocksTestData(t *testing.T, initialL2Block, modulus uint64) CheckL2BlocksTestData { | ||
res := CheckL2BlocksTestData{ | ||
mockState: mock_syncinterfaces.NewStateFullInterface(t), | ||
zKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), | ||
zKEVMClient: mock_syncinterfaces.NewZKEVMClientEthereumCompatibleInterface(t), | ||
} | ||
res.sut = actions.NewCheckL2BlockHash(res.mockState, res.zKEVMClient, initialL2Block, modulus) | ||
return res | ||
|
@@ -97,18 +96,23 @@ func TestCheckL2BlockHashMatch(t *testing.T) { | |
|
||
data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) | ||
data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) | ||
l2blockHash := stateBlock.Hash() | ||
rpcL2Block := rpctypes.Block{ | ||
Hash: &l2blockHash, | ||
Number: rpctypes.ArgUint64(lastL2Block), | ||
} | ||
//l2blockHash := stateBlock.Hash() | ||
// rpcL2Block := rpctypes.Block{ | ||
// Hash: &l2blockHash, | ||
// Number: rpctypes.ArgUint64(lastL2Block), | ||
// } | ||
// create a types.Block object | ||
|
||
rpcL2Block := types.NewBlock(&types.Header{ | ||
Number: big.NewInt(int64(lastL2Block)), | ||
}, nil, nil, nil, nil) | ||
|
||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) | ||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) | ||
err := data.sut.CheckL2Block(context.Background(), nil) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestCheckL2BlockHashMissmatch(t *testing.T) { | ||
func TestCheckL2BlockHashMismatch(t *testing.T) { | ||
data := newCheckL2BlocksTestData(t, 1, 10) | ||
lastL2Block := uint64(14) | ||
lastL2BlockBigInt := big.NewInt(int64(lastL2Block)) | ||
|
@@ -119,13 +123,14 @@ func TestCheckL2BlockHashMissmatch(t *testing.T) { | |
|
||
data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) | ||
data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) | ||
l2blockHash := common.HexToHash("0x1234") | ||
rpcL2Block := rpctypes.Block{ | ||
Hash: &l2blockHash, | ||
Number: rpctypes.ArgUint64(lastL2Block), | ||
} | ||
//l2blockHash := common.HexToHash("0x1234") | ||
|
||
rpcL2Block := types.NewBlock(&types.Header{ | ||
Number: big.NewInt(int64(lastL2Block)), | ||
ParentHash: common.HexToHash("0x1234"), | ||
}, nil, nil, nil, nil) | ||
|
||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) | ||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) | ||
err := data.sut.CheckL2Block(context.Background(), nil) | ||
require.Error(t, err) | ||
} |
98 changes: 98 additions & 0 deletions
98
synchronizer/common/syncinterfaces/mocks/zkevm_client_ethereum_compatible_interface.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
synchronizer/common/syncinterfaces/zkevm_ethereum_compatible_client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package syncinterfaces | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// ZKEVMClientEthereumCompatibleInterface contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible | ||
// | ||
// Reason behind: the zkEVMClient have some extensions to ethereum-API that are not compatible with all nodes. So if you need to maximize | ||
// the compatibility the idea is to use a regular ethereum-API compatible client | ||
type ZKEVMClientEthereumCompatibleInterface interface { | ||
ZKEVMClientEthereumCompatibleL2BlockGetter | ||
} | ||
|
||
// ZKEVMClientEthereumCompatibleL2BlockGetter contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible for obtain Block information | ||
type ZKEVMClientEthereumCompatibleL2BlockGetter interface { | ||
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.