Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize miner for qng #46

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading