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

core: change block hash history scope #411

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ func (kvm *keyValueMigrator) migrateCollectedKeyValues(tree *trie.VerkleTrie) er

func InsertBlockHashHistoryAtEip2935Fork(statedb *state.StateDB, prevNumber uint64, prevHash common.Hash, chain consensus.ChainHeaderReader) {
ancestor := chain.GetHeader(prevHash, prevNumber)
for i := prevNumber; i > 0 && i >= prevNumber-256; i-- {
for i := prevNumber; i > 0 && i >= prevNumber-params.Eip2935BlockHashHistorySize; i-- {
ProcessParentBlockHash(statedb, i, ancestor.Hash())
ancestor = chain.GetHeader(ancestor.ParentHash, ancestor.Number.Uint64()-1)
}
}

func ProcessParentBlockHash(statedb *state.StateDB, prevNumber uint64, prevHash common.Hash) {
ringIndex := prevNumber % 256
ringIndex := prevNumber % params.Eip2935BlockHashHistorySize
var key common.Hash
binary.BigEndian.PutUint64(key[24:], ringIndex)
statedb.SetState(params.HistoryStorageAddress, key, prevHash)
Expand Down
2 changes: 1 addition & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
}

func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness) common.Hash {
ringIndex := number % 256
ringIndex := number % params.Eip2935BlockHashHistorySize
var pnum common.Hash
binary.BigEndian.PutUint64(pnum[24:], ringIndex)
treeIndex, suffix := utils.GetTreeKeyStorageSlotTreeIndexes(pnum.Bytes())
Expand Down
3 changes: 3 additions & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ const (
BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs
BlobTxBlobGaspriceUpdateFraction = 2225652 // Controls the maximum rate of change for blob gas price
BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile.

// Block hash history parameters
Eip2935BlockHashHistorySize = 8192
)

// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations
Expand Down
Loading