Skip to content

Commit

Permalink
Count ready tx (#196)
Browse files Browse the repository at this point in the history
* add transaction counter

use set instead of increase

add balance issue situation

* tidy code

* fix tx counter

remove lock

* add setReadyTxCount to close block
  • Loading branch information
giskook authored Apr 29, 2024
1 parent 0490418 commit 8a75c24
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 554 deletions.
8 changes: 1 addition & 7 deletions docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

97 changes: 0 additions & 97 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ SecretKey=""
| - [FreeGasAddress](#Pool_FreeGasAddress ) | No | array of string | No | - | XLayer config<br />FreeGasAddress is the default free gas address |
| - [FreeClaimGasLimit](#Pool_FreeClaimGasLimit ) | No | integer | No | - | FreeClaimGasLimit is the max gas allowed use to do a free claim |
| - [BridgeClaimMethodSigs](#Pool_BridgeClaimMethodSigs ) | No | array of string | No | - | BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method |
| - [PendingStat](#Pool_PendingStat ) | No | object | No | - | PendingStat is the configuration for the pending statistics |

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

Expand Down Expand Up @@ -1249,102 +1248,6 @@ FreeClaimGasLimit=150000
**Type:** : `array of string`
**Description:** BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method

### <a name="Pool_PendingStat"></a>7.18. `[Pool.PendingStat]`

**Type:** : `object`
**Description:** PendingStat is the configuration for the pending statistics

| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| --------------------------------------------------- | ------- | ------- | ---------- | ---------- | ----------------- |
| - [Enable](#Pool_PendingStat_Enable ) | No | boolean | No | - | - |
| - [Interval](#Pool_PendingStat_Interval ) | No | string | No | - | Duration |
| - [StaleInterval](#Pool_PendingStat_StaleInterval ) | No | string | No | - | Duration |
| - [CacheInternal](#Pool_PendingStat_CacheInternal ) | No | string | No | - | Duration |

#### <a name="Pool_PendingStat_Enable"></a>7.18.1. `Pool.PendingStat.Enable`

**Type:** : `boolean`

**Default:** `false`

**Example setting the default value** (false):
```
[Pool.PendingStat]
Enable=false
```

#### <a name="Pool_PendingStat_Interval"></a>7.18.2. `Pool.PendingStat.Interval`

**Title:** Duration

**Type:** : `string`

**Default:** `"0s"`

**Examples:**

```json
"1m"
```

```json
"300ms"
```

**Example setting the default value** ("0s"):
```
[Pool.PendingStat]
Interval="0s"
```

#### <a name="Pool_PendingStat_StaleInterval"></a>7.18.3. `Pool.PendingStat.StaleInterval`

**Title:** Duration

**Type:** : `string`

**Default:** `"0s"`

**Examples:**

```json
"1m"
```

```json
"300ms"
```

**Example setting the default value** ("0s"):
```
[Pool.PendingStat]
StaleInterval="0s"
```

#### <a name="Pool_PendingStat_CacheInternal"></a>7.18.4. `Pool.PendingStat.CacheInternal`

**Title:** Duration

**Type:** : `string`

**Default:** `"0s"`

**Examples:**

```json
"1m"
```

```json
"300ms"
```

**Example setting the default value** ("0s"):
```
[Pool.PendingStat]
CacheInternal="0s"
```

## <a name="RPC"></a>8. `[RPC]`

**Type:** : `object`
Expand Down
38 changes: 0 additions & 38 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,44 +471,6 @@
},
"type": "array",
"description": "BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method"
},
"PendingStat": {
"properties": {
"Enable": {
"type": "boolean",
"default": false
},
"Interval": {
"type": "string",
"title": "Duration",
"default": "0s",
"examples": [
"1m",
"300ms"
]
},
"StaleInterval": {
"type": "string",
"title": "Duration",
"default": "0s",
"examples": [
"1m",
"300ms"
]
},
"CacheInternal": {
"type": "string",
"title": "Duration",
"default": "0s",
"examples": [
"1m",
"300ms"
]
}
},
"additionalProperties": false,
"type": "object",
"description": "PendingStat is the configuration for the pending statistics"
}
},
"additionalProperties": false,
Expand Down
19 changes: 4 additions & 15 deletions jsonrpc/dynamic_gas_price_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
zktypes "github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/ethereum/go-ethereum/core/types"
)

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

func (e *EthEndpoints) isCongested(ctx context.Context) (bool, error) {
var txCount uint64
if e.pool != nil && e.pool.IsPendingStatEnabled(ctx) {
stat := pool.GetPendingStat()
if stat.Total < stat.SkipNonce+stat.BalanceIssue+stat.ErrorNonce {
txCount = 0
} else {
txCount = stat.Total - stat.SkipNonce - stat.BalanceIssue - stat.ErrorNonce
}
} else {
cnt, err := e.pool.CountPendingTransactions(ctx)
if err != nil {
return false, err
}
txCount = cnt
txCount, err := e.pool.GetReadyTxCount(ctx)
if err != nil {
return false, err
}

if txCount >= e.cfg.DynamicGP.CongestionTxThreshold {
return true, nil
}
Expand Down
20 changes: 17 additions & 3 deletions jsonrpc/endpoints_eth_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -401,8 +400,23 @@ func (e *EthEndpoints) getMinPriceFromSequencerNode() (interface{}, types.Error)

// GetPendingStat returns the pending stat
func (e *EthEndpoints) GetPendingStat() (interface{}, types.Error) {
if e.isDisabled("eth_getPendingStat") || (e.pool != nil && !e.pool.IsPendingStatEnabled(context.Background())) {
if e.isDisabled("eth_getPendingStat") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil, true)
}
return pool.GetPendingStat(), nil

pendingTotal, err := e.pool.CountPendingTransactions(context.Background())
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get pending transactions count", err, true)
}
readyTxCount, err := e.pool.GetReadyTxCount(context.Background())
if err != nil {
return RPCErrorResponse(types.DefaultErrorCode, "failed to get ready tx count", err, true)
}
return struct {
Total uint64 `json:"total"`
ReadyTxCount uint64 `json:"readyTxCount"`
}{
Total: pendingTotal,
ReadyTxCount: readyTxCount,
}, nil
}
23 changes: 15 additions & 8 deletions jsonrpc/mocks/mock_pool_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,32 @@ func (_m *PoolMock) GetMinSuggestedGasPriceWithDelta(ctx context.Context, delta
return r0, r1
}

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

if len(ret) == 0 {
panic("no return value specified for IsPendingStatEnabled")
panic("no return value specified for GetReadyTxCount")
}

var r0 bool
if rf, ok := ret.Get(0).(func(context.Context) bool); ok {
var r0 uint64
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) bool); ok {
if rf, ok := ret.Get(0).(func(context.Context) uint64); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(bool)
r0 = ret.Get(0).(uint64)
}
}

return r0
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
r1 = rf(ctx)
} else {
r1 = ret.Error(1)
}

return r0, r1
}
2 changes: 1 addition & 1 deletion jsonrpc/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type PoolInterface interface {
AddInnerTx(ctx context.Context, txHash common.Hash, innerTx []byte) error
GetInnerTx(ctx context.Context, txHash common.Hash) (string, error)
GetMinSuggestedGasPriceWithDelta(ctx context.Context, delta time.Duration) (uint64, error)
IsPendingStatEnabled(ctx context.Context) bool
GetReadyTxCount(ctx context.Context) (uint64, error)
}

// StateInterface gathers the methods required to interact with the state.
Expand Down
11 changes: 0 additions & 11 deletions pool/apollo_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func UpdateConfig(apolloConfig Config) {
getApolloConfig().setFreeGasAddresses(apolloConfig.FreeGasAddress)
getApolloConfig().EnableWhitelist = apolloConfig.EnableWhitelist
getApolloConfig().setBridgeClaimMethods(apolloConfig.BridgeClaimMethodSigs)
getApolloConfig().EnablePendingStat = apolloConfig.PendingStat.Enable
getApolloConfig().Unlock()
}

Expand Down Expand Up @@ -125,13 +124,3 @@ func getEnableWhitelist(enableWhitelist bool) bool {

return enableWhitelist
}

func getEnablePendingStat(enablePendingStat bool) bool {
if getApolloConfig().enable() {
getApolloConfig().RLock()
defer getApolloConfig().RUnlock()
return getApolloConfig().EnablePendingStat
}

return enablePendingStat
}
3 changes: 0 additions & 3 deletions pool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ type Config struct {
FreeClaimGasLimit uint64 `mapstructure:"FreeClaimGasLimit"`
// BridgeClaimMethodSignature for tracking BridgeClaimMethodSignature method
BridgeClaimMethodSigs []string `mapstructure:"BridgeClaimMethodSigs"`

// PendingStat is the configuration for the pending statistics
PendingStat PendingStatCfg `mapstructure:"PendingStat"`
}

// EffectiveGasPriceCfg contains the configuration properties for the effective gas price
Expand Down
8 changes: 2 additions & 6 deletions pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ type storage interface {
GetEarliestProcessedTx(ctx context.Context) (common.Hash, error)
AddInnerTx(ctx context.Context, txHash common.Hash, innerTx []byte) error
GetInnerTx(ctx context.Context, txHash common.Hash) (string, error)
GetPendingFromAndMinNonceBefore(ctx context.Context, timeDuration time.Duration) ([]common.Address, []uint64, error)
LockStat(ctx context.Context, timeDuration time.Duration) (bool, error)
UnLockStat(ctx context.Context) error
UpdateStatAndUnlock(ctx context.Context, totoal, skip, balanceIssue, nonceIssue uint64) error
GetStat(ctx context.Context) (uint64, uint64, uint64, uint64, error)
CountTransactionsByFromStatusAndNonce(ctx context.Context, from common.Address, nonce uint64, status ...TxStatus) (uint64, error)
UpdateReadyTxCount(ctx context.Context, count uint64) error
GetReadyTxCount(ctx context.Context) (uint64, error)
}

type stateInterface interface {
Expand Down
Loading

0 comments on commit 8a75c24

Please sign in to comment.