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

Modifications to support snap sync #152

Merged
merged 9 commits into from
Jun 25, 2024

Conversation

piersy
Copy link

@piersy piersy commented Jun 21, 2024

This PR contains a collection of additional changes that were required to support snap syncing.

They are:

  • Handling celo block receipts - celo-blockchain would add an extra block receipt to the end of the receipts in a block containing any logs generated from system calls executed in that block. So we need to handle that quirk here, in order to support handling migrated legacy data.
  • Ensuring non nil difficulty in pre-gingerbread blocks. Before the gingerbread hardfork celo blocks did not have a difficulty field. While the obvious choice to represent this is nil, the go-ethereum codebase assumes non nil difficulties, and so rather than try to catch all locations which try to access difficulty it is simpler to set a zero valued difficulty on pre gingerbread blocks.
  • Skip the downloader uncle hash check for pre-gingerbread blocks. Pre-gingerbread blocks lacked an uncleHash field (and uncles), but as the field is a non pointer hash in the op-geth structure, when decoding pre-gingerbread blocks the uncleHash is a zero valued hash. go-ethereum expects a block that lacks uncles to have a hash of the empty list which is not a zero valued hash, so in order to allow the downloader to process pre gingerbread blocks we skip this check for pre-gingerbread blocks.
  • Handle the base fee calculation for the transition block. The EIP-1559 implementation provides a method to calculate the base fee for a block based on the parent block, this is used in block construction and validation. We set the london hardfork activation block to the the "l2 genesis" and when validating the first EIP-1559 block (I.E the current block is on the london hardfork and the parent is not) the method considers the base fee to be params.InitialBaseFee which is a hardcoded value. That doesn't work in our case because we probably want to set the base fee to match that defined at the transition point which can vary, so instead we take the value of the parent block, and if that is missing fall back to the base fee.

@piersy piersy force-pushed the piersy/modifications-to-support-snap-sync branch from 5ae796d to f6b1f51 Compare June 24, 2024 10:56
piersy added 5 commits June 24, 2024 12:16
This pr adds code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.
Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof since it
upholds the assumptions of the go-ethereum codebase.
Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.
@piersy piersy force-pushed the piersy/modifications-to-support-snap-sync branch from f6b1f51 to 9795aca Compare June 24, 2024 11:16
@piersy piersy marked this pull request as ready for review June 24, 2024 11:17
@piersy piersy requested review from palango, carterqw2 and alecps June 24, 2024 11:17
internal/ethapi/celo_block_receipt.go Show resolved Hide resolved
core/types/receipt.go Show resolved Hide resolved
core/genesis.go Show resolved Hide resolved
consensus/misc/eip1559/eip1559.go Outdated Show resolved Hide resolved
@piersy piersy merged commit 0659ff9 into celo6 Jun 25, 2024
7 checks passed
@piersy piersy deleted the piersy/modifications-to-support-snap-sync branch June 25, 2024 13:16
karlb pushed a commit that referenced this pull request Jul 10, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Jul 10, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Jul 12, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Aug 20, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Aug 26, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Aug 30, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Oct 11, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
piersy added a commit that referenced this pull request Oct 15, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Dec 13, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Dec 16, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
karlb pushed a commit that referenced this pull request Dec 17, 2024
* Add code to handle block receipts

Add code to handle the extra block receipt added by celo to the
list of receipts in a block and also adds the GetBlockReceipt rpc api
which was an additional api added by celo to allow retrieveal of the
block receipt.

* Ensure non nil difficulty in pre-gingerbread blocks

Nil difficulty in headers causes problems because it is assumed by the
go-ethereum codebase that difficulty is non nil.

The specific problem requiring this fix was a NPE in
Downloader.processHeaders where the total difficulty (td) is calculated
by adding individual header difficulty values.

Rather than try to fix this specific case it seems safer to ensure
blocks have a non nil Difficulty which should help future proof our code
 since it upholds the assumptions of the go-ethereum codebase.

* Skip uncle hash check for pre gingerbread headers

Pre gingerbread headers do not have a valid uncle hash because they have
no notion of uncles.

* Handle choosing the cel2 transition block base fee

If the parent block has a base fee then we use that, otherwise we use
the initial base fee.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants