Skip to content

Commit

Permalink
engine/fcu: throw error instead of return invalid in safe block hash …
Browse files Browse the repository at this point in the history
…validation
  • Loading branch information
cbrzn committed Mar 21, 2022
1 parent 7053af7 commit e2c8f7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
8 changes: 3 additions & 5 deletions packages/client/lib/rpc/modules/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,10 @@ export class Engine {
try {
await this.chain.getBlock(toBuffer(safeBlockHash))
} catch (error) {
const payloadStatus = {
status: Status.INVALID,
latestValidHash: null,
validationError: 'Safe head not available',
throw {
code: INVALID_PARAMS,
message: 'safe block hash not available',
}
return { payloadStatus, payloadId: null }
}
}

Expand Down
38 changes: 33 additions & 5 deletions packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,44 @@ tape(`${method}: call with deep parent lookup`, async (t) => {
await baseRequest(t, server, req, 200, expectRes)
})

tape(`${method}: invalid safe block hash`, async (t) => {
tape(`${method}: call with deep parent lookup and with stored safe block hash`, async (t) => {
const { server } = await setupChain(genesisJSON, 'post-merge', { engine: true })

let req = params(method, [validForkChoiceState])
let expectRes = (res: any) => {
t.equal(res.body.result.payloadStatus.status, 'VALID')
}
await baseRequest(t, server, req, 200, expectRes, false)

for (let i = 0; i < 3; i++) {
const req = params('engine_newPayloadV1', [blocks[i]])
const expectRes = (res: any) => {
t.equal(res.body.result.status, 'VALID')
}
await baseRequest(t, server, req, 200, expectRes, false)
}

req = params(method, [
{
...validForkChoiceState,
headBlockHash: blocks[2].blockHash,
safeBlockHash: blocks[0].blockHash,
},
])
expectRes = (res: any) => {
t.equal(res.body.result.payloadStatus.status, 'VALID')
}
await baseRequest(t, server, req, 200, expectRes)
})

tape.only(`${method}: invalid safe block hash`, async (t) => {
const { server } = await setupChain(genesisJSON, 'post-merge', { engine: true })
const req = params(method, [
{
...validForkChoiceState,
safeBlockHash: '0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4b',
},
])
const expectRes = (res: any) => {
t.equal(res.body.result.payloadStatus.status, 'INVALID')
}
await baseRequest(t, server, req, 200, expectRes, false)
const expectRes = checkError(t, INVALID_PARAMS, 'safe block hash not available')
await baseRequest(t, server, req, 200, expectRes)
})

0 comments on commit e2c8f7e

Please sign in to comment.