worker.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package miner
  17. import (
  18. "bytes"
  19. "fmt"
  20. "math/big"
  21. "sync"
  22. "sync/atomic"
  23. "time"
  24. "github.com/ethereum/go-ethereum/accounts"
  25. "github.com/ethereum/go-ethereum/common"
  26. "github.com/ethereum/go-ethereum/core"
  27. "github.com/ethereum/go-ethereum/core/state"
  28. "github.com/ethereum/go-ethereum/core/types"
  29. "github.com/ethereum/go-ethereum/core/vm"
  30. "github.com/ethereum/go-ethereum/ethdb"
  31. "github.com/ethereum/go-ethereum/event"
  32. "github.com/ethereum/go-ethereum/logger"
  33. "github.com/ethereum/go-ethereum/logger/glog"
  34. "github.com/ethereum/go-ethereum/params"
  35. "github.com/ethereum/go-ethereum/pow"
  36. "gopkg.in/fatih/set.v0"
  37. )
  38. const (
  39. resultQueueSize = 10
  40. miningLogAtDepth = 5
  41. )
  42. // Agent can register themself with the worker
  43. type Agent interface {
  44. Work() chan<- *Work
  45. SetReturnCh(chan<- *Result)
  46. Stop()
  47. Start()
  48. GetHashRate() int64
  49. }
  50. // Work is the workers current environment and holds
  51. // all of the current state information
  52. type Work struct {
  53. config *params.ChainConfig
  54. signer types.Signer
  55. state *state.StateDB // apply state changes here
  56. ancestors *set.Set // ancestor set (used for checking uncle parent validity)
  57. family *set.Set // family set (used for checking uncle invalidity)
  58. uncles *set.Set // uncle set
  59. tcount int // tx count in cycle
  60. ownedAccounts *set.Set
  61. lowGasTxs types.Transactions
  62. failedTxs types.Transactions
  63. Block *types.Block // the new block
  64. header *types.Header
  65. txs []*types.Transaction
  66. receipts []*types.Receipt
  67. createdAt time.Time
  68. }
  69. type Result struct {
  70. Work *Work
  71. Block *types.Block
  72. }
  73. // worker is the main object which takes care of applying messages to the new state
  74. type worker struct {
  75. config *params.ChainConfig
  76. mu sync.Mutex
  77. // update loop
  78. mux *event.TypeMux
  79. events event.Subscription
  80. wg sync.WaitGroup
  81. agents map[Agent]struct{}
  82. recv chan *Result
  83. pow pow.PoW
  84. eth Backend
  85. chain *core.BlockChain
  86. proc core.Validator
  87. chainDb ethdb.Database
  88. coinbase common.Address
  89. gasPrice *big.Int
  90. extra []byte
  91. currentMu sync.Mutex
  92. current *Work
  93. uncleMu sync.Mutex
  94. possibleUncles map[common.Hash]*types.Block
  95. txQueueMu sync.Mutex
  96. txQueue map[common.Hash]*types.Transaction
  97. unconfirmed *unconfirmedBlocks // set of locally mined blocks pending canonicalness confirmations
  98. // atomic status counters
  99. mining int32
  100. atWork int32
  101. fullValidation bool
  102. }
  103. func newWorker(config *params.ChainConfig, coinbase common.Address, eth Backend, mux *event.TypeMux) *worker {
  104. worker := &worker{
  105. config: config,
  106. eth: eth,
  107. mux: mux,
  108. chainDb: eth.ChainDb(),
  109. recv: make(chan *Result, resultQueueSize),
  110. gasPrice: new(big.Int),
  111. chain: eth.BlockChain(),
  112. proc: eth.BlockChain().Validator(),
  113. possibleUncles: make(map[common.Hash]*types.Block),
  114. coinbase: coinbase,
  115. txQueue: make(map[common.Hash]*types.Transaction),
  116. agents: make(map[Agent]struct{}),
  117. unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), 5),
  118. fullValidation: false,
  119. }
  120. worker.events = worker.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
  121. go worker.update()
  122. go worker.wait()
  123. worker.commitNewWork()
  124. return worker
  125. }
  126. func (self *worker) setEtherbase(addr common.Address) {
  127. self.mu.Lock()
  128. defer self.mu.Unlock()
  129. self.coinbase = addr
  130. }
  131. func (self *worker) setExtra(extra []byte) {
  132. self.mu.Lock()
  133. defer self.mu.Unlock()
  134. self.extra = extra
  135. }
  136. func (self *worker) pending() (*types.Block, *state.StateDB) {
  137. self.currentMu.Lock()
  138. defer self.currentMu.Unlock()
  139. if atomic.LoadInt32(&self.mining) == 0 {
  140. return types.NewBlock(
  141. self.current.header,
  142. self.current.txs,
  143. nil,
  144. self.current.receipts,
  145. ), self.current.state.Copy()
  146. }
  147. return self.current.Block, self.current.state.Copy()
  148. }
  149. func (self *worker) pendingBlock() *types.Block {
  150. self.currentMu.Lock()
  151. defer self.currentMu.Unlock()
  152. if atomic.LoadInt32(&self.mining) == 0 {
  153. return types.NewBlock(
  154. self.current.header,
  155. self.current.txs,
  156. nil,
  157. self.current.receipts,
  158. )
  159. }
  160. return self.current.Block
  161. }
  162. func (self *worker) start() {
  163. self.mu.Lock()
  164. defer self.mu.Unlock()
  165. atomic.StoreInt32(&self.mining, 1)
  166. // spin up agents
  167. for agent := range self.agents {
  168. agent.Start()
  169. }
  170. }
  171. func (self *worker) stop() {
  172. self.wg.Wait()
  173. self.mu.Lock()
  174. defer self.mu.Unlock()
  175. if atomic.LoadInt32(&self.mining) == 1 {
  176. // Stop all agents.
  177. for agent := range self.agents {
  178. agent.Stop()
  179. // Remove CPU agents.
  180. if _, ok := agent.(*CpuAgent); ok {
  181. delete(self.agents, agent)
  182. }
  183. }
  184. }
  185. atomic.StoreInt32(&self.mining, 0)
  186. atomic.StoreInt32(&self.atWork, 0)
  187. }
  188. func (self *worker) register(agent Agent) {
  189. self.mu.Lock()
  190. defer self.mu.Unlock()
  191. self.agents[agent] = struct{}{}
  192. agent.SetReturnCh(self.recv)
  193. }
  194. func (self *worker) unregister(agent Agent) {
  195. self.mu.Lock()
  196. defer self.mu.Unlock()
  197. delete(self.agents, agent)
  198. agent.Stop()
  199. }
  200. func (self *worker) update() {
  201. for event := range self.events.Chan() {
  202. // A real event arrived, process interesting content
  203. switch ev := event.Data.(type) {
  204. case core.ChainHeadEvent:
  205. self.commitNewWork()
  206. case core.ChainSideEvent:
  207. self.uncleMu.Lock()
  208. self.possibleUncles[ev.Block.Hash()] = ev.Block
  209. self.uncleMu.Unlock()
  210. case core.TxPreEvent:
  211. // Apply transaction to the pending state if we're not mining
  212. if atomic.LoadInt32(&self.mining) == 0 {
  213. self.currentMu.Lock()
  214. acc, _ := types.Sender(self.current.signer, ev.Tx)
  215. txs := map[common.Address]types.Transactions{acc: {ev.Tx}}
  216. txset := types.NewTransactionsByPriceAndNonce(txs)
  217. self.current.commitTransactions(self.mux, txset, self.gasPrice, self.chain)
  218. self.currentMu.Unlock()
  219. }
  220. }
  221. }
  222. }
  223. func (self *worker) wait() {
  224. for {
  225. mustCommitNewWork := true
  226. for result := range self.recv {
  227. atomic.AddInt32(&self.atWork, -1)
  228. if result == nil {
  229. continue
  230. }
  231. block := result.Block
  232. work := result.Work
  233. if self.fullValidation {
  234. if _, err := self.chain.InsertChain(types.Blocks{block}); err != nil {
  235. glog.V(logger.Error).Infoln("mining err", err)
  236. continue
  237. }
  238. go self.mux.Post(core.NewMinedBlockEvent{Block: block})
  239. } else {
  240. work.state.Commit(self.config.IsEIP158(block.Number()))
  241. parent := self.chain.GetBlock(block.ParentHash(), block.NumberU64()-1)
  242. if parent == nil {
  243. glog.V(logger.Error).Infoln("Invalid block found during mining")
  244. continue
  245. }
  246. auxValidator := self.eth.BlockChain().AuxValidator()
  247. if err := core.ValidateHeader(self.config, auxValidator, block.Header(), parent.Header(), true, false); err != nil && err != core.BlockFutureErr {
  248. glog.V(logger.Error).Infoln("Invalid header on mined block:", err)
  249. continue
  250. }
  251. stat, err := self.chain.WriteBlock(block)
  252. if err != nil {
  253. glog.V(logger.Error).Infoln("error writing block to chain", err)
  254. continue
  255. }
  256. // update block hash since it is now available and not when the receipt/log of individual transactions were created
  257. for _, r := range work.receipts {
  258. for _, l := range r.Logs {
  259. l.BlockHash = block.Hash()
  260. }
  261. }
  262. for _, log := range work.state.Logs() {
  263. log.BlockHash = block.Hash()
  264. }
  265. // check if canon block and write transactions
  266. if stat == core.CanonStatTy {
  267. // This puts transactions in a extra db for rpc
  268. core.WriteTransactions(self.chainDb, block)
  269. // store the receipts
  270. core.WriteReceipts(self.chainDb, work.receipts)
  271. // Write map map bloom filters
  272. core.WriteMipmapBloom(self.chainDb, block.NumberU64(), work.receipts)
  273. // implicit by posting ChainHeadEvent
  274. mustCommitNewWork = false
  275. }
  276. // broadcast before waiting for validation
  277. go func(block *types.Block, logs []*types.Log, receipts []*types.Receipt) {
  278. self.mux.Post(core.NewMinedBlockEvent{Block: block})
  279. self.mux.Post(core.ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
  280. if stat == core.CanonStatTy {
  281. self.mux.Post(core.ChainHeadEvent{Block: block})
  282. self.mux.Post(logs)
  283. }
  284. if err := core.WriteBlockReceipts(self.chainDb, block.Hash(), block.NumberU64(), receipts); err != nil {
  285. glog.V(logger.Warn).Infoln("error writing block receipts:", err)
  286. }
  287. }(block, work.state.Logs(), work.receipts)
  288. }
  289. // Insert the block into the set of pending ones to wait for confirmations
  290. self.unconfirmed.Insert(block.NumberU64(), block.Hash())
  291. if mustCommitNewWork {
  292. self.commitNewWork()
  293. }
  294. }
  295. }
  296. }
  297. // push sends a new work task to currently live miner agents.
  298. func (self *worker) push(work *Work) {
  299. if atomic.LoadInt32(&self.mining) != 1 {
  300. return
  301. }
  302. for agent := range self.agents {
  303. atomic.AddInt32(&self.atWork, 1)
  304. if ch := agent.Work(); ch != nil {
  305. ch <- work
  306. }
  307. }
  308. }
  309. // makeCurrent creates a new environment for the current cycle.
  310. func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error {
  311. state, err := self.chain.StateAt(parent.Root())
  312. if err != nil {
  313. return err
  314. }
  315. work := &Work{
  316. config: self.config,
  317. signer: types.NewEIP155Signer(self.config.ChainId),
  318. state: state,
  319. ancestors: set.New(),
  320. family: set.New(),
  321. uncles: set.New(),
  322. header: header,
  323. createdAt: time.Now(),
  324. }
  325. // when 08 is processed ancestors contain 07 (quick block)
  326. for _, ancestor := range self.chain.GetBlocksFromHash(parent.Hash(), 7) {
  327. for _, uncle := range ancestor.Uncles() {
  328. work.family.Add(uncle.Hash())
  329. }
  330. work.family.Add(ancestor.Hash())
  331. work.ancestors.Add(ancestor.Hash())
  332. }
  333. accounts := self.eth.AccountManager().Accounts()
  334. // Keep track of transactions which return errors so they can be removed
  335. work.tcount = 0
  336. work.ownedAccounts = accountAddressesSet(accounts)
  337. self.current = work
  338. return nil
  339. }
  340. func (w *worker) setGasPrice(p *big.Int) {
  341. w.mu.Lock()
  342. defer w.mu.Unlock()
  343. // calculate the minimal gas price the miner accepts when sorting out transactions.
  344. const pct = int64(90)
  345. w.gasPrice = gasprice(p, pct)
  346. w.mux.Post(core.GasPriceChanged{Price: w.gasPrice})
  347. }
  348. func (self *worker) commitNewWork() {
  349. self.mu.Lock()
  350. defer self.mu.Unlock()
  351. self.uncleMu.Lock()
  352. defer self.uncleMu.Unlock()
  353. self.currentMu.Lock()
  354. defer self.currentMu.Unlock()
  355. tstart := time.Now()
  356. parent := self.chain.CurrentBlock()
  357. tstamp := tstart.Unix()
  358. if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 {
  359. tstamp = parent.Time().Int64() + 1
  360. }
  361. // this will ensure we're not going off too far in the future
  362. if now := time.Now().Unix(); tstamp > now+4 {
  363. wait := time.Duration(tstamp-now) * time.Second
  364. glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait)
  365. time.Sleep(wait)
  366. }
  367. num := parent.Number()
  368. header := &types.Header{
  369. ParentHash: parent.Hash(),
  370. Number: num.Add(num, common.Big1),
  371. Difficulty: core.CalcDifficulty(self.config, uint64(tstamp), parent.Time().Uint64(), parent.Number(), parent.Difficulty()),
  372. GasLimit: core.CalcGasLimit(parent),
  373. GasUsed: new(big.Int),
  374. Coinbase: self.coinbase,
  375. Extra: self.extra,
  376. Time: big.NewInt(tstamp),
  377. }
  378. // If we are care about TheDAO hard-fork check whether to override the extra-data or not
  379. if daoBlock := self.config.DAOForkBlock; daoBlock != nil {
  380. // Check whether the block is among the fork extra-override range
  381. limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
  382. if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
  383. // Depending whether we support or oppose the fork, override differently
  384. if self.config.DAOForkSupport {
  385. header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
  386. } else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
  387. header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
  388. }
  389. }
  390. }
  391. // Could potentially happen if starting to mine in an odd state.
  392. err := self.makeCurrent(parent, header)
  393. if err != nil {
  394. glog.V(logger.Info).Infoln("Could not create new env for mining, retrying on next block.")
  395. return
  396. }
  397. // Create the current work task and check any fork transitions needed
  398. work := self.current
  399. if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
  400. core.ApplyDAOHardFork(work.state)
  401. }
  402. pending, err := self.eth.TxPool().Pending()
  403. if err != nil {
  404. glog.Errorf("Could not fetch pending transactions: %v", err)
  405. return
  406. }
  407. txs := types.NewTransactionsByPriceAndNonce(pending)
  408. work.commitTransactions(self.mux, txs, self.gasPrice, self.chain)
  409. self.eth.TxPool().RemoveBatch(work.lowGasTxs)
  410. self.eth.TxPool().RemoveBatch(work.failedTxs)
  411. // compute uncles for the new block.
  412. var (
  413. uncles []*types.Header
  414. badUncles []common.Hash
  415. )
  416. for hash, uncle := range self.possibleUncles {
  417. if len(uncles) == 2 {
  418. break
  419. }
  420. if err := self.commitUncle(work, uncle.Header()); err != nil {
  421. if glog.V(logger.Ridiculousness) {
  422. glog.V(logger.Detail).Infof("Bad uncle found and will be removed (%x)\n", hash[:4])
  423. glog.V(logger.Detail).Infoln(uncle)
  424. }
  425. badUncles = append(badUncles, hash)
  426. } else {
  427. glog.V(logger.Debug).Infof("commiting %x as uncle\n", hash[:4])
  428. uncles = append(uncles, uncle.Header())
  429. }
  430. }
  431. for _, hash := range badUncles {
  432. delete(self.possibleUncles, hash)
  433. }
  434. if atomic.LoadInt32(&self.mining) == 1 {
  435. // commit state root after all state transitions.
  436. core.AccumulateRewards(work.state, header, uncles)
  437. header.Root = work.state.IntermediateRoot(self.config.IsEIP158(header.Number))
  438. }
  439. // create the new block whose nonce will be mined.
  440. work.Block = types.NewBlock(header, work.txs, uncles, work.receipts)
  441. // We only care about logging if we're actually mining.
  442. if atomic.LoadInt32(&self.mining) == 1 {
  443. glog.V(logger.Info).Infof("commit new work on block %v with %d txs & %d uncles. Took %v\n", work.Block.Number(), work.tcount, len(uncles), time.Since(tstart))
  444. self.unconfirmed.Shift(work.Block.NumberU64() - 1)
  445. }
  446. self.push(work)
  447. }
  448. func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
  449. hash := uncle.Hash()
  450. if work.uncles.Has(hash) {
  451. return core.UncleError("Uncle not unique")
  452. }
  453. if !work.ancestors.Has(uncle.ParentHash) {
  454. return core.UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4]))
  455. }
  456. if work.family.Has(hash) {
  457. return core.UncleError(fmt.Sprintf("Uncle already in family (%x)", hash))
  458. }
  459. work.uncles.Add(uncle.Hash())
  460. return nil
  461. }
  462. func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsByPriceAndNonce, gasPrice *big.Int, bc *core.BlockChain) {
  463. gp := new(core.GasPool).AddGas(env.header.GasLimit)
  464. var coalescedLogs []*types.Log
  465. for {
  466. // Retrieve the next transaction and abort if all done
  467. tx := txs.Peek()
  468. if tx == nil {
  469. break
  470. }
  471. // Error may be ignored here. The error has already been checked
  472. // during transaction acceptance is the transaction pool.
  473. //
  474. // We use the eip155 signer regardless of the current hf.
  475. from, _ := types.Sender(env.signer, tx)
  476. // Check whether the tx is replay protected. If we're not in the EIP155 hf
  477. // phase, start ignoring the sender until we do.
  478. if tx.Protected() && !env.config.IsEIP155(env.header.Number) {
  479. glog.V(logger.Detail).Infof("Transaction (%x) is replay protected, but we haven't yet hardforked. Transaction will be ignored until we hardfork.\n", tx.Hash())
  480. txs.Pop()
  481. continue
  482. }
  483. // Ignore any transactions (and accounts subsequently) with low gas limits
  484. if tx.GasPrice().Cmp(gasPrice) < 0 && !env.ownedAccounts.Has(from) {
  485. // Pop the current low-priced transaction without shifting in the next from the account
  486. glog.V(logger.Info).Infof("Transaction (%x) below gas price (tx=%v ask=%v). All sequential txs from this address(%x) will be ignored\n", tx.Hash().Bytes()[:4], common.CurrencyToString(tx.GasPrice()), common.CurrencyToString(gasPrice), from[:4])
  487. env.lowGasTxs = append(env.lowGasTxs, tx)
  488. txs.Pop()
  489. continue
  490. }
  491. // Start executing the transaction
  492. env.state.StartRecord(tx.Hash(), common.Hash{}, env.tcount)
  493. err, logs := env.commitTransaction(tx, bc, gp)
  494. switch {
  495. case core.IsGasLimitErr(err):
  496. // Pop the current out-of-gas transaction without shifting in the next from the account
  497. glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
  498. txs.Pop()
  499. case err != nil:
  500. // Pop the current failed transaction without shifting in the next from the account
  501. glog.V(logger.Detail).Infof("Transaction (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
  502. env.failedTxs = append(env.failedTxs, tx)
  503. txs.Pop()
  504. default:
  505. // Everything ok, collect the logs and shift in the next transaction from the same account
  506. coalescedLogs = append(coalescedLogs, logs...)
  507. env.tcount++
  508. txs.Shift()
  509. }
  510. }
  511. if len(coalescedLogs) > 0 || env.tcount > 0 {
  512. // make a copy, the state caches the logs and these logs get "upgraded" from pending to mined
  513. // logs by filling in the block hash when the block was mined by the local miner. This can
  514. // cause a race condition if a log was "upgraded" before the PendingLogsEvent is processed.
  515. cpy := make([]*types.Log, len(coalescedLogs))
  516. for i, l := range coalescedLogs {
  517. cpy[i] = new(types.Log)
  518. *cpy[i] = *l
  519. }
  520. go func(logs []*types.Log, tcount int) {
  521. if len(logs) > 0 {
  522. mux.Post(core.PendingLogsEvent{Logs: logs})
  523. }
  524. if tcount > 0 {
  525. mux.Post(core.PendingStateEvent{})
  526. }
  527. }(cpy, env.tcount)
  528. }
  529. }
  530. func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, gp *core.GasPool) (error, []*types.Log) {
  531. snap := env.state.Snapshot()
  532. receipt, _, err := core.ApplyTransaction(env.config, bc, gp, env.state, env.header, tx, env.header.GasUsed, vm.Config{})
  533. if err != nil {
  534. env.state.RevertToSnapshot(snap)
  535. return err, nil
  536. }
  537. env.txs = append(env.txs, tx)
  538. env.receipts = append(env.receipts, receipt)
  539. return nil, receipt.Logs
  540. }
  541. // TODO: remove or use
  542. func (self *worker) HashRate() int64 {
  543. return 0
  544. }
  545. // gasprice calculates a reduced gas price based on the pct
  546. // XXX Use big.Rat?
  547. func gasprice(price *big.Int, pct int64) *big.Int {
  548. p := new(big.Int).Set(price)
  549. p.Div(p, big.NewInt(100))
  550. p.Mul(p, big.NewInt(pct))
  551. return p
  552. }
  553. func accountAddressesSet(accounts []accounts.Account) *set.Set {
  554. accountSet := set.New()
  555. for _, account := range accounts {
  556. accountSet.Add(account.Address)
  557. }
  558. return accountSet
  559. }