mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-08 07:58:40 +00:00
Record beacon block root contract access in BAL
Signed-off-by: Miroslav Kovář <miroslavkovar@protonmail.com>
This commit is contained in:
parent
b7719e1c3d
commit
0c4f33bc6d
2 changed files with 22 additions and 16 deletions
|
|
@ -80,6 +80,11 @@ func (b *BlockGen) SetNonce(nonce types.BlockNonce) {
|
|||
b.header.Nonce = nonce
|
||||
}
|
||||
|
||||
// SetSlotNumber sets the slot number field of the generated block.
|
||||
func (b *BlockGen) SetSlotNumber(slot uint64) {
|
||||
b.header.SlotNumber = &slot
|
||||
}
|
||||
|
||||
// SetDifficulty sets the difficulty field of the generated block. This method is
|
||||
// useful for Clique tests where the difficulty does not depend on time. For the
|
||||
// ethash tests, please use OffsetTime, which implicitly recalculates the diff.
|
||||
|
|
@ -102,7 +107,11 @@ func (b *BlockGen) Difficulty() *big.Int {
|
|||
func (b *BlockGen) SetParentBeaconRoot(root common.Hash) {
|
||||
b.header.ParentBeaconRoot = &root
|
||||
blockContext := NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
|
||||
ProcessBeaconBlockRoot(root, vm.NewEVM(blockContext, b.statedb, b.cm.config, vm.Config{}))
|
||||
reads, writes := ProcessBeaconBlockRoot(root, vm.NewEVM(blockContext, b.statedb, b.cm.config, vm.Config{}))
|
||||
if b.accessList != nil {
|
||||
b.accessList.AddBlockInitMutations(writes)
|
||||
b.accessList.AddAccesses(reads)
|
||||
}
|
||||
}
|
||||
|
||||
// addTx adds a transaction to the generated block. If no coinbase has
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ func TestGenerateBALChain(t *testing.T) {
|
|||
// TODO: I think we can remove SetBeaconRoot entirely
|
||||
// and provide a different mechanism to set it?
|
||||
|
||||
// gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
|
||||
gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
|
||||
|
||||
if gspec.Config.IsAmsterdam(gen.header.Number, gen.header.Time) {
|
||||
// TODO: parameterize the slot num
|
||||
|
|
@ -333,20 +333,17 @@ func TestGenerateBALChain(t *testing.T) {
|
|||
withdrawalIndex += 1
|
||||
}
|
||||
|
||||
// TODO: can we reinstate the following?
|
||||
/*
|
||||
// Verify parent beacon root.
|
||||
want := common.Hash{byte(blocknum)}
|
||||
if got := block.BeaconRoot(); *got != want {
|
||||
t.Fatalf("block %d, wrong parent beacon root: got %s, want %s", i, got, want)
|
||||
}
|
||||
state, _ := blockchain.State()
|
||||
idx := block.Time()%8191 + 8191
|
||||
got := state.GetState(params.BeaconRootsAddress, common.BigToHash(new(big.Int).SetUint64(idx)))
|
||||
if got != want {
|
||||
t.Fatalf("block %d, wrong parent beacon root in state: got %s, want %s", i, got, want)
|
||||
}
|
||||
*/
|
||||
// Verify parent beacon root.
|
||||
want := common.Hash{byte(blocknum)}
|
||||
if got := block.BeaconRoot(); *got != want {
|
||||
t.Fatalf("block %d, wrong parent beacon root: got %s, want %s", i, got, want)
|
||||
}
|
||||
state, _ := blockchain.State()
|
||||
idx := block.Time()%8191 + 8191
|
||||
got := state.GetState(params.BeaconRootsAddress, common.BigToHash(new(big.Int).SetUint64(idx)))
|
||||
if got != want {
|
||||
t.Fatalf("block %d, wrong parent beacon root in state: got %s, want %s", i, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue