mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Updated code and new test
Noticed that the parent hash was not being set. The way we do getHash relies on the parentHash to be cached correctly, so setting the parentHash after doing makeHeader fixes the issue.
This commit is contained in:
parent
0553f3ba86
commit
fe3bfc2f45
2 changed files with 33 additions and 7 deletions
|
|
@ -953,15 +953,19 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
|
|||
}
|
||||
defer release()
|
||||
|
||||
// Apply block override to header to ensure GetHashFn works correctly with
|
||||
// blocks in the future (#32175).
|
||||
h := block.Header()
|
||||
if config != nil {
|
||||
h = config.BlockOverrides.MakeHeader(h)
|
||||
h := *block.Header()
|
||||
|
||||
if config != nil && config.BlockOverrides != nil {
|
||||
h = *config.BlockOverrides.MakeHeader(block.Header())
|
||||
if h.Number.Uint64() == block.NumberU64()+1 {
|
||||
h.ParentHash = block.Hash()
|
||||
} else if h.Number.Uint64() > block.NumberU64()+1 {
|
||||
h.ParentHash = common.Hash{}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply block overrides to block context, if applicable.
|
||||
vmctx := core.NewEVMBlockContext(h, api.chainContext(ctx), nil)
|
||||
vmctx := core.NewEVMBlockContext(&h, api.chainContext(ctx), nil)
|
||||
// Apply the customization rules if required.
|
||||
if config != nil {
|
||||
if overrideErr := config.BlockOverrides.Apply(&vmctx); overrideErr != nil {
|
||||
return nil, overrideErr
|
||||
|
|
|
|||
|
|
@ -689,6 +689,9 @@ func TestTracingWithOverrides(t *testing.T) {
|
|||
Failed bool
|
||||
ReturnValue string
|
||||
}
|
||||
overrideBlockNumber := genBlocks + 1
|
||||
parentHash := backend.chain.GetHeaderByNumber(uint64(genBlocks)).Hash().Hex()[2:]
|
||||
expectParent := fmt.Sprintf("0x%064s", parentHash)
|
||||
|
||||
var testSuite = []struct {
|
||||
blockNumber rpc.BlockNumber
|
||||
|
|
@ -789,6 +792,25 @@ func TestTracingWithOverrides(t *testing.T) {
|
|||
},
|
||||
want: `{"gas":72666,"failed":false,"returnValue":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}`,
|
||||
},
|
||||
{ // Override blocknumber, and query a blockhash
|
||||
blockNumber: rpc.LatestBlockNumber,
|
||||
call: ethapi.TransactionArgs{
|
||||
From: &accounts[0].addr,
|
||||
Input: newRPCBytes([]byte{
|
||||
byte(vm.PUSH1), byte(genBlocks),
|
||||
byte(vm.BLOCKHASH),
|
||||
byte(vm.PUSH1), 0x00,
|
||||
byte(vm.MSTORE),
|
||||
byte(vm.PUSH1), 0x20,
|
||||
byte(vm.PUSH1), 0x00,
|
||||
byte(vm.RETURN),
|
||||
}), // blocknumber
|
||||
},
|
||||
config: &TraceCallConfig{
|
||||
BlockOverrides: &override.BlockOverrides{Number: (*hexutil.Big)(big.NewInt(int64(overrideBlockNumber)))},
|
||||
},
|
||||
want: fmt.Sprintf(`{"gas":59590,"failed":false,"returnValue":"%s"}`, expectParent),
|
||||
},
|
||||
/*
|
||||
pragma solidity =0.8.12;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue