Skip to content

Commit

Permalink
add disable apis
Browse files Browse the repository at this point in the history
use slice to check

add configures

modify comments

only disable eth_newFilter's http request, diable eth_getInternalTransactions

default support all

lint code

add disable rpc api

fix e2e

add check nil

use RPCEroorResponse

restore configure
  • Loading branch information
giskook committed Dec 17, 2023
1 parent 6de0441 commit 44d7ca2
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 50 deletions.
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ MaxRequestsPerIPAndSecond = 500
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = true
TraceBatchUseHTTPS = true
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Host = "0.0.0.0"
Expand Down
1 change: 1 addition & 0 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://internal.xgon-test.net:2083/"
EnableL2SuggestedGasPricePolling = true
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Port = 8546
Expand Down
1 change: 1 addition & 0 deletions config/environments/mainnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://xgon-rpc.com"
EnableL2SuggestedGasPricePolling = false
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Port = 8546
Expand Down
1 change: 1 addition & 0 deletions config/environments/testnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://rpc.public.xgon-test.net/"
EnableL2SuggestedGasPricePolling = false
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Port = 8546
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,21 +748,21 @@ FreeGasAddress="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
**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 |
| - [EnablePendingTransactionFilter](#RPC_EnablePendingTransactionFilter ) | No | boolean | No | - | EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction |
| - [Nacos](#RPC_Nacos ) | No | object | No | - | Nacos configuration |
| - [NacosWs](#RPC_NacosWs ) | No | object | No | - | NacosWs configuration |
| 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 |
| - [Nacos](#RPC_Nacos ) | No | object | No | - | Nacos configuration |
| - [NacosWs](#RPC_NacosWs ) | No | object | No | - | NacosWs configuration |
| - [DisableAPIs](#RPC_DisableAPIs ) | No | array of string | No | - | DisableAPIs disable some API |

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

Expand Down Expand Up @@ -972,21 +972,7 @@ to do the parallel requests to RPC.debug_traceTransaction endpoint
TraceBatchUseHTTPS=true
```

### <a name="RPC_EnablePendingTransactionFilter"></a>8.11. `RPC.EnablePendingTransactionFilter`

**Type:** : `boolean`

**Default:** `false`

**Description:** EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction

**Example setting the default value** (false):
```
[RPC]
EnablePendingTransactionFilter=false
```

### <a name="RPC_Nacos"></a>8.12. `[RPC.Nacos]`
### <a name="RPC_Nacos"></a>8.11. `[RPC.Nacos]`

**Type:** : `object`
**Description:** Nacos configuration
Expand All @@ -998,7 +984,7 @@ EnablePendingTransactionFilter=false
| - [ApplicationName](#RPC_Nacos_ApplicationName ) | No | string | No | - | ApplicationName rest application name in nacos |
| - [ExternalListenAddr](#RPC_Nacos_ExternalListenAddr ) | No | string | No | - | ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker |

#### <a name="RPC_Nacos_URLs"></a>8.12.1. `RPC.Nacos.URLs`
#### <a name="RPC_Nacos_URLs"></a>8.11.1. `RPC.Nacos.URLs`

**Type:** : `string`

Expand All @@ -1012,7 +998,7 @@ EnablePendingTransactionFilter=false
URLs=""
```

#### <a name="RPC_Nacos_NamespaceId"></a>8.12.2. `RPC.Nacos.NamespaceId`
#### <a name="RPC_Nacos_NamespaceId"></a>8.11.2. `RPC.Nacos.NamespaceId`

**Type:** : `string`

Expand All @@ -1026,7 +1012,7 @@ URLs=""
NamespaceId=""
```

#### <a name="RPC_Nacos_ApplicationName"></a>8.12.3. `RPC.Nacos.ApplicationName`
#### <a name="RPC_Nacos_ApplicationName"></a>8.11.3. `RPC.Nacos.ApplicationName`

**Type:** : `string`

Expand All @@ -1040,7 +1026,7 @@ NamespaceId=""
ApplicationName=""
```

#### <a name="RPC_Nacos_ExternalListenAddr"></a>8.12.4. `RPC.Nacos.ExternalListenAddr`
#### <a name="RPC_Nacos_ExternalListenAddr"></a>8.11.4. `RPC.Nacos.ExternalListenAddr`

**Type:** : `string`

Expand All @@ -1054,7 +1040,7 @@ ApplicationName=""
ExternalListenAddr=""
```

### <a name="RPC_NacosWs"></a>8.13. `[RPC.NacosWs]`
### <a name="RPC_NacosWs"></a>8.12. `[RPC.NacosWs]`

**Type:** : `object`
**Description:** NacosWs configuration
Expand All @@ -1066,7 +1052,7 @@ ExternalListenAddr=""
| - [ApplicationName](#RPC_NacosWs_ApplicationName ) | No | string | No | - | ApplicationName rest application name in nacos |
| - [ExternalListenAddr](#RPC_NacosWs_ExternalListenAddr ) | No | string | No | - | ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker |

#### <a name="RPC_NacosWs_URLs"></a>8.13.1. `RPC.NacosWs.URLs`
#### <a name="RPC_NacosWs_URLs"></a>8.12.1. `RPC.NacosWs.URLs`

**Type:** : `string`

Expand All @@ -1080,7 +1066,7 @@ ExternalListenAddr=""
URLs=""
```

#### <a name="RPC_NacosWs_NamespaceId"></a>8.13.2. `RPC.NacosWs.NamespaceId`
#### <a name="RPC_NacosWs_NamespaceId"></a>8.12.2. `RPC.NacosWs.NamespaceId`

**Type:** : `string`

Expand All @@ -1094,7 +1080,7 @@ URLs=""
NamespaceId=""
```

#### <a name="RPC_NacosWs_ApplicationName"></a>8.13.3. `RPC.NacosWs.ApplicationName`
#### <a name="RPC_NacosWs_ApplicationName"></a>8.12.3. `RPC.NacosWs.ApplicationName`

**Type:** : `string`

Expand All @@ -1108,7 +1094,7 @@ NamespaceId=""
ApplicationName=""
```

#### <a name="RPC_NacosWs_ExternalListenAddr"></a>8.13.4. `RPC.NacosWs.ExternalListenAddr`
#### <a name="RPC_NacosWs_ExternalListenAddr"></a>8.12.4. `RPC.NacosWs.ExternalListenAddr`

**Type:** : `string`

Expand All @@ -1122,6 +1108,20 @@ ApplicationName=""
ExternalListenAddr=""
```

### <a name="RPC_DisableAPIs"></a>8.13. `RPC.DisableAPIs`

**Type:** : `array of string`

**Default:** `[]`

**Description:** DisableAPIs disable some API

**Example setting the default value** ([]):
```
[RPC]
DisableAPIs=[]
```

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

**Type:** : `object`
Expand Down
13 changes: 8 additions & 5 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,6 @@
"description": "TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)\nto do the parallel requests to RPC.debug_traceTransaction endpoint",
"default": true
},
"EnablePendingTransactionFilter": {
"type": "boolean",
"description": "EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction",
"default": false
},
"Nacos": {
"properties": {
"URLs": {
Expand Down Expand Up @@ -418,6 +413,14 @@
"additionalProperties": false,
"type": "object",
"description": "NacosWs configuration"
},
"DisableAPIs": {
"items": {
"type": "string"
},
"type": "array",
"description": "DisableAPIs disable some API",
"default": []
}
},
"additionalProperties": false,
Expand Down
6 changes: 3 additions & 3 deletions jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type Config struct {
// to do the parallel requests to RPC.debug_traceTransaction endpoint
TraceBatchUseHTTPS bool `mapstructure:"TraceBatchUseHTTPS"`

// EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction
EnablePendingTransactionFilter bool `mapstructure:"EnablePendingTransactionFilter"`

// Nacos configuration
Nacos NacosConfig `mapstructure:"Nacos"`

// NacosWs configuration
NacosWs NacosConfig `mapstructure:"NacosWs"`

// DisableAPIs disable some API
DisableAPIs []string `mapstructure:"DisableAPIs"`
}

// WebSocketsConfig has parameters to config the rpc websocket support
Expand Down
14 changes: 12 additions & 2 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ func (e *EthEndpoints) GetLogs(filter LogFilter) (interface{}, types.Error) {
}

func (e *EthEndpoints) internalGetLogs(ctx context.Context, dbTx pgx.Tx, filter LogFilter) (interface{}, types.Error) {
if len(e.cfg.DisableAPIs) > 0 && types.Contains(e.cfg.DisableAPIs, "eth_getLogs") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil)
}

var err error
var fromBlock uint64 = 0
if filter.FromBlock != nil {
Expand Down Expand Up @@ -794,6 +798,9 @@ func (e *EthEndpoints) NewBlockFilter() (interface{}, types.Error) {

// internal
func (e *EthEndpoints) newBlockFilter(wsConn *websocket.Conn) (interface{}, types.Error) {
if len(e.cfg.DisableAPIs) > 0 && types.Contains(e.cfg.DisableAPIs, "eth_newBlockFilter") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil)
}
id, err := e.storage.NewBlockFilter(wsConn)
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to create new block filter", err)
Expand All @@ -811,6 +818,9 @@ func (e *EthEndpoints) NewFilter(filter LogFilter) (interface{}, types.Error) {

// internal
func (e *EthEndpoints) newFilter(wsConn *websocket.Conn, filter LogFilter) (interface{}, types.Error) {
if len(e.cfg.DisableAPIs) > 0 && types.Contains(e.cfg.DisableAPIs, "eth_newFilter") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil)
}
id, err := e.storage.NewLogFilter(wsConn, filter)
if errors.Is(err, ErrFilterInvalidPayload) {
return RPCErrorResponse(types.InvalidParamsErrorCode, err.Error(), nil)
Expand All @@ -830,8 +840,8 @@ func (e *EthEndpoints) NewPendingTransactionFilter() (interface{}, types.Error)

// internal
func (e *EthEndpoints) newPendingTransactionFilter(wsConn *websocket.Conn) (interface{}, types.Error) {
if !e.cfg.EnablePendingTransactionFilter {
return nil, types.NewRPCError(types.DefaultErrorCode, "not supported yet")
if len(e.cfg.DisableAPIs) > 0 && types.Contains(e.cfg.DisableAPIs, "eth_newPendingTransactionFilter") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil)
}
id, err := e.storage.NewPendingTransactionFilter(wsConn)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions jsonrpc/endpoints_eth_innertx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var once sync.Once

// GetInternalTransactions returns a transaction by his hash
func (e *EthEndpoints) GetInternalTransactions(hash types.ArgHash) (interface{}, types.Error) {
if len(e.cfg.DisableAPIs) > 0 && types.Contains(e.cfg.DisableAPIs, "eth_getInternalTransactions") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil)
}
once.Do(func() {
debugEndPoints = &DebugEndpoints{
state: e.state,
Expand Down
11 changes: 11 additions & 0 deletions jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,14 @@ func ToBatchNumArg(number *big.Int) string {
}
return hex.EncodeBig(number)
}

// Contains checks if a string is contained in a slice of strings
func Contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}

return false
}
1 change: 1 addition & 0 deletions test/config/debug.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 10000
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = true
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Port = 8133
Expand Down
1 change: 1 addition & 0 deletions test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = true
DisableAPIs = []
[RPC.WebSockets]
Enabled = true
Port = 8133
Expand Down

0 comments on commit 44d7ca2

Please sign in to comment.