mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
Update to devnet-1 spec
This commit is contained in:
parent
20f1d2ceed
commit
83ceaacf2e
6 changed files with 24 additions and 68 deletions
|
|
@ -197,16 +197,12 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
||||||
core.ProcessBeaconBlockRoot(*beaconRoot, evm, statedb)
|
core.ProcessBeaconBlockRoot(*beaconRoot, evm, statedb)
|
||||||
}
|
}
|
||||||
if pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp) {
|
if pre.Env.BlockHashes != nil && chainConfig.IsPrague(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp) {
|
||||||
// insert all parent hashes in the contract
|
var (
|
||||||
for i, h := range pre.Env.BlockHashes {
|
prevNumber = pre.Env.Number - 1
|
||||||
n := uint64(i)
|
prevHash = pre.Env.BlockHashes[math.HexOrDecimal64(prevNumber)]
|
||||||
if n >= pre.Env.Number || pre.Env.Number > (n+params.HistoryServeWindow) {
|
)
|
||||||
continue
|
core.ProcessParentBlockHash(statedb, prevHash, prevNumber)
|
||||||
}
|
}
|
||||||
core.ProcessParentBlockHash(statedb, n, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; txIt.Next(); i++ {
|
for i := 0; txIt.Next(); i++ {
|
||||||
tx, err := txIt.Tx()
|
tx, err := txIt.Tx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||||
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
|
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
|
||||||
}
|
}
|
||||||
if p.config.IsPrague(block.Number(), block.Time()) {
|
if p.config.IsPrague(block.Number(), block.Time()) {
|
||||||
ProcessBlockHashHistory(statedb, block.Header(), p.config, p.bc)
|
// This should not underflow as genesis block is not processed.
|
||||||
|
ProcessParentBlockHash(statedb, block.ParentHash(), block.NumberU64()-1)
|
||||||
}
|
}
|
||||||
// Iterate over and process the individual transactions
|
// Iterate over and process the individual transactions
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
|
|
@ -214,34 +215,9 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
|
||||||
statedb.Finalise(true)
|
statedb.Finalise(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessBlockHashHistory is called at every block to insert the parent block hash
|
|
||||||
// in the history storage contract as per EIP-2935. At the EIP-2935 fork block, it
|
|
||||||
// populates the whole buffer with block hashes.
|
|
||||||
func ProcessBlockHashHistory(statedb *state.StateDB, header *types.Header, chainConfig *params.ChainConfig, chain consensus.ChainHeaderReader) {
|
|
||||||
var (
|
|
||||||
prevHash = header.ParentHash
|
|
||||||
parent = chain.GetHeaderByHash(prevHash)
|
|
||||||
number = header.Number.Uint64()
|
|
||||||
prevNumber = parent.Number.Uint64()
|
|
||||||
)
|
|
||||||
ProcessParentBlockHash(statedb, prevNumber, prevHash)
|
|
||||||
// History already inserted.
|
|
||||||
if chainConfig.IsPrague(parent.Number, parent.Time) || prevNumber == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var low uint64
|
|
||||||
if number > params.HistoryServeWindow {
|
|
||||||
low = number - params.HistoryServeWindow
|
|
||||||
}
|
|
||||||
for i := prevNumber; i > low; i-- {
|
|
||||||
ProcessParentBlockHash(statedb, i-1, parent.ParentHash)
|
|
||||||
parent = chain.GetHeader(parent.ParentHash, i-1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessParentBlockHash stores the parent block hash in the history storage contract
|
// ProcessParentBlockHash stores the parent block hash in the history storage contract
|
||||||
// as per EIP-2935.
|
// as per EIP-2935.
|
||||||
func ProcessParentBlockHash(statedb *state.StateDB, prevNumber uint64, prevHash common.Hash) {
|
func ProcessParentBlockHash(statedb *state.StateDB, prevHash common.Hash, prevNumber uint64) {
|
||||||
ringIndex := prevNumber % params.HistoryServeWindow
|
ringIndex := prevNumber % params.HistoryServeWindow
|
||||||
var key common.Hash
|
var key common.Hash
|
||||||
binary.BigEndian.PutUint64(key[24:], ringIndex)
|
binary.BigEndian.PutUint64(key[24:], ringIndex)
|
||||||
|
|
|
||||||
|
|
@ -552,21 +552,18 @@ func (m *MockChain) GetHeader(hash common.Hash, number uint64) *types.Header {
|
||||||
return m.chain[hash]
|
return m.chain[hash]
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessBlockHashHistory(t *testing.T) {
|
func TestProcessParentBlockHash(t *testing.T) {
|
||||||
hashA := common.Hash{0x01}
|
var (
|
||||||
hashB := common.Hash{0x02}
|
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewDatabase(memorydb.New())), nil)
|
||||||
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewDatabase(memorydb.New())), nil)
|
hashA = common.Hash{0x01}
|
||||||
header := &types.Header{ParentHash: hashA, Number: big.NewInt(2)}
|
hashB = common.Hash{0x02}
|
||||||
parent := &types.Header{ParentHash: hashB, Number: big.NewInt(1)}
|
header = &types.Header{ParentHash: hashA, Number: big.NewInt(2)}
|
||||||
parentParent := &types.Header{ParentHash: common.Hash{}, Number: big.NewInt(0)}
|
parent = &types.Header{ParentHash: hashB, Number: big.NewInt(1)}
|
||||||
chainConfig := params.AllDevChainProtocolChanges
|
genesis = &types.Header{ParentHash: common.Hash{}, Number: big.NewInt(0)}
|
||||||
chainConfig.PragueTime = nil
|
)
|
||||||
chain := new(MockChain)
|
|
||||||
chain.chain = make(map[common.Hash]*types.Header)
|
|
||||||
chain.chain[hashA] = parent
|
|
||||||
chain.chain[hashB] = parentParent
|
|
||||||
|
|
||||||
ProcessBlockHashHistory(statedb, header, chainConfig, chain)
|
ProcessParentBlockHash(statedb, header.ParentHash, parent.Number.Uint64())
|
||||||
|
ProcessParentBlockHash(statedb, parent.ParentHash, genesis.Number.Uint64())
|
||||||
|
|
||||||
// make sure that the state is correct
|
// make sure that the state is correct
|
||||||
if have := getParentBlockHash(statedb, 1); have != hashA {
|
if have := getParentBlockHash(statedb, 1); have != hashA {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -435,27 +434,15 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
|
||||||
num.Clear()
|
num.Clear()
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
historySize := uint64(256)
|
|
||||||
isPrague := interpreter.evm.ChainConfig().IsPrague(interpreter.evm.Context.BlockNumber, interpreter.evm.Context.Time)
|
|
||||||
// EIP-2935 extends the observable history window.
|
|
||||||
if isPrague {
|
|
||||||
historySize = params.HistoryServeWindow
|
|
||||||
}
|
|
||||||
var upper, lower uint64
|
var upper, lower uint64
|
||||||
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
||||||
if upper < historySize+1 {
|
if upper < 257 {
|
||||||
lower = 0
|
lower = 0
|
||||||
} else {
|
} else {
|
||||||
lower = upper - historySize
|
lower = upper - 256
|
||||||
}
|
}
|
||||||
if num64 >= lower && num64 < upper {
|
if num64 >= lower && num64 < upper {
|
||||||
if isPrague {
|
|
||||||
var key common.Hash
|
|
||||||
binary.BigEndian.PutUint64(key[24:], num64 % params.HistoryServeWindow)
|
|
||||||
num.SetBytes(interpreter.evm.StateDB.GetState(params.HistoryStorageAddress, key).Bytes())
|
|
||||||
} else {
|
|
||||||
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
|
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
num.Clear()
|
num.Clear()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error)
|
||||||
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
|
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
|
||||||
}
|
}
|
||||||
if miner.chainConfig.IsPrague(header.Number, header.Time) {
|
if miner.chainConfig.IsPrague(header.Number, header.Time) {
|
||||||
core.ProcessBlockHashHistory(env.state, header, miner.chainConfig, miner.chain)
|
core.ProcessParentBlockHash(env.state, header.ParentHash, header.Number.Uint64()-1)
|
||||||
}
|
}
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit fa51c5c164f79140730ccb8fe26a46c3d3994338
|
Subproject commit faf33b471465d3c6cdc3d04fbd690895f78d33f2
|
||||||
Loading…
Reference in a new issue