aboutsummaryrefslogtreecommitdiffstats
path: root/miner/worker.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2019-04-23 15:08:51 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-04-23 15:08:51 +0800
commit6269e5574c024bb82617b33f673550231b3a3b37 (patch)
tree2cacec84e759833f3e3e77174e65d1ca7b584e75 /miner/worker.go
parentd9403690ecaf1beecc4369c56c4600caf275dae8 (diff)
downloadgo-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar.gz
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar.bz2
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar.lz
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar.xz
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.tar.zst
go-tangerine-6269e5574c024bb82617b33f673550231b3a3b37.zip
miner: polish miner configuration (#19480)
* cmd, eth, miner: disable advance sealing if user require * cmd, console, miner, les, eth: wrap the miner config * eth: remove todo * cmd, miner: revert noadvance flag The reason for this is: if the transaction execution is even longer than block time, then this kind of transactions is DoS attack.
Diffstat (limited to 'miner/worker.go')
-rw-r--r--miner/worker.go43
1 files changed, 21 insertions, 22 deletions
diff --git a/miner/worker.go b/miner/worker.go
index a9e440aec..802c7e365 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -122,13 +122,11 @@ type intervalAdjust struct {
// worker is the main object which takes care of submitting new work to consensus engine
// and gathering the sealing result.
type worker struct {
- config *params.ChainConfig
- engine consensus.Engine
- eth Backend
- chain *core.BlockChain
-
- gasFloor uint64
- gasCeil uint64
+ config *Config
+ chainConfig *params.ChainConfig
+ engine consensus.Engine
+ eth Backend
+ chain *core.BlockChain
// Subscriptions
mux *event.TypeMux
@@ -178,15 +176,14 @@ type worker struct {
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
}
-func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool) *worker {
+func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker {
worker := &worker{
config: config,
+ chainConfig: chainConfig,
engine: engine,
eth: eth,
mux: mux,
chain: eth.BlockChain(),
- gasFloor: gasFloor,
- gasCeil: gasCeil,
isLocalBlock: isLocalBlock,
localUncles: make(map[common.Hash]*types.Block),
remoteUncles: make(map[common.Hash]*types.Block),
@@ -210,6 +207,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
// Sanitize recommit interval if the user-specified one is too short.
+ recommit := worker.config.Recommit
if recommit < minRecommitInterval {
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
recommit = minRecommitInterval
@@ -354,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
case <-timer.C:
// If mining is running resubmit a new work cycle periodically to pull in
// higher priced transactions. Disable this overhead for pending blocks.
- if w.isRunning() && (w.config.Clique == nil || w.config.Clique.Period > 0) {
+ if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
// Short circuit if no new transaction arrives.
if atomic.LoadInt32(&w.newTxs) == 0 {
timer.Reset(recommit)
@@ -468,9 +466,10 @@ func (w *worker) mainLoop() {
w.commitTransactions(txset, coinbase, nil)
w.updateSnapshot()
} else {
- // If we're mining, but nothing is being processed, wake on new transactions
- if w.config.Clique != nil && w.config.Clique.Period == 0 {
- w.commitNewWork(nil, false, time.Now().Unix())
+ // If clique is running in dev mode(period is 0), disable
+ // advance sealing here.
+ if w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0 {
+ w.commitNewWork(nil, true, time.Now().Unix())
}
}
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))
@@ -618,7 +617,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
return err
}
env := &environment{
- signer: types.NewEIP155Signer(w.config.ChainID),
+ signer: types.NewEIP155Signer(w.chainConfig.ChainID),
state: state,
ancestors: mapset.NewSet(),
family: mapset.NewSet(),
@@ -696,7 +695,7 @@ func (w *worker) updateSnapshot() {
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
snap := w.current.state.Snapshot()
- receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
+ receipt, _, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
w.current.state.RevertToSnapshot(snap)
return nil, err
@@ -757,8 +756,8 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
from, _ := types.Sender(w.current.signer, tx)
// Check whether the tx is replay protected. If we're not in the EIP155 hf
// phase, start ignoring the sender until we do.
- if tx.Protected() && !w.config.IsEIP155(w.current.header.Number) {
- log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.config.EIP155Block)
+ if tx.Protected() && !w.chainConfig.IsEIP155(w.current.header.Number) {
+ log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.chainConfig.EIP155Block)
txs.Pop()
continue
@@ -842,7 +841,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
header := &types.Header{
ParentHash: parent.Hash(),
Number: num.Add(num, common.Big1),
- GasLimit: core.CalcGasLimit(parent, w.gasFloor, w.gasCeil),
+ GasLimit: core.CalcGasLimit(parent, w.config.GasFloor, w.config.GasCeil),
Extra: w.extra,
Time: uint64(timestamp),
}
@@ -859,12 +858,12 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
return
}
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
- if daoBlock := w.config.DAOForkBlock; daoBlock != nil {
+ if daoBlock := w.chainConfig.DAOForkBlock; daoBlock != nil {
// Check whether the block is among the fork extra-override range
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
// Depending whether we support or oppose the fork, override differently
- if w.config.DAOForkSupport {
+ if w.chainConfig.DAOForkSupport {
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
} else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
@@ -879,7 +878,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
}
// Create the current work task and check any fork transitions needed
env := w.current
- if w.config.DAOForkSupport && w.config.DAOForkBlock != nil && w.config.DAOForkBlock.Cmp(header.Number) == 0 {
+ if w.chainConfig.DAOForkSupport && w.chainConfig.DAOForkBlock != nil && w.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(env.state)
}
// Accumulate the uncles for the current block