Skip to content

Commit 55178f4

Browse files
authored
client: small fixes (txpool result not iterable, rpc validation for exchangeTransitionConfiguration) (#1793)
* engine: add validation for exchangeTransitionConfiguration * create separate type for test utils type StartRPCOpts * TxPool: fix `(intermediate value) is not iterable` error on `await getPooledTransactions`
1 parent 3916fc0 commit 55178f4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

packages/client/lib/rpc/modules/engine.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,16 @@ export class Engine {
256256

257257
this.exchangeTransitionConfigurationV1 = middleware(
258258
this.exchangeTransitionConfigurationV1.bind(this),
259-
0
259+
1,
260+
[
261+
[
262+
validators.object({
263+
terminalTotalDifficulty: validators.hex,
264+
terminalBlockHash: validators.hex,
265+
terminalBlockNumber: validators.hex,
266+
}),
267+
],
268+
]
260269
)
261270
}
262271

packages/client/lib/sync/txpool.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import { Address, BN } from 'ethereumjs-util'
99
import { Config } from '../config'
1010
import { Peer } from '../net/peer'
11-
import { EthProtocolMethods } from '../net/protocol'
1211
import type { PeerPool } from '../net/peerpool'
1312
import type { Block } from '@ethereumjs/block'
1413
import type { StateManager } from '@ethereumjs/vm/dist/state'
@@ -369,16 +368,16 @@ export class TxPool {
369368
this.config.logger.debug(
370369
`TxPool: requesting txs number=${reqHashes.length} pending=${this.pending.length}`
371370
)
372-
const [_, txs] = await (peer!.eth as EthProtocolMethods).getPooledTransactions({
371+
const getPooledTxs = await peer.eth!.getPooledTransactions({
373372
hashes: reqHashes.slice(0, this.TX_RETRIEVAL_LIMIT),
374373
})
375374

376-
this.config.logger.debug(`TxPool: received requested txs number=${txs.length}`)
377-
378375
// Remove from pending list regardless if tx is in result
379-
for (const reqHashStr of reqHashesStr) {
380-
this.pending = this.pending.filter((hash) => hash !== reqHashStr)
381-
}
376+
this.pending = this.pending.filter((hash) => !reqHashesStr.includes(hash))
377+
378+
if (!getPooledTxs) return
379+
const [_, txs] = getPooledTxs
380+
this.config.logger.debug(`TxPool: received requested txs number=${txs.length}`)
382381

383382
const newTxHashes = []
384383
for (const tx of txs) {

packages/client/test/rpc/helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ const level = require('level-mem')
2222
const config: any = {}
2323
config.logger = getLogger(config)
2424

25+
type StartRPCOpts = { port?: number; wsServer?: boolean }
2526
type WithEngineMiddleware = { jwtSecret: Buffer; unlessFn?: (req: IncomingMessage) => boolean }
2627

2728
export function startRPC(
2829
methods: any,
29-
{ port, wsServer }: { port?: number; wsServer?: boolean } = { port: 3000 },
30+
opts: StartRPCOpts = { port: 3000 },
3031
withEngineMiddleware?: WithEngineMiddleware
3132
) {
33+
const { port, wsServer } = opts
3234
const server = new RPCServer(methods)
3335
const httpServer = wsServer
3436
? createWsRPCServerListener({ server, withEngineMiddleware })

0 commit comments

Comments
 (0)