Skip to content

Commit

Permalink
Merge branch 'dev' into zjg/merge-v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Jun 25, 2024
2 parents fd233e3 + 889bf00 commit 868ffaf
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

79 changes: 46 additions & 33 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ FreeGasLimit=0
| - [Nacos](#RPC_Nacos ) | No | object | No | - | Nacos configuration |
| - [NacosWs](#RPC_NacosWs ) | No | object | No | - | NacosWs configuration |
| - [GasLimitFactor](#RPC_GasLimitFactor ) | No | number | No | - | GasLimitFactor is used to multiply the suggested gas provided by the network<br />in order to allow a enough gas to be set for all the transactions default value is 1.<br /><br />ex:<br />suggested gas limit: 100<br />GasLimitFactor: 1<br />gas limit = 100<br /><br />suggested gas limit: 100<br />GasLimitFactor: 1.1<br />gas limit = 110 |
| - [EnableEstimateGasOpt](#RPC_EnableEstimateGasOpt ) | No | boolean | No | - | - |
| - [DisableAPIs](#RPC_DisableAPIs ) | No | array of string | No | - | DisableAPIs disable some API |
| - [RateLimit](#RPC_RateLimit ) | No | object | No | - | RateLimit enable rate limit |
| - [DynamicGP](#RPC_DynamicGP ) | No | object | No | - | DynamicGP defines the config of dynamic gas price |
Expand Down Expand Up @@ -1945,7 +1946,19 @@ gas limit = 110
GasLimitFactor=1
```

### <a name="RPC_DisableAPIs"></a>8.22. `RPC.DisableAPIs`
### <a name="RPC_EnableEstimateGasOpt"></a>8.22. `RPC.EnableEstimateGasOpt`

**Type:** : `boolean`

**Default:** `false`

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

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

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

Expand All @@ -1959,7 +1972,7 @@ GasLimitFactor=1
DisableAPIs=[]
```

### <a name="RPC_RateLimit"></a>8.23. `[RPC.RateLimit]`
### <a name="RPC_RateLimit"></a>8.24. `[RPC.RateLimit]`

**Type:** : `object`
**Description:** RateLimit enable rate limit
Expand All @@ -1972,7 +1985,7 @@ DisableAPIs=[]
| - [RateLimitDuration](#RPC_RateLimit_RateLimitDuration ) | No | integer | No | - | RateLimitDuration defines the time window for the rate limit |
| - [SpecialApis](#RPC_RateLimit_SpecialApis ) | No | array of object | No | - | SpecialApis defines the apis that need to be rate limited with special rate limit |

#### <a name="RPC_RateLimit_Enabled"></a>8.23.1. `RPC.RateLimit.Enabled`
#### <a name="RPC_RateLimit_Enabled"></a>8.24.1. `RPC.RateLimit.Enabled`

**Type:** : `boolean`

Expand All @@ -1986,7 +1999,7 @@ DisableAPIs=[]
Enabled=false
```

#### <a name="RPC_RateLimit_RateLimitApis"></a>8.23.2. `RPC.RateLimit.RateLimitApis`
#### <a name="RPC_RateLimit_RateLimitApis"></a>8.24.2. `RPC.RateLimit.RateLimitApis`

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

Expand All @@ -2000,7 +2013,7 @@ Enabled=false
RateLimitApis=[]
```

#### <a name="RPC_RateLimit_RateLimitCount"></a>8.23.3. `RPC.RateLimit.RateLimitCount`
#### <a name="RPC_RateLimit_RateLimitCount"></a>8.24.3. `RPC.RateLimit.RateLimitCount`

**Type:** : `integer`

Expand All @@ -2014,7 +2027,7 @@ RateLimitApis=[]
RateLimitCount=100
```

#### <a name="RPC_RateLimit_RateLimitDuration"></a>8.23.4. `RPC.RateLimit.RateLimitDuration`
#### <a name="RPC_RateLimit_RateLimitDuration"></a>8.24.4. `RPC.RateLimit.RateLimitDuration`

**Type:** : `integer`

Expand All @@ -2028,7 +2041,7 @@ RateLimitCount=100
RateLimitDuration=1
```

#### <a name="RPC_RateLimit_SpecialApis"></a>8.23.5. `RPC.RateLimit.SpecialApis`
#### <a name="RPC_RateLimit_SpecialApis"></a>8.24.5. `RPC.RateLimit.SpecialApis`

**Type:** : `array of object`

Expand All @@ -2054,7 +2067,7 @@ SpecialApis=[]
| ----------------------------------------------------- | ---------------------------------------------------------- |
| [SpecialApis items](#RPC_RateLimit_SpecialApis_items) | RateLimitItem defines the special rate limit for some apis |

##### <a name="autogenerated_heading_3"></a>8.23.5.1. [RPC.RateLimit.SpecialApis.SpecialApis items]
##### <a name="autogenerated_heading_3"></a>8.24.5.1. [RPC.RateLimit.SpecialApis.SpecialApis items]

**Type:** : `object`
**Description:** RateLimitItem defines the special rate limit for some apis
Expand All @@ -2065,22 +2078,22 @@ SpecialApis=[]
| - [Count](#RPC_RateLimit_SpecialApis_items_Count ) | No | integer | No | - | Count defines the maximum burst size of requests |
| - [Duration](#RPC_RateLimit_SpecialApis_items_Duration ) | No | integer | No | - | Duration defines the time window for the rate limit |

##### <a name="RPC_RateLimit_SpecialApis_items_Api"></a>8.23.5.1.1. `RPC.RateLimit.SpecialApis.SpecialApis items.Api`
##### <a name="RPC_RateLimit_SpecialApis_items_Api"></a>8.24.5.1.1. `RPC.RateLimit.SpecialApis.SpecialApis items.Api`

**Type:** : `string`
**Description:** Api defines the api that need to be rate limited

##### <a name="RPC_RateLimit_SpecialApis_items_Count"></a>8.23.5.1.2. `RPC.RateLimit.SpecialApis.SpecialApis items.Count`
##### <a name="RPC_RateLimit_SpecialApis_items_Count"></a>8.24.5.1.2. `RPC.RateLimit.SpecialApis.SpecialApis items.Count`

**Type:** : `integer`
**Description:** Count defines the maximum burst size of requests

##### <a name="RPC_RateLimit_SpecialApis_items_Duration"></a>8.23.5.1.3. `RPC.RateLimit.SpecialApis.SpecialApis items.Duration`
##### <a name="RPC_RateLimit_SpecialApis_items_Duration"></a>8.24.5.1.3. `RPC.RateLimit.SpecialApis.SpecialApis items.Duration`

**Type:** : `integer`
**Description:** Duration defines the time window for the rate limit

### <a name="RPC_DynamicGP"></a>8.24. `[RPC.DynamicGP]`
### <a name="RPC_DynamicGP"></a>8.25. `[RPC.DynamicGP]`

**Type:** : `object`
**Description:** DynamicGP defines the config of dynamic gas price
Expand All @@ -2096,7 +2109,7 @@ SpecialApis=[]
| - [MinPrice](#RPC_DynamicGP_MinPrice ) | No | integer | No | - | MinPrice defines the dynamic gas price lower limit |
| - [UpdatePeriod](#RPC_DynamicGP_UpdatePeriod ) | No | string | No | - | Duration |

#### <a name="RPC_DynamicGP_Enabled"></a>8.24.1. `RPC.DynamicGP.Enabled`
#### <a name="RPC_DynamicGP_Enabled"></a>8.25.1. `RPC.DynamicGP.Enabled`

**Type:** : `boolean`

Expand All @@ -2110,7 +2123,7 @@ SpecialApis=[]
Enabled=false
```

#### <a name="RPC_DynamicGP_CongestionTxThreshold"></a>8.24.2. `RPC.DynamicGP.CongestionTxThreshold`
#### <a name="RPC_DynamicGP_CongestionTxThreshold"></a>8.25.2. `RPC.DynamicGP.CongestionTxThreshold`

**Type:** : `integer`

Expand All @@ -2124,7 +2137,7 @@ Enabled=false
CongestionTxThreshold=100
```

#### <a name="RPC_DynamicGP_CheckBatches"></a>8.24.3. `RPC.DynamicGP.CheckBatches`
#### <a name="RPC_DynamicGP_CheckBatches"></a>8.25.3. `RPC.DynamicGP.CheckBatches`

**Type:** : `integer`

Expand All @@ -2138,7 +2151,7 @@ CongestionTxThreshold=100
CheckBatches=5
```

#### <a name="RPC_DynamicGP_SampleNumber"></a>8.24.4. `RPC.DynamicGP.SampleNumber`
#### <a name="RPC_DynamicGP_SampleNumber"></a>8.25.4. `RPC.DynamicGP.SampleNumber`

**Type:** : `integer`

Expand All @@ -2152,7 +2165,7 @@ CheckBatches=5
SampleNumber=3
```

#### <a name="RPC_DynamicGP_Percentile"></a>8.24.5. `RPC.DynamicGP.Percentile`
#### <a name="RPC_DynamicGP_Percentile"></a>8.25.5. `RPC.DynamicGP.Percentile`

**Type:** : `integer`

Expand All @@ -2166,7 +2179,7 @@ SampleNumber=3
Percentile=70
```

#### <a name="RPC_DynamicGP_MaxPrice"></a>8.24.6. `RPC.DynamicGP.MaxPrice`
#### <a name="RPC_DynamicGP_MaxPrice"></a>8.25.6. `RPC.DynamicGP.MaxPrice`

**Type:** : `integer`

Expand All @@ -2180,7 +2193,7 @@ Percentile=70
MaxPrice=20000000000
```

#### <a name="RPC_DynamicGP_MinPrice"></a>8.24.7. `RPC.DynamicGP.MinPrice`
#### <a name="RPC_DynamicGP_MinPrice"></a>8.25.7. `RPC.DynamicGP.MinPrice`

**Type:** : `integer`

Expand All @@ -2194,7 +2207,7 @@ MaxPrice=20000000000
MinPrice=2000000000
```

#### <a name="RPC_DynamicGP_UpdatePeriod"></a>8.24.8. `RPC.DynamicGP.UpdatePeriod`
#### <a name="RPC_DynamicGP_UpdatePeriod"></a>8.25.8. `RPC.DynamicGP.UpdatePeriod`

**Title:** Duration

Expand All @@ -2220,7 +2233,7 @@ MinPrice=2000000000
UpdatePeriod="10s"
```

### <a name="RPC_EnableInnerTxCacheDB"></a>8.25. `RPC.EnableInnerTxCacheDB`
### <a name="RPC_EnableInnerTxCacheDB"></a>8.26. `RPC.EnableInnerTxCacheDB`

**Type:** : `boolean`

Expand All @@ -2234,12 +2247,12 @@ UpdatePeriod="10s"
EnableInnerTxCacheDB=false
```

### <a name="RPC_BridgeAddress"></a>8.26. `RPC.BridgeAddress`
### <a name="RPC_BridgeAddress"></a>8.27. `RPC.BridgeAddress`

**Type:** : `array of integer`
**Description:** BridgeAddress is the address of the bridge contract

### <a name="RPC_ApiAuthentication"></a>8.27. `[RPC.ApiAuthentication]`
### <a name="RPC_ApiAuthentication"></a>8.28. `[RPC.ApiAuthentication]`

**Type:** : `object`
**Description:** ApiAuthentication defines the authentication configuration for the API
Expand All @@ -2249,7 +2262,7 @@ EnableInnerTxCacheDB=false
| - [Enabled](#RPC_ApiAuthentication_Enabled ) | No | boolean | No | - | Enabled defines if the api authentication is enabled |
| - [ApiKeys](#RPC_ApiAuthentication_ApiKeys ) | No | array of object | No | - | ApiKeys defines the api keys |

#### <a name="RPC_ApiAuthentication_Enabled"></a>8.27.1. `RPC.ApiAuthentication.Enabled`
#### <a name="RPC_ApiAuthentication_Enabled"></a>8.28.1. `RPC.ApiAuthentication.Enabled`

**Type:** : `boolean`

Expand All @@ -2263,7 +2276,7 @@ EnableInnerTxCacheDB=false
Enabled=false
```

#### <a name="RPC_ApiAuthentication_ApiKeys"></a>8.27.2. `RPC.ApiAuthentication.ApiKeys`
#### <a name="RPC_ApiAuthentication_ApiKeys"></a>8.28.2. `RPC.ApiAuthentication.ApiKeys`

**Type:** : `array of object`

Expand All @@ -2289,7 +2302,7 @@ ApiKeys=[]
| ----------------------------------------------------- | --------------------------- |
| [ApiKeys items](#RPC_ApiAuthentication_ApiKeys_items) | KeyItem is the api key item |

##### <a name="autogenerated_heading_4"></a>8.27.2.1. [RPC.ApiAuthentication.ApiKeys.ApiKeys items]
##### <a name="autogenerated_heading_4"></a>8.28.2.1. [RPC.ApiAuthentication.ApiKeys.ApiKeys items]

**Type:** : `object`
**Description:** KeyItem is the api key item
Expand All @@ -2300,22 +2313,22 @@ ApiKeys=[]
| - [Key](#RPC_ApiAuthentication_ApiKeys_items_Key ) | No | string | No | - | Key defines the key |
| - [Timeout](#RPC_ApiAuthentication_ApiKeys_items_Timeout ) | No | string | No | - | Timeout defines the timeout |

##### <a name="RPC_ApiAuthentication_ApiKeys_items_Project"></a>8.27.2.1.1. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Project`
##### <a name="RPC_ApiAuthentication_ApiKeys_items_Project"></a>8.28.2.1.1. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Project`

**Type:** : `string`
**Description:** Name defines the name of the key

##### <a name="RPC_ApiAuthentication_ApiKeys_items_Key"></a>8.27.2.1.2. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Key`
##### <a name="RPC_ApiAuthentication_ApiKeys_items_Key"></a>8.28.2.1.2. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Key`

**Type:** : `string`
**Description:** Key defines the key

##### <a name="RPC_ApiAuthentication_ApiKeys_items_Timeout"></a>8.27.2.1.3. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Timeout`
##### <a name="RPC_ApiAuthentication_ApiKeys_items_Timeout"></a>8.28.2.1.3. `RPC.ApiAuthentication.ApiKeys.ApiKeys items.Timeout`

**Type:** : `string`
**Description:** Timeout defines the timeout

### <a name="RPC_ApiRelay"></a>8.28. `[RPC.ApiRelay]`
### <a name="RPC_ApiRelay"></a>8.29. `[RPC.ApiRelay]`

**Type:** : `object`
**Description:** ApiRelay defines the relay configuration for the API
Expand All @@ -2326,7 +2339,7 @@ ApiKeys=[]
| - [DestURI](#RPC_ApiRelay_DestURI ) | No | string | No | - | - |
| - [RPCs](#RPC_ApiRelay_RPCs ) | No | array of string | No | - | - |

#### <a name="RPC_ApiRelay_Enabled"></a>8.28.1. `RPC.ApiRelay.Enabled`
#### <a name="RPC_ApiRelay_Enabled"></a>8.29.1. `RPC.ApiRelay.Enabled`

**Type:** : `boolean`

Expand All @@ -2338,7 +2351,7 @@ ApiKeys=[]
Enabled=false
```

#### <a name="RPC_ApiRelay_DestURI"></a>8.28.2. `RPC.ApiRelay.DestURI`
#### <a name="RPC_ApiRelay_DestURI"></a>8.29.2. `RPC.ApiRelay.DestURI`

**Type:** : `string`

Expand All @@ -2350,7 +2363,7 @@ Enabled=false
DestURI=""
```

#### <a name="RPC_ApiRelay_RPCs"></a>8.28.3. `RPC.ApiRelay.RPCs`
#### <a name="RPC_ApiRelay_RPCs"></a>8.29.3. `RPC.ApiRelay.RPCs`

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

Expand Down
4 changes: 4 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@
"description": "GasLimitFactor is used to multiply the suggested gas provided by the network\nin order to allow a enough gas to be set for all the transactions default value is 1.\n\nex:\nsuggested gas limit: 100\nGasLimitFactor: 1\ngas limit = 100\n\nsuggested gas limit: 100\nGasLimitFactor: 1.1\ngas limit = 110",
"default": 1
},
"EnableEstimateGasOpt": {
"type": "boolean",
"default": false
},
"DisableAPIs": {
"items": {
"type": "string"
Expand Down
2 changes: 2 additions & 0 deletions jsonrpc/apollo_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ApolloConfig struct {
BatchRequestsEnabled bool
BatchRequestsLimit uint
GasLimitFactor float64
EnableEstimateGasOpt bool
DisableAPIs []string
RateLimit RateLimitConfig
DynamicGP DynamicGPConfig
Expand Down Expand Up @@ -63,6 +64,7 @@ func UpdateConfig(apolloConfig Config) {
getApolloConfig().BatchRequestsEnabled = apolloConfig.BatchRequestsEnabled
getApolloConfig().BatchRequestsLimit = apolloConfig.BatchRequestsLimit
getApolloConfig().GasLimitFactor = apolloConfig.GasLimitFactor
getApolloConfig().EnableEstimateGasOpt = apolloConfig.EnableEstimateGasOpt
getApolloConfig().setDisableAPIs(apolloConfig.DisableAPIs)
setRateLimit(apolloConfig.RateLimit)
setApiAuth(apolloConfig.ApiAuthentication)
Expand Down
3 changes: 2 additions & 1 deletion jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type Config struct {
// suggested gas limit: 100
// GasLimitFactor: 1.1
// gas limit = 110
GasLimitFactor float64 `mapstructure:"GasLimitFactor"`
GasLimitFactor float64 `mapstructure:"GasLimitFactor"`
EnableEstimateGasOpt bool `mapstructure:"EnableEstimateGasOpt"`

// DisableAPIs disable some API
DisableAPIs []string `mapstructure:"DisableAPIs"`
Expand Down
9 changes: 7 additions & 2 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,13 @@ func (e *EthEndpoints) EstimateGas(arg *types.TxArgs, blockArg *types.BlockNumbe
if err != nil {
return nil, types.NewRPCError(types.DefaultErrorCode, "failed to check gas-free", err)
}

gasEstimation, returnValue, err := e.state.EstimateGas(tx, sender, isGasFreeSender, blockToProcess, nil)
var gasEstimation uint64
var returnValue []byte
if e.enableEstimateGasOpt() {
gasEstimation, returnValue, err = e.state.EstimateGasOpt(tx, sender, isGasFreeSender, blockToProcess, nil)
} else {
gasEstimation, returnValue, err = e.state.EstimateGas(tx, sender, isGasFreeSender, blockToProcess, nil)
}
if errors.Is(err, runtime.ErrExecutionReverted) {
data := make([]byte, len(returnValue))
copy(data, returnValue)
Expand Down
16 changes: 16 additions & 0 deletions jsonrpc/endpoints_eth_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,25 @@ func (e *EthEndpoints) getGasEstimationWithFactorXLayer(gasEstimation uint64) ui
if gasLimitFactor > 0 {
gasEstimationWithFactor = uint64(float64(gasEstimation) * gasLimitFactor)
}
if gasEstimationWithFactor > state.MaxTxGasLimit {
gasEstimationWithFactor = state.MaxTxGasLimit
}
return gasEstimationWithFactor
}

func (e *EthEndpoints) enableEstimateGasOpt() bool {
res := false
if getApolloConfig().Enable() {
getApolloConfig().RLock()
res = getApolloConfig().EnableEstimateGasOpt
getApolloConfig().RUnlock()
} else {
res = e.cfg.EnableEstimateGasOpt
}

return res
}

// internal
func (e *EthEndpoints) newPendingTransactionFilterXLayer(wsConn *concurrentWsConn) (interface{}, types.Error) {
//XLayer handle
Expand Down
5 changes: 5 additions & 0 deletions jsonrpc/mocks/mock_state.go

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

1 change: 1 addition & 0 deletions jsonrpc/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type StateInterface interface {
BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
DebugTransaction(ctx context.Context, transactionHash common.Hash, traceConfig state.TraceConfig, dbTx pgx.Tx) (*runtime.ExecutionResult, error)
EstimateGas(transaction *types.Transaction, senderAddress common.Address, isGasFreeSender bool, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error)
EstimateGasOpt(transaction *types.Transaction, senderAddress common.Address, isGasFreeSender bool, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, []byte, error)
GetBalance(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error)
GetCode(ctx context.Context, address common.Address, root common.Hash) ([]byte, error)
GetL2BlockByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*state.L2Block, error)
Expand Down
Loading

0 comments on commit 868ffaf

Please sign in to comment.