Skip to content

Commit

Permalink
tidy / fixes / updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Oct 20, 2021
1 parent 59d1fdc commit be611cf
Show file tree
Hide file tree
Showing 59 changed files with 492 additions and 608 deletions.
4 changes: 2 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function runRpcServers(client: EthereumClient, config: Config) {

if (rpc) {
const methods =
rpcEngine && rpcEnginePort === rpcport
rpcEngine && rpcEnginePort === rpcport && rpcEngineAddr === rpcaddr
? { ...manager.getMethods(), ...manager.getMethods(true) }
: { ...manager.getMethods() }
const server = new RPCServer(methods)
Expand All @@ -296,7 +296,7 @@ function runRpcServers(client: EthereumClient, config: Config) {
}

if (rpcEngine) {
if (rpc && rpcport === rpcEnginePort) {
if (rpc && rpcport === rpcEnginePort && rpcaddr === rpcEngineAddr) {
return servers
}
const server = new RPCServer(manager.getMethods(true))
Expand Down
11 changes: 1 addition & 10 deletions packages/client/lib/blockchain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ export class Chain {
public chainDB: LevelUp
public blockchain: Blockchain
public opened: boolean
public mergeFirstFinalizedBlock: Block | undefined
public mergeLastFinalizedBlock: Block | undefined
public lastFinalizedBlock: Block | undefined

private _headers: ChainHeaders = {
latest: null,
Expand Down Expand Up @@ -167,7 +166,6 @@ export class Chain {

/**
* Returns properties of the canonical blockchain.
* @return {ChainBlocks}
*/
get blocks(): ChainBlocks {
return { ...this._blocks }
Expand Down Expand Up @@ -235,10 +233,6 @@ export class Chain {

this.config.chainCommon.setHardforkByBlockNumber(headers.latest.number, headers.td)

if (this.config.chainCommon.hardfork() === Hardfork.Merge) {
this.config.synchronized = true
}

if (emit) {
this.config.events.emit(Event.CHAIN_UPDATED)
}
Expand Down Expand Up @@ -333,9 +327,6 @@ export class Chain {
let numAdded = 0
for (const [i, h] of headers.entries()) {
if (!mergeIncludes && this.config.chainCommon.gteHardfork(Hardfork.Merge)) {
this.config.logger.info(
`Merge hardfork reached at block number=${h.number} td=${this.headers.td}`
)
if (i > 0) {
// emitOnLast below won't be reached, so run an update here
await this.update(true)
Expand Down
10 changes: 2 additions & 8 deletions packages/client/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default class EthereumClient extends events.EventEmitter {

/**
* Create new node
* @param {EthereumClientOptions}
*/
constructor(options: EthereumClientOptions) {
super()
Expand All @@ -74,7 +73,6 @@ export default class EthereumClient extends events.EventEmitter {

/**
* Open node. Must be called before node is started
* @return {Promise}
*/
async open() {
if (this.opened) {
Expand All @@ -94,7 +92,6 @@ export default class EthereumClient extends events.EventEmitter {

/**
* Starts node and all services and network servers.
* @return {Promise}
*/
async start() {
if (this.started) {
Expand All @@ -108,7 +105,6 @@ export default class EthereumClient extends events.EventEmitter {

/**
* Stops node and all services and network servers.
* @return {Promise}
*/
async stop() {
if (!this.started) {
Expand All @@ -121,17 +117,15 @@ export default class EthereumClient extends events.EventEmitter {

/**
* Returns the service with the specified name.
* @param {string} name name of service
* @return {Service}
* @param name name of service
*/
service(name: string) {
return this.services.find((s) => s.name === name)
}

/**
* Returns the server with the specified name.
* @param {string} name name of server
* @return {Server}
* @param name name of server
*/
server(name: string) {
return this.config.servers.find((s) => s.name === name)
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/miner/miner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Miner {
this._boundChainUpdatedHandler = this.chainUpdated.bind(this)
this.config.events.on(Event.CHAIN_UPDATED, this._boundChainUpdatedHandler)
this.config.logger.info(`Miner started. Assembling next block in ${this.period / 1000}s`)
void this.queueNextAssembly() // void operator satisfies eslint rule for no-floating-promises
void this.queueNextAssembly()
return true
}

Expand Down Expand Up @@ -251,7 +251,7 @@ export class Miner {
calcDifficultyFromHeader,
},
builderOpts: {
insertBlockIntoBlockchain: false,
putBlockIntoBlockchain: false,
},
})

Expand Down
8 changes: 2 additions & 6 deletions packages/client/lib/net/peer/libp2ppeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Libp2pPeerOptions extends Omit<PeerOptions, 'address' | 'transp
* Libp2p peer
* @memberof module:net/peer
* @example
*
* ```typescript
* import multiaddr from 'multiaddr'
* import { Libp2pPeer } from './lib/net/peer'
* import { Chain } from './lib/blockchain'
Expand All @@ -32,14 +32,14 @@ export interface Libp2pPeerOptions extends Omit<PeerOptions, 'address' | 'transp
* .on('connected', () => console.log('Connected'))
* .on('disconnected', (reason) => console.log('Disconnected: ', reason))
* .connect()
* ```
*/
export class Libp2pPeer extends Peer {
private multiaddrs: multiaddr[]
private connected: boolean

/**
* Create new libp2p peer
* @param {Libp2pPeerOptions}
*/
constructor(options: Libp2pPeerOptions) {
const multiaddrs = options.multiaddrs ?? [multiaddr('/ip4/0.0.0.0/tcp/0')]
Expand All @@ -53,7 +53,6 @@ export class Libp2pPeer extends Peer {

/**
* Initiate peer connection
* @return {Promise}
*/
async connect(): Promise<void> {
if (this.connected) {
Expand All @@ -72,8 +71,6 @@ export class Libp2pPeer extends Peer {

/**
* Accept new peer connection from a libp2p server
* @private
* @return {Promise}
*/
async accept(protocol: Protocol, stream: MuxedStream, server: Libp2pServer): Promise<void> {
await this.bindProtocol(protocol, new Libp2pSender(stream))
Expand All @@ -83,7 +80,6 @@ export class Libp2pPeer extends Peer {

/**
* Adds protocols to the peer given a libp2p node and peerId or multiaddr
* @private
* @param node libp2p node
* @param peer libp2p peerId or mutliaddr
* @param server server that initiated connection
Expand Down
13 changes: 5 additions & 8 deletions packages/client/lib/net/peer/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class Peer extends events.EventEmitter {

/**
* Create new peer
* @param {PeerOptions}
*/
constructor(options: PeerOptions) {
super()
Expand All @@ -80,15 +79,13 @@ export class Peer extends events.EventEmitter {

/**
* Get idle state of peer
* @type {boolean}
*/
get idle() {
return this._idle
}

/**
* Set idle state of peer
* @type {boolean}
*/
set idle(value) {
this._idle = value
Expand All @@ -102,11 +99,10 @@ export class Peer extends events.EventEmitter {
* arguments. send() only sends a message without waiting for a response, whereas
* request() also sends the message but will return a promise that resolves with
* the response payload.
* @protected
* @param {Protocol} protocol protocol instance
* @param {Sender} sender Sender instance provided by subclass
* @return {Promise}
* @param protocol protocol instance
* @param sender sender instance provided by subclass
* @example
* ```typescript
* await peer.bindProtocol(ethProtocol, sender)
* // Example: Directly call message name as a method on the bound protocol
* const headers1 = await peer.eth.getBlockHeaders({ block: new BN(1), max: 100 })
Expand All @@ -116,8 +112,9 @@ export class Peer extends events.EventEmitter {
* // wait for response message as an event
* peer.eth.send('getBlockHeaders', { block: new BN(1), max: 100 })
* peer.eth.on('message', ({ data }) => console.log(`Received ${data.length} headers`))
* ```
*/
async bindProtocol(protocol: Protocol, sender: Sender): Promise<void> {
protected async bindProtocol(protocol: Protocol, sender: Sender): Promise<void> {
const bound = await protocol.bind(this, sender)
this.bound.set(bound.name, bound)
}
Expand Down
16 changes: 5 additions & 11 deletions packages/client/lib/net/peer/rlpxpeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface RlpxPeerOptions extends Omit<PeerOptions, 'address' | 'transpor
* Devp2p/RLPx peer
* @memberof module:net/peer
* @example
*
* ```typescript
* import { RlpxPeer } from './lib/net/peer'
* import { Chain } from './lib/blockchain'
* import { EthProtocol } from './lib/net/protocol'
Expand All @@ -45,6 +45,7 @@ export interface RlpxPeerOptions extends Omit<PeerOptions, 'address' | 'transpor
* .on('connected', () => console.log('Connected'))
* .on('disconnected', (reason) => console.log('Disconnected:', reason))
* .connect()
* ```
*/
export class RlpxPeer extends Peer {
private host: string
Expand All @@ -55,7 +56,6 @@ export class RlpxPeer extends Peer {

/**
* Create new devp2p/rlpx peer
* @param {RlpxPeerOptions}
*/
constructor(options: RlpxPeerOptions) {
const address = `${options.host}:${options.port}`
Expand All @@ -74,8 +74,7 @@ export class RlpxPeer extends Peer {

/**
* Return devp2p/rlpx capabilities for the specified protocols
* @param {Protocols[]} protocols protocol instances
* @return {Object[]} capabilities
* @param protocols protocol instances
*/
static capabilities(protocols: Protocol[]): Devp2pCapabilities[] {
const capabilities: Devp2pCapabilities[] = []
Expand All @@ -94,7 +93,6 @@ export class RlpxPeer extends Peer {

/**
* Initiate peer connection
* @return {Promise}
*/
async connect(): Promise<void> {
if (this.connected) {
Expand Down Expand Up @@ -138,8 +136,6 @@ export class RlpxPeer extends Peer {

/**
* Accept new peer connection from an rlpx server
* @private
* @return {Promise}
*/
async accept(rlpxPeer: Devp2pRlpxPeer, server: RlpxServer): Promise<void> {
if (this.connected) {
Expand All @@ -151,11 +147,9 @@ export class RlpxPeer extends Peer {

/**
* Adds protocols to this peer given an rlpx native peer instance.
* @private
* @param {Object} rlpxPeer rlpx native peer
* @return {Promise}
* @param rlpxPeer rlpx native peer
*/
async bindProtocols(rlpxPeer: Devp2pRlpxPeer): Promise<void> {
private async bindProtocols(rlpxPeer: Devp2pRlpxPeer): Promise<void> {
this.rlpxPeer = rlpxPeer
await Promise.all(
rlpxPeer.getProtocols().map((rlpxProtocol) => {
Expand Down
Loading

1 comment on commit be611cf

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: be611cf Previous: e001ba0 Ratio
Block 9422914 8067 ops/sec (±27.06%) 16993 ops/sec (±4.54%) 2.11

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.