From 9b1550daa2d409dc2277bb34597fd9c2047a5e9c Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Wed, 6 Mar 2024 15:23:37 -0800 Subject: [PATCH 1/9] Adding length check upto 100 --- node/impl/full/eth.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 5c3ab316562..297a25c050a 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -687,6 +687,9 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth if params.BlkCount > 1024 { return ethtypes.EthFeeHistory{}, fmt.Errorf("block count should be smaller than 1024") } + if len(*params.RewardPercentiles) >= 100 { + return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") + } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) From 97fc51aeffbb9db641b6c2781ea8b0804e674b3a Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Thu, 7 Mar 2024 23:09:42 -0800 Subject: [PATCH 2/9] Update node/impl/full/eth.go Co-authored-by: Rod Vagg --- node/impl/full/eth.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 297a25c050a..7a7dbd95f74 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -687,11 +687,11 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth if params.BlkCount > 1024 { return ethtypes.EthFeeHistory{}, fmt.Errorf("block count should be smaller than 1024") } - if len(*params.RewardPercentiles) >= 100 { - return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") - } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { + if len(*params.RewardPercentiles) >= 100 { + return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") + } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) } for i, rp := range rewardPercentiles { From 60028e277da6eb62c6808ad7ad66bffc3566125c Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 12:56:17 -0800 Subject: [PATCH 3/9] Update node/impl/full/eth.go Co-authored-by: Steven Allen --- node/impl/full/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 7a7dbd95f74..f3b082fe9ec 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -689,7 +689,7 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { - if len(*params.RewardPercentiles) >= 100 { + if len(*params.RewardPercentiles) > 100 { return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) From a274f46615071e1f05fbd7235b26baaeca351c81 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 13:21:07 -0800 Subject: [PATCH 4/9] Adding global variable called RewardPercentileArrayLimit --- node/impl/full/eth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index f3b082fe9ec..f0056f83871 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -40,6 +40,7 @@ import ( ) var ErrUnsupported = errors.New("unsupported method") +var RewardPercentileArrayLimit = 100 type EthModuleAPI interface { EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) @@ -689,7 +690,7 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { - if len(*params.RewardPercentiles) > 100 { + if len(*params.RewardPercentiles) > RewardPercentileArrayLimit { return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) From 03ccee7934b23771cd061c536d3ea5016bc22c3d Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 14:48:02 -0800 Subject: [PATCH 5/9] Refactoring --- node/impl/full/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index f0056f83871..d03ec55ca0b 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -40,7 +40,7 @@ import ( ) var ErrUnsupported = errors.New("unsupported method") -var RewardPercentileArrayLimit = 100 +var RewardPercentileArrayLimit int = 100 type EthModuleAPI interface { EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) From ba44428f6301bc4738892bae735eee9d747f16b6 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 15:44:21 -0800 Subject: [PATCH 6/9] Adding const --- node/impl/full/eth.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index d03ec55ca0b..a7871d2a2d7 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -40,7 +40,7 @@ import ( ) var ErrUnsupported = errors.New("unsupported method") -var RewardPercentileArrayLimit int = 100 +const maxEthFeeHistoryRewardPercentiles = 100 type EthModuleAPI interface { EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) @@ -690,8 +690,8 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth } rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { - if len(*params.RewardPercentiles) > RewardPercentileArrayLimit { - return ethtypes.EthFeeHistory{}, fmt.Errorf("Length cannot be greater than 100") + if len(*params.RewardPercentiles) > maxEthFeeHistoryRewardPercentiles { + return ethtypes.EthFeeHistory{}, fmt.Errorf("Length of the precentile array cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) } From 2927fbf6259fecf8ffec9fde141630a218c44464 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 17:29:02 -0800 Subject: [PATCH 7/9] Fixing lint --- node/impl/full/eth.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index a7871d2a2d7..9de8310c1da 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -40,6 +40,7 @@ import ( ) var ErrUnsupported = errors.New("unsupported method") + const maxEthFeeHistoryRewardPercentiles = 100 type EthModuleAPI interface { From 952c9b38108cdaceadaf4eb5601a98894db21e26 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Fri, 8 Mar 2024 17:45:30 -0800 Subject: [PATCH 8/9] Fixing typos --- node/impl/full/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 9de8310c1da..e7cfc44ce8a 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -692,7 +692,7 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { if len(*params.RewardPercentiles) > maxEthFeeHistoryRewardPercentiles { - return ethtypes.EthFeeHistory{}, fmt.Errorf("Length of the precentile array cannot be greater than 100") + return ethtypes.EthFeeHistory{}, fmt.Errorf("Length of the reward percentile array cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) } From 5d791968951019d24bfb10c79009fec7d6959835 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 11 Mar 2024 12:24:47 +1100 Subject: [PATCH 9/9] Update node/impl/full/eth.go --- node/impl/full/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index e7cfc44ce8a..031a8360561 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -692,7 +692,7 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth rewardPercentiles := make([]float64, 0) if params.RewardPercentiles != nil { if len(*params.RewardPercentiles) > maxEthFeeHistoryRewardPercentiles { - return ethtypes.EthFeeHistory{}, fmt.Errorf("Length of the reward percentile array cannot be greater than 100") + return ethtypes.EthFeeHistory{}, errors.New("length of the reward percentile array cannot be greater than 100") } rewardPercentiles = append(rewardPercentiles, *params.RewardPercentiles...) }