mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
core: add BlockGen.ConsensusLayerRequests
I need this to collect the requests in cmd/hivechain.
This commit is contained in:
parent
9cdbb3f2e2
commit
6af5c6247e
1 changed files with 36 additions and 19 deletions
|
|
@ -293,6 +293,41 @@ func (b *BlockGen) OffsetTime(seconds int64) {
|
||||||
b.header.Difficulty = b.engine.CalcDifficulty(b.cm, b.header.Time, b.parent.Header())
|
b.header.Difficulty = b.engine.CalcDifficulty(b.cm, b.header.Time, b.parent.Header())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsensusLayerRequests returns the EIP-7685 requests which have accumulated so far.
|
||||||
|
func (b *BlockGen) ConsensusLayerRequests() [][]byte {
|
||||||
|
return b.collectRequests(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlockGen) collectRequests(readonly bool) (requests [][]byte) {
|
||||||
|
statedb := b.statedb
|
||||||
|
if readonly {
|
||||||
|
// The system contracts clear themselves on a system-initiated read.
|
||||||
|
// When reading the requests mid-block, we don't want this behavior, so fork
|
||||||
|
// off the statedb before executing the system calls.
|
||||||
|
statedb = statedb.Copy()
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.cm.config.IsPrague(b.header.Number, b.header.Time) {
|
||||||
|
requests = [][]byte{}
|
||||||
|
// EIP-6110 deposits
|
||||||
|
var blockLogs []*types.Log
|
||||||
|
for _, r := range b.receipts {
|
||||||
|
blockLogs = append(blockLogs, r.Logs...)
|
||||||
|
}
|
||||||
|
if err := ParseDepositLogs(&requests, blockLogs, b.cm.config); err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
|
||||||
|
}
|
||||||
|
// create EVM for system calls
|
||||||
|
blockContext := NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
|
||||||
|
evm := vm.NewEVM(blockContext, statedb, b.cm.config, vm.Config{})
|
||||||
|
// EIP-7002
|
||||||
|
ProcessWithdrawalQueue(&requests, evm)
|
||||||
|
// EIP-7251
|
||||||
|
ProcessConsolidationQueue(&requests, evm)
|
||||||
|
}
|
||||||
|
return requests
|
||||||
|
}
|
||||||
|
|
||||||
// GenerateChain creates a chain of n blocks. The first block's
|
// GenerateChain creates a chain of n blocks. The first block's
|
||||||
// parent will be the provided parent. db is used to store
|
// parent will be the provided parent. db is used to store
|
||||||
// intermediate states and should contain the parent's state trie.
|
// intermediate states and should contain the parent's state trie.
|
||||||
|
|
@ -357,25 +392,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
||||||
gen(i, b)
|
gen(i, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
var requests [][]byte
|
requests := b.collectRequests(false)
|
||||||
if config.IsPrague(b.header.Number, b.header.Time) {
|
|
||||||
requests = [][]byte{}
|
|
||||||
// EIP-6110 deposits
|
|
||||||
var blockLogs []*types.Log
|
|
||||||
for _, r := range b.receipts {
|
|
||||||
blockLogs = append(blockLogs, r.Logs...)
|
|
||||||
}
|
|
||||||
if err := ParseDepositLogs(&requests, blockLogs, config); err != nil {
|
|
||||||
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
|
|
||||||
}
|
|
||||||
// create EVM for system calls
|
|
||||||
blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase)
|
|
||||||
evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{})
|
|
||||||
// EIP-7002
|
|
||||||
ProcessWithdrawalQueue(&requests, evm)
|
|
||||||
// EIP-7251
|
|
||||||
ProcessConsolidationQueue(&requests, evm)
|
|
||||||
}
|
|
||||||
if requests != nil {
|
if requests != nil {
|
||||||
reqHash := types.CalcRequestsHash(requests)
|
reqHash := types.CalcRequestsHash(requests)
|
||||||
b.header.RequestsHash = &reqHash
|
b.header.RequestsHash = &reqHash
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue