Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Memory Optimizations #2675

Merged
merged 8 commits into from
May 4, 2023
Merged
6 changes: 6 additions & 0 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ const args: ClientOpts = yargs(hideBin(process.argv))
describe: 'EIP-1459 ENR tree urls to query for peer discovery targets',
array: true,
})
.option('execution', {
describe: 'Start continuous VM execution (pre-Merge setting)',
boolean: true,
default: Config.EXECUTION,
})
.option('numBlocksPerIteration', {
describe: 'Number of blocks to execute in batch mode and logged to console',
number: true,
Expand Down Expand Up @@ -738,6 +743,7 @@ async function run() {
discDns: args.discDns,
discV4: args.discV4,
dnsAddr: args.dnsAddr,
execution: args.execution,
numBlocksPerIteration: args.numBlocksPerIteration,
accountCache: args.accountCache,
storageCache: args.storageCache,
Expand Down
8 changes: 8 additions & 0 deletions packages/client/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ export interface ConfigOptions {
*/
dnsNetworks?: string[]

/**
* Start continuous VM execution (pre-Merge setting)
*/
execution?: boolean

/**
* Number of blocks to execute in batch mode and logged to console
*/
Expand Down Expand Up @@ -310,6 +315,7 @@ export class Config {
public static readonly MINPEERS_DEFAULT = 1
public static readonly MAXPEERS_DEFAULT = 25
public static readonly DNSADDR_DEFAULT = '8.8.8.8'
public static readonly EXECUTION = true
public static readonly NUM_BLOCKS_PER_ITERATION = 100
public static readonly ACCOUNT_CACHE = 400000
public static readonly STORAGE_CACHE = 200000
Expand Down Expand Up @@ -345,6 +351,7 @@ export class Config {
public readonly minPeers: number
public readonly maxPeers: number
public readonly dnsAddr: string
public readonly execution: boolean
public readonly numBlocksPerIteration: number
public readonly accountCache: number
public readonly storageCache: number
Expand Down Expand Up @@ -402,6 +409,7 @@ export class Config {
this.minPeers = options.minPeers ?? Config.MINPEERS_DEFAULT
this.maxPeers = options.maxPeers ?? Config.MAXPEERS_DEFAULT
this.dnsAddr = options.dnsAddr ?? Config.DNSADDR_DEFAULT
this.execution = options.execution ?? Config.EXECUTION
this.numBlocksPerIteration = options.numBlocksPerIteration ?? Config.NUM_BLOCKS_PER_ITERATION
this.accountCache = options.accountCache ?? Config.ACCOUNT_CACHE
this.storageCache = options.storageCache ?? Config.STORAGE_CACHE
Expand Down
10 changes: 8 additions & 2 deletions packages/client/lib/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ export abstract class Execution {
*/
async open(): Promise<void> {
this.started = true
this.config.logger.info('Setup EVM execution.')
if (this.config.execution) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should not change the log UX here as the execution could still be triggered by beacon sync for e.g. and then stop would not log the stop message.

instead we should just add a log when we trigger execution run in full service start

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Could you eventually directly push ah update?

this.config.logger.info('Setup EVM execution.')
} else {
this.config.logger.info('EVM execution skipped.')
}
}

/**
* Stop execution. Returns a promise that resolves once stopped.
*/
async stop(): Promise<boolean> {
this.started = false
this.config.logger.info('Stopped execution.')
if (this.config.execution) {
this.config.logger.info('Stopped execution.')
}
return true
}
}
6 changes: 4 additions & 2 deletions packages/client/lib/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ export class VMExecution extends Execution {
}
const td = await this.vm.blockchain.getTotalDifficulty(headBlock.header.hash())
this.config.execCommon.setHardforkByBlockNumber(number, td, timestamp)
this.hardfork = this.config.execCommon.hardfork()
this.config.logger.info(`Initializing VM execution hardfork=${this.hardfork}`)
if (this.config.execution) {
this.hardfork = this.config.execCommon.hardfork()
this.config.logger.info(`Initializing VM execution hardfork=${this.hardfork}`)
}
if (number === BigInt(0)) {
if (typeof this.vm.blockchain.genesisState !== 'function') {
throw new Error('cannot get iterator head: blockchain has no genesisState function')
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/service/fullethereumservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class FullEthereumService extends EthereumService {
}
await super.start()
this.miner?.start()
if (!this.config.execCommon.gteHardfork(Hardfork.Paris)) {
if (!this.config.execCommon.gteHardfork(Hardfork.Paris) && this.config.execution) {
void this.execution.run(true, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void this.execution.run(true, true)
this.logger.info("Triggering execution of already downloaded blocks if any")
void this.execution.run(true, true)

something like this...

}
return true
Expand Down
8 changes: 6 additions & 2 deletions packages/client/lib/sync/beaconsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class BeaconSynchronizer extends Synchronizer {
await this.skeleton.open()

this.config.events.on(Event.SYNC_FETCHED_BLOCKS, this.processSkeletonBlocks)
this.config.events.on(Event.CHAIN_UPDATED, this.runExecution)
if (this.config.execution) {
this.config.events.on(Event.CHAIN_UPDATED, this.runExecution)
}

const { height: number, td } = this.chain.blocks
const hash = this.chain.blocks.latest!.hash()
Expand Down Expand Up @@ -331,7 +333,9 @@ export class BeaconSynchronizer extends Synchronizer {
async close() {
if (!this.opened) return
this.config.events.removeListener(Event.SYNC_FETCHED_BLOCKS, this.processSkeletonBlocks)
this.config.events.removeListener(Event.CHAIN_UPDATED, this.runExecution)
if (this.config.execution) {
this.config.events.removeListener(Event.CHAIN_UPDATED, this.runExecution)
}
await super.close()
}
}
8 changes: 6 additions & 2 deletions packages/client/lib/sync/fullsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class FullSynchronizer extends Synchronizer {

this.config.events.on(Event.SYNC_FETCHED_BLOCKS, this.processBlocks)
this.config.events.on(Event.SYNC_EXECUTION_VM_ERROR, this.stop)
this.config.events.on(Event.CHAIN_UPDATED, this.runExecution)
if (this.config.execution) {
this.config.events.on(Event.CHAIN_UPDATED, this.runExecution)
}

await this.pool.open()
const { height: number, td } = this.chain.blocks
Expand Down Expand Up @@ -404,7 +406,9 @@ export class FullSynchronizer extends Synchronizer {
async stop(): Promise<boolean> {
this.config.events.removeListener(Event.SYNC_FETCHED_BLOCKS, this.processBlocks)
this.config.events.removeListener(Event.SYNC_EXECUTION_VM_ERROR, this.stop)
this.config.events.removeListener(Event.CHAIN_UPDATED, this.runExecution)
if (this.config.execution) {
this.config.events.removeListener(Event.CHAIN_UPDATED, this.runExecution)
}
return super.stop()
}

Expand Down
1 change: 1 addition & 0 deletions packages/client/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface ClientOpts {
minPeers?: number
maxPeers?: number
dnsAddr?: string
execution?: boolean
numBlocksPerIteration?: number
accountCache?: number
storageCache?: number
Expand Down