worker.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. mapset "github.com/deckarep/golang-set"
  25. "github.com/ethereum/go-ethereum/common"
  26. "github.com/ethereum/go-ethereum/consensus"
  27. "github.com/ethereum/go-ethereum/consensus/misc"
  28. "github.com/ethereum/go-ethereum/core"
  29. "github.com/ethereum/go-ethereum/core/state"
  30. "github.com/ethereum/go-ethereum/core/types"
  31. "github.com/ethereum/go-ethereum/core/vm"
  32. "github.com/ethereum/go-ethereum/ethdb"
  33. "github.com/ethereum/go-ethereum/event"
  34. "github.com/ethereum/go-ethereum/log"
  35. "github.com/ethereum/go-ethereum/params"
  36. )
  37. const (
  38. resultQueueSize = 10
  39. miningLogAtDepth = 5
  40. // txChanSize is the size of channel listening to NewTxsEvent.
  41. // The number is referenced from the size of tx pool.
  42. txChanSize = 4096
  43. // chainHeadChanSize is the size of channel listening to ChainHeadEvent.
  44. chainHeadChanSize = 10
  45. // chainSideChanSize is the size of channel listening to ChainSideEvent.
  46. chainSideChanSize = 10
  47. )
  48. // Agent can register themself with the worker
  49. type Agent interface {
  50. Work() chan<- *Work
  51. SetReturnCh(chan<- *Result)
  52. Start()
  53. Stop()
  54. }
  55. // Work is the workers current environment and holds
  56. // all of the current state information
  57. type Work struct {
  58. config *params.ChainConfig
  59. signer types.Signer
  60. state *state.StateDB // apply state changes here
  61. ancestors mapset.Set // ancestor set (used for checking uncle parent validity)
  62. family mapset.Set // family set (used for checking uncle invalidity)
  63. uncles mapset.Set // uncle set
  64. tcount int // tx count in cycle
  65. gasPool *core.GasPool // available gas used to pack transactions
  66. Block *types.Block // the new block
  67. header *types.Header
  68. txs []*types.Transaction
  69. receipts []*types.Receipt
  70. createdAt time.Time
  71. }
  72. type Result struct {
  73. Work *Work
  74. Block *types.Block
  75. }
  76. // worker is the main object which takes care of applying messages to the new state
  77. type worker struct {
  78. config *params.ChainConfig
  79. engine consensus.Engine
  80. mu sync.Mutex
  81. // update loop
  82. mux *event.TypeMux
  83. txsCh chan core.NewTxsEvent
  84. txsSub event.Subscription
  85. chainHeadCh chan core.ChainHeadEvent
  86. chainHeadSub event.Subscription
  87. chainSideCh chan core.ChainSideEvent
  88. chainSideSub event.Subscription
  89. agents map[Agent]struct{}
  90. recv chan *Result
  91. eth Backend
  92. chain *core.BlockChain
  93. proc core.Validator
  94. chainDb ethdb.Database
  95. coinbase common.Address
  96. extra []byte
  97. currentMu sync.Mutex
  98. current *Work
  99. snapshotMu sync.RWMutex
  100. snapshotBlock *types.Block
  101. snapshotState *state.StateDB
  102. uncleMu sync.Mutex
  103. possibleUncles map[common.Hash]*types.Block
  104. unconfirmed *unconfirmedBlocks // set of locally mined blocks pending canonicalness confirmations
  105. // atomic status counters
  106. atWork int32 // The number of in-flight consensus engine work.
  107. running int32 // The indicator whether the consensus engine is running or not.
  108. }
  109. func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux) *worker {
  110. worker := &worker{
  111. config: config,
  112. engine: engine,
  113. eth: eth,
  114. mux: mux,
  115. txsCh: make(chan core.NewTxsEvent, txChanSize),
  116. chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
  117. chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize),
  118. chainDb: eth.ChainDb(),
  119. recv: make(chan *Result, resultQueueSize),
  120. chain: eth.BlockChain(),
  121. proc: eth.BlockChain().Validator(),
  122. possibleUncles: make(map[common.Hash]*types.Block),
  123. agents: make(map[Agent]struct{}),
  124. unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
  125. }
  126. // Subscribe NewTxsEvent for tx pool
  127. worker.txsSub = eth.TxPool().SubscribeNewTxsEvent(worker.txsCh)
  128. // Subscribe events for blockchain
  129. worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
  130. worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
  131. go worker.update()
  132. go worker.wait()
  133. worker.commitNewWork()
  134. return worker
  135. }
  136. func (self *worker) setEtherbase(addr common.Address) {
  137. self.mu.Lock()
  138. defer self.mu.Unlock()
  139. self.coinbase = addr
  140. }
  141. func (self *worker) setExtra(extra []byte) {
  142. self.mu.Lock()
  143. defer self.mu.Unlock()
  144. self.extra = extra
  145. }
  146. func (self *worker) pending() (*types.Block, *state.StateDB) {
  147. // return a snapshot to avoid contention on currentMu mutex
  148. self.snapshotMu.RLock()
  149. defer self.snapshotMu.RUnlock()
  150. return self.snapshotBlock, self.snapshotState.Copy()
  151. }
  152. func (self *worker) pendingBlock() *types.Block {
  153. // return a snapshot to avoid contention on currentMu mutex
  154. self.snapshotMu.RLock()
  155. defer self.snapshotMu.RUnlock()
  156. return self.snapshotBlock
  157. }
  158. func (self *worker) start() {
  159. self.mu.Lock()
  160. defer self.mu.Unlock()
  161. atomic.StoreInt32(&self.running, 1)
  162. for agent := range self.agents {
  163. agent.Start()
  164. }
  165. }
  166. func (self *worker) stop() {
  167. self.mu.Lock()
  168. defer self.mu.Unlock()
  169. atomic.StoreInt32(&self.running, 0)
  170. for agent := range self.agents {
  171. agent.Stop()
  172. }
  173. atomic.StoreInt32(&self.atWork, 0)
  174. }
  175. func (self *worker) isRunning() bool {
  176. return atomic.LoadInt32(&self.running) == 1
  177. }
  178. func (self *worker) register(agent Agent) {
  179. self.mu.Lock()
  180. defer self.mu.Unlock()
  181. self.agents[agent] = struct{}{}
  182. agent.SetReturnCh(self.recv)
  183. if self.isRunning() {
  184. agent.Start()
  185. }
  186. }
  187. func (self *worker) unregister(agent Agent) {
  188. self.mu.Lock()
  189. defer self.mu.Unlock()
  190. delete(self.agents, agent)
  191. agent.Stop()
  192. }
  193. func (self *worker) update() {
  194. defer self.txsSub.Unsubscribe()
  195. defer self.chainHeadSub.Unsubscribe()
  196. defer self.chainSideSub.Unsubscribe()
  197. for {
  198. // A real event arrived, process interesting content
  199. select {
  200. // Handle ChainHeadEvent
  201. case <-self.chainHeadCh:
  202. self.commitNewWork()
  203. // Handle ChainSideEvent
  204. case ev := <-self.chainSideCh:
  205. self.uncleMu.Lock()
  206. self.possibleUncles[ev.Block.Hash()] = ev.Block
  207. self.uncleMu.Unlock()
  208. // Handle NewTxsEvent
  209. case ev := <-self.txsCh:
  210. // Apply transactions to the pending state if we're not mining.
  211. //
  212. // Note all transactions received may not be continuous with transactions
  213. // already included in the current mining block. These transactions will
  214. // be automatically eliminated.
  215. if !self.isRunning() {
  216. self.currentMu.Lock()
  217. txs := make(map[common.Address]types.Transactions)
  218. for _, tx := range ev.Txs {
  219. acc, _ := types.Sender(self.current.signer, tx)
  220. txs[acc] = append(txs[acc], tx)
  221. }
  222. txset := types.NewTransactionsByPriceAndNonce(self.current.signer, txs)
  223. self.current.commitTransactions(self.mux, txset, self.chain, self.coinbase)
  224. self.updateSnapshot()
  225. self.currentMu.Unlock()
  226. } else {
  227. // If we're mining, but nothing is being processed, wake on new transactions
  228. if self.config.Clique != nil && self.config.Clique.Period == 0 {
  229. self.commitNewWork()
  230. }
  231. }
  232. // System stopped
  233. case <-self.txsSub.Err():
  234. return
  235. case <-self.chainHeadSub.Err():
  236. return
  237. case <-self.chainSideSub.Err():
  238. return
  239. }
  240. }
  241. }
  242. func (self *worker) wait() {
  243. for {
  244. for result := range self.recv {
  245. atomic.AddInt32(&self.atWork, -1)
  246. if result == nil {
  247. continue
  248. }
  249. block := result.Block
  250. work := result.Work
  251. // Update the block hash in all logs since it is now available and not when the
  252. // receipt/log of individual transactions were created.
  253. for _, r := range work.receipts {
  254. for _, l := range r.Logs {
  255. l.BlockHash = block.Hash()
  256. }
  257. }
  258. for _, log := range work.state.Logs() {
  259. log.BlockHash = block.Hash()
  260. }
  261. self.currentMu.Lock()
  262. stat, err := self.chain.WriteBlockWithState(block, work.receipts, work.state)
  263. self.currentMu.Unlock()
  264. if err != nil {
  265. log.Error("Failed writing block to chain", "err", err)
  266. continue
  267. }
  268. // Broadcast the block and announce chain insertion event
  269. self.mux.Post(core.NewMinedBlockEvent{Block: block})
  270. var (
  271. events []interface{}
  272. logs = work.state.Logs()
  273. )
  274. events = append(events, core.ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
  275. if stat == core.CanonStatTy {
  276. events = append(events, core.ChainHeadEvent{Block: block})
  277. }
  278. self.chain.PostChainEvents(events, logs)
  279. // Insert the block into the set of pending ones to wait for confirmations
  280. self.unconfirmed.Insert(block.NumberU64(), block.Hash())
  281. }
  282. }
  283. }
  284. // push sends a new work task to currently live miner agents.
  285. func (self *worker) push(work *Work) {
  286. for agent := range self.agents {
  287. atomic.AddInt32(&self.atWork, 1)
  288. if ch := agent.Work(); ch != nil {
  289. ch <- work
  290. }
  291. }
  292. }
  293. // makeCurrent creates a new environment for the current cycle.
  294. func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error {
  295. state, err := self.chain.StateAt(parent.Root())
  296. if err != nil {
  297. return err
  298. }
  299. work := &Work{
  300. config: self.config,
  301. signer: types.NewEIP155Signer(self.config.ChainID),
  302. state: state,
  303. ancestors: mapset.NewSet(),
  304. family: mapset.NewSet(),
  305. uncles: mapset.NewSet(),
  306. header: header,
  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. // Keep track of transactions which return errors so they can be removed
  318. work.tcount = 0
  319. self.current = work
  320. return nil
  321. }
  322. func (self *worker) commitNewWork() {
  323. self.mu.Lock()
  324. defer self.mu.Unlock()
  325. self.uncleMu.Lock()
  326. defer self.uncleMu.Unlock()
  327. self.currentMu.Lock()
  328. defer self.currentMu.Unlock()
  329. tstart := time.Now()
  330. parent := self.chain.CurrentBlock()
  331. tstamp := tstart.Unix()
  332. if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 {
  333. tstamp = parent.Time().Int64() + 1
  334. }
  335. // this will ensure we're not going off too far in the future
  336. if now := time.Now().Unix(); tstamp > now+1 {
  337. wait := time.Duration(tstamp-now) * time.Second
  338. log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait))
  339. time.Sleep(wait)
  340. }
  341. num := parent.Number()
  342. header := &types.Header{
  343. ParentHash: parent.Hash(),
  344. Number: num.Add(num, common.Big1),
  345. GasLimit: core.CalcGasLimit(parent),
  346. Extra: self.extra,
  347. Time: big.NewInt(tstamp),
  348. }
  349. // Only set the coinbase if our consensus engine is running (avoid spurious block rewards)
  350. if self.isRunning() {
  351. if self.coinbase == (common.Address{}) {
  352. log.Error("Refusing to mine without etherbase")
  353. return
  354. }
  355. header.Coinbase = self.coinbase
  356. }
  357. if err := self.engine.Prepare(self.chain, header); err != nil {
  358. log.Error("Failed to prepare header for mining", "err", err)
  359. return
  360. }
  361. // If we are care about TheDAO hard-fork check whether to override the extra-data or not
  362. if daoBlock := self.config.DAOForkBlock; daoBlock != nil {
  363. // Check whether the block is among the fork extra-override range
  364. limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
  365. if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
  366. // Depending whether we support or oppose the fork, override differently
  367. if self.config.DAOForkSupport {
  368. header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
  369. } else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
  370. header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
  371. }
  372. }
  373. }
  374. // Could potentially happen if starting to mine in an odd state.
  375. err := self.makeCurrent(parent, header)
  376. if err != nil {
  377. log.Error("Failed to create mining context", "err", err)
  378. return
  379. }
  380. // Create the current work task and check any fork transitions needed
  381. work := self.current
  382. if self.config.DAOForkSupport && self.config.DAOForkBlock != nil && self.config.DAOForkBlock.Cmp(header.Number) == 0 {
  383. misc.ApplyDAOHardFork(work.state)
  384. }
  385. // compute uncles for the new block.
  386. var (
  387. uncles []*types.Header
  388. badUncles []common.Hash
  389. )
  390. for hash, uncle := range self.possibleUncles {
  391. if len(uncles) == 2 {
  392. break
  393. }
  394. if err := self.commitUncle(work, uncle.Header()); err != nil {
  395. log.Trace("Bad uncle found and will be removed", "hash", hash)
  396. log.Trace(fmt.Sprint(uncle))
  397. badUncles = append(badUncles, hash)
  398. } else {
  399. log.Debug("Committing new uncle to block", "hash", hash)
  400. uncles = append(uncles, uncle.Header())
  401. }
  402. }
  403. for _, hash := range badUncles {
  404. delete(self.possibleUncles, hash)
  405. }
  406. // Create an empty block based on temporary copied state for sealing in advance without waiting block
  407. // execution finished.
  408. if work.Block, err = self.engine.Finalize(self.chain, header, work.state.Copy(), nil, uncles, nil); err != nil {
  409. log.Error("Failed to finalize block for temporary sealing", "err", err)
  410. } else {
  411. // Push empty work in advance without applying pending transaction.
  412. // The reason is transactions execution can cost a lot and sealer need to
  413. // take advantage of this part time.
  414. if self.isRunning() {
  415. log.Info("Commit new empty mining work", "number", work.Block.Number(), "uncles", len(uncles))
  416. self.push(work)
  417. }
  418. }
  419. // Fill the block with all available pending transactions.
  420. pending, err := self.eth.TxPool().Pending()
  421. if err != nil {
  422. log.Error("Failed to fetch pending transactions", "err", err)
  423. return
  424. }
  425. txs := types.NewTransactionsByPriceAndNonce(self.current.signer, pending)
  426. work.commitTransactions(self.mux, txs, self.chain, self.coinbase)
  427. // Create the full block to seal with the consensus engine
  428. if work.Block, err = self.engine.Finalize(self.chain, header, work.state, work.txs, uncles, work.receipts); err != nil {
  429. log.Error("Failed to finalize block for sealing", "err", err)
  430. return
  431. }
  432. // We only care about logging if we're actually mining.
  433. if self.isRunning() {
  434. log.Info("Commit new full mining work", "number", work.Block.Number(), "txs", work.tcount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
  435. self.unconfirmed.Shift(work.Block.NumberU64() - 1)
  436. self.push(work)
  437. }
  438. self.updateSnapshot()
  439. }
  440. func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
  441. hash := uncle.Hash()
  442. if work.uncles.Contains(hash) {
  443. return fmt.Errorf("uncle not unique")
  444. }
  445. if !work.ancestors.Contains(uncle.ParentHash) {
  446. return fmt.Errorf("uncle's parent unknown (%x)", uncle.ParentHash[0:4])
  447. }
  448. if work.family.Contains(hash) {
  449. return fmt.Errorf("uncle already in family (%x)", hash)
  450. }
  451. work.uncles.Add(uncle.Hash())
  452. return nil
  453. }
  454. func (self *worker) updateSnapshot() {
  455. self.snapshotMu.Lock()
  456. defer self.snapshotMu.Unlock()
  457. var uncles []*types.Header
  458. self.current.uncles.Each(func(item interface{}) bool {
  459. if header, ok := item.(*types.Header); ok {
  460. uncles = append(uncles, header)
  461. return true
  462. }
  463. return false
  464. })
  465. self.snapshotBlock = types.NewBlock(
  466. self.current.header,
  467. self.current.txs,
  468. uncles,
  469. self.current.receipts,
  470. )
  471. self.snapshotState = self.current.state.Copy()
  472. }
  473. func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsByPriceAndNonce, bc *core.BlockChain, coinbase common.Address) {
  474. if env.gasPool == nil {
  475. env.gasPool = new(core.GasPool).AddGas(env.header.GasLimit)
  476. }
  477. var coalescedLogs []*types.Log
  478. for {
  479. // If we don't have enough gas for any further transactions then we're done
  480. if env.gasPool.Gas() < params.TxGas {
  481. log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", params.TxGas)
  482. break
  483. }
  484. // Retrieve the next transaction and abort if all done
  485. tx := txs.Peek()
  486. if tx == nil {
  487. break
  488. }
  489. // Error may be ignored here. The error has already been checked
  490. // during transaction acceptance is the transaction pool.
  491. //
  492. // We use the eip155 signer regardless of the current hf.
  493. from, _ := types.Sender(env.signer, tx)
  494. // Check whether the tx is replay protected. If we're not in the EIP155 hf
  495. // phase, start ignoring the sender until we do.
  496. if tx.Protected() && !env.config.IsEIP155(env.header.Number) {
  497. log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", env.config.EIP155Block)
  498. txs.Pop()
  499. continue
  500. }
  501. // Start executing the transaction
  502. env.state.Prepare(tx.Hash(), common.Hash{}, env.tcount)
  503. err, logs := env.commitTransaction(tx, bc, coinbase, env.gasPool)
  504. switch err {
  505. case core.ErrGasLimitReached:
  506. // Pop the current out-of-gas transaction without shifting in the next from the account
  507. log.Trace("Gas limit exceeded for current block", "sender", from)
  508. txs.Pop()
  509. case core.ErrNonceTooLow:
  510. // New head notification data race between the transaction pool and miner, shift
  511. log.Trace("Skipping transaction with low nonce", "sender", from, "nonce", tx.Nonce())
  512. txs.Shift()
  513. case core.ErrNonceTooHigh:
  514. // Reorg notification data race between the transaction pool and miner, skip account =
  515. log.Trace("Skipping account with hight nonce", "sender", from, "nonce", tx.Nonce())
  516. txs.Pop()
  517. case nil:
  518. // Everything ok, collect the logs and shift in the next transaction from the same account
  519. coalescedLogs = append(coalescedLogs, logs...)
  520. env.tcount++
  521. txs.Shift()
  522. default:
  523. // Strange error, discard the transaction and get the next in line (note, the
  524. // nonce-too-high clause will prevent us from executing in vain).
  525. log.Debug("Transaction failed, account skipped", "hash", tx.Hash(), "err", err)
  526. txs.Shift()
  527. }
  528. }
  529. if len(coalescedLogs) > 0 || env.tcount > 0 {
  530. // make a copy, the state caches the logs and these logs get "upgraded" from pending to mined
  531. // logs by filling in the block hash when the block was mined by the local miner. This can
  532. // cause a race condition if a log was "upgraded" before the PendingLogsEvent is processed.
  533. cpy := make([]*types.Log, len(coalescedLogs))
  534. for i, l := range coalescedLogs {
  535. cpy[i] = new(types.Log)
  536. *cpy[i] = *l
  537. }
  538. go func(logs []*types.Log, tcount int) {
  539. if len(logs) > 0 {
  540. mux.Post(core.PendingLogsEvent{Logs: logs})
  541. }
  542. if tcount > 0 {
  543. mux.Post(core.PendingStateEvent{})
  544. }
  545. }(cpy, env.tcount)
  546. }
  547. }
  548. func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, coinbase common.Address, gp *core.GasPool) (error, []*types.Log) {
  549. snap := env.state.Snapshot()
  550. receipt, _, err := core.ApplyTransaction(env.config, bc, &coinbase, gp, env.state, env.header, tx, &env.header.GasUsed, vm.Config{})
  551. if err != nil {
  552. env.state.RevertToSnapshot(snap)
  553. return err, nil
  554. }
  555. env.txs = append(env.txs, tx)
  556. env.receipts = append(env.receipts, receipt)
  557. return nil, receipt.Logs
  558. }