Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
9ad50801
Unverified
Commit
9ad50801
authored
Jul 29, 2022
by
lightclient
Committed by
GitHub
Jul 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethereum, ethclient: add FeeHistory support (#25403)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
377c7d79
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
ethclient.go
ethclient/ethclient.go
+32
-0
ethclient_test.go
ethclient/ethclient_test.go
+23
-0
interfaces.go
interfaces.go
+9
-0
api.go
internal/ethapi/api.go
+1
-0
No files found.
ethclient/ethclient.go
View file @
9ad50801
...
...
@@ -505,6 +505,38 @@ func (ec *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return
(
*
big
.
Int
)(
&
hex
),
nil
}
type
feeHistoryResultMarshaling
struct
{
OldestBlock
*
hexutil
.
Big
`json:"oldestBlock"`
Reward
[][]
*
hexutil
.
Big
`json:"reward,omitempty"`
BaseFee
[]
*
hexutil
.
Big
`json:"baseFeePerGas,omitempty"`
GasUsedRatio
[]
float64
`json:"gasUsedRatio"`
}
// FeeHistory retrieves the fee market history.
func
(
ec
*
Client
)
FeeHistory
(
ctx
context
.
Context
,
blockCount
uint64
,
lastBlock
*
big
.
Int
,
rewardPercentiles
[]
float64
)
(
*
ethereum
.
FeeHistory
,
error
)
{
var
res
feeHistoryResultMarshaling
if
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
res
,
"eth_feeHistory"
,
hexutil
.
Uint
(
blockCount
),
toBlockNumArg
(
lastBlock
),
rewardPercentiles
);
err
!=
nil
{
return
nil
,
err
}
reward
:=
make
([][]
*
big
.
Int
,
len
(
res
.
Reward
))
for
i
,
r
:=
range
res
.
Reward
{
reward
[
i
]
=
make
([]
*
big
.
Int
,
len
(
r
))
for
j
,
r
:=
range
r
{
reward
[
i
][
j
]
=
(
*
big
.
Int
)(
r
)
}
}
baseFee
:=
make
([]
*
big
.
Int
,
len
(
res
.
BaseFee
))
for
i
,
b
:=
range
res
.
BaseFee
{
baseFee
[
i
]
=
(
*
big
.
Int
)(
b
)
}
return
&
ethereum
.
FeeHistory
{
OldestBlock
:
(
*
big
.
Int
)(
res
.
OldestBlock
),
Reward
:
reward
,
BaseFee
:
baseFee
,
GasUsedRatio
:
res
.
GasUsedRatio
,
},
nil
}
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
// the current pending state of the backend blockchain. There is no guarantee that this is
// the true gas limit requirement as other transactions may be added or removed by miners,
...
...
ethclient/ethclient_test.go
View file @
9ad50801
...
...
@@ -508,6 +508,29 @@ func testStatusFunctions(t *testing.T, client *rpc.Client) {
if
gasTipCap
.
Cmp
(
big
.
NewInt
(
234375000
))
!=
0
{
t
.
Fatalf
(
"unexpected gas tip cap: %v"
,
gasTipCap
)
}
// FeeHistory
history
,
err
:=
ec
.
FeeHistory
(
context
.
Background
(),
1
,
big
.
NewInt
(
2
),
[]
float64
{
95
,
99
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
want
:=
&
ethereum
.
FeeHistory
{
OldestBlock
:
big
.
NewInt
(
2
),
Reward
:
[][]
*
big
.
Int
{
{
big
.
NewInt
(
234375000
),
big
.
NewInt
(
234375000
),
},
},
BaseFee
:
[]
*
big
.
Int
{
big
.
NewInt
(
765625000
),
big
.
NewInt
(
671627818
),
},
GasUsedRatio
:
[]
float64
{
0.008912678667376286
},
}
if
!
reflect
.
DeepEqual
(
history
,
want
)
{
t
.
Fatalf
(
"FeeHistory result doesn't match expected: (got: %v, want: %v)"
,
history
,
want
)
}
}
func
testCallContractAtHash
(
t
*
testing
.
T
,
client
*
rpc
.
Client
)
{
...
...
interfaces.go
View file @
9ad50801
...
...
@@ -201,6 +201,15 @@ type GasPricer interface {
SuggestGasPrice
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
}
// FeeHistory provides recent fee market data that consumers can use to determine
// a reasonable maxPriorityFeePerGas value.
type
FeeHistory
struct
{
OldestBlock
*
big
.
Int
// block coresponding to first response value
Reward
[][]
*
big
.
Int
// list every txs priority fee per block
BaseFee
[]
*
big
.
Int
// list of each block's base fee
GasUsedRatio
[]
float64
// ratio of gas used out of the total available limit
}
// A PendingStateReader provides access to the pending state, which is the result of all
// known executable transactions which have not yet been included in the blockchain. It is
// commonly used to display the result of ’unconfirmed’ actions (e.g. wallet value
...
...
internal/ethapi/api.go
View file @
9ad50801
...
...
@@ -86,6 +86,7 @@ type feeHistoryResult struct {
GasUsedRatio
[]
float64
`json:"gasUsedRatio"`
}
// FeeHistory returns the fee market history.
func
(
s
*
EthereumAPI
)
FeeHistory
(
ctx
context
.
Context
,
blockCount
rpc
.
DecimalOrHex
,
lastBlock
rpc
.
BlockNumber
,
rewardPercentiles
[]
float64
)
(
*
feeHistoryResult
,
error
)
{
oldest
,
reward
,
baseFee
,
gasUsed
,
err
:=
s
.
b
.
FeeHistory
(
ctx
,
int
(
blockCount
),
lastBlock
,
rewardPercentiles
)
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment