Skip to content

Commit c072bba

Browse files
JukLee0iragzliudan
authored andcommitted
eth,les,miner: implement feeHistory API (ethereum#23033)
1 parent acaf943 commit c072bba

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

eth/api_backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ func (b *EthApiBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
179179
return nil, errors.New("invalid arguments; neither block nor hash specified")
180180
}
181181

182+
func (b *EthApiBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
183+
return b.eth.miner.PendingBlockAndReceipts()
184+
}
185+
182186
func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
183187
// Pending state is only known by the miner
184188
if blockNr == rpc.PendingBlockNumber {

les/api_backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (b *LesApiBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
130130
return nil, errors.New("invalid arguments; neither block nor hash specified")
131131
}
132132

133+
func (b *LesApiBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
134+
return nil, nil
135+
}
136+
133137
func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
134138
header, err := b.HeaderByNumber(ctx, blockNr)
135139
if header == nil || err != nil {

miner/miner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (self *Miner) PendingBlock() *types.Block {
178178
return self.worker.pendingBlock()
179179
}
180180

181+
// PendingBlockAndReceipts returns the currently pending block and corresponding receipts.
182+
func (miner *Miner) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
183+
return miner.worker.pendingBlockAndReceipts()
184+
}
185+
181186
func (self *Miner) SetEtherbase(addr common.Address) {
182187
self.coinbase = addr
183188
self.worker.setEtherbase(addr)

miner/worker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ type worker struct {
128128
coinbase common.Address
129129
extra []byte
130130

131+
snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot
132+
snapshotBlock *types.Block
133+
snapshotReceipts types.Receipts
134+
131135
currentMu sync.Mutex
132136
current *Work
133137

@@ -219,6 +223,14 @@ func (self *worker) pendingBlock() *types.Block {
219223
return self.current.Block
220224
}
221225

226+
// pendingBlockAndReceipts returns pending block and corresponding receipts.
227+
func (w *worker) pendingBlockAndReceipts() (*types.Block, types.Receipts) {
228+
// return a snapshot to avoid contention on currentMu mutex
229+
w.snapshotMu.RLock()
230+
defer w.snapshotMu.RUnlock()
231+
return w.snapshotBlock, w.snapshotReceipts
232+
}
233+
222234
func (self *worker) start() {
223235
self.mu.Lock()
224236
defer self.mu.Unlock()

0 commit comments

Comments
 (0)