Skip to content

Commit

Permalink
client: ensure chain head updates correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Oct 22, 2023
1 parent da48eca commit 586868b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/client/src/blockchain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,18 @@ export class Chain {
height: BIGINT_0,
}

blocks.latest = await this.getCanonicalHeadBlock()
blocks.finalized = (await this.getCanonicalFinalizedBlock()) ?? null
blocks.safe = (await this.getCanonicalSafeBlock()) ?? null
blocks.vm = await this.getCanonicalVmHead()

headers.latest = blocks.latest.header
headers.latest = await this.getCanonicalHeadHeader()
// finalized and safe are always blocks since they have to have valid execution
// before they can be saved in chain
headers.finalized = blocks.finalized?.header ?? null
headers.safe = blocks.safe?.header ?? null
headers.vm = (await this.getCanonicalVmHead()).header

This comment has been minimized.

Copy link
@gabrocheleau

gabrocheleau Oct 22, 2023

Contributor

By switching around headers and blocks assignments, we can assign headers.vm = blocks.vm.header and avoid making an extra relatively expensive asynchronous call.

This comment has been minimized.

Copy link
@jochem-brouwer

jochem-brouwer Oct 23, 2023

Author Member

Yes, exactly this was my optimization idea :) But since we have to get headers first and then blocks (otherwise we run into this problem I mentioned with tests) we cannot do this currently. Will investigate today :)


blocks.latest = await this.getCanonicalHeadBlock()
blocks.finalized = (await this.getCanonicalFinalizedBlock()) ?? null
blocks.safe = (await this.getCanonicalSafeBlock()) ?? null
blocks.vm = await this.getCanonicalVmHead()

headers.height = headers.latest.number
blocks.height = blocks.latest.header.number

Expand Down

0 comments on commit 586868b

Please sign in to comment.