mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
all: delete useless interfaces
This commit is contained in:
parent
64abec0196
commit
1e844fe7a0
13 changed files with 41 additions and 146 deletions
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
|
@ -197,7 +196,6 @@ func ecrecover(header *types.Header, sigcache *lru.ARCCache) (common.Address, er
|
||||||
type Clique struct {
|
type Clique struct {
|
||||||
config *params.CliqueConfig // Consensus engine configuration parameters
|
config *params.CliqueConfig // Consensus engine configuration parameters
|
||||||
db ethdb.Database // Database to store and retrieve snapshot checkpoints
|
db ethdb.Database // Database to store and retrieve snapshot checkpoints
|
||||||
running int32 // Indicator whether clique engine is running or not.
|
|
||||||
|
|
||||||
recents *lru.ARCCache // Snapshots for recent block to speed up reorgs
|
recents *lru.ARCCache // Snapshots for recent block to speed up reorgs
|
||||||
signatures *lru.ARCCache // Signatures of recent blocks to speed up mining
|
signatures *lru.ARCCache // Signatures of recent blocks to speed up mining
|
||||||
|
|
@ -603,10 +601,6 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch
|
||||||
if c.config.Period == 0 && len(block.Transactions()) == 0 {
|
if c.config.Period == 0 && len(block.Transactions()) == 0 {
|
||||||
return nil, errWaitTransactions
|
return nil, errWaitTransactions
|
||||||
}
|
}
|
||||||
// Make sure clique engine is started.
|
|
||||||
if !c.IsRunning() {
|
|
||||||
return nil, consensus.ErrEngineNotStart
|
|
||||||
}
|
|
||||||
// Don't hold the signer fields for the entire sealing procedure
|
// Don't hold the signer fields for the entire sealing procedure
|
||||||
c.lock.RLock()
|
c.lock.RLock()
|
||||||
signer, signFn := c.signer, c.signFn
|
signer, signFn := c.signer, c.signFn
|
||||||
|
|
@ -678,25 +672,6 @@ func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int {
|
||||||
return new(big.Int).Set(diffNoTurn)
|
return new(big.Int).Set(diffNoTurn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start implements consensus.Engine, starting the clique consensus engine.
|
|
||||||
func (c *Clique) Start() {
|
|
||||||
if atomic.CompareAndSwapInt32(&c.running, 0, 1) {
|
|
||||||
log.Info("Start clique consensus engine")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop implements consensus.Engine, stopping the clique consensus engine.
|
|
||||||
func (c *Clique) Stop() {
|
|
||||||
if atomic.CompareAndSwapInt32(&c.running, 1, 0) {
|
|
||||||
log.Info("Stop clique consensus engine")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRunning implements consensus.Engine, returning an indication if the clique engine is currently mining.
|
|
||||||
func (c *Clique) IsRunning() bool {
|
|
||||||
return atomic.LoadInt32(&c.running) > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close implements consensus.Engine, returning internal error and close the clique.
|
// Close implements consensus.Engine, returning internal error and close the clique.
|
||||||
func (c *Clique) Close() error {
|
func (c *Clique) Close() error {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -97,15 +97,6 @@ type Engine interface {
|
||||||
// APIs returns the RPC APIs this consensus engine provides.
|
// APIs returns the RPC APIs this consensus engine provides.
|
||||||
APIs(chain ChainReader) []rpc.API
|
APIs(chain ChainReader) []rpc.API
|
||||||
|
|
||||||
// Start starts the consensus engine.
|
|
||||||
Start()
|
|
||||||
|
|
||||||
// Stop stops the consensus engine.
|
|
||||||
Stop()
|
|
||||||
|
|
||||||
// IsRunning returns an indication whether consensus engine is running or not.
|
|
||||||
IsRunning() bool
|
|
||||||
|
|
||||||
// Close closes the consensus engine.
|
// Close closes the consensus engine.
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,4 @@ var (
|
||||||
// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
|
// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
|
||||||
// plus one.
|
// plus one.
|
||||||
ErrInvalidNumber = errors.New("invalid block number")
|
ErrInvalidNumber = errors.New("invalid block number")
|
||||||
|
|
||||||
// ErrEngineNotStart is returned if the consensus engine is not started.
|
|
||||||
ErrEngineNotStart = errors.New("consensus engine is not started")
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,6 @@ func (api *API) GetWork() ([3]string, error) {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// Trigger ethash to start in remote mining mode(local/cpu mining is disabled)
|
|
||||||
// if ethash is not running.
|
|
||||||
if !api.ethash.IsRunning() {
|
|
||||||
api.ethash.StartMining(new(int))
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case api.ethash.fetchWorkCh <- &sealWork{errCh: errCh, resCh: workCh}:
|
case api.ethash.fetchWorkCh <- &sealWork{errCh: errCh, resCh: workCh}:
|
||||||
case <-api.ethash.exitCh:
|
case <-api.ethash.exitCh:
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mapset "github.com/deckarep/golang-set"
|
mapset "github.com/deckarep/golang-set"
|
||||||
|
|
@ -32,7 +31,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc"
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -554,22 +552,3 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
||||||
}
|
}
|
||||||
state.AddBalance(header.Coinbase, reward)
|
state.AddBalance(header.Coinbase, reward)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start implements consensus.Engine, starting the ethash engine.
|
|
||||||
func (ethash *Ethash) Start() {
|
|
||||||
if atomic.CompareAndSwapInt32(ðash.running, 0, 1) {
|
|
||||||
log.Info("Start ethash consensus engine")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop implements consensus.Engine, stopping the ethash engine.
|
|
||||||
func (ethash *Ethash) Stop() {
|
|
||||||
if atomic.CompareAndSwapInt32(ðash.running, 1, 0) {
|
|
||||||
log.Info("Stop ethash consensus engine")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRunning implements consensus.Engine, returning an indication if the ethash engine is currently mining.
|
|
||||||
func (ethash *Ethash) IsRunning() bool {
|
|
||||||
return atomic.LoadInt32(ðash.running) > 0
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -428,7 +428,6 @@ type Ethash struct {
|
||||||
threads int // Number of threads to mine on if mining
|
threads int // Number of threads to mine on if mining
|
||||||
update chan struct{} // Notification channel to update mining parameters
|
update chan struct{} // Notification channel to update mining parameters
|
||||||
hashrate metrics.Meter // Meter tracking the average hashrate
|
hashrate metrics.Meter // Meter tracking the average hashrate
|
||||||
running int32 // Indicator whether ethash engine is running or not.
|
|
||||||
|
|
||||||
// Remote sealer related fields
|
// Remote sealer related fields
|
||||||
workCh chan *types.Block // Notification channel to push new work to remote sealer
|
workCh chan *types.Block // Notification channel to push new work to remote sealer
|
||||||
|
|
@ -487,7 +486,6 @@ func NewTester() *Ethash {
|
||||||
datasets: newlru("dataset", 1, newDataset),
|
datasets: newlru("dataset", 1, newDataset),
|
||||||
update: make(chan struct{}),
|
update: make(chan struct{}),
|
||||||
hashrate: metrics.NewMeter(),
|
hashrate: metrics.NewMeter(),
|
||||||
running: 1, // enable local mining by default
|
|
||||||
workCh: make(chan *types.Block),
|
workCh: make(chan *types.Block),
|
||||||
resultCh: make(chan *types.Block),
|
resultCh: make(chan *types.Block),
|
||||||
fetchWorkCh: make(chan *sealWork),
|
fetchWorkCh: make(chan *sealWork),
|
||||||
|
|
@ -680,20 +678,6 @@ func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartMining starts the ethash engine with the given number of threads.
|
|
||||||
// If threads is nil the number of workers started is equal to the number of logical CPUs
|
|
||||||
// that are usable by this process. If threads is 0, than local/cpu mining will be disabled.
|
|
||||||
// If mining is already running, this method adjust the number of threads allowed to use.
|
|
||||||
func (ethash *Ethash) StartMining(threads *int) {
|
|
||||||
if threads == nil {
|
|
||||||
threads = new(int)
|
|
||||||
} else if *threads == 0 {
|
|
||||||
*threads = -1 // Disable local/cpu mining.
|
|
||||||
}
|
|
||||||
ethash.Start()
|
|
||||||
ethash.SetThreads(*threads)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SeedHash is the seed to use for generating a verification cache and the mining
|
// SeedHash is the seed to use for generating a verification cache and the mining
|
||||||
// dataset.
|
// dataset.
|
||||||
func SeedHash(block uint64) []byte {
|
func SeedHash(block uint64) []byte {
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,6 @@ func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, stop
|
||||||
if ethash.shared != nil {
|
if ethash.shared != nil {
|
||||||
return ethash.shared.Seal(chain, block, stop)
|
return ethash.shared.Seal(chain, block, stop)
|
||||||
}
|
}
|
||||||
// Make sure ethash engine is started.
|
|
||||||
if !ethash.IsRunning() {
|
|
||||||
return nil, consensus.ErrEngineNotStart
|
|
||||||
}
|
|
||||||
// Create a runner and the multiple search threads it directs
|
// Create a runner and the multiple search threads it directs
|
||||||
abort := make(chan struct{})
|
abort := make(chan struct{})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -465,9 +465,6 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
|
||||||
pool.mu.Lock()
|
pool.mu.Lock()
|
||||||
defer pool.mu.Unlock()
|
defer pool.mu.Unlock()
|
||||||
|
|
||||||
if pool.gasPrice == price {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pool.gasPrice = price
|
pool.gasPrice = price
|
||||||
for _, tx := range pool.priced.Cap(price, pool.locals) {
|
for _, tx := range pool.priced.Cap(price, pool.locals) {
|
||||||
pool.removeTx(tx.Hash(), false)
|
pool.removeTx(tx.Hash(), false)
|
||||||
|
|
|
||||||
|
|
@ -112,14 +112,16 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
|
||||||
log.Info("Updated mining threads", "threads", *threads)
|
log.Info("Updated mining threads", "threads", *threads)
|
||||||
th.SetThreads(*threads)
|
th.SetThreads(*threads)
|
||||||
}
|
}
|
||||||
|
// Start the miner and return
|
||||||
|
if !api.e.IsMining() {
|
||||||
// Propagate the initial price point to the transaction pool
|
// Propagate the initial price point to the transaction pool
|
||||||
api.e.lock.RLock()
|
api.e.lock.RLock()
|
||||||
price := api.e.gasPrice
|
price := api.e.gasPrice
|
||||||
api.e.lock.RUnlock()
|
api.e.lock.RUnlock()
|
||||||
api.e.txPool.SetGasPrice(price)
|
api.e.txPool.SetGasPrice(price)
|
||||||
|
|
||||||
// Start the miner and return
|
|
||||||
return api.e.StartMining(true)
|
return api.e.StartMining(true)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the miner
|
// Stop the miner
|
||||||
|
|
|
||||||
|
|
@ -167,12 +167,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specify etherbase explicitly.
|
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine)
|
||||||
var etherbase common.Address
|
|
||||||
if addr, err := eth.Etherbase(); err == nil {
|
|
||||||
etherbase = addr
|
|
||||||
}
|
|
||||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, etherbase)
|
|
||||||
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
||||||
|
|
||||||
eth.APIBackend = &EthAPIBackend{eth, nil}
|
eth.APIBackend = &EthAPIBackend{eth, nil}
|
||||||
|
|
@ -344,7 +339,7 @@ func (s *Ethereum) StartMining(local bool) error {
|
||||||
log.Error("Cannot start mining without etherbase", "err", err)
|
log.Error("Cannot start mining without etherbase", "err", err)
|
||||||
return fmt.Errorf("etherbase missing: %v", err)
|
return fmt.Errorf("etherbase missing: %v", err)
|
||||||
}
|
}
|
||||||
if clique, ok := s.engine.(*clique.Clique); ok && !clique.IsRunning() {
|
if clique, ok := s.engine.(*clique.Clique); ok {
|
||||||
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
|
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
|
||||||
if wallet == nil || err != nil {
|
if wallet == nil || err != nil {
|
||||||
log.Error("Etherbase account unavailable locally", "err", err)
|
log.Error("Etherbase account unavailable locally", "err", err)
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,7 @@ func (self *CpuAgent) Stop() {
|
||||||
if !atomic.CompareAndSwapInt32(&self.started, 1, 0) {
|
if !atomic.CompareAndSwapInt32(&self.started, 1, 0) {
|
||||||
return // agent already stopped
|
return // agent already stopped
|
||||||
}
|
}
|
||||||
// Close the pending routines.
|
self.stop <- struct{}{}
|
||||||
close(self.stop)
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
// Empty work channel
|
// Empty work channel
|
||||||
for {
|
for {
|
||||||
|
|
@ -105,7 +103,7 @@ func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {
|
||||||
log.Info("Successfully sealed new block", "number", result.Number(), "hash", result.Hash())
|
log.Info("Successfully sealed new block", "number", result.Number(), "hash", result.Hash())
|
||||||
self.returnCh <- &Result{work, result}
|
self.returnCh <- &Result{work, result}
|
||||||
} else {
|
} else {
|
||||||
if err != nil && err != consensus.ErrEngineNotStart {
|
if err != nil {
|
||||||
log.Warn("Block sealing failed", "err", err)
|
log.Warn("Block sealing failed", "err", err)
|
||||||
}
|
}
|
||||||
self.returnCh <- nil
|
self.returnCh <- nil
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,12 @@ type Miner struct {
|
||||||
shouldStart int32 // should start indicates whether we should start after sync
|
shouldStart int32 // should start indicates whether we should start after sync
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, coinbase common.Address) *Miner {
|
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
coinbase: coinbase,
|
worker: newWorker(config, engine, eth, mux),
|
||||||
worker: newWorker(config, engine, coinbase, eth, mux),
|
|
||||||
canStart: 1,
|
canStart: 1,
|
||||||
}
|
}
|
||||||
miner.Register(NewCpuAgent(eth.BlockChain(), engine))
|
miner.Register(NewCpuAgent(eth.BlockChain(), engine))
|
||||||
|
|
@ -110,6 +109,7 @@ func (self *Miner) Start(coinbase common.Address) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
self.worker.commitNewWork()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Stop() {
|
func (self *Miner) Stop() {
|
||||||
|
|
@ -126,7 +126,7 @@ func (self *Miner) Unregister(agent Agent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Mining() bool {
|
func (self *Miner) Mining() bool {
|
||||||
return self.engine.IsRunning()
|
return self.worker.isRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) HashRate() uint64 {
|
func (self *Miner) HashRate() uint64 {
|
||||||
|
|
|
||||||
|
|
@ -127,9 +127,10 @@ type worker struct {
|
||||||
|
|
||||||
// atomic status counters
|
// atomic status counters
|
||||||
atWork int32 // The number of in-flight consensus engine work.
|
atWork int32 // The number of in-flight consensus engine work.
|
||||||
|
running int32 // The indicator whether the consensus engine is running or not.
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase common.Address, eth Backend, mux *event.TypeMux) *worker {
|
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux) *worker {
|
||||||
worker := &worker{
|
worker := &worker{
|
||||||
config: config,
|
config: config,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
|
|
@ -143,7 +144,6 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase com
|
||||||
chain: eth.BlockChain(),
|
chain: eth.BlockChain(),
|
||||||
proc: eth.BlockChain().Validator(),
|
proc: eth.BlockChain().Validator(),
|
||||||
possibleUncles: make(map[common.Hash]*types.Block),
|
possibleUncles: make(map[common.Hash]*types.Block),
|
||||||
coinbase: coinbase,
|
|
||||||
agents: make(map[Agent]struct{}),
|
agents: make(map[Agent]struct{}),
|
||||||
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
|
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
|
||||||
}
|
}
|
||||||
|
|
@ -189,8 +189,7 @@ func (self *worker) pendingBlock() *types.Block {
|
||||||
func (self *worker) start() {
|
func (self *worker) start() {
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
defer self.mu.Unlock()
|
defer self.mu.Unlock()
|
||||||
|
atomic.StoreInt32(&self.running, 1)
|
||||||
self.engine.Start()
|
|
||||||
for agent := range self.agents {
|
for agent := range self.agents {
|
||||||
agent.Start()
|
agent.Start()
|
||||||
}
|
}
|
||||||
|
|
@ -200,19 +199,25 @@ func (self *worker) stop() {
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
defer self.mu.Unlock()
|
defer self.mu.Unlock()
|
||||||
|
|
||||||
self.engine.Stop()
|
atomic.StoreInt32(&self.running, 0)
|
||||||
for agent := range self.agents {
|
for agent := range self.agents {
|
||||||
agent.Stop()
|
agent.Stop()
|
||||||
}
|
}
|
||||||
atomic.StoreInt32(&self.atWork, 0)
|
atomic.StoreInt32(&self.atWork, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *worker) isRunning() bool {
|
||||||
|
return atomic.LoadInt32(&self.running) == 1
|
||||||
|
}
|
||||||
|
|
||||||
func (self *worker) register(agent Agent) {
|
func (self *worker) register(agent Agent) {
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
defer self.mu.Unlock()
|
defer self.mu.Unlock()
|
||||||
self.agents[agent] = struct{}{}
|
self.agents[agent] = struct{}{}
|
||||||
agent.SetReturnCh(self.recv)
|
agent.SetReturnCh(self.recv)
|
||||||
|
if self.isRunning() {
|
||||||
agent.Start()
|
agent.Start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) unregister(agent Agent) {
|
func (self *worker) unregister(agent Agent) {
|
||||||
|
|
@ -227,11 +232,6 @@ func (self *worker) update() {
|
||||||
defer self.chainHeadSub.Unsubscribe()
|
defer self.chainHeadSub.Unsubscribe()
|
||||||
defer self.chainSideSub.Unsubscribe()
|
defer self.chainSideSub.Unsubscribe()
|
||||||
|
|
||||||
ticker := time.NewTicker(500 * time.Millisecond)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
var started bool // Indication whether consensus engine is started
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// A real event arrived, process interesting content
|
// A real event arrived, process interesting content
|
||||||
select {
|
select {
|
||||||
|
|
@ -252,7 +252,7 @@ func (self *worker) update() {
|
||||||
// Note all transactions received may not be continuous with transactions
|
// Note all transactions received may not be continuous with transactions
|
||||||
// already included in the current mining block. These transactions will
|
// already included in the current mining block. These transactions will
|
||||||
// be automatically eliminated.
|
// be automatically eliminated.
|
||||||
if !self.engine.IsRunning() {
|
if !self.isRunning() {
|
||||||
self.currentMu.Lock()
|
self.currentMu.Lock()
|
||||||
txs := make(map[common.Address]types.Transactions)
|
txs := make(map[common.Address]types.Transactions)
|
||||||
for _, tx := range ev.Txs {
|
for _, tx := range ev.Txs {
|
||||||
|
|
@ -270,17 +270,6 @@ func (self *worker) update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit new work when consensus engine is started.
|
|
||||||
case <-ticker.C:
|
|
||||||
if self.engine.IsRunning() {
|
|
||||||
if !started {
|
|
||||||
self.commitNewWork()
|
|
||||||
started = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
started = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// System stopped
|
// System stopped
|
||||||
case <-self.txsSub.Err():
|
case <-self.txsSub.Err():
|
||||||
return
|
return
|
||||||
|
|
@ -340,11 +329,6 @@ func (self *worker) wait() {
|
||||||
|
|
||||||
// push sends a new work task to currently live miner agents.
|
// push sends a new work task to currently live miner agents.
|
||||||
func (self *worker) push(work *Work) {
|
func (self *worker) push(work *Work) {
|
||||||
// Never send task to consensus engine if the etherbase is not specified.
|
|
||||||
if self.engine.IsRunning() && work.header.Coinbase == (common.Address{}) {
|
|
||||||
log.Info("Please explicitly specifies the etherbase")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for agent := range self.agents {
|
for agent := range self.agents {
|
||||||
atomic.AddInt32(&self.atWork, 1)
|
atomic.AddInt32(&self.atWork, 1)
|
||||||
if ch := agent.Work(); ch != nil {
|
if ch := agent.Work(); ch != nil {
|
||||||
|
|
@ -416,7 +400,11 @@ func (self *worker) commitNewWork() {
|
||||||
Time: big.NewInt(tstamp),
|
Time: big.NewInt(tstamp),
|
||||||
}
|
}
|
||||||
// Only set the coinbase if our consensus engine is running (avoid spurious block rewards)
|
// Only set the coinbase if our consensus engine is running (avoid spurious block rewards)
|
||||||
if self.engine.IsRunning() {
|
if self.isRunning() {
|
||||||
|
if self.coinbase == (common.Address{}) {
|
||||||
|
log.Error("Refusing to mine without etherbase")
|
||||||
|
return
|
||||||
|
}
|
||||||
header.Coinbase = self.coinbase
|
header.Coinbase = self.coinbase
|
||||||
}
|
}
|
||||||
if err := self.engine.Prepare(self.chain, header); err != nil {
|
if err := self.engine.Prepare(self.chain, header); err != nil {
|
||||||
|
|
@ -479,11 +467,11 @@ func (self *worker) commitNewWork() {
|
||||||
// Push empty work in advance without applying pending transaction.
|
// Push empty work in advance without applying pending transaction.
|
||||||
// The reason is transactions execution can cost a lot and sealer need to
|
// The reason is transactions execution can cost a lot and sealer need to
|
||||||
// take advantage of this part time.
|
// take advantage of this part time.
|
||||||
if self.engine.IsRunning() {
|
if self.isRunning() {
|
||||||
log.Info("Commit new empty mining work", "number", work.Block.Number(), "uncles", len(uncles))
|
log.Info("Commit new empty mining work", "number", work.Block.Number(), "uncles", len(uncles))
|
||||||
}
|
|
||||||
self.push(work)
|
self.push(work)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fill the block with all available pending transactions.
|
// Fill the block with all available pending transactions.
|
||||||
pending, err := self.eth.TxPool().Pending()
|
pending, err := self.eth.TxPool().Pending()
|
||||||
|
|
@ -500,12 +488,11 @@ func (self *worker) commitNewWork() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// We only care about logging if we're actually mining.
|
// We only care about logging if we're actually mining.
|
||||||
if self.engine.IsRunning() {
|
if self.isRunning() {
|
||||||
log.Info("Commit new full mining work", "number", work.Block.Number(), "txs", work.tcount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
log.Info("Commit new full mining work", "number", work.Block.Number(), "txs", work.tcount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
||||||
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
||||||
}
|
|
||||||
// Push full work to sealer, which will replace the empty work sent before automatically.
|
|
||||||
self.push(work)
|
self.push(work)
|
||||||
|
}
|
||||||
self.updateSnapshot()
|
self.updateSnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue