Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block: fix the block body parsing as well as save/load from blockchain #3392

Merged
merged 5 commits into from
May 3, 2024

Conversation

g11tech
Copy link
Contributor

@g11tech g11tech commented May 3, 2024

fixes the block body parsing and removes the body save optimization making the body load simple enough

tested kaustinen6 network and confimed working (so in general all post merge networks) as well as mainnet pow first few thousand blocks

@@ -43,14 +43,7 @@ function DBSetBlockOrHeader(blockBody: Block | BlockHeader): DBOp[] {

const isGenesis = header.number === BIGINT_0

if (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the optimization of not saving the body when there aren't non zero fields is not worth it compared to the body load complexity where we would push empty [] to resconstruct the body

@@ -107,40 +104,6 @@ export class DBManager {
if (hash === undefined || number === undefined) return undefined
const header = await this.getHeader(hash, number)
const body = await this.getBody(hash, number)
if (body[0].length === 0 && body[1].length === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this reconstruction now because we now just simply write the body array as is

@@ -217,10 +220,22 @@ export class Block {

// First try to load header so that we can use its common (in case of setHardfork being activated)
// to correctly make checks on the hardforks
const [headerData, txsData, uhsData, withdrawalBytes, requestBytes, executionWitnessBytes] =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't do a simple assignment because this sequence is dependent on the eip activation

@@ -375,8 +375,8 @@ export class Blockchain implements BlockchainInterface {
async getCanonicalHeadHeader(): Promise<BlockHeader> {
return this.runWithLock<BlockHeader>(async () => {
if (!this._headHeaderHash) throw new Error('No head header set')
const block = await this.getBlock(this._headHeaderHash)
return block.header
const header = await this._getHeader(this._headHeaderHash)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

various fixes in this class to not refer block for header based functionality

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holgerd77 holgerd77 merged commit 63a530f into master May 3, 2024
33 of 34 checks passed
@holgerd77 holgerd77 deleted the fix-blockchain-body branch May 3, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants