1- import { bufferToHex } from 'ethereumjs-util'
21import { version as packageVersion } from '../package.json'
32import { MultiaddrLike } from './types'
43import { Config , SyncMode } from './config'
54import { FullEthereumService , LightEthereumService } from './service'
65import { Event } from './types'
7- import { VMExecution } from './execution'
86import { Chain } from './blockchain'
97// eslint-disable-next-line implicit-dependencies/no-implicit
108import type { LevelUp } from 'levelup'
@@ -57,7 +55,6 @@ export default class EthereumClient {
5755 public config : Config
5856 public chain : Chain
5957 public services : ( FullEthereumService | LightEthereumService ) [ ]
60- public execution : VMExecution | undefined
6158
6259 public opened : boolean
6360 public started : boolean
@@ -70,20 +67,13 @@ export default class EthereumClient {
7067 this . chain = new Chain ( options )
7168
7269 if ( this . config . syncmode === SyncMode . Full ) {
73- this . execution = new VMExecution ( {
74- config : options . config ,
75- stateDB : options . stateDB ,
76- metaDB : options . metaDB ,
77- chain : this . chain ,
78- } )
7970 this . services = [
8071 new FullEthereumService ( {
8172 config : this . config ,
8273 chainDB : options . chainDB ,
8374 stateDB : options . stateDB ,
8475 metaDB : options . metaDB ,
8576 chain : this . chain ,
86- execution : this . execution ,
8777 } ) ,
8878 ]
8979 } else {
@@ -123,7 +113,6 @@ export default class EthereumClient {
123113 this . config . logger . info ( `Synchronized blockchain at height=${ height } ` )
124114 } )
125115
126- await this . execution ?. open ( )
127116 await Promise . all ( this . services . map ( ( s ) => s . open ( ) ) )
128117
129118 this . opened = true
@@ -152,7 +141,6 @@ export default class EthereumClient {
152141 return false
153142 }
154143 this . config . events . emit ( Event . CLIENT_SHUTDOWN )
155- await this . execution ?. stop ( )
156144 await Promise . all ( this . services . map ( ( s ) => s . stop ( ) ) )
157145 await Promise . all ( this . config . servers . map ( ( s ) => s . stop ( ) ) )
158146 this . started = false
@@ -173,62 +161,4 @@ export default class EthereumClient {
173161 server ( name : string ) {
174162 return this . config . servers . find ( ( s ) => s . name === name )
175163 }
176-
177- /**
178- * Execute a range of blocks on a copy of the VM
179- * without changing any chain or client state
180- *
181- * Possible input formats:
182- *
183- * - Single block, '5'
184- * - Range of blocks, '5-10'
185- *
186- */
187- async executeBlocks ( first : number , last : number , txHashes : string [ ] ) {
188- this . config . logger . info ( 'Preparing for block execution (debug mode, no services started)...' )
189- if ( ! this . execution ) throw new Error ( 'executeBlocks requires execution' )
190- const vm = this . execution . vm . copy ( )
191-
192- for ( let blockNumber = first ; blockNumber <= last ; blockNumber ++ ) {
193- const block = await vm . blockchain . getBlock ( blockNumber )
194- const parentBlock = await vm . blockchain . getBlock ( block . header . parentHash )
195-
196- // Set the correct state root
197- await vm . stateManager . setStateRoot ( parentBlock . header . stateRoot )
198-
199- const td = await vm . blockchain . getTotalDifficulty ( block . header . parentHash )
200- vm . _common . setHardforkByBlockNumber ( blockNumber , td )
201-
202- if ( txHashes . length === 0 ) {
203- const res = await vm . runBlock ( { block } )
204- this . config . logger . info (
205- `Executed block num=${ blockNumber } hash=0x${ block . hash ( ) . toString ( 'hex' ) } txs=${
206- block . transactions . length
207- } gasUsed=${ res . gasUsed } `
208- )
209- } else {
210- let count = 0
211- // Special verbose tx execution mode triggered by BLOCK_NUMBER[*]
212- // Useful e.g. to trace slow txs
213- const allTxs = txHashes . length === 1 && txHashes [ 0 ] === '*' ? true : false
214- for ( const tx of block . transactions ) {
215- const txHash = bufferToHex ( tx . hash ( ) )
216- if ( allTxs || txHashes . includes ( txHash ) ) {
217- const res = await vm . runTx ( { block, tx } )
218- this . config . logger . info (
219- `Executed tx hash=${ txHash } gasUsed=${ res . gasUsed } from block num=${ blockNumber } `
220- )
221- count += 1
222- }
223- }
224- if ( count === 0 ) {
225- if ( ! allTxs ) {
226- this . config . logger . warn ( `Block number ${ first } contains no txs with provided hashes` )
227- } else {
228- this . config . logger . info ( `Block has 0 transactions (no execution)` )
229- }
230- }
231- }
232- }
233- }
234164}
0 commit comments