Skip to content

Commit

Permalink
Merge pull request ethereum#46 from lochjin/master
Browse files Browse the repository at this point in the history
Optimize miner for qng
  • Loading branch information
dindinw authored May 26, 2024
2 parents 240e000 + 027a502 commit ceffb8d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
10 changes: 3 additions & 7 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Ethereum struct {

APIBackend *EthAPIBackend

miner miner.IMiner
miner *miner.Miner
gasPrice *big.Int

networkID uint64
Expand Down Expand Up @@ -263,11 +263,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

if config.Miner.External == nil {
eth.miner = miner.New(eth, config.Miner, eth.engine)
} else {
eth.miner = config.Miner.External
}
eth.miner = miner.New(eth, config.Miner, eth.engine)

eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

Expand Down Expand Up @@ -356,7 +352,7 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}

func (s *Ethereum) Miner() miner.IMiner { return s.miner }
func (s *Ethereum) Miner() *miner.Miner { return s.miner }

func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
Expand Down
2 changes: 0 additions & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type Config struct {
GasCeil uint64 // Target gas ceiling for mined blocks.
GasPrice *big.Int // Minimum gas price for mining a transaction
Recommit time.Duration // The time interval for miner to re-create mining work.
External IMiner // External miner

}

// DefaultConfig contains default settings for miner.
Expand Down
41 changes: 21 additions & 20 deletions miner/miner_qng.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package miner

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
"math/big"
)

type IMiner interface {
SetExtra(extra []byte) error
Pending() (*types.Block, types.Receipts, *state.StateDB)
SetGasCeil(ceil uint64)
SetGasTip(tip *big.Int) error
BuildPayload(args *BuildPayloadArgs) (*Payload, error)
}

type TransactionsByPriceAndNonce interface {
Peek() (*txpool.LazyTransaction, *uint256.Int)
Shift()
Pop()
}
func (payload *Payload) ResolveFullBlock() *types.Block {
payload.lock.Lock()
defer payload.lock.Unlock()

func NewTransactionsByPriceAndNonce(signer types.Signer, txs map[common.Address][]*txpool.LazyTransaction, baseFee *big.Int) TransactionsByPriceAndNonce {
return newTransactionsByPriceAndNonce(signer, txs, baseFee)
if payload.full == nil {
select {
case <-payload.stop:
return nil
default:
}
// Wait the full payload construction. Note it might block
// forever if Resolve is called in the meantime which
// terminates the background construction process.
payload.cond.Wait()
}
// Terminate the background payload construction
select {
case <-payload.stop:
default:
close(payload.stop)
}
return payload.full
}

0 comments on commit ceffb8d

Please sign in to comment.