Skip to content

Commit

Permalink
client/engine: delete invalid skeleton blocks (#2584)
Browse files Browse the repository at this point in the history
Co-authored-by: acolytec3 <[email protected]>
  • Loading branch information
jochem-brouwer and acolytec3 authored Mar 14, 2023
1 parent 9c957b7 commit f0f0cc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/client/lib/rpc/modules/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,10 @@ export class Engine {

blocks.push(block)

let lastBlock: Block
try {
for (const [i, block] of blocks.entries()) {
lastBlock = block
const root = (i > 0 ? blocks[i - 1] : await this.chain.getBlock(block.header.parentHash))
.header.stateRoot
await this.execution.runWithoutSetHead({
Expand All @@ -605,6 +607,14 @@ export class Engine {
this.config.logger.error(validationError)
const latestValidHash = await validHash(block.header.parentHash, this.chain)
const response = { status: Status.INVALID, latestValidHash, validationError }
try {
await this.chain.blockchain.delBlock(lastBlock!.hash())
// eslint-disable-next-line no-empty
} catch {}
try {
await this.service.beaconSync?.skeleton.deleteBlock(lastBlock!)
// eslint-disable-next-line no-empty
} catch {}
return response
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/sync/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ export class Skeleton extends MetaDBManager {
/**
* Deletes a skeleton block from the db by number
*/
private async deleteBlock(block: Block): Promise<boolean> {
async deleteBlock(block: Block): Promise<boolean> {
try {
await this.delete(DBKey.SkeletonBlock, bigIntToBuffer(block.header.number))
await this.delete(DBKey.SkeletonBlockHashToNumber, block.hash())
Expand Down

0 comments on commit f0f0cc5

Please sign in to comment.