|
|
@ -21,21 +21,41 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
var jsonlogger = logger.NewJsonLogger() |
|
|
|
var jsonlogger = logger.NewJsonLogger() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Work holds the current work
|
|
|
|
|
|
|
|
type Work struct { |
|
|
|
|
|
|
|
Number uint64 |
|
|
|
|
|
|
|
Nonce uint64 |
|
|
|
|
|
|
|
MixDigest []byte |
|
|
|
|
|
|
|
SeedHash []byte |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Agent can register themself with the worker
|
|
|
|
|
|
|
|
type Agent interface { |
|
|
|
|
|
|
|
Work() chan<- *types.Block |
|
|
|
|
|
|
|
SetReturnCh(chan<- *types.Block) |
|
|
|
|
|
|
|
Stop() |
|
|
|
|
|
|
|
Start() |
|
|
|
|
|
|
|
GetHashRate() int64 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// environment is the workers current environment and holds
|
|
|
|
|
|
|
|
// all of the current state information
|
|
|
|
type environment struct { |
|
|
|
type environment struct { |
|
|
|
totalUsedGas *big.Int |
|
|
|
totalUsedGas *big.Int // total gas usage in the cycle
|
|
|
|
state *state.StateDB |
|
|
|
state *state.StateDB // apply state changes here
|
|
|
|
coinbase *state.StateObject |
|
|
|
coinbase *state.StateObject // the miner's account
|
|
|
|
block *types.Block |
|
|
|
block *types.Block // the new block
|
|
|
|
family *set.Set |
|
|
|
family *set.Set // family set (used for checking uncles)
|
|
|
|
uncles *set.Set |
|
|
|
uncles *set.Set // uncle set
|
|
|
|
remove *set.Set |
|
|
|
remove *set.Set // tx which will be removed
|
|
|
|
tcount int |
|
|
|
tcount int // tx count in cycle
|
|
|
|
ignoredTransactors *set.Set |
|
|
|
ignoredTransactors *set.Set |
|
|
|
lowGasTransactors *set.Set |
|
|
|
lowGasTransactors *set.Set |
|
|
|
ownedAccounts *set.Set |
|
|
|
ownedAccounts *set.Set |
|
|
|
lowGasTxs types.Transactions |
|
|
|
lowGasTxs types.Transactions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// env returns a new environment for the current cycle
|
|
|
|
func env(block *types.Block, eth core.Backend) *environment { |
|
|
|
func env(block *types.Block, eth core.Backend) *environment { |
|
|
|
state := state.New(block.Root(), eth.StateDb()) |
|
|
|
state := state.New(block.Root(), eth.StateDb()) |
|
|
|
env := &environment{ |
|
|
|
env := &environment{ |
|
|
@ -50,21 +70,7 @@ func env(block *types.Block, eth core.Backend) *environment { |
|
|
|
return env |
|
|
|
return env |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Work struct { |
|
|
|
// worker is the main object which takes care of applying messages to the new state
|
|
|
|
Number uint64 |
|
|
|
|
|
|
|
Nonce uint64 |
|
|
|
|
|
|
|
MixDigest []byte |
|
|
|
|
|
|
|
SeedHash []byte |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Agent interface { |
|
|
|
|
|
|
|
Work() chan<- *types.Block |
|
|
|
|
|
|
|
SetReturnCh(chan<- *types.Block) |
|
|
|
|
|
|
|
Stop() |
|
|
|
|
|
|
|
Start() |
|
|
|
|
|
|
|
GetHashRate() int64 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type worker struct { |
|
|
|
type worker struct { |
|
|
|
mu sync.Mutex |
|
|
|
mu sync.Mutex |
|
|
|
|
|
|
|
|
|
|
@ -375,8 +381,8 @@ func (self *worker) commitTransactions(transactions types.Transactions) { |
|
|
|
// We can skip err. It has already been validated in the tx pool
|
|
|
|
// We can skip err. It has already been validated in the tx pool
|
|
|
|
from, _ := tx.From() |
|
|
|
from, _ := tx.From() |
|
|
|
|
|
|
|
|
|
|
|
// check if it falls within margin
|
|
|
|
// Check if it falls within margin. Txs from owned accounts are always processed.
|
|
|
|
if tx.GasPrice().Cmp(self.gasPrice) < 0 { |
|
|
|
if tx.GasPrice().Cmp(self.gasPrice) < 0 && !current.ownedAccounts.Has(from) { |
|
|
|
// ignore the transaction and transactor. We ignore the transactor
|
|
|
|
// ignore the transaction and transactor. We ignore the transactor
|
|
|
|
// because nonce will fail after ignoring this transaction so there's
|
|
|
|
// because nonce will fail after ignoring this transaction so there's
|
|
|
|
// no point
|
|
|
|
// no point
|
|
|
|