eth/gasprice: implement feeHistory API (#23033)
* eth/gasprice: implement feeHistory API * eth/gasprice: factored out resolveBlockRange * eth/gasprice: add sanity check for missing block * eth/gasprice: fetch actual gas used from receipts * miner, eth/gasprice: add PendingBlockAndReceipts * internal/ethapi: use hexutil.Big * eth/gasprice: return error when requesting beyond head block * eth/gasprice: fixed tests and return errors correctly * eth/gasprice: rename receiver name * eth/gasprice: return directly if blockCount == 0 Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
@ -162,9 +162,10 @@ type worker struct {
|
||||
pendingMu sync.RWMutex
|
||||
pendingTasks map[common.Hash]*task
|
||||
|
||||
snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot
|
||||
snapshotBlock *types.Block
|
||||
snapshotState *state.StateDB
|
||||
snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot
|
||||
snapshotBlock *types.Block
|
||||
snapshotReceipts types.Receipts
|
||||
snapshotState *state.StateDB
|
||||
|
||||
// atomic status counters
|
||||
running int32 // The indicator whether the consensus engine is running or not.
|
||||
@ -284,6 +285,14 @@ func (w *worker) pendingBlock() *types.Block {
|
||||
return w.snapshotBlock
|
||||
}
|
||||
|
||||
// pendingBlockAndReceipts returns pending block and corresponding receipts.
|
||||
func (w *worker) pendingBlockAndReceipts() (*types.Block, types.Receipts) {
|
||||
// return a snapshot to avoid contention on currentMu mutex
|
||||
w.snapshotMu.RLock()
|
||||
defer w.snapshotMu.RUnlock()
|
||||
return w.snapshotBlock, w.snapshotReceipts
|
||||
}
|
||||
|
||||
// start sets the running status as 1 and triggers new work submitting.
|
||||
func (w *worker) start() {
|
||||
atomic.StoreInt32(&w.running, 1)
|
||||
@ -730,6 +739,7 @@ func (w *worker) updateSnapshot() {
|
||||
w.current.receipts,
|
||||
trie.NewStackTrie(nil),
|
||||
)
|
||||
w.snapshotReceipts = w.current.receipts
|
||||
w.snapshotState = w.current.state.Copy()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user