good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
maticnetwork
bor
Commits
dea71556
Unverified
Commit
dea71556
authored
Jul 8, 2021
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
eth/gasprice, internal/ethapi, miner: minor feehistory fixes
parent
5441a8fa
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
eth/gasprice/feehistory.go
+88
-81
88 additions, 81 deletions
eth/gasprice/feehistory.go
eth/gasprice/feehistory_test.go
+3
-2
3 additions, 2 deletions
eth/gasprice/feehistory_test.go
internal/ethapi/api.go
+15
-15
15 additions, 15 deletions
internal/ethapi/api.go
miner/worker.go
+2
-2
2 additions, 2 deletions
miner/worker.go
with
108 additions
and
100 deletions
eth/gasprice/feehistory.go
+
88
−
81
View file @
dea71556
...
@@ -19,6 +19,7 @@ package gasprice
...
@@ -19,6 +19,7 @@ package gasprice
import
(
import
(
"context"
"context"
"errors"
"errors"
"fmt"
"math/big"
"math/big"
"sort"
"sort"
"sync/atomic"
"sync/atomic"
...
@@ -30,11 +31,19 @@ import (
...
@@ -30,11 +31,19 @@ import (
)
)
var
(
var
(
errInvalidPercentile
s
=
errors
.
New
(
"
I
nvalid reward percentile
s
"
)
errInvalidPercentile
=
errors
.
New
(
"
i
nvalid reward percentile"
)
errRequestBeyondHead
=
errors
.
New
(
"
R
equest beyond head block"
)
errRequestBeyondHead
=
errors
.
New
(
"
r
equest beyond head block"
)
)
)
const
maxBlockCount
=
1024
// number of blocks retrievable with a single query
const
(
// maxFeeHistory is the maximum number of blocks that can be retrieved for a
// fee history request.
maxFeeHistory
=
1024
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
// for the fee history calculation (mostly relevant for LES).
maxBlockFetchers
=
4
)
// blockFees represents a single block for processing
// blockFees represents a single block for processing
type
blockFees
struct
{
type
blockFees
struct
{
...
@@ -124,23 +133,22 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
...
@@ -124,23 +133,22 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
// also returned if requested and available.
// also returned if requested and available.
// Note: an error is only returned if retrieving the head header has failed. If there are no
// Note: an error is only returned if retrieving the head header has failed. If there are no
// retrievable blocks in the specified range then zero block count is returned with no error.
// retrievable blocks in the specified range then zero block count is returned with no error.
func
(
oracle
*
Oracle
)
resolveBlockRange
(
ctx
context
.
Context
,
lastBlock
Number
rpc
.
BlockNumber
,
block
Count
,
maxHistory
int
)
(
*
types
.
Block
,
types
.
Receipt
s
,
rpc
.
BlockNumber
,
int
,
error
)
{
func
(
oracle
*
Oracle
)
resolveBlockRange
(
ctx
context
.
Context
,
lastBlock
rpc
.
BlockNumber
,
block
s
,
maxHistory
int
)
(
*
types
.
Block
,
[]
*
types
.
Receipt
,
rpc
.
BlockNumber
,
int
,
error
)
{
var
(
var
(
headBlock
Number
rpc
.
BlockNumber
headBlock
rpc
.
BlockNumber
pendingBlock
*
types
.
Block
pendingBlock
*
types
.
Block
pendingReceipts
types
.
Receipts
pendingReceipts
types
.
Receipts
)
)
// query either pending block or head header and set headBlock
// query either pending block or head header and set headBlockNumber
if
lastBlock
==
rpc
.
PendingBlockNumber
{
if
lastBlockNumber
==
rpc
.
PendingBlockNumber
{
if
pendingBlock
,
pendingReceipts
=
oracle
.
backend
.
PendingBlockAndReceipts
();
pendingBlock
!=
nil
{
if
pendingBlock
,
pendingReceipts
=
oracle
.
backend
.
PendingBlockAndReceipts
();
pendingBlock
!=
nil
{
lastBlock
Number
=
rpc
.
BlockNumber
(
pendingBlock
.
NumberU64
())
lastBlock
=
rpc
.
BlockNumber
(
pendingBlock
.
NumberU64
())
headBlock
Number
=
lastBlock
Number
-
1
headBlock
=
lastBlock
-
1
}
else
{
}
else
{
// pending block not supported by backend, process until latest block
// pending block not supported by backend, process until latest block
lastBlock
Number
=
rpc
.
LatestBlockNumber
lastBlock
=
rpc
.
LatestBlockNumber
block
Count
--
block
s
--
if
block
Count
==
0
{
if
block
s
==
0
{
return
nil
,
nil
,
0
,
0
,
nil
return
nil
,
nil
,
0
,
0
,
nil
}
}
}
}
...
@@ -148,32 +156,32 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlockNumber rpc
...
@@ -148,32 +156,32 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlockNumber rpc
if
pendingBlock
==
nil
{
if
pendingBlock
==
nil
{
// if pending block is not fetched then we retrieve the head header to get the head block number
// if pending block is not fetched then we retrieve the head header to get the head block number
if
latestHeader
,
err
:=
oracle
.
backend
.
HeaderByNumber
(
ctx
,
rpc
.
LatestBlockNumber
);
err
==
nil
{
if
latestHeader
,
err
:=
oracle
.
backend
.
HeaderByNumber
(
ctx
,
rpc
.
LatestBlockNumber
);
err
==
nil
{
headBlock
Number
=
rpc
.
BlockNumber
(
latestHeader
.
Number
.
Uint64
())
headBlock
=
rpc
.
BlockNumber
(
latestHeader
.
Number
.
Uint64
())
}
else
{
}
else
{
return
nil
,
nil
,
0
,
0
,
err
return
nil
,
nil
,
0
,
0
,
err
}
}
}
}
if
lastBlock
Number
==
rpc
.
LatestBlockNumber
{
if
lastBlock
==
rpc
.
LatestBlockNumber
{
lastBlock
Number
=
headBlock
Number
lastBlock
=
headBlock
}
else
if
pendingBlock
==
nil
&&
lastBlock
Number
>
headBlock
Number
{
}
else
if
pendingBlock
==
nil
&&
lastBlock
>
headBlock
{
return
nil
,
nil
,
0
,
0
,
errRequestBeyondHead
return
nil
,
nil
,
0
,
0
,
fmt
.
Errorf
(
"%w: requested %d, head %d"
,
errRequestBeyondHead
,
lastBlock
,
headBlock
)
}
}
if
maxHistory
!=
0
{
if
maxHistory
!=
0
{
// limit retrieval to the given number of latest blocks
// limit retrieval to the given number of latest blocks
if
tooOldCount
:=
int64
(
headBlock
Number
)
-
int64
(
maxHistory
)
-
int64
(
lastBlock
Number
)
+
int64
(
block
Count
);
tooOldCount
>
0
{
if
tooOldCount
:=
int64
(
headBlock
)
-
int64
(
maxHistory
)
-
int64
(
lastBlock
)
+
int64
(
block
s
);
tooOldCount
>
0
{
// tooOldCount is the number of requested blocks that are too old to be served
// tooOldCount is the number of requested blocks that are too old to be served
if
int64
(
block
Count
)
>
tooOldCount
{
if
int64
(
block
s
)
>
tooOldCount
{
block
Count
-=
int
(
tooOldCount
)
block
s
-=
int
(
tooOldCount
)
}
else
{
}
else
{
return
nil
,
nil
,
0
,
0
,
nil
return
nil
,
nil
,
0
,
0
,
nil
}
}
}
}
}
}
// ensure not trying to retrieve before genesis
// ensure not trying to retrieve before genesis
if
rpc
.
BlockNumber
(
block
Count
)
>
lastBlock
Number
+
1
{
if
rpc
.
BlockNumber
(
block
s
)
>
lastBlock
+
1
{
block
Count
=
int
(
lastBlock
Number
+
1
)
block
s
=
int
(
lastBlock
+
1
)
}
}
return
pendingBlock
,
pendingReceipts
,
lastBlock
Number
,
block
Count
,
nil
return
pendingBlock
,
pendingReceipts
,
lastBlock
,
block
s
,
nil
}
}
// FeeHistory returns data relevant for fee estimation based on the specified range of blocks.
// FeeHistory returns data relevant for fee estimation based on the specified range of blocks.
...
@@ -189,90 +197,89 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlockNumber rpc
...
@@ -189,90 +197,89 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlockNumber rpc
// - gasUsedRatio: gasUsed/gasLimit in the given block
// - gasUsedRatio: gasUsed/gasLimit in the given block
// Note: baseFee includes the next block after the newest of the returned range, because this
// Note: baseFee includes the next block after the newest of the returned range, because this
// value can be derived from the newest block.
// value can be derived from the newest block.
func
(
oracle
*
Oracle
)
FeeHistory
(
ctx
context
.
Context
,
blockCount
int
,
lastBlockNumber
rpc
.
BlockNumber
,
rewardPercentiles
[]
float64
)
(
firstBlockNumber
rpc
.
BlockNumber
,
reward
[][]
*
big
.
Int
,
baseFee
[]
*
big
.
Int
,
gasUsedRatio
[]
float64
,
err
error
)
{
func
(
oracle
*
Oracle
)
FeeHistory
(
ctx
context
.
Context
,
blocks
int
,
lastBlock
rpc
.
BlockNumber
,
rewardPercentiles
[]
float64
)
(
rpc
.
BlockNumber
,
[][]
*
big
.
Int
,
[]
*
big
.
Int
,
[]
float64
,
error
)
{
if
blockCount
<
1
{
if
blocks
<
1
{
// returning with no data and no error means there are no retrievable blocks
return
0
,
nil
,
nil
,
nil
,
nil
// returning with no data and no error means there are no retrievable blocks
return
}
}
if
blockCount
>
maxBlockCount
{
if
blocks
>
maxFeeHistory
{
blockCount
=
maxBlockCount
log
.
Warn
(
"Sanitizing fee history length"
,
"requested"
,
blocks
,
"truncated"
,
maxFeeHistory
)
blocks
=
maxFeeHistory
}
}
for
i
,
p
:=
range
rewardPercentiles
{
for
i
,
p
:=
range
rewardPercentiles
{
if
p
<
0
||
p
>
100
||
(
i
>
0
&&
p
<
rewardPercentiles
[
i
-
1
])
{
if
p
<
0
||
p
>
100
{
return
0
,
nil
,
nil
,
nil
,
errInvalidPercentile
s
return
0
,
nil
,
nil
,
nil
,
fmt
.
Errorf
(
"%w: %f"
,
errInvalidPercentile
,
p
)
}
}
if
i
>
0
&&
p
<
rewardPercentiles
[
i
-
1
]
{
return
0
,
nil
,
nil
,
nil
,
fmt
.
Errorf
(
"%w: #%d:%f > #%d:%f"
,
errInvalidPercentile
,
i
-
1
,
rewardPercentiles
[
i
-
1
],
i
,
p
)
}
}
}
processBlocks
:=
len
(
rewardPercentiles
)
!=
0
// Only process blocks if reward percentiles were requested
// limit retrieval to maxHistory if set
maxHistory
:=
oracle
.
maxHeaderHistory
var
maxHistory
int
if
len
(
rewardPercentiles
)
!=
0
{
if
processBlocks
{
maxHistory
=
oracle
.
maxBlockHistory
maxHistory
=
oracle
.
maxBlockHistory
}
else
{
maxHistory
=
oracle
.
maxHeaderHistory
}
}
var
(
var
(
pendingBlock
*
types
.
Block
pendingBlock
*
types
.
Block
pendingReceipts
types
.
Receipts
pendingReceipts
[]
*
types
.
Receipt
err
error
)
)
if
pendingBlock
,
pendingReceipts
,
lastBlockNumber
,
blockCount
,
err
=
oracle
.
resolveBlockRange
(
ctx
,
lastBlockNumber
,
blockCount
,
maxHistory
);
err
!=
nil
||
blockCount
==
0
{
pendingBlock
,
pendingReceipts
,
lastBlock
,
blocks
,
err
=
oracle
.
resolveBlockRange
(
ctx
,
lastBlock
,
blocks
,
maxHistory
)
return
if
err
!=
nil
||
blocks
==
0
{
return
0
,
nil
,
nil
,
nil
,
err
}
}
fir
stBlock
Number
=
lastBlock
Number
+
1
-
rpc
.
BlockNumber
(
block
Count
)
olde
stBlock
:
=
lastBlock
+
1
-
rpc
.
BlockNumber
(
block
s
)
processNext
:=
int64
(
firstBlockNumber
)
var
(
resultCh
:=
make
(
chan
*
blockFees
,
blockCount
)
next
=
int64
(
oldestBlock
)
threadCount
:=
4
results
=
make
(
chan
*
blockFees
,
blocks
)
if
blockCount
<
threadCount
{
)
threadCount
=
blockCount
for
i
:=
0
;
i
<
maxBlockFetchers
&&
i
<
blocks
;
i
++
{
}
for
i
:=
0
;
i
<
threadCount
;
i
++
{
go
func
()
{
go
func
()
{
for
{
for
{
blockNumber
:=
rpc
.
BlockNumber
(
atomic
.
AddInt64
(
&
processNext
,
1
)
-
1
)
// Retrieve the next block number to fetch with this goroutine
if
blockNumber
>
lastBlockNumber
{
blockNumber
:=
rpc
.
BlockNumber
(
atomic
.
AddInt64
(
&
next
,
1
)
-
1
)
if
blockNumber
>
lastBlock
{
return
return
}
}
b
f
:=
&
blockFees
{
blockNumber
:
blockNumber
}
f
ees
:=
&
blockFees
{
blockNumber
:
blockNumber
}
if
pendingBlock
!=
nil
&&
blockNumber
>=
rpc
.
BlockNumber
(
pendingBlock
.
NumberU64
())
{
if
pendingBlock
!=
nil
&&
blockNumber
>=
rpc
.
BlockNumber
(
pendingBlock
.
NumberU64
())
{
b
f
.
block
,
b
f
.
receipts
=
pendingBlock
,
pendingReceipts
f
ees
.
block
,
f
ees
.
receipts
=
pendingBlock
,
pendingReceipts
}
else
{
}
else
{
if
processBlocks
{
if
len
(
rewardPercentiles
)
!=
0
{
b
f
.
block
,
b
f
.
err
=
oracle
.
backend
.
BlockByNumber
(
ctx
,
blockNumber
)
f
ees
.
block
,
f
ees
.
err
=
oracle
.
backend
.
BlockByNumber
(
ctx
,
blockNumber
)
if
b
f
.
block
!=
nil
{
if
f
ees
.
block
!=
nil
&&
fees
.
err
==
nil
{
b
f
.
receipts
,
b
f
.
err
=
oracle
.
backend
.
GetReceipts
(
ctx
,
b
f
.
block
.
Hash
())
f
ees
.
receipts
,
f
ees
.
err
=
oracle
.
backend
.
GetReceipts
(
ctx
,
f
ees
.
block
.
Hash
())
}
}
}
else
{
}
else
{
b
f
.
header
,
b
f
.
err
=
oracle
.
backend
.
HeaderByNumber
(
ctx
,
blockNumber
)
f
ees
.
header
,
f
ees
.
err
=
oracle
.
backend
.
HeaderByNumber
(
ctx
,
blockNumber
)
}
}
}
}
if
b
f
.
block
!=
nil
{
if
f
ees
.
block
!=
nil
{
b
f
.
header
=
b
f
.
block
.
Header
()
f
ees
.
header
=
f
ees
.
block
.
Header
()
}
}
if
b
f
.
header
!=
nil
{
if
f
ees
.
header
!=
nil
{
oracle
.
processBlock
(
b
f
,
rewardPercentiles
)
oracle
.
processBlock
(
f
ees
,
rewardPercentiles
)
}
}
// send to result
Ch
even if empty to guarantee that block
Count
items are sent in total
// send to result
s
even if empty to guarantee that block
s
items are sent in total
result
Ch
<-
b
f
result
s
<-
f
ees
}
}
}()
}()
}
}
var
(
reward
=
make
([][]
*
big
.
Int
,
block
Count
)
reward
=
make
([][]
*
big
.
Int
,
block
s
)
baseFee
=
make
([]
*
big
.
Int
,
block
Count
+
1
)
baseFee
=
make
([]
*
big
.
Int
,
block
s
+
1
)
gasUsedRatio
=
make
([]
float64
,
block
Count
)
gasUsedRatio
=
make
([]
float64
,
block
s
)
firstMissing
:
=
block
Count
firstMissing
=
block
s
)
for
;
block
Count
>
0
;
block
Count
--
{
for
;
block
s
>
0
;
block
s
--
{
b
f
:=
<-
result
Ch
f
ees
:=
<-
result
s
if
b
f
.
err
!=
nil
{
if
f
ees
.
err
!=
nil
{
return
0
,
nil
,
nil
,
nil
,
b
f
.
err
return
0
,
nil
,
nil
,
nil
,
f
ees
.
err
}
}
i
:=
int
(
b
f
.
blockNumber
-
fir
stBlock
Number
)
i
:=
int
(
f
ees
.
blockNumber
-
olde
stBlock
)
if
b
f
.
header
!=
nil
{
if
f
ees
.
header
!=
nil
{
reward
[
i
],
baseFee
[
i
],
baseFee
[
i
+
1
],
gasUsedRatio
[
i
]
=
b
f
.
reward
,
b
f
.
baseFee
,
b
f
.
nextBaseFee
,
b
f
.
gasUsedRatio
reward
[
i
],
baseFee
[
i
],
baseFee
[
i
+
1
],
gasUsedRatio
[
i
]
=
f
ees
.
reward
,
f
ees
.
baseFee
,
f
ees
.
nextBaseFee
,
f
ees
.
gasUsedRatio
}
else
{
}
else
{
// getting no block and no error means we are requesting into the future (might happen because of a reorg)
// getting no block and no error means we are requesting into the future (might happen because of a reorg)
if
i
<
firstMissing
{
if
i
<
firstMissing
{
...
@@ -283,11 +290,11 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blockCount int, lastBlockN
...
@@ -283,11 +290,11 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blockCount int, lastBlockN
if
firstMissing
==
0
{
if
firstMissing
==
0
{
return
0
,
nil
,
nil
,
nil
,
nil
return
0
,
nil
,
nil
,
nil
,
nil
}
}
if
processBlocks
{
if
len
(
rewardPercentiles
)
!=
0
{
reward
=
reward
[
:
firstMissing
]
reward
=
reward
[
:
firstMissing
]
}
else
{
}
else
{
reward
=
nil
reward
=
nil
}
}
baseFee
,
gasUsedRatio
=
baseFee
[
:
firstMissing
+
1
],
gasUsedRatio
[
:
firstMissing
]
baseFee
,
gasUsedRatio
=
baseFee
[
:
firstMissing
+
1
],
gasUsedRatio
[
:
firstMissing
]
return
return
oldestBlock
,
reward
,
baseFee
,
gasUsedRatio
,
nil
}
}
This diff is collapsed.
Click to expand it.
eth/gasprice/feehistory_test.go
+
3
−
2
View file @
dea71556
...
@@ -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
,
errInvalidPercentile
s
},
{
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
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
internal/ethapi/api.go
+
15
−
15
View file @
dea71556
...
@@ -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
feeHistoryResult
s
struct
{
type
feeHistoryResult
struct
{
Fir
stBlock
rpc
.
BlockNumber
Olde
stBlock
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
)
(
feeHistoryResult
s
,
error
)
{
func
(
s
*
PublicEthereumAPI
)
FeeHistory
(
ctx
context
.
Context
,
blockCount
int
,
lastBlock
rpc
.
BlockNumber
,
rewardPercentiles
[]
float64
)
(
*
feeHistoryResult
,
error
)
{
firstBlock
,
reward
,
baseFee
,
gasUsed
Ratio
,
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
:=
feeHistoryResult
s
{
results
:=
&
feeHistoryResult
{
Fir
stBlock
:
firstBlock
,
Olde
stBlock
:
oldest
,
GasUsedRatio
:
gasUsed
Ratio
,
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
)
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
miner/worker.go
+
2
−
2
View file @
dea71556
...
@@ -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 snapshot
s 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
()
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment