mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
eth,les,miner: implement feeHistory API (#23033)
This commit is contained in:
parent
acaf943e59
commit
c072bbaac1
4 changed files with 25 additions and 0 deletions
|
|
@ -179,6 +179,10 @@ func (b *EthApiBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
|
|||
return nil, errors.New("invalid arguments; neither block nor hash specified")
|
||||
}
|
||||
|
||||
func (b *EthApiBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
|
||||
return b.eth.miner.PendingBlockAndReceipts()
|
||||
}
|
||||
|
||||
func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
|
||||
// Pending state is only known by the miner
|
||||
if blockNr == rpc.PendingBlockNumber {
|
||||
|
|
|
|||
|
|
@ -130,6 +130,10 @@ func (b *LesApiBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
|
|||
return nil, errors.New("invalid arguments; neither block nor hash specified")
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
|
||||
header, err := b.HeaderByNumber(ctx, blockNr)
|
||||
if header == nil || err != nil {
|
||||
|
|
|
|||
|
|
@ -178,6 +178,11 @@ func (self *Miner) PendingBlock() *types.Block {
|
|||
return self.worker.pendingBlock()
|
||||
}
|
||||
|
||||
// PendingBlockAndReceipts returns the currently pending block and corresponding receipts.
|
||||
func (miner *Miner) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
|
||||
return miner.worker.pendingBlockAndReceipts()
|
||||
}
|
||||
|
||||
func (self *Miner) SetEtherbase(addr common.Address) {
|
||||
self.coinbase = addr
|
||||
self.worker.setEtherbase(addr)
|
||||
|
|
|
|||
|
|
@ -128,6 +128,10 @@ type worker struct {
|
|||
coinbase common.Address
|
||||
extra []byte
|
||||
|
||||
snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot
|
||||
snapshotBlock *types.Block
|
||||
snapshotReceipts types.Receipts
|
||||
|
||||
currentMu sync.Mutex
|
||||
current *Work
|
||||
|
||||
|
|
@ -219,6 +223,14 @@ func (self *worker) pendingBlock() *types.Block {
|
|||
return self.current.Block
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (self *worker) start() {
|
||||
self.mu.Lock()
|
||||
defer self.mu.Unlock()
|
||||
|
|
|
|||
Loading…
Reference in a new issue