Skip to content

Commit

Permalink
support dynamic gas price (#110)
Browse files Browse the repository at this point in the history
* support dynamic gas price

* Update dynamic_gas_price.go

* Update dynamic_gas_price.go

* Update dynamic_gas_price.go

* add rpc only for test

* only for test follower and fixed

* only for test

* only for test

* only for test

* only for stress test

* delete test code

* delete test rpc

* fix ut

* Update endpoints_eth.go

* add apollo config

* Update dynamic_gas_price.go

* Update go.mod

* Update endpoints_eth.go
  • Loading branch information
LeoGuo621 authored Feb 28, 2024
1 parent 77b0dce commit 5c53019
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ ForkID=0
| - [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 |
| - [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 |

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

Expand Down Expand Up @@ -1805,6 +1806,119 @@ SpecialApis=[]
**Type:** : `integer`
**Description:** Duration defines the time window for the rate limit

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

**Type:** : `object`
**Description:** DynamicGP defines the config of dynamic gas price

| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| ---------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | ------------------------------------------------------------------------------------- |
| - [Enabled](#RPC_DynamicGP_Enabled ) | No | boolean | No | - | Enabled defines if the dynamic gas price is enabled or disabled |
| - [CongestionTxThreshold](#RPC_DynamicGP_CongestionTxThreshold ) | No | integer | No | - | CongestionTxThreshold defines the tx threshold to measure whether there is congestion |
| - [CheckBatches](#RPC_DynamicGP_CheckBatches ) | No | integer | No | - | CheckBatches defines the number of recent Batches used to sample gas price |
| - [SampleNumber](#RPC_DynamicGP_SampleNumber ) | No | integer | No | - | SampleTxNumer defines the number of sampled gas prices in each batch |
| - [Percentile](#RPC_DynamicGP_Percentile ) | No | integer | No | - | Percentile defines the sampling weight of all sampled gas prices |
| - [MaxPrice](#RPC_DynamicGP_MaxPrice ) | No | integer | No | - | MaxPrice defines the dynamic gas price upper limit |
| - [MinPrice](#RPC_DynamicGP_MinPrice ) | No | integer | No | - | MinPrice defines the dynamic gas price lower limit |

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

**Type:** : `boolean`

**Default:** `false`

**Description:** Enabled defines if the dynamic gas price is enabled or disabled

**Example setting the default value** (false):
```
[RPC.DynamicGP]
Enabled=false
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** CongestionTxThreshold defines the tx threshold to measure whether there is congestion

**Example setting the default value** (0):
```
[RPC.DynamicGP]
CongestionTxThreshold=0
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** CheckBatches defines the number of recent Batches used to sample gas price

**Example setting the default value** (0):
```
[RPC.DynamicGP]
CheckBatches=0
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** SampleTxNumer defines the number of sampled gas prices in each batch

**Example setting the default value** (0):
```
[RPC.DynamicGP]
SampleNumber=0
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** Percentile defines the sampling weight of all sampled gas prices

**Example setting the default value** (0):
```
[RPC.DynamicGP]
Percentile=0
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** MaxPrice defines the dynamic gas price upper limit

**Example setting the default value** (0):
```
[RPC.DynamicGP]
MaxPrice=0
```

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

**Type:** : `integer`

**Default:** `0`

**Description:** MinPrice defines the dynamic gas price lower limit

**Example setting the default value** (0):
```
[RPC.DynamicGP]
MinPrice=0
```

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

**Type:** : `object`
Expand Down
42 changes: 42 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,48 @@
"additionalProperties": false,
"type": "object",
"description": "RateLimit enable rate limit"
},
"DynamicGP": {
"properties": {
"Enabled": {
"type": "boolean",
"description": "Enabled defines if the dynamic gas price is enabled or disabled",
"default": false
},
"CongestionTxThreshold": {
"type": "integer",
"description": "CongestionTxThreshold defines the tx threshold to measure whether there is congestion",
"default": 0
},
"CheckBatches": {
"type": "integer",
"description": "CheckBatches defines the number of recent Batches used to sample gas price",
"default": 0
},
"SampleNumber": {
"type": "integer",
"description": "SampleTxNumer defines the number of sampled gas prices in each batch",
"default": 0
},
"Percentile": {
"type": "integer",
"description": "Percentile defines the sampling weight of all sampled gas prices",
"default": 0
},
"MaxPrice": {
"type": "integer",
"description": "MaxPrice defines the dynamic gas price upper limit",
"default": 0
},
"MinPrice": {
"type": "integer",
"description": "MinPrice defines the dynamic gas price lower limit",
"default": 0
}
},
"additionalProperties": false,
"type": "object",
"description": "DynamicGP defines the config of dynamic gas price"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ require (
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -178,6 +177,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/segmentio/kafka-go v0.4.43
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/time v0.3.0
)

replace github.com/0xPolygon/cdk-data-availability => github.com/okx/x1-data-availability v0.0.0-20231113064732-3afebde141fc
Expand Down
2 changes: 2 additions & 0 deletions jsonrpc/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ApolloConfig struct {
GasLimitFactor float64 `json:"gasLimitFactor"`
DisableAPIs []string `json:"disableAPIs"`
RateLimit RateLimitConfig `json:"rateLimit"`
DynamicGP DynamicGPConfig `json:"dynamicGP"`

sync.RWMutex
}
Expand Down Expand Up @@ -52,6 +53,7 @@ func UpdateConfig(apolloConfig Config) {
getApolloConfig().GasLimitFactor = apolloConfig.GasLimitFactor
getApolloConfig().setDisableAPIs(apolloConfig.DisableAPIs)
setRateLimit(apolloConfig.RateLimit)
getApolloConfig().DynamicGP = apolloConfig.DynamicGP
getApolloConfig().Unlock()
}

Expand Down
3 changes: 3 additions & 0 deletions jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type Config struct {

// RateLimit enable rate limit
RateLimit RateLimitConfig `mapstructure:"RateLimit"`

// DynamicGP defines the config of dynamic gas price
DynamicGP DynamicGPConfig `mapstructure:"DynamicGP"`
}

// RateLimitConfig has parameters to config the rate limit
Expand Down
Loading

0 comments on commit 5c53019

Please sign in to comment.