Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jRPC support to eth_coinbase #2500

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func runJSONRPCServer(c config.Config, etherman *etherman.Client, chainID uint64
var err error
storage := jsonrpc.NewStorage()
c.RPC.MaxCumulativeGasUsed = c.State.Batch.Constraints.MaxCumulativeGasUsed
c.RPC.L2Coinbase = c.SequenceSender.L2Coinbase
if !c.IsTrustedSequencer {
if c.RPC.SequencerNodeURI == "" {
log.Debug("getting trusted sequencer URL from smc")
Expand Down
4 changes: 2 additions & 2 deletions docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,20 +718,21 @@ GlobalQueue=1024
**Type:** : `object`
**Description:** Configuration for RPC service. THis one offers a extended Ethereum JSON-RPC API interface to interact with the node

| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| ---------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| - [Host](#RPC_Host ) | No | string | No | - | Host defines the network adapter that will be used to serve the HTTP requests |
| - [Port](#RPC_Port ) | No | integer | No | - | Port defines the port to serve the endpoints via HTTP |
| - [ReadTimeout](#RPC_ReadTimeout ) | No | string | No | - | Duration |
| - [WriteTimeout](#RPC_WriteTimeout ) | No | string | No | - | Duration |
| - [MaxRequestsPerIPAndSecond](#RPC_MaxRequestsPerIPAndSecond ) | No | number | No | - | MaxRequestsPerIPAndSecond defines how much requests a single IP can<br />send within a single second |
| - [SequencerNodeURI](#RPC_SequencerNodeURI ) | No | string | No | - | SequencerNodeURI is used allow Non-Sequencer nodes<br />to relay transactions to the Sequencer node |
| - [MaxCumulativeGasUsed](#RPC_MaxCumulativeGasUsed ) | No | integer | No | - | MaxCumulativeGasUsed is the max gas allowed per batch |
| - [WebSockets](#RPC_WebSockets ) | No | object | No | - | WebSockets configuration |
| - [EnableL2SuggestedGasPricePolling](#RPC_EnableL2SuggestedGasPricePolling ) | No | boolean | No | - | EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price. |
| - [TraceBatchUseHTTPS](#RPC_TraceBatchUseHTTPS ) | No | boolean | No | - | TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)<br />to do the parallel requests to RPC.debug_traceTransaction endpoint |
| - [BatchRequestsEnabled](#RPC_BatchRequestsEnabled ) | No | boolean | No | - | BatchRequestsEnabled defines if the Batch requests are enabled or disabled |
| - [BatchRequestsLimit](#RPC_BatchRequestsLimit ) | No | integer | No | - | BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request |
| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| ---------------------------------------------------------------------------- | ------- | ---------------- | ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| - [Host](#RPC_Host ) | No | string | No | - | Host defines the network adapter that will be used to serve the HTTP requests |
| - [Port](#RPC_Port ) | No | integer | No | - | Port defines the port to serve the endpoints via HTTP |
| - [ReadTimeout](#RPC_ReadTimeout ) | No | string | No | - | Duration |
| - [WriteTimeout](#RPC_WriteTimeout ) | No | string | No | - | Duration |
| - [MaxRequestsPerIPAndSecond](#RPC_MaxRequestsPerIPAndSecond ) | No | number | No | - | MaxRequestsPerIPAndSecond defines how much requests a single IP can<br />send within a single second |
| - [SequencerNodeURI](#RPC_SequencerNodeURI ) | No | string | No | - | SequencerNodeURI is used allow Non-Sequencer nodes<br />to relay transactions to the Sequencer node |
| - [MaxCumulativeGasUsed](#RPC_MaxCumulativeGasUsed ) | No | integer | No | - | MaxCumulativeGasUsed is the max gas allowed per batch |
| - [WebSockets](#RPC_WebSockets ) | No | object | No | - | WebSockets configuration |
| - [EnableL2SuggestedGasPricePolling](#RPC_EnableL2SuggestedGasPricePolling ) | No | boolean | No | - | EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price. |
| - [TraceBatchUseHTTPS](#RPC_TraceBatchUseHTTPS ) | No | boolean | No | - | TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)<br />to do the parallel requests to RPC.debug_traceTransaction endpoint |
| - [BatchRequestsEnabled](#RPC_BatchRequestsEnabled ) | No | boolean | No | - | BatchRequestsEnabled defines if the Batch requests are enabled or disabled |
| - [BatchRequestsLimit](#RPC_BatchRequestsLimit ) | No | integer | No | - | BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request |
| - [L2Coinbase](#RPC_L2Coinbase ) | No | array of integer | No | - | L2Coinbase defines which address is going to receive the fees |

### <a name="RPC_Host"></a>8.1. `RPC.Host`

Expand Down Expand Up @@ -984,6 +985,11 @@ BatchRequestsEnabled=false
BatchRequestsLimit=20
```

### <a name="RPC_L2Coinbase"></a>8.13. `RPC.L2Coinbase`

**Type:** : `array of integer`
**Description:** L2Coinbase defines which address is going to receive the fees

## <a name="Synchronizer"></a>9. `[Synchronizer]`

**Type:** : `object`
Expand Down Expand Up @@ -1626,7 +1632,7 @@ DefaultMinGasPriceAllowed=0
| - [LastBatchVirtualizationTimeMaxWaitPeriod](#SequenceSender_LastBatchVirtualizationTimeMaxWaitPeriod ) | No | string | No | - | Duration |
| - [MaxTxSizeForL1](#SequenceSender_MaxTxSizeForL1 ) | No | integer | No | - | MaxTxSizeForL1 is the maximum size a single transaction can have. This field has<br />non-trivial consequences: larger transactions than 128KB are significantly harder and<br />more expensive to propagate; larger transactions also take more resources<br />to validate whether they fit into the pool or not. |
| - [SenderAddress](#SequenceSender_SenderAddress ) | No | array of integer | No | - | SenderAddress defines which private key the eth tx manager needs to use<br />to sign the L1 txs |
| - [L2Coinbase](#SequenceSender_L2Coinbase ) | No | array of integer | No | - | L2Coinbase defines which addess is going to receive the fees |
| - [L2Coinbase](#SequenceSender_L2Coinbase ) | No | array of integer | No | - | L2Coinbase defines which address is going to receive the fees |
| - [PrivateKey](#SequenceSender_PrivateKey ) | No | object | No | - | PrivateKey defines all the key store files that are going<br />to be read in order to provide the private keys to sign the L1 txs |
| - [ForkUpgradeBatchNumber](#SequenceSender_ForkUpgradeBatchNumber ) | No | integer | No | - | Batch number where there is a forkid change (fork upgrade) |

Expand Down Expand Up @@ -1712,7 +1718,7 @@ to sign the L1 txs

**Default:** `"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"`

**Description:** L2Coinbase defines which addess is going to receive the fees
**Description:** L2Coinbase defines which address is going to receive the fees

**Example setting the default value** ("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"):
```
Expand Down
11 changes: 10 additions & 1 deletion docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@
"type": "integer",
"description": "BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request",
"default": 20
},
"L2Coinbase": {
"items": {
"type": "integer"
},
"type": "array",
"maxItems": 20,
"minItems": 20,
"description": "L2Coinbase defines which address is going to receive the fees"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -656,7 +665,7 @@
"type": "array",
"maxItems": 20,
"minItems": 20,
"description": "L2Coinbase defines which addess is going to receive the fees",
"description": "L2Coinbase defines which address is going to receive the fees",
"default": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
},
"PrivateKey": {
Expand Down
8 changes: 7 additions & 1 deletion jsonrpc/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jsonrpc

import "github.com/0xPolygonHermez/zkevm-node/config/types"
import (
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/ethereum/go-ethereum/common"
)

// Config represents the configuration of the json rpc
type Config struct {
Expand Down Expand Up @@ -44,6 +47,9 @@ type Config struct {

// BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request
BatchRequestsLimit uint `mapstructure:"BatchRequestsLimit"`

// L2Coinbase defines which address is going to receive the fees
L2Coinbase common.Address
}

// WebSocketsConfig has parameters to config the rpc websocket support
Expand Down
26 changes: 26 additions & 0 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ func (e *EthEndpoints) ChainId() (interface{}, types.Error) { //nolint:revive
return hex.EncodeUint64(e.chainID), nil
}

// Coinbase Returns the client coinbase address.
func (e *EthEndpoints) Coinbase() (interface{}, types.Error) { //nolint:revive
if e.cfg.SequencerNodeURI != "" {
return e.getCoinbaseFromSequencerNode()
}
return e.cfg.L2Coinbase.String(), nil
}

func (e *EthEndpoints) getCoinbaseFromSequencerNode() (interface{}, types.Error) {
res, err := client.JSONRPCCall(e.cfg.SequencerNodeURI, "eth_coinbase")
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get coinbase from sequencer node", err)
}

if res.Error != nil {
return RPCErrorResponse(res.Error.Code, res.Error.Message, nil)
}

var coinbaseAddress common.Address
err = json.Unmarshal(res.Result, &coinbaseAddress)
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to read coinbase from sequencer node", err)
}
return coinbaseAddress.String(), nil
}

// EstimateGas generates and returns an estimate of how much gas is necessary to
// allow the transaction to complete.
// The transaction will not be added to the blockchain.
Expand Down
59 changes: 59 additions & 0 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,65 @@ func TestChainID(t *testing.T) {
assert.Equal(t, s.ChainID(), chainID.Uint64())
}

func TestCoinbase(t *testing.T) {
testCases := []struct {
name string
callSequencer bool
trustedCoinbase *common.Address
permissionlessCoinbase *common.Address
error error
expectedCoinbase common.Address
}{
{"Coinbase not configured", true, nil, nil, nil, common.Address{}},
{"Get trusted sequencer coinbase directly", true, state.AddressPtr(common.HexToAddress("0x1")), nil, nil, common.HexToAddress("0x1")},
{"Get trusted sequencer coinbase via permissionless", false, state.AddressPtr(common.HexToAddress("0x1")), nil, nil, common.HexToAddress("0x1")},
{"Ignore permissionless config", false, state.AddressPtr(common.HexToAddress("0x2")), state.AddressPtr(common.HexToAddress("0x1")), nil, common.HexToAddress("0x2")},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := getSequencerDefaultConfig()
if tc.trustedCoinbase != nil {
cfg.L2Coinbase = *tc.trustedCoinbase
}
sequencerServer, _, _ := newMockedServerWithCustomConfig(t, cfg)

var nonSequencerServer *mockedServer
if !tc.callSequencer {
cfg = getNonSequencerDefaultConfig(sequencerServer.ServerURL)
if tc.permissionlessCoinbase != nil {
cfg.L2Coinbase = *tc.permissionlessCoinbase
}
nonSequencerServer, _, _ = newMockedServerWithCustomConfig(t, cfg)
}

var res types.Response
var err error
if tc.callSequencer {
res, err = sequencerServer.JSONRPCCall("eth_coinbase")
} else {
res, err = nonSequencerServer.JSONRPCCall("eth_coinbase")
}
require.NoError(t, err)

assert.Nil(t, res.Error)
assert.NotNil(t, res.Result)

var s string
err = json.Unmarshal(res.Result, &s)
require.NoError(t, err)
result := common.HexToAddress(s)

assert.Equal(t, tc.expectedCoinbase.String(), result.String())

sequencerServer.Stop()
if !tc.callSequencer {
nonSequencerServer.Stop()
}
})
}
}

func TestEstimateGas(t *testing.T) {
s, m, _ := newSequencerMockedServer(t)
defer s.Stop()
Expand Down
Loading