-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
EIP-2935 Historical block hashes #9991
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
abfdbca
Add 2935 draft
somnathb1 071ec48
Update with latest eip
somnathb1 61a6d81
Temporary test fix
somnathb1 4bb2f74
Update naming
somnathb1 007b006
Optimize
somnathb1 bcab980
Rename param
somnathb1 45bc07e
Save
somnathb1 c3d8d95
Cleanup
somnathb1 d169572
Default cfg for Execute fn
somnathb1 31ac394
Fix test
somnathb1 ad60013
review comments
somnathb1 b419d41
revert defaults
somnathb1 0ecac2e
Add gas costs and fork enable
somnathb1 4349ff0
Disable Prague on pre-EIP blockhash
somnathb1 8a08671
Cleanup
somnathb1 27c7148
Update numPop for BLOCKHASH op
somnathb1 2ef0306
Gas for blockHash update
somnathb1 1e22375
Update comment
somnathb1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package misc | ||
|
||
import ( | ||
"github.com/holiman/uint256" | ||
|
||
"github.com/ledgerwatch/erigon-lib/chain" | ||
libcommon "github.com/ledgerwatch/erigon-lib/common" | ||
|
||
"github.com/ledgerwatch/erigon/consensus" | ||
"github.com/ledgerwatch/erigon/core/state" | ||
"github.com/ledgerwatch/erigon/core/types" | ||
"github.com/ledgerwatch/erigon/params" | ||
) | ||
|
||
func StoreBlockHashesEip2935(header *types.Header, state *state.IntraBlockState, config *chain.Config, headerReader consensus.ChainHeaderReader) { | ||
headerNum := header.Number.Uint64() | ||
if headerNum == 0 { // Activation of fork at Genesis | ||
return | ||
} | ||
storeHash(headerNum-1, header.ParentHash, state) | ||
// If this is the fork block, add the parent's direct `HISTORY_SERVE_WINDOW - 1` ancestors as well | ||
parent := headerReader.GetHeader(header.ParentHash, headerNum-1) | ||
if parent.Time < config.PragueTime.Uint64() { | ||
p := headerNum - 1 | ||
window := params.BlockHashHistoryServeWindow - 1 | ||
if p < window { | ||
window = p | ||
} | ||
for i := window; i > 0; i-- { | ||
p = p - 1 | ||
storeHash(p, parent.ParentHash, state) | ||
parent = headerReader.GetHeader(parent.ParentHash, p) | ||
} | ||
} | ||
} | ||
|
||
func storeHash(num uint64, hash libcommon.Hash, state *state.IntraBlockState) { | ||
slotNum := num % params.BlockHashHistoryServeWindow | ||
storageSlot := libcommon.BytesToHash(uint256.NewInt(slotNum).Bytes()) | ||
parentHashInt := uint256.NewInt(0).SetBytes32(hash.Bytes()) | ||
state.SetState(params.HistoryStorageAddress, &storageSlot, *parentHashInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably equivalent, but I find the pseudo-code in the spec easier to read. What I mean that instead of this
p < window
branch you have a early break in the loop. Something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an optimization to not have to do
big.Int
touint64()
, or anybig.Int
operation that many timesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Between optimization and clarity I'd choose clarity until profiling confirms that the performance degradation is material, but OK.