Skip to content

Commit adae367

Browse files
fjlgballet
authored andcommitted
core: fixes for Prague fork in GenerateChain (ethereum#30924)
Adding some missing functionality I noticed while updating the hivechain tool for the Prague fork: - we forgot to process the parent block hash - added `ConsensusLayerRequests` to get the requests list of the block
1 parent 6de8e02 commit adae367

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

core/chain_makers.go

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,41 @@ func (b *BlockGen) OffsetTime(seconds int64) {
293293
b.header.Difficulty = b.engine.CalcDifficulty(b.cm, b.header.Time, b.parent.Header())
294294
}
295295

296+
// ConsensusLayerRequests returns the EIP-7685 requests which have accumulated so far.
297+
func (b *BlockGen) ConsensusLayerRequests() [][]byte {
298+
return b.collectRequests(true)
299+
}
300+
301+
func (b *BlockGen) collectRequests(readonly bool) (requests [][]byte) {
302+
statedb := b.statedb
303+
if readonly {
304+
// The system contracts clear themselves on a system-initiated read.
305+
// When reading the requests mid-block, we don't want this behavior, so fork
306+
// off the statedb before executing the system calls.
307+
statedb = statedb.Copy()
308+
}
309+
310+
if b.cm.config.IsPrague(b.header.Number, b.header.Time) {
311+
requests = [][]byte{}
312+
// EIP-6110 deposits
313+
var blockLogs []*types.Log
314+
for _, r := range b.receipts {
315+
blockLogs = append(blockLogs, r.Logs...)
316+
}
317+
if err := ParseDepositLogs(&requests, blockLogs, b.cm.config); err != nil {
318+
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
319+
}
320+
// create EVM for system calls
321+
blockContext := NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
322+
evm := vm.NewEVM(blockContext, statedb, b.cm.config, vm.Config{})
323+
// EIP-7002
324+
ProcessWithdrawalQueue(&requests, evm)
325+
// EIP-7251
326+
ProcessConsolidationQueue(&requests, evm)
327+
}
328+
return requests
329+
}
330+
296331
// GenerateChain creates a chain of n blocks. The first block's
297332
// parent will be the provided parent. db is used to store
298333
// intermediate states and should contain the parent's state trie.
@@ -330,6 +365,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
330365
b.header.Difficulty = big.NewInt(0)
331366
}
332367
}
368+
333369
// Mutate the state and block according to any hard-fork specs
334370
if daoBlock := config.DAOForkBlock; daoBlock != nil {
335371
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
@@ -342,30 +378,21 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
342378
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
343379
misc.ApplyDAOHardFork(statedb)
344380
}
345-
// Execute any user modifications to the block
346-
if gen != nil {
347-
gen(i, b)
348-
}
349381

350-
var requests [][]byte
351382
if config.IsPrague(b.header.Number, b.header.Time) {
352-
requests = [][]byte{}
353-
// EIP-6110 deposits
354-
var blockLogs []*types.Log
355-
for _, r := range b.receipts {
356-
blockLogs = append(blockLogs, r.Logs...)
357-
}
358-
if err := ParseDepositLogs(&requests, blockLogs, config); err != nil {
359-
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
360-
}
361-
// create EVM for system calls
383+
// EIP-2935
362384
blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase)
385+
blockContext.Random = &common.Hash{} // enable post-merge instruction set
363386
evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{})
364-
// EIP-7002
365-
ProcessWithdrawalQueue(&requests, evm)
366-
// EIP-7251
367-
ProcessConsolidationQueue(&requests, evm)
387+
ProcessParentBlockHash(b.header.ParentHash, evm)
388+
}
389+
390+
// Execute any user modifications to the block
391+
if gen != nil {
392+
gen(i, b)
368393
}
394+
395+
requests := b.collectRequests(false)
369396
if requests != nil {
370397
reqHash := types.CalcRequestsHash(requests)
371398
b.header.RequestsHash = &reqHash

0 commit comments

Comments
 (0)