diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index e825ebd042..8b58221b25 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -20,7 +20,7 @@
"300ms"
MaxRequestsPerIPAndSecond defines how much requests a single IP can
send within a single second
SequencerNodeURI is used allow Non-Sequencer nodes
to relay transactions to the Sequencer node
MaxCumulativeGasUsed is the max gas allowed per batch
Enabled defines if the WebSocket requests are enabled or disabled
Host defines the network adapter that will be used to serve the WS requests
Port defines the port to serve the endpoints via WS
ReadLimit defines the maximum size of a message read from the client (in bytes)
EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.
BatchRequestsEnabled defines if the Batch requests are enabled or disabled
BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request
L2Coinbase defines which address is going to receive the fees
Must contain a minimum of 20 items
Must contain a maximum of 20 items
MaxLogsCount is a configuration to set the max number of logs that can be returned
in a single call to the state, if zero it means no limit
MaxLogsBlockRange is a configuration to set the max range for block number when querying TXs
logs in a single call to the state, if zero it means no limit
MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying
native block hashes in a single call to the state, if zero it means no limit
EnableHttpLog allows the user to enable or disable the logs related to the HTTP
requests to be captured by the server.
XLayer config
EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction
URLs nacos server urls for discovery service of rest api, url is separated by ","
NamespaceId nacos namepace id for discovery service of rest api
ApplicationName rest application name in nacos
ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker
URLs nacos server urls for discovery service of rest api, url is separated by ","
NamespaceId nacos namepace id for discovery service of rest api
ApplicationName rest application name in nacos
ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker
GasLimitFactor is used to multiply the suggested gas provided by the network
in order to allow a enough gas to be set for all the transactions default value is 1.
ex:
suggested gas limit: 100
GasLimitFactor: 1
gas limit = 100
suggested gas limit: 100
GasLimitFactor: 1.1
gas limit = 110
DisableAPIs disable some API
Enabled defines if the rate limit is enabled or disabled
RateLimitApis defines the apis that need to be rate limited
RateLimitBurst defines the maximum burst size of requests
RateLimitDuration defines the time window for the rate limit
SpecialApis defines the apis that need to be rate limited with special rate limit
Api defines the api that need to be rate limited
Count defines the maximum burst size of requests
Duration defines the time window for the rate limit
Enabled defines if the dynamic gas price is enabled or disabled
CongestionTxThreshold defines the tx threshold to measure whether there is congestion
CheckBatches defines the number of recent Batches used to sample gas price
SampleTxNumer defines the number of sampled gas prices in each batch
Percentile defines the sampling weight of all sampled gas prices
MaxPrice defines the dynamic gas price upper limit
MinPrice defines the dynamic gas price lower limit
UpdatePeriod defines the time interval for updating dynamic gas price
"1m"
"300ms"
-EnableInnerTxCacheDB enables the inner tx cache db
BridgeAddress is the address of the bridge contract
Must contain a minimum of 20 items
Must contain a maximum of 20 items
Enabled defines if the api authentication is enabled
ApiKeys defines the api keys
Name defines the name of the key
Key defines the key
Timeout defines the timeout
SyncInterval is the delay interval between reading new rollup information
"1m"
+EnableInnerTxCacheDB enables the inner tx cache db
BridgeAddress is the address of the bridge contract
Must contain a minimum of 20 items
Must contain a maximum of 20 items
Enabled defines if the api authentication is enabled
ApiKeys defines the api keys
Name defines the name of the key
Key defines the key
Timeout defines the timeout
SyncInterval is the delay interval between reading new rollup information
"1m"
"300ms"
SyncChunkSize is the number of blocks to sync on each chunk
TrustedSequencerURL is the rpc url to connect and sync the trusted state
SyncBlockProtection specify the state to sync (lastest, finalized or safe)
L1SyncCheckL2BlockHash if is true when a batch is closed is force to check L2Block hash against trustedNode (only apply for permissionless)
L1SyncCheckL2BlockNumberhModulus is the modulus used to choose the l2block to check
a modules 5, for instance, means check all l2block multiples of 5 (10,15,20,...)
If enabled then the check l1 Block Hash is active
L1SafeBlockPoint is the point that a block is considered safe enough to be checked
it can be: finalized, safe,pending or latest
L1SafeBlockOffset is the offset to add to L1SafeBlockPoint as a safe point
it can be positive or negative
Example: L1SafeBlockPoint= finalized, L1SafeBlockOffset= -10, then the safe block ten blocks before the finalized block
ForceCheckBeforeStart if is true then the first time the system is started it will force to check all pending blocks
If enabled then the pre-check is active, will check blocks between L1SafeBlock and L1PreSafeBlock
L1PreSafeBlockPoint is the point that a block is considered safe enough to be checked
it can be: finalized, safe,pending or latest
L1PreSafeBlockOffset is the offset to add to L1PreSafeBlockPoint as a safe point
it can be positive or negative
Example: L1PreSafeBlockPoint= finalized, L1PreSafeBlockOffset= -10, then the safe block ten blocks before the finalized block
L1SynchronizationMode define how to synchronize with L1:
- parallel: Request data to L1 in parallel, and process sequentially. The advantage is that executor is not blocked waiting for L1 data
- sequential: Request data to L1 and execute
MaxClients Number of clients used to synchronize with L1
MaxPendingNoProcessedBlocks Size of the buffer used to store rollup information from L1, must be >= to NumberOfEthereumClientsToSync
sugested twice of NumberOfParallelOfEthereumClients
RequestLastBlockPeriod is the time to wait to request the
last block to L1 to known if we need to retrieve more data.
This value only apply when the system is synchronized
"1m"
"300ms"
diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md
index cf6cba6a3a..e13f7abb5b 100644
--- a/docs/config-file/node-config-doc.md
+++ b/docs/config-file/node-config-doc.md
@@ -2412,12 +2412,13 @@ ApiKeys=[]
**Type:** : `object`
**Description:** ApiRelay defines the relay configuration for the API
-| Property | Pattern | Type | Deprecated | Definition | Title/Description |
-| ----------------------------------- | ------- | --------------- | ---------- | ---------- | ----------------- |
-| - [Enabled](#RPC_ApiRelay_Enabled ) | No | boolean | No | - | - |
-| - [DestURI](#RPC_ApiRelay_DestURI ) | No | string | No | - | - |
-| - [RPCs](#RPC_ApiRelay_RPCs ) | No | array of string | No | - | - |
-| - [Rerun](#RPC_ApiRelay_Rerun ) | No | boolean | No | - | - |
+| Property | Pattern | Type | Deprecated | Definition | Title/Description |
+| ------------------------------------- | ------- | --------------- | ---------- | ---------- | ----------------- |
+| - [Enabled](#RPC_ApiRelay_Enabled ) | No | boolean | No | - | - |
+| - [DestURI](#RPC_ApiRelay_DestURI ) | No | string | No | - | - |
+| - [RPCs](#RPC_ApiRelay_RPCs ) | No | array of string | No | - | - |
+| - [Rerun](#RPC_ApiRelay_Rerun ) | No | boolean | No | - | - |
+| - [RelayAll](#RPC_ApiRelay_RelayAll ) | No | boolean | No | - | - |
#### 8.30.1. `RPC.ApiRelay.Enabled`
@@ -2467,6 +2468,18 @@ RPCs=[]
Rerun=false
```
+#### 8.30.5. `RPC.ApiRelay.RelayAll`
+
+**Type:** : `boolean`
+
+**Default:** `false`
+
+**Example setting the default value** (false):
+```
+[RPC.ApiRelay]
+RelayAll=false
+```
+
## 9. `[Synchronizer]`
**Type:** : `object`
diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json
index 052ef87908..e6b07662ce 100644
--- a/docs/config-file/node-config-schema.json
+++ b/docs/config-file/node-config-schema.json
@@ -964,6 +964,10 @@
"Rerun": {
"type": "boolean",
"default": false
+ },
+ "RelayAll": {
+ "type": "boolean",
+ "default": false
}
},
"additionalProperties": false,
diff --git a/jsonrpc/api_relay_xlayer.go b/jsonrpc/api_relay_xlayer.go
index b2d3d78e05..d7484ee672 100644
--- a/jsonrpc/api_relay_xlayer.go
+++ b/jsonrpc/api_relay_xlayer.go
@@ -1,6 +1,8 @@
package jsonrpc
import (
+ "time"
+
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/client"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
@@ -9,13 +11,14 @@ import (
// ApiRelayConfig is the api relay config
type ApiRelayConfig struct {
- Enabled bool `mapstructure:"Enabled"`
- DestURI string `mapstructure:"DestURI"`
- RPCs []string `mapstructure:"RPCs"`
- Rerun bool `mapstructure:"Rerun"`
+ Enabled bool `mapstructure:"Enabled"`
+ DestURI string `mapstructure:"DestURI"`
+ RPCs []string `mapstructure:"RPCs"`
+ Rerun bool `mapstructure:"Rerun"`
+ RelayAll bool `mapstructure:"RelayAll"`
}
-func shouldRelay(localCfg ApiRelayConfig, name string) bool {
+func shouldRelayByMethod(localCfg ApiRelayConfig, name string) bool {
enable := localCfg.Enabled && localCfg.DestURI != ""
contained := types.Contains(localCfg.RPCs, name)
if getApolloConfig().Enable() {
@@ -50,17 +53,37 @@ func getRelayDestURI(localDestURI string) string {
}
func tryRelay(localCfg ApiRelayConfig, request types.Request) (types.Response, bool) {
- if shouldRelay(localCfg, request.Method) && pass(&request) {
+ if shouldRelay(localCfg, &request) {
destURI := getRelayDestURI(localCfg.DestURI)
+ ts := time.Now()
res, err := client.JSONRPCRelay(destURI, request, shouldRerun(localCfg))
if err != nil {
log.Errorf("failed to relay %v to %s: %v", request.Method, destURI, err)
metrics.RequestRelayFailCount(request.Method)
return types.Response{}, false
}
+ log.Infof("relayed %v to %s in %v", request.Method, destURI, time.Since(ts))
return res, true
}
return types.Response{}, false
}
+
+func shouldRelay(localCfg ApiRelayConfig, request *types.Request) bool {
+ enable := localCfg.Enabled &&
+ localCfg.DestURI != ""
+ relayAll := localCfg.RelayAll
+ if getApolloConfig().Enable() {
+ getApolloConfig().RLock()
+ defer getApolloConfig().RUnlock()
+ enable = getApolloConfig().ApiRelay.Enabled &&
+ getApolloConfig().ApiRelay.DestURI != ""
+ relayAll = getApolloConfig().ApiRelay.RelayAll
+ }
+ if enable && relayAll {
+ return true
+ }
+
+ return shouldRelayByMethod(localCfg, request.Method) && pass(request)
+}
diff --git a/jsonrpc/apollo_xlayer.go b/jsonrpc/apollo_xlayer.go
index bcbd7ab9c8..4788c431ae 100644
--- a/jsonrpc/apollo_xlayer.go
+++ b/jsonrpc/apollo_xlayer.go
@@ -56,6 +56,7 @@ func (c *ApolloConfig) setApiRelayCfg(apiRelayCfg ApiRelayConfig) {
c.ApiRelay.DestURI = apiRelayCfg.DestURI
c.ApiRelay.RPCs = make([]string, len(apiRelayCfg.RPCs))
c.ApiRelay.Rerun = apiRelayCfg.Rerun
+ c.ApiRelay.RelayAll = apiRelayCfg.RelayAll
copy(c.ApiRelay.RPCs, apiRelayCfg.RPCs)
}
diff --git a/pool/pool_xlayer.go b/pool/pool_xlayer.go
index e6d2e16713..39772d9a4c 100644
--- a/pool/pool_xlayer.go
+++ b/pool/pool_xlayer.go
@@ -8,9 +8,10 @@ import (
"sync"
"time"
+ "github.com/ethereum/go-ethereum/common"
+
"github.com/0xPolygonHermez/zkevm-node/hex"
"github.com/0xPolygonHermez/zkevm-node/log"
- "github.com/ethereum/go-ethereum/common"
)
const (
@@ -134,6 +135,7 @@ func (p *Pool) checkFreeGp(ctx context.Context, poolTx Transaction, from common.
fromToName, freeGpList := GetSpecialFreeGasList(p.cfg.FreeGasList)
info := freeGpList[fromToName[from.String()]]
if info != nil &&
+ poolTx.To() != nil &&
Contains(info.ToList, *poolTx.To()) &&
ContainsMethod("0x"+common.Bytes2Hex(poolTx.Data()), info.MethodSigs) {
return true, nil