From f9048e076780a5b3030e8a530f28d4d16e8ee2e4 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Tue, 24 Sep 2024 18:00:56 -0600 Subject: [PATCH] client: revert where unnecessary --- packages/client/bin/cli.ts | 5 +---- packages/client/src/execution/level.ts | 3 --- packages/client/src/miner/pendingBlock.ts | 2 +- packages/client/src/net/peer/rlpxpeer.ts | 3 --- packages/client/src/net/protocol/boundprotocol.ts | 6 ------ packages/client/src/net/protocol/rlpxsender.ts | 6 ------ packages/client/src/rpc/modules/debug.ts | 5 +---- packages/client/src/rpc/modules/engine/engine.ts | 13 ++----------- .../client/src/rpc/modules/engine/util/generic.ts | 5 +---- packages/client/src/rpc/modules/eth.ts | 5 +---- packages/client/src/service/skeleton.ts | 10 ++-------- 11 files changed, 9 insertions(+), 54 deletions(-) diff --git a/packages/client/bin/cli.ts b/packages/client/bin/cli.ts index af84384ee9..c59d3c10e0 100755 --- a/packages/client/bin/cli.ts +++ b/packages/client/bin/cli.ts @@ -554,10 +554,7 @@ async function executeBlocks(client: EthereumClient) { if ((blockRange[0][1] as string[]).length > 0 && blockRange.length === 2) { throw new Error('wrong input') } - } catch (e) { - if (!(e instanceof Error)) { - e = new Error(e) - } + } catch { client.config.logger.error( 'Wrong input format for block execution, allowed format types: 5, 5-10, 5[0xba4b5fd92a26badad3cad22eb6f7c7e745053739b5f5d1e8a3afb00f8fb2a280,[TX_HASH_2],...], 5[*] (all txs in verbose mode)', ) diff --git a/packages/client/src/execution/level.ts b/packages/client/src/execution/level.ts index bbdd004b67..d3d537eaa0 100644 --- a/packages/client/src/execution/level.ts +++ b/packages/client/src/execution/level.ts @@ -68,9 +68,6 @@ export class LevelDB< value = await this._leveldb.get(key, encodings) if (value === null) return undefined } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } // https://github.com/Level/abstract-level/blob/915ad1317694d0ce8c580b5ab85d81e1e78a3137/abstract-level.js#L309 // This should be `true` if the error came from LevelDB // so we can check for `NOT true` to identify any non-404 errors diff --git a/packages/client/src/miner/pendingBlock.ts b/packages/client/src/miner/pendingBlock.ts index 3544e67592..35571e08d3 100644 --- a/packages/client/src/miner/pendingBlock.ts +++ b/packages/client/src/miner/pendingBlock.ts @@ -359,7 +359,7 @@ export class PendingBlock { } else { addTxResult = AddTxResult.SkippedByGasLimit } - } else if ((error as Error).message.includes('blobs missing')) { + } else if (error.message.includes('blobs missing') === true) { // Remove the blob tx which doesn't has blobs bundled this.txPool.removeByHash(bytesToHex(tx.hash()), tx) this.config.logger.error( diff --git a/packages/client/src/net/peer/rlpxpeer.ts b/packages/client/src/net/peer/rlpxpeer.ts index b07745f2b6..911dc14210 100644 --- a/packages/client/src/net/peer/rlpxpeer.ts +++ b/packages/client/src/net/peer/rlpxpeer.ts @@ -126,9 +126,6 @@ export class RlpxPeer extends Peer { await this.bindProtocols(rlpxPeer) this.config.events.emit(Event.PEER_CONNECTED, this) } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } this.config.events.emit(Event.PEER_ERROR, error, this) } } diff --git a/packages/client/src/net/protocol/boundprotocol.ts b/packages/client/src/net/protocol/boundprotocol.ts index 51d40be58d..c4991bbc44 100644 --- a/packages/client/src/net/protocol/boundprotocol.ts +++ b/packages/client/src/net/protocol/boundprotocol.ts @@ -80,9 +80,6 @@ export class BoundProtocol { } } } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } this.config.events.emit(Event.PROTOCOL_ERROR, error, this.peer) } }) @@ -121,9 +118,6 @@ export class BoundProtocol { try { data = this.protocol.decode(message, incoming.payload) } catch (e) { - if (!(e instanceof Error)) { - e = new Error(e) - } error = new Error(`Could not decode message ${message.name}: ${e}`) } const resolver = this.resolvers.get(incoming.code) diff --git a/packages/client/src/net/protocol/rlpxsender.ts b/packages/client/src/net/protocol/rlpxsender.ts index 9a8ca397d9..6755f8dff9 100644 --- a/packages/client/src/net/protocol/rlpxsender.ts +++ b/packages/client/src/net/protocol/rlpxsender.ts @@ -35,9 +35,6 @@ export class RlpxSender extends Sender { try { this.sender.sendStatus(status) } catch (err) { - if (!(err instanceof Error)) { - err = new Error(err) - } this.emit('error', err) } } @@ -52,9 +49,6 @@ export class RlpxSender extends Sender { //@ts-ignore "type number is not assignable to type never" this.sender.sendMessage(code, data) } catch (err) { - if (!(err instanceof Error)) { - err = new Error(err) - } this.emit('error', err) } } diff --git a/packages/client/src/rpc/modules/debug.ts b/packages/client/src/rpc/modules/debug.ts index 0da7152460..cd2e1298a3 100644 --- a/packages/client/src/rpc/modules/debug.ts +++ b/packages/client/src/rpc/modules/debug.ts @@ -349,10 +349,7 @@ export class Debug { try { // Validator already verified that `blockHash` is properly formatted. block = await this.chain.getBlock(hexToBytes(blockHash)) - } catch (err) { - if (!(err instanceof Error)) { - err = new Error(err) - } + } catch { throw { code: INTERNAL_ERROR, message: 'Could not get requested block hash.', diff --git a/packages/client/src/rpc/modules/engine/engine.ts b/packages/client/src/rpc/modules/engine/engine.ts index 837deccb66..f2898fab2d 100644 --- a/packages/client/src/rpc/modules/engine/engine.ts +++ b/packages/client/src/rpc/modules/engine/engine.ts @@ -447,10 +447,7 @@ export class Engine { if (headBlock.common.isActivatedEIP(4844)) { try { headBlock.validateBlobTransactions(parent.header) - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { const validationError = `Invalid 4844 transactions: ${error}` const latestValidHash = await validHash( hexToBytes(parentHash as PrefixedHexString), @@ -473,10 +470,7 @@ export class Engine { if (!executedParentExists) { throw new Error(`Parent block not yet executed number=${parent.header.number}`) } - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { // Stash the block for a potential forced forkchoice update to it later. this.remoteBlocks.set(bytesToUnprefixedHex(headBlock.hash()), headBlock) @@ -1387,9 +1381,6 @@ export class Engine { ) return executionPayload } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } if (validEngineCodes.includes(error.code)) throw error throw { code: INTERNAL_ERROR, diff --git a/packages/client/src/rpc/modules/engine/util/generic.ts b/packages/client/src/rpc/modules/engine/util/generic.ts index 3f014b4eb7..9ef3345b96 100644 --- a/packages/client/src/rpc/modules/engine/util/generic.ts +++ b/packages/client/src/rpc/modules/engine/util/generic.ts @@ -65,10 +65,7 @@ export const validExecutedChainBlock = async ( // if the block was canonical and executed we would have returned by now return null - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { return null } } diff --git a/packages/client/src/rpc/modules/eth.ts b/packages/client/src/rpc/modules/eth.ts index bf35290161..41fbf16fec 100644 --- a/packages/client/src/rpc/modules/eth.ts +++ b/packages/client/src/rpc/modules/eth.ts @@ -1076,10 +1076,7 @@ export class Eth { if (blockHash !== undefined) { try { from = to = await this._chain.getBlock(hexToBytes(blockHash)) - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { throw { code: INVALID_PARAMS, message: 'unknown blockHash', diff --git a/packages/client/src/service/skeleton.ts b/packages/client/src/service/skeleton.ts index 52ee4d65dd..bde837ade6 100644 --- a/packages/client/src/service/skeleton.ts +++ b/packages/client/src/service/skeleton.ts @@ -1401,10 +1401,7 @@ export class Skeleton extends MetaDBManager { throw Error(`SkeletonBlock rlp lookup failed for ${number} onlyCanonical=${onlyCanonical}`) } return this.skeletonBlockRlpToBlock(skeletonBlockRlp) - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { // If skeleton is linked, it probably has deleted the block and put it into the chain if (onlyCanonical && !this.status.linked) return undefined // As a fallback, try to get the block from the canonical chain in case it is available there @@ -1477,10 +1474,7 @@ export class Skeleton extends MetaDBManager { await this.delete(DBKey.SkeletonBlockHashToNumber, block.hash()) await this.delete(DBKey.SkeletonUnfinalizedBlockByHash, block.hash()) return true - } catch (error) { - if (!(error instanceof Error)) { - error = new Error(error) - } + } catch { return false } }