Skip to content

Commit

Permalink
client: revert where unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Sep 25, 2024
1 parent 2a18d4f commit f9048e0
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 54 deletions.
5 changes: 1 addition & 4 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
)
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/execution/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/net/peer/rlpxpeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 0 additions & 6 deletions packages/client/src/net/protocol/boundprotocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions packages/client/src/net/protocol/rlpxsender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/client/src/rpc/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
13 changes: 2 additions & 11 deletions packages/client/src/rpc/modules/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions packages/client/src/rpc/modules/engine/util/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
5 changes: 1 addition & 4 deletions packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 2 additions & 8 deletions packages/client/src/service/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit f9048e0

Please sign in to comment.