worker.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. "fmt"
  19. "math/big"
  20. "sort"
  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/ethdb"
  30. "github.com/ethereum/go-ethereum/event"
  31. "github.com/ethereum/go-ethereum/logger"
  32. "github.com/ethereum/go-ethereum/logger/glog"
  33. "github.com/ethereum/go-ethereum/pow"
  34. "gopkg.in/fatih/set.v0"
  35. )
  36. var jsonlogger = logger.NewJsonLogger()
  37. const (
  38. resultQueueSize = 10
  39. miningLogAtDepth = 5
  40. )
  41. // Agent can register themself with the worker
  42. type Agent interface {
  43. Work() chan<- *Work
  44. SetReturnCh(chan<- *Result)
  45. Stop()
  46. Start()
  47. GetHashRate() int64
  48. }
  49. type uint64RingBuffer struct {
  50. ints []uint64 //array of all integers in buffer
  51. next int //where is the next insertion? assert 0 <= next < len(ints)
  52. }
  53. // environment is the workers current environment and holds
  54. // all of the current state information
  55. type Work struct {
  56. state *state.StateDB // apply state changes here
  57. coinbase *state.StateObject // the miner's account
  58. ancestors *set.Set // ancestor set (used for checking uncle parent validity)
  59. family *set.Set // family set (used for checking uncle invalidity)
  60. uncles *set.Set // uncle set
  61. remove *set.Set // tx which will be removed
  62. tcount int // tx count in cycle
  63. ignoredTransactors *set.Set
  64. lowGasTransactors *set.Set
  65. ownedAccounts *set.Set
  66. lowGasTxs types.Transactions
  67. localMinedBlocks *uint64RingBuffer // the most recent block numbers that were mined locally (used to check block inclusion)
  68. Block *types.Block // the new block
  69. header *types.Header
  70. txs []*types.Transaction
  71. receipts []*types.Receipt
  72. createdAt time.Time
  73. }
  74. type Result struct {
  75. Work *Work
  76. Block *types.Block
  77. }
  78. // worker is the main object which takes care of applying messages to the new state
  79. type worker struct {
  80. mu sync.Mutex
  81. agents []Agent
  82. recv chan *Result
  83. mux *event.TypeMux
  84. quit chan struct{}
  85. pow pow.PoW
  86. eth core.Backend
  87. chain *core.ChainManager
  88. proc *core.BlockProcessor
  89. chainDb ethdb.Database
  90. coinbase common.Address
  91. gasPrice *big.Int
  92. extra []byte
  93. currentMu sync.Mutex
  94. current *Work
  95. uncleMu sync.Mutex
  96. possibleUncles map[common.Hash]*types.Block
  97. txQueueMu sync.Mutex
  98. txQueue map[common.Hash]*types.Transaction
  99. // atomic status counters
  100. mining int32
  101. atWork int32
  102. fullValidation bool
  103. }
  104. func newWorker(coinbase common.Address, eth core.Backend) *worker {
  105. worker := &worker{
  106. eth: eth,
  107. mux: eth.EventMux(),
  108. chainDb: eth.ChainDb(),
  109. recv: make(chan *Result, resultQueueSize),
  110. gasPrice: new(big.Int),
  111. chain: eth.ChainManager(),
  112. proc: eth.BlockProcessor(),
  113. possibleUncles: make(map[common.Hash]*types.Block),
  114. coinbase: coinbase,
  115. txQueue: make(map[common.Hash]*types.Transaction),
  116. quit: make(chan struct{}),
  117. fullValidation: false,
  118. }
  119. go worker.update()
  120. go worker.wait()
  121. worker.commitNewWork()
  122. return worker
  123. }
  124. func (self *worker) setEtherbase(addr common.Address) {
  125. self.mu.Lock()
  126. defer self.mu.Unlock()
  127. self.coinbase = addr
  128. }
  129. func (self *worker) pendingState() *state.StateDB {
  130. self.currentMu.Lock()
  131. defer self.currentMu.Unlock()
  132. return self.current.state
  133. }
  134. func (self *worker) pendingBlock() *types.Block {
  135. self.currentMu.Lock()
  136. defer self.currentMu.Unlock()
  137. if atomic.LoadInt32(&self.mining) == 0 {
  138. return types.NewBlock(
  139. self.current.header,
  140. self.current.txs,
  141. nil,
  142. self.current.receipts,
  143. )
  144. }
  145. return self.current.Block
  146. }
  147. func (self *worker) start() {
  148. self.mu.Lock()
  149. defer self.mu.Unlock()
  150. atomic.StoreInt32(&self.mining, 1)
  151. // spin up agents
  152. for _, agent := range self.agents {
  153. agent.Start()
  154. }
  155. }
  156. func (self *worker) stop() {
  157. self.mu.Lock()
  158. defer self.mu.Unlock()
  159. if atomic.LoadInt32(&self.mining) == 1 {
  160. var keep []Agent
  161. // stop all agents
  162. for _, agent := range self.agents {
  163. agent.Stop()
  164. // keep all that's not a cpu agent
  165. if _, ok := agent.(*CpuAgent); !ok {
  166. keep = append(keep, agent)
  167. }
  168. }
  169. self.agents = keep
  170. }
  171. atomic.StoreInt32(&self.mining, 0)
  172. atomic.StoreInt32(&self.atWork, 0)
  173. }
  174. func (self *worker) register(agent Agent) {
  175. self.mu.Lock()
  176. defer self.mu.Unlock()
  177. self.agents = append(self.agents, agent)
  178. agent.SetReturnCh(self.recv)
  179. }
  180. func (self *worker) update() {
  181. events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
  182. out:
  183. for {
  184. select {
  185. case event := <-events.Chan():
  186. switch ev := event.(type) {
  187. case core.ChainHeadEvent:
  188. self.commitNewWork()
  189. case core.ChainSideEvent:
  190. self.uncleMu.Lock()
  191. self.possibleUncles[ev.Block.Hash()] = ev.Block
  192. self.uncleMu.Unlock()
  193. case core.TxPreEvent:
  194. // Apply transaction to the pending state if we're not mining
  195. if atomic.LoadInt32(&self.mining) == 0 {
  196. self.currentMu.Lock()
  197. self.current.commitTransactions(types.Transactions{ev.Tx}, self.gasPrice, self.proc)
  198. self.currentMu.Unlock()
  199. }
  200. }
  201. case <-self.quit:
  202. break out
  203. }
  204. }
  205. events.Unsubscribe()
  206. }
  207. func newLocalMinedBlock(blockNumber uint64, prevMinedBlocks *uint64RingBuffer) (minedBlocks *uint64RingBuffer) {
  208. if prevMinedBlocks == nil {
  209. minedBlocks = &uint64RingBuffer{next: 0, ints: make([]uint64, miningLogAtDepth+1)}
  210. } else {
  211. minedBlocks = prevMinedBlocks
  212. }
  213. minedBlocks.ints[minedBlocks.next] = blockNumber
  214. minedBlocks.next = (minedBlocks.next + 1) % len(minedBlocks.ints)
  215. return minedBlocks
  216. }
  217. func (self *worker) wait() {
  218. for {
  219. for result := range self.recv {
  220. atomic.AddInt32(&self.atWork, -1)
  221. if result == nil {
  222. continue
  223. }
  224. block := result.Block
  225. work := result.Work
  226. if self.fullValidation {
  227. if _, err := self.chain.InsertChain(types.Blocks{block}); err != nil {
  228. glog.V(logger.Error).Infoln("mining err", err)
  229. continue
  230. }
  231. go self.mux.Post(core.NewMinedBlockEvent{block})
  232. } else {
  233. work.state.Commit()
  234. parent := self.chain.GetBlock(block.ParentHash())
  235. if parent == nil {
  236. glog.V(logger.Error).Infoln("Invalid block found during mining")
  237. continue
  238. }
  239. if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent.Header(), true, false); err != nil && err != core.BlockFutureErr {
  240. glog.V(logger.Error).Infoln("Invalid header on mined block:", err)
  241. continue
  242. }
  243. stat, err := self.chain.WriteBlock(block)
  244. if err != nil {
  245. glog.V(logger.Error).Infoln("error writing block to chain", err)
  246. continue
  247. }
  248. // check if canon block and write transactions
  249. if stat == core.CanonStatTy {
  250. // This puts transactions in a extra db for rpc
  251. core.PutTransactions(self.chainDb, block, block.Transactions())
  252. // store the receipts
  253. core.PutReceipts(self.chainDb, work.receipts)
  254. }
  255. // broadcast before waiting for validation
  256. go func(block *types.Block, logs state.Logs, receipts []*types.Receipt) {
  257. self.mux.Post(core.NewMinedBlockEvent{block})
  258. self.mux.Post(core.ChainEvent{block, block.Hash(), logs})
  259. if stat == core.CanonStatTy {
  260. self.mux.Post(core.ChainHeadEvent{block})
  261. self.mux.Post(logs)
  262. }
  263. if err := core.PutBlockReceipts(self.chainDb, block, receipts); err != nil {
  264. glog.V(logger.Warn).Infoln("error writing block receipts:", err)
  265. }
  266. }(block, work.state.Logs(), work.receipts)
  267. }
  268. // check staleness and display confirmation
  269. var stale, confirm string
  270. canonBlock := self.chain.GetBlockByNumber(block.NumberU64())
  271. if canonBlock != nil && canonBlock.Hash() != block.Hash() {
  272. stale = "stale "
  273. } else {
  274. confirm = "Wait 5 blocks for confirmation"
  275. work.localMinedBlocks = newLocalMinedBlock(block.Number().Uint64(), work.localMinedBlocks)
  276. }
  277. glog.V(logger.Info).Infof("🔨 Mined %sblock (#%v / %x). %s", stale, block.Number(), block.Hash().Bytes()[:4], confirm)
  278. self.commitNewWork()
  279. }
  280. }
  281. }
  282. func (self *worker) push(work *Work) {
  283. if atomic.LoadInt32(&self.mining) == 1 {
  284. if core.Canary(work.state) {
  285. glog.Infoln("Toxicity levels rising to deadly levels. Your canary has died. You can go back or continue down the mineshaft --more--")
  286. glog.Infoln("You turn back and abort mining")
  287. return
  288. }
  289. // push new work to agents
  290. for _, agent := range self.agents {
  291. atomic.AddInt32(&self.atWork, 1)
  292. if agent.Work() != nil {
  293. agent.Work() <- work
  294. }
  295. }
  296. }
  297. }
  298. // makeCurrent creates a new environment for the current cycle.
  299. func (self *worker) makeCurrent(parent *types.Block, header *types.Header) {
  300. state := state.New(parent.Root(), self.eth.ChainDb())
  301. work := &Work{
  302. state: state,
  303. ancestors: set.New(),
  304. family: set.New(),
  305. uncles: set.New(),
  306. header: header,
  307. coinbase: state.GetOrNewStateObject(self.coinbase),
  308. createdAt: time.Now(),
  309. }
  310. // when 08 is processed ancestors contain 07 (quick block)
  311. for _, ancestor := range self.chain.GetBlocksFromHash(parent.Hash(), 7) {
  312. for _, uncle := range ancestor.Uncles() {
  313. work.family.Add(uncle.Hash())
  314. }
  315. work.family.Add(ancestor.Hash())
  316. work.ancestors.Add(ancestor.Hash())
  317. }
  318. accounts, _ := self.eth.AccountManager().Accounts()
  319. // Keep track of transactions which return errors so they can be removed
  320. work.remove = set.New()
  321. work.tcount = 0
  322. work.ignoredTransactors = set.New()
  323. work.lowGasTransactors = set.New()
  324. work.ownedAccounts = accountAddressesSet(accounts)
  325. if self.current != nil {
  326. work.localMinedBlocks = self.current.localMinedBlocks
  327. }
  328. self.current = work
  329. }
  330. func (w *worker) setGasPrice(p *big.Int) {
  331. w.mu.Lock()
  332. defer w.mu.Unlock()
  333. // calculate the minimal gas price the miner accepts when sorting out transactions.
  334. const pct = int64(90)
  335. w.gasPrice = gasprice(p, pct)
  336. w.mux.Post(core.GasPriceChanged{w.gasPrice})
  337. }
  338. func (self *worker) isBlockLocallyMined(current *Work, deepBlockNum uint64) bool {
  339. //Did this instance mine a block at {deepBlockNum} ?
  340. var isLocal = false
  341. for idx, blockNum := range current.localMinedBlocks.ints {
  342. if deepBlockNum == blockNum {
  343. isLocal = true
  344. current.localMinedBlocks.ints[idx] = 0 //prevent showing duplicate logs
  345. break
  346. }
  347. }
  348. //Short-circuit on false, because the previous and following tests must both be true
  349. if !isLocal {
  350. return false
  351. }
  352. //Does the block at {deepBlockNum} send earnings to my coinbase?
  353. var block = self.chain.GetBlockByNumber(deepBlockNum)
  354. return block != nil && block.Coinbase() == self.coinbase
  355. }
  356. func (self *worker) logLocalMinedBlocks(current, previous *Work) {
  357. if previous != nil && current.localMinedBlocks != nil {
  358. nextBlockNum := current.Block.NumberU64()
  359. for checkBlockNum := previous.Block.NumberU64(); checkBlockNum < nextBlockNum; checkBlockNum++ {
  360. inspectBlockNum := checkBlockNum - miningLogAtDepth
  361. if self.isBlockLocallyMined(current, inspectBlockNum) {
  362. glog.V(logger.Info).Infof("🔨 🔗 Mined %d blocks back: block #%v", miningLogAtDepth, inspectBlockNum)
  363. }
  364. }
  365. }
  366. }
  367. func (self *worker) commitNewWork() {
  368. self.mu.Lock()
  369. defer self.mu.Unlock()
  370. self.uncleMu.Lock()
  371. defer self.uncleMu.Unlock()
  372. self.currentMu.Lock()
  373. defer self.currentMu.Unlock()
  374. tstart := time.Now()
  375. parent := self.chain.CurrentBlock()
  376. tstamp := tstart.Unix()
  377. if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 {
  378. tstamp = parent.Time().Int64() + 1
  379. }
  380. // this will ensure we're not going off too far in the future
  381. if now := time.Now().Unix(); tstamp > now+4 {
  382. wait := time.Duration(tstamp-now) * time.Second
  383. glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait)
  384. time.Sleep(wait)
  385. }
  386. num := parent.Number()
  387. header := &types.Header{
  388. ParentHash: parent.Hash(),
  389. Number: num.Add(num, common.Big1),
  390. Difficulty: core.CalcDifficulty(uint64(tstamp), parent.Time().Uint64(), parent.Number(), parent.Difficulty()),
  391. GasLimit: core.CalcGasLimit(parent),
  392. GasUsed: new(big.Int),
  393. Coinbase: self.coinbase,
  394. Extra: self.extra,
  395. Time: big.NewInt(tstamp),
  396. }
  397. previous := self.current
  398. self.makeCurrent(parent, header)
  399. work := self.current
  400. /* //approach 1
  401. transactions := self.eth.TxPool().GetTransactions()
  402. sort.Sort(types.TxByNonce{transactions})
  403. */
  404. //approach 2
  405. transactions := self.eth.TxPool().GetTransactions()
  406. sort.Sort(types.TxByPriceAndNonce{transactions})
  407. /* // approach 3
  408. // commit transactions for this run.
  409. txPerOwner := make(map[common.Address]types.Transactions)
  410. // Sort transactions by owner
  411. for _, tx := range self.eth.TxPool().GetTransactions() {
  412. from, _ := tx.From() // we can ignore the sender error
  413. txPerOwner[from] = append(txPerOwner[from], tx)
  414. }
  415. var (
  416. singleTxOwner types.Transactions
  417. multiTxOwner types.Transactions
  418. )
  419. // Categorise transactions by
  420. // 1. 1 owner tx per block
  421. // 2. multi txs owner per block
  422. for _, txs := range txPerOwner {
  423. if len(txs) == 1 {
  424. singleTxOwner = append(singleTxOwner, txs[0])
  425. } else {
  426. multiTxOwner = append(multiTxOwner, txs...)
  427. }
  428. }
  429. sort.Sort(types.TxByPrice{singleTxOwner})
  430. sort.Sort(types.TxByNonce{multiTxOwner})
  431. transactions := append(singleTxOwner, multiTxOwner...)
  432. */
  433. work.coinbase.SetGasLimit(header.GasLimit)
  434. work.commitTransactions(transactions, self.gasPrice, self.proc)
  435. self.eth.TxPool().RemoveTransactions(work.lowGasTxs)
  436. // compute uncles for the new block.
  437. var (
  438. uncles []*types.Header
  439. badUncles []common.Hash
  440. )
  441. for hash, uncle := range self.possibleUncles {
  442. if len(uncles) == 2 {
  443. break
  444. }
  445. if err := self.commitUncle(work, uncle.Header()); err != nil {
  446. if glog.V(logger.Ridiculousness) {
  447. glog.V(logger.Detail).Infof("Bad uncle found and will be removed (%x)\n", hash[:4])
  448. glog.V(logger.Detail).Infoln(uncle)
  449. }
  450. badUncles = append(badUncles, hash)
  451. } else {
  452. glog.V(logger.Debug).Infof("commiting %x as uncle\n", hash[:4])
  453. uncles = append(uncles, uncle.Header())
  454. }
  455. }
  456. for _, hash := range badUncles {
  457. delete(self.possibleUncles, hash)
  458. }
  459. if atomic.LoadInt32(&self.mining) == 1 {
  460. // commit state root after all state transitions.
  461. core.AccumulateRewards(work.state, header, uncles)
  462. header.Root = work.state.IntermediateRoot()
  463. }
  464. // create the new block whose nonce will be mined.
  465. work.Block = types.NewBlock(header, work.txs, uncles, work.receipts)
  466. // We only care about logging if we're actually mining.
  467. if atomic.LoadInt32(&self.mining) == 1 {
  468. 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))
  469. self.logLocalMinedBlocks(work, previous)
  470. }
  471. self.push(work)
  472. }
  473. func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
  474. hash := uncle.Hash()
  475. if work.uncles.Has(hash) {
  476. return core.UncleError("Uncle not unique")
  477. }
  478. if !work.ancestors.Has(uncle.ParentHash) {
  479. return core.UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4]))
  480. }
  481. if work.family.Has(hash) {
  482. return core.UncleError(fmt.Sprintf("Uncle already in family (%x)", hash))
  483. }
  484. work.uncles.Add(uncle.Hash())
  485. return nil
  486. }
  487. func (env *Work) commitTransactions(transactions types.Transactions, gasPrice *big.Int, proc *core.BlockProcessor) {
  488. for _, tx := range transactions {
  489. // We can skip err. It has already been validated in the tx pool
  490. from, _ := tx.From()
  491. // Check if it falls within margin. Txs from owned accounts are always processed.
  492. if tx.GasPrice().Cmp(gasPrice) < 0 && !env.ownedAccounts.Has(from) {
  493. // ignore the transaction and transactor. We ignore the transactor
  494. // because nonce will fail after ignoring this transaction so there's
  495. // no point
  496. env.lowGasTransactors.Add(from)
  497. 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])
  498. }
  499. // Continue with the next transaction if the transaction sender is included in
  500. // the low gas tx set. This will also remove the tx and all sequential transaction
  501. // from this transactor
  502. if env.lowGasTransactors.Has(from) {
  503. // add tx to the low gas set. This will be removed at the end of the run
  504. // owned accounts are ignored
  505. if !env.ownedAccounts.Has(from) {
  506. env.lowGasTxs = append(env.lowGasTxs, tx)
  507. }
  508. continue
  509. }
  510. // Move on to the next transaction when the transactor is in ignored transactions set
  511. // This may occur when a transaction hits the gas limit. When a gas limit is hit and
  512. // the transaction is processed (that could potentially be included in the block) it
  513. // will throw a nonce error because the previous transaction hasn't been processed.
  514. // Therefor we need to ignore any transaction after the ignored one.
  515. if env.ignoredTransactors.Has(from) {
  516. continue
  517. }
  518. env.state.StartRecord(tx.Hash(), common.Hash{}, 0)
  519. err := env.commitTransaction(tx, proc)
  520. switch {
  521. case state.IsGasLimitErr(err):
  522. // ignore the transactor so no nonce errors will be thrown for this account
  523. // next time the worker is run, they'll be picked up again.
  524. env.ignoredTransactors.Add(from)
  525. glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
  526. case err != nil:
  527. env.remove.Add(tx.Hash())
  528. if glog.V(logger.Detail) {
  529. glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
  530. }
  531. default:
  532. env.tcount++
  533. }
  534. }
  535. }
  536. func (env *Work) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error {
  537. snap := env.state.Copy()
  538. receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true)
  539. if err != nil {
  540. env.state.Set(snap)
  541. return err
  542. }
  543. env.txs = append(env.txs, tx)
  544. env.receipts = append(env.receipts, receipt)
  545. return nil
  546. }
  547. // TODO: remove or use
  548. func (self *worker) HashRate() int64 {
  549. return 0
  550. }
  551. // gasprice calculates a reduced gas price based on the pct
  552. // XXX Use big.Rat?
  553. func gasprice(price *big.Int, pct int64) *big.Int {
  554. p := new(big.Int).Set(price)
  555. p.Div(p, big.NewInt(100))
  556. p.Mul(p, big.NewInt(pct))
  557. return p
  558. }
  559. func accountAddressesSet(accounts []accounts.Account) *set.Set {
  560. accountSet := set.New()
  561. for _, account := range accounts {
  562. accountSet.Add(account.Address)
  563. }
  564. return accountSet
  565. }