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