Skip to content

Commit

Permalink
Collapse EthereumService abstraction service (#2943)
Browse files Browse the repository at this point in the history
* Collapse ethereumservice into service

* Clean up ethereumservice references
  • Loading branch information
acolytec3 authored Aug 7, 2023
1 parent f28ddcd commit 0a612d0
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 172 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { middleware } from '../validation'
import type { Chain } from '../../blockchain'
import type { EthereumClient } from '../../client'
import type { RlpxServer } from '../../net/server'
import type { EthereumService } from '../../service'
import type { Service } from '../../service'

/**
* admin_* RPC module
Expand All @@ -21,7 +21,7 @@ export class Admin {
* @param client Client to which the module binds
*/
constructor(client: EthereumClient) {
const service = client.services.find((s) => s.name === 'eth') as EthereumService
const service = client.services.find((s) => s.name === 'eth') as Service
this._chain = service.chain
this._client = client

Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { EthereumClient } from '../..'
import type { Chain } from '../../blockchain'
import type { ReceiptsManager } from '../../execution/receipt'
import type { EthProtocol } from '../../net/protocol'
import type { EthereumService, FullEthereumService } from '../../service'
import type { FullEthereumService, Service } from '../../service'
import type { RpcTx } from '../types'
import type { Block, JsonRpcBlock } from '@ethereumjs/block'
import type { Log } from '@ethereumjs/evm'
Expand Down Expand Up @@ -203,7 +203,7 @@ const jsonRpcReceipt = async (
*/
export class Eth {
private client: EthereumClient
private service: EthereumService
private service: Service
private receiptsManager: ReceiptsManager | undefined
private _chain: Chain
private _vm: VM | undefined
Expand All @@ -215,7 +215,7 @@ export class Eth {
*/
constructor(client: EthereumClient) {
this.client = client
this.service = client.services.find((s) => s.name === 'eth') as EthereumService
this.service = client.services.find((s) => s.name === 'eth') as Service
this._chain = this.service.chain
this._vm = (this.service as FullEthereumService).execution?.vm
this.receiptsManager = (this.service as FullEthereumService).execution?.receiptsManager
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { middleware } from '../validation'
import type { EthereumClient } from '../..'
import type { Chain } from '../../blockchain'
import type { PeerPool } from '../../net/peerpool'
import type { EthereumService } from '../../service/ethereumservice'
import type { Service } from '../../service/service'

/**
* net_* RPC module
Expand All @@ -21,7 +21,7 @@ export class Net {
* @param client Client to which the module binds
*/
constructor(client: EthereumClient) {
const service = client.services.find((s) => s.name === 'eth') as EthereumService
const service = client.services.find((s) => s.name === 'eth') as Service
this._chain = service.chain
this._client = client
this._peerPool = service.pool
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { middleware, validators } from '../validation'

import type { EthereumClient } from '../..'
import type { Chain } from '../../blockchain'
import type { EthereumService } from '../../service'
import type { Service } from '../../service'

/**
* web3_* RPC module
Expand All @@ -20,7 +20,7 @@ export class Web3 {
* @param client Client to which the module binds
*/
constructor(client: EthereumClient) {
const service = client.services.find((s) => s.name === 'eth') as EthereumService
const service = client.services.find((s) => s.name === 'eth') as Service
this._chain = service.chain

this.clientVersion = middleware(this.clientVersion.bind(this), 0, [])
Expand Down
152 changes: 0 additions & 152 deletions packages/client/src/service/ethereumservice.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/client/src/service/fullethereumservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import { BeaconSynchronizer, FullSynchronizer, SnapSynchronizer } from '../sync'
import { Skeleton } from '../sync/skeleton'
import { Event } from '../types'

import { EthereumService } from './ethereumservice'
import { Service, type ServiceOptions } from './service'
import { TxPool } from './txpool'

import type { Peer } from '../net/peer/peer'
import type { Protocol } from '../net/protocol'
import type { EthereumServiceOptions } from './ethereumservice'
import type { Block } from '@ethereumjs/block'
import type { BlobEIP4844Transaction } from '@ethereumjs/tx'

interface FullEthereumServiceOptions extends EthereumServiceOptions {
interface FullEthereumServiceOptions extends ServiceOptions {
/** Serve LES requests (default: false) */
lightserv?: boolean
}
Expand All @@ -31,7 +30,7 @@ interface FullEthereumServiceOptions extends EthereumServiceOptions {
* Full Ethereum service
* @memberof module:service
*/
export class FullEthereumService extends EthereumService {
export class FullEthereumService extends Service {
public synchronizer?: BeaconSynchronizer | FullSynchronizer | SnapSynchronizer
public lightserv: boolean
public miner: Miner | undefined
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module service
*/

export * from './ethereumservice'
export * from './fullethereumservice'
export * from './lightethereumservice'
export * from './service'
20 changes: 16 additions & 4 deletions packages/client/src/service/lightethereumservice.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { LesProtocol } from '../net/protocol/lesprotocol'
import { LightSynchronizer } from '../sync/lightsync'

import { EthereumService } from './ethereumservice'
import { Service } from './service'

import type { Peer } from '../net/peer/peer'
import type { EthereumServiceOptions } from './ethereumservice'
import type { ServiceOptions } from './service'

/**
* Light Ethereum service
* @memberof module:service
*/
export class LightEthereumService extends EthereumService {
export class LightEthereumService extends Service {
public synchronizer: LightSynchronizer

/**
* Create new LES service
*/
constructor(options: EthereumServiceOptions) {
constructor(options: ServiceOptions) {
super(options)

this.config.logger.info('Light sync mode')
Expand Down Expand Up @@ -49,4 +49,16 @@ export class LightEthereumService extends EthereumService {
* @param peer peer
*/
async handle(_message: any, _protocol: string, _peer: Peer) {}

/**
* Stop service
*/
async stop(): Promise<boolean> {
if (!this.running) {
return false
}
await this.synchronizer?.stop()
await super.stop()
return true
}
}
Loading

0 comments on commit 0a612d0

Please sign in to comment.