Skip to content

Commit

Permalink
new metric for extra relayed tx gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Jan 9, 2025
1 parent 0ed8bb0 commit 7092e61
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/groups/networkGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ func TestNetworkConfigMetrics_GasLimitGuardedTxShouldWork(t *testing.T) {
assert.True(t, keyAndValueFoundInResponse)
}

func TestNetworkConfigMetrics_GasLimitRelayedTxShouldWork(t *testing.T) {
t.Parallel()

statusMetricsProvider := statusHandler.NewStatusMetrics()
key := common.MetricExtraGasLimitRelayedTx
val := uint64(123)
statusMetricsProvider.SetUInt64Value(key, val)

facade := mock.FacadeStub{}
facade.StatusMetricsHandler = func() external.StatusMetricsHandler {
return statusMetricsProvider
}

networkGroup, err := groups.NewNetworkGroup(&facade)
require.NoError(t, err)

ws := startWebServer(networkGroup, "network", getNetworkRoutesConfig())

req, _ := http.NewRequest("GET", "/network/config", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

respBytes, _ := io.ReadAll(resp.Body)
respStr := string(respBytes)
assert.Equal(t, resp.Code, http.StatusOK)

keyAndValueFoundInResponse := strings.Contains(respStr, key) && strings.Contains(respStr, fmt.Sprintf("%d", val))
assert.True(t, keyAndValueFoundInResponse)
}

func TestNetworkStatusMetrics_ShouldWork(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 3 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ const MetricMinGasLimit = "erd_min_gas_limit"
// MetricExtraGasLimitGuardedTx specifies the extra gas limit required for guarded transactions
const MetricExtraGasLimitGuardedTx = "erd_extra_gas_limit_guarded_tx"

// MetricExtraGasLimitRelayedTx specifies the extra gas limit required for relayed v3 transactions
const MetricExtraGasLimitRelayedTx = "erd_extra_gas_limit_relayed_tx"

// MetricRewardsTopUpGradientPoint is the metric that specifies the rewards top up gradient point
const MetricRewardsTopUpGradientPoint = "erd_rewards_top_up_gradient_point"

Expand Down
1 change: 1 addition & 0 deletions node/chainSimulator/components/nodeFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (node *testOnlyProcessingNode) createMetrics(configs config.Configs) error
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricMinGasPrice, node.CoreComponentsHolder.EconomicsData().MinGasPrice())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricMinGasLimit, node.CoreComponentsHolder.EconomicsData().MinGasLimit())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricExtraGasLimitGuardedTx, node.CoreComponentsHolder.EconomicsData().ExtraGasLimitGuardedTx())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricExtraGasLimitRelayedTx, node.CoreComponentsHolder.EconomicsData().MinGasLimit())
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricRewardsTopUpGradientPoint, node.CoreComponentsHolder.EconomicsData().RewardsTopUpGradientPoint().String())
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricTopUpFactor, fmt.Sprintf("%g", node.CoreComponentsHolder.EconomicsData().RewardsTopUpFactor()))
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricGasPriceModifier, fmt.Sprintf("%g", node.CoreComponentsHolder.EconomicsData().GasPriceModifier()))
Expand Down
1 change: 1 addition & 0 deletions node/nodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ func (nr *nodeRunner) createMetrics(
metrics.SaveUint64Metric(statusCoreComponents.AppStatusHandler(), common.MetricMinGasPrice, coreComponents.EconomicsData().MinGasPrice())
metrics.SaveUint64Metric(statusCoreComponents.AppStatusHandler(), common.MetricMinGasLimit, coreComponents.EconomicsData().MinGasLimit())
metrics.SaveUint64Metric(statusCoreComponents.AppStatusHandler(), common.MetricExtraGasLimitGuardedTx, coreComponents.EconomicsData().ExtraGasLimitGuardedTx())
metrics.SaveUint64Metric(statusCoreComponents.AppStatusHandler(), common.MetricExtraGasLimitRelayedTx, coreComponents.EconomicsData().MinGasLimit())
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricRewardsTopUpGradientPoint, coreComponents.EconomicsData().RewardsTopUpGradientPoint().String())
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricTopUpFactor, fmt.Sprintf("%g", coreComponents.EconomicsData().RewardsTopUpFactor()))
metrics.SaveStringMetric(statusCoreComponents.AppStatusHandler(), common.MetricGasPriceModifier, fmt.Sprintf("%g", coreComponents.EconomicsData().GasPriceModifier()))
Expand Down
1 change: 1 addition & 0 deletions statusHandler/statusMetricsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (sm *statusMetrics) ConfigMetrics() (map[string]interface{}, error) {
configMetrics[common.MetricMinGasPrice] = sm.uint64Metrics[common.MetricMinGasPrice]
configMetrics[common.MetricMinGasLimit] = sm.uint64Metrics[common.MetricMinGasLimit]
configMetrics[common.MetricExtraGasLimitGuardedTx] = sm.uint64Metrics[common.MetricExtraGasLimitGuardedTx]
configMetrics[common.MetricExtraGasLimitRelayedTx] = sm.uint64Metrics[common.MetricExtraGasLimitRelayedTx]
configMetrics[common.MetricMaxGasPerTransaction] = sm.uint64Metrics[common.MetricMaxGasPerTransaction]
configMetrics[common.MetricRoundDuration] = sm.uint64Metrics[common.MetricRoundDuration]
configMetrics[common.MetricStartTime] = sm.uint64Metrics[common.MetricStartTime]
Expand Down
2 changes: 2 additions & 0 deletions statusHandler/statusMetricsProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func TestStatusMetrics_NetworkConfig(t *testing.T) {
sm.SetUInt64Value(common.MetricMinGasPrice, 1000)
sm.SetUInt64Value(common.MetricMinGasLimit, 50000)
sm.SetUInt64Value(common.MetricExtraGasLimitGuardedTx, 50000)
sm.SetUInt64Value(common.MetricExtraGasLimitRelayedTx, 50000)
sm.SetStringValue(common.MetricRewardsTopUpGradientPoint, "12345")
sm.SetUInt64Value(common.MetricGasPerDataByte, 1500)
sm.SetStringValue(common.MetricChainId, "local-id")
Expand All @@ -202,6 +203,7 @@ func TestStatusMetrics_NetworkConfig(t *testing.T) {
"erd_meta_consensus_group_size": uint64(25),
"erd_min_gas_limit": uint64(50000),
"erd_extra_gas_limit_guarded_tx": uint64(50000),
"erd_extra_gas_limit_relayed_tx": uint64(50000),
"erd_min_gas_price": uint64(1000),
"erd_min_transaction_version": uint64(2),
"erd_num_metachain_nodes": uint64(50),
Expand Down

0 comments on commit 7092e61

Please sign in to comment.