Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 8a75c24

Browse files
authored
Count ready tx (#196)
* add transaction counter use set instead of increase add balance issue situation * tidy code * fix tx counter remove lock * add setReadyTxCount to close block
1 parent 0490418 commit 8a75c24

25 files changed

Lines changed: 172 additions & 554 deletions

docs/config-file/node-config-doc.html

Lines changed: 1 addition & 7 deletions
Large diffs are not rendered by default.

docs/config-file/node-config-doc.md

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,6 @@ SecretKey=""
709709
| - [FreeGasAddress](#Pool_FreeGasAddress ) | No | array of string | No | - | XLayer config<br />FreeGasAddress is the default free gas address |
710710
| - [FreeClaimGasLimit](#Pool_FreeClaimGasLimit ) | No | integer | No | - | FreeClaimGasLimit is the max gas allowed use to do a free claim |
711711
| - [BridgeClaimMethodSigs](#Pool_BridgeClaimMethodSigs ) | No | array of string | No | - | BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method |
712-
| - [PendingStat](#Pool_PendingStat ) | No | object | No | - | PendingStat is the configuration for the pending statistics |
713712

714713
### <a name="Pool_IntervalToRefreshBlockedAddresses"></a>7.1. `Pool.IntervalToRefreshBlockedAddresses`
715714

@@ -1249,102 +1248,6 @@ FreeClaimGasLimit=150000
12491248
**Type:** : `array of string`
12501249
**Description:** BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method
12511250

1252-
### <a name="Pool_PendingStat"></a>7.18. `[Pool.PendingStat]`
1253-
1254-
**Type:** : `object`
1255-
**Description:** PendingStat is the configuration for the pending statistics
1256-
1257-
| Property | Pattern | Type | Deprecated | Definition | Title/Description |
1258-
| --------------------------------------------------- | ------- | ------- | ---------- | ---------- | ----------------- |
1259-
| - [Enable](#Pool_PendingStat_Enable ) | No | boolean | No | - | - |
1260-
| - [Interval](#Pool_PendingStat_Interval ) | No | string | No | - | Duration |
1261-
| - [StaleInterval](#Pool_PendingStat_StaleInterval ) | No | string | No | - | Duration |
1262-
| - [CacheInternal](#Pool_PendingStat_CacheInternal ) | No | string | No | - | Duration |
1263-
1264-
#### <a name="Pool_PendingStat_Enable"></a>7.18.1. `Pool.PendingStat.Enable`
1265-
1266-
**Type:** : `boolean`
1267-
1268-
**Default:** `false`
1269-
1270-
**Example setting the default value** (false):
1271-
```
1272-
[Pool.PendingStat]
1273-
Enable=false
1274-
```
1275-
1276-
#### <a name="Pool_PendingStat_Interval"></a>7.18.2. `Pool.PendingStat.Interval`
1277-
1278-
**Title:** Duration
1279-
1280-
**Type:** : `string`
1281-
1282-
**Default:** `"0s"`
1283-
1284-
**Examples:**
1285-
1286-
```json
1287-
"1m"
1288-
```
1289-
1290-
```json
1291-
"300ms"
1292-
```
1293-
1294-
**Example setting the default value** ("0s"):
1295-
```
1296-
[Pool.PendingStat]
1297-
Interval="0s"
1298-
```
1299-
1300-
#### <a name="Pool_PendingStat_StaleInterval"></a>7.18.3. `Pool.PendingStat.StaleInterval`
1301-
1302-
**Title:** Duration
1303-
1304-
**Type:** : `string`
1305-
1306-
**Default:** `"0s"`
1307-
1308-
**Examples:**
1309-
1310-
```json
1311-
"1m"
1312-
```
1313-
1314-
```json
1315-
"300ms"
1316-
```
1317-
1318-
**Example setting the default value** ("0s"):
1319-
```
1320-
[Pool.PendingStat]
1321-
StaleInterval="0s"
1322-
```
1323-
1324-
#### <a name="Pool_PendingStat_CacheInternal"></a>7.18.4. `Pool.PendingStat.CacheInternal`
1325-
1326-
**Title:** Duration
1327-
1328-
**Type:** : `string`
1329-
1330-
**Default:** `"0s"`
1331-
1332-
**Examples:**
1333-
1334-
```json
1335-
"1m"
1336-
```
1337-
1338-
```json
1339-
"300ms"
1340-
```
1341-
1342-
**Example setting the default value** ("0s"):
1343-
```
1344-
[Pool.PendingStat]
1345-
CacheInternal="0s"
1346-
```
1347-
13481251
## <a name="RPC"></a>8. `[RPC]`
13491252

13501253
**Type:** : `object`

docs/config-file/node-config-schema.json

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -471,44 +471,6 @@
471471
},
472472
"type": "array",
473473
"description": "BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method"
474-
},
475-
"PendingStat": {
476-
"properties": {
477-
"Enable": {
478-
"type": "boolean",
479-
"default": false
480-
},
481-
"Interval": {
482-
"type": "string",
483-
"title": "Duration",
484-
"default": "0s",
485-
"examples": [
486-
"1m",
487-
"300ms"
488-
]
489-
},
490-
"StaleInterval": {
491-
"type": "string",
492-
"title": "Duration",
493-
"default": "0s",
494-
"examples": [
495-
"1m",
496-
"300ms"
497-
]
498-
},
499-
"CacheInternal": {
500-
"type": "string",
501-
"title": "Duration",
502-
"default": "0s",
503-
"examples": [
504-
"1m",
505-
"300ms"
506-
]
507-
}
508-
},
509-
"additionalProperties": false,
510-
"type": "object",
511-
"description": "PendingStat is the configuration for the pending statistics"
512474
}
513475
},
514476
"additionalProperties": false,

jsonrpc/dynamic_gas_price_xlayer.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
zktypes "github.com/0xPolygonHermez/zkevm-node/config/types"
1111
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
1212
"github.com/0xPolygonHermez/zkevm-node/log"
13-
"github.com/0xPolygonHermez/zkevm-node/pool"
1413
"github.com/ethereum/go-ethereum/core/types"
1514
)
1615

@@ -213,21 +212,11 @@ func (e *EthEndpoints) getL2BatchTxsTips(ctx context.Context, l2BlockNumber uint
213212
}
214213

215214
func (e *EthEndpoints) isCongested(ctx context.Context) (bool, error) {
216-
var txCount uint64
217-
if e.pool != nil && e.pool.IsPendingStatEnabled(ctx) {
218-
stat := pool.GetPendingStat()
219-
if stat.Total < stat.SkipNonce+stat.BalanceIssue+stat.ErrorNonce {
220-
txCount = 0
221-
} else {
222-
txCount = stat.Total - stat.SkipNonce - stat.BalanceIssue - stat.ErrorNonce
223-
}
224-
} else {
225-
cnt, err := e.pool.CountPendingTransactions(ctx)
226-
if err != nil {
227-
return false, err
228-
}
229-
txCount = cnt
215+
txCount, err := e.pool.GetReadyTxCount(ctx)
216+
if err != nil {
217+
return false, err
230218
}
219+
231220
if txCount >= e.cfg.DynamicGP.CongestionTxThreshold {
232221
return true, nil
233222
}

jsonrpc/endpoints_eth_xlayer.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
1717
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
1818
"github.com/0xPolygonHermez/zkevm-node/log"
19-
"github.com/0xPolygonHermez/zkevm-node/pool"
2019
"github.com/0xPolygonHermez/zkevm-node/state"
2120
"github.com/ethereum/go-ethereum/common"
2221
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -401,8 +400,23 @@ func (e *EthEndpoints) getMinPriceFromSequencerNode() (interface{}, types.Error)
401400

402401
// GetPendingStat returns the pending stat
403402
func (e *EthEndpoints) GetPendingStat() (interface{}, types.Error) {
404-
if e.isDisabled("eth_getPendingStat") || (e.pool != nil && !e.pool.IsPendingStatEnabled(context.Background())) {
403+
if e.isDisabled("eth_getPendingStat") {
405404
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil, true)
406405
}
407-
return pool.GetPendingStat(), nil
406+
407+
pendingTotal, err := e.pool.CountPendingTransactions(context.Background())
408+
if err != nil {
409+
return RPCErrorResponse(types.DefaultErrorCode, "failed to get pending transactions count", err, true)
410+
}
411+
readyTxCount, err := e.pool.GetReadyTxCount(context.Background())
412+
if err != nil {
413+
return RPCErrorResponse(types.DefaultErrorCode, "failed to get ready tx count", err, true)
414+
}
415+
return struct {
416+
Total uint64 `json:"total"`
417+
ReadyTxCount uint64 `json:"readyTxCount"`
418+
}{
419+
Total: pendingTotal,
420+
ReadyTxCount: readyTxCount,
421+
}, nil
408422
}

jsonrpc/mocks/mock_pool_xlayer.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,32 @@ func (_m *PoolMock) GetMinSuggestedGasPriceWithDelta(ctx context.Context, delta
8585
return r0, r1
8686
}
8787

88-
// IsPendingStatEnabled provides a mock function with given fields: ctx
89-
func (_m *PoolMock) IsPendingStatEnabled(ctx context.Context) bool {
88+
// GetReadyTxCount provides a mock function with given fields: ctx
89+
func (_m *PoolMock) GetReadyTxCount(ctx context.Context) (uint64, error) {
9090
ret := _m.Called(ctx)
9191

9292
if len(ret) == 0 {
93-
panic("no return value specified for IsPendingStatEnabled")
93+
panic("no return value specified for GetReadyTxCount")
9494
}
9595

96-
var r0 bool
97-
if rf, ok := ret.Get(0).(func(context.Context) bool); ok {
96+
var r0 uint64
97+
var r1 error
98+
if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok {
9899
return rf(ctx)
99100
}
100-
if rf, ok := ret.Get(0).(func(context.Context) bool); ok {
101+
if rf, ok := ret.Get(0).(func(context.Context) uint64); ok {
101102
r0 = rf(ctx)
102103
} else {
103104
if ret.Get(0) != nil {
104-
r0 = ret.Get(0).(bool)
105+
r0 = ret.Get(0).(uint64)
105106
}
106107
}
107108

108-
return r0
109+
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
110+
r1 = rf(ctx)
111+
} else {
112+
r1 = ret.Error(1)
113+
}
114+
115+
return r0, r1
109116
}

jsonrpc/types/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type PoolInterface interface {
2828
AddInnerTx(ctx context.Context, txHash common.Hash, innerTx []byte) error
2929
GetInnerTx(ctx context.Context, txHash common.Hash) (string, error)
3030
GetMinSuggestedGasPriceWithDelta(ctx context.Context, delta time.Duration) (uint64, error)
31-
IsPendingStatEnabled(ctx context.Context) bool
31+
GetReadyTxCount(ctx context.Context) (uint64, error)
3232
}
3333

3434
// StateInterface gathers the methods required to interact with the state.

pool/apollo_xlayer.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func UpdateConfig(apolloConfig Config) {
6666
getApolloConfig().setFreeGasAddresses(apolloConfig.FreeGasAddress)
6767
getApolloConfig().EnableWhitelist = apolloConfig.EnableWhitelist
6868
getApolloConfig().setBridgeClaimMethods(apolloConfig.BridgeClaimMethodSigs)
69-
getApolloConfig().EnablePendingStat = apolloConfig.PendingStat.Enable
7069
getApolloConfig().Unlock()
7170
}
7271

@@ -125,13 +124,3 @@ func getEnableWhitelist(enableWhitelist bool) bool {
125124

126125
return enableWhitelist
127126
}
128-
129-
func getEnablePendingStat(enablePendingStat bool) bool {
130-
if getApolloConfig().enable() {
131-
getApolloConfig().RLock()
132-
defer getApolloConfig().RUnlock()
133-
return getApolloConfig().EnablePendingStat
134-
}
135-
136-
return enablePendingStat
137-
}

pool/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ type Config struct {
5757
FreeClaimGasLimit uint64 `mapstructure:"FreeClaimGasLimit"`
5858
// BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method
5959
BridgeClaimMethodSigs []string `mapstructure:"BridgeClaimMethodSigs"`
60-
61-
// PendingStat is the configuration for the pending statistics
62-
PendingStat PendingStatCfg `mapstructure:"PendingStat"`
6360
}
6461

6562
// EffectiveGasPriceCfg contains the configuration properties for the effective gas price

pool/interfaces.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ type storage interface {
4242
GetEarliestProcessedTx(ctx context.Context) (common.Hash, error)
4343
AddInnerTx(ctx context.Context, txHash common.Hash, innerTx []byte) error
4444
GetInnerTx(ctx context.Context, txHash common.Hash) (string, error)
45-
GetPendingFromAndMinNonceBefore(ctx context.Context, timeDuration time.Duration) ([]common.Address, []uint64, error)
46-
LockStat(ctx context.Context, timeDuration time.Duration) (bool, error)
47-
UnLockStat(ctx context.Context) error
48-
UpdateStatAndUnlock(ctx context.Context, totoal, skip, balanceIssue, nonceIssue uint64) error
49-
GetStat(ctx context.Context) (uint64, uint64, uint64, uint64, error)
50-
CountTransactionsByFromStatusAndNonce(ctx context.Context, from common.Address, nonce uint64, status ...TxStatus) (uint64, error)
45+
UpdateReadyTxCount(ctx context.Context, count uint64) error
46+
GetReadyTxCount(ctx context.Context) (uint64, error)
5147
}
5248

5349
type stateInterface interface {

0 commit comments

Comments
 (0)