eth/gasprice, internal/ethapi, miner: minor feehistory fixes

parent 5441a8fa
This diff is collapsed.
...@@ -18,6 +18,7 @@ package gasprice ...@@ -18,6 +18,7 @@ package gasprice
import ( import (
"context" "context"
"errors"
"math/big" "math/big"
"testing" "testing"
...@@ -37,7 +38,7 @@ func TestFeeHistory(t *testing.T) { ...@@ -37,7 +38,7 @@ func TestFeeHistory(t *testing.T) {
}{ }{
{false, 0, 0, 10, 30, nil, 21, 10, nil}, {false, 0, 0, 10, 30, nil, 21, 10, nil},
{false, 0, 0, 10, 30, []float64{0, 10}, 21, 10, nil}, {false, 0, 0, 10, 30, []float64{0, 10}, 21, 10, nil},
{false, 0, 0, 10, 30, []float64{20, 10}, 0, 0, errInvalidPercentiles}, {false, 0, 0, 10, 30, []float64{20, 10}, 0, 0, errInvalidPercentile},
{false, 0, 0, 1000000000, 30, nil, 0, 31, nil}, {false, 0, 0, 1000000000, 30, nil, 0, 31, nil},
{false, 0, 0, 1000000000, rpc.LatestBlockNumber, nil, 0, 33, nil}, {false, 0, 0, 1000000000, rpc.LatestBlockNumber, nil, 0, 33, nil},
{false, 0, 0, 10, 40, nil, 0, 0, errRequestBeyondHead}, {false, 0, 0, 10, 40, nil, 0, 0, errRequestBeyondHead},
...@@ -81,7 +82,7 @@ func TestFeeHistory(t *testing.T) { ...@@ -81,7 +82,7 @@ func TestFeeHistory(t *testing.T) {
if len(ratio) != c.expCount { if len(ratio) != c.expCount {
t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio)) t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio))
} }
if err != c.expErr { if err != c.expErr && !errors.Is(err, c.expErr) {
t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err) t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err)
} }
} }
......
...@@ -80,28 +80,28 @@ func (s *PublicEthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil. ...@@ -80,28 +80,28 @@ func (s *PublicEthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.
return (*hexutil.Big)(tipcap), err return (*hexutil.Big)(tipcap), err
} }
type feeHistoryResults struct { type feeHistoryResult struct {
FirstBlock rpc.BlockNumber OldestBlock rpc.BlockNumber `json:"oldestBlock"`
Reward [][]*hexutil.Big Reward [][]*hexutil.Big `json:"reward,omitempty"`
BaseFee []*hexutil.Big BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 GasUsedRatio []float64 `json:"gasUsedRatio"`
} }
func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (feeHistoryResults, error) { func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) {
firstBlock, reward, baseFee, gasUsedRatio, err := s.b.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
if err != nil { if err != nil {
return feeHistoryResults{}, err return nil, err
} }
results := feeHistoryResults{ results := &feeHistoryResult{
FirstBlock: firstBlock, OldestBlock: oldest,
GasUsedRatio: gasUsedRatio, GasUsedRatio: gasUsed,
} }
if reward != nil { if reward != nil {
results.Reward = make([][]*hexutil.Big, len(reward)) results.Reward = make([][]*hexutil.Big, len(reward))
for j, w := range reward { for i, w := range reward {
results.Reward[j] = make([]*hexutil.Big, len(w)) results.Reward[i] = make([]*hexutil.Big, len(w))
for i, v := range w { for j, v := range w {
results.Reward[j][i] = (*hexutil.Big)(v) results.Reward[i][j] = (*hexutil.Big)(v)
} }
} }
} }
......
...@@ -162,7 +162,7 @@ type worker struct { ...@@ -162,7 +162,7 @@ type worker struct {
pendingMu sync.RWMutex pendingMu sync.RWMutex
pendingTasks map[common.Hash]*task pendingTasks map[common.Hash]*task
snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot snapshotMu sync.RWMutex // The lock used to protect the snapshots below
snapshotBlock *types.Block snapshotBlock *types.Block
snapshotReceipts types.Receipts snapshotReceipts types.Receipts
snapshotState *state.StateDB snapshotState *state.StateDB
...@@ -745,7 +745,7 @@ func (w *worker) updateSnapshot() { ...@@ -745,7 +745,7 @@ func (w *worker) updateSnapshot() {
w.current.receipts, w.current.receipts,
trie.NewStackTrie(nil), trie.NewStackTrie(nil),
) )
w.snapshotReceipts = w.current.receipts w.snapshotReceipts = copyReceipts(w.current.receipts)
w.snapshotState = w.current.state.Copy() w.snapshotState = w.current.state.Copy()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment