internal/ethapi: add timestamp to logs in eth_simulate (#32831)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Adds blockTimestamp to the logs in response of eth_simulateV1.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
Nikita Mescheryakov 2025-10-06 21:19:25 +05:00 committed by GitHub
parent 1e4b39ed12
commit 477ee5873b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 23 deletions

View file

@ -1331,6 +1331,7 @@ func TestSimulateV1(t *testing.T) {
Topics []common.Hash `json:"topics"` Topics []common.Hash `json:"topics"`
Data hexutil.Bytes `json:"data"` Data hexutil.Bytes `json:"data"`
BlockNumber hexutil.Uint64 `json:"blockNumber"` BlockNumber hexutil.Uint64 `json:"blockNumber"`
BlockTimestamp hexutil.Uint64 `json:"blockTimestamp"`
// Skip txHash // Skip txHash
//TxHash common.Hash `json:"transactionHash" gencodec:"required"` //TxHash common.Hash `json:"transactionHash" gencodec:"required"`
TxIndex hexutil.Uint `json:"transactionIndex"` TxIndex hexutil.Uint `json:"transactionIndex"`
@ -1680,6 +1681,7 @@ func TestSimulateV1(t *testing.T) {
Address: randomAccounts[2].addr, Address: randomAccounts[2].addr,
Topics: []common.Hash{common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")}, Topics: []common.Hash{common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},
BlockNumber: hexutil.Uint64(11), BlockNumber: hexutil.Uint64(11),
BlockTimestamp: hexutil.Uint64(0x70),
Data: hexutil.Bytes{}, Data: hexutil.Bytes{},
}}, }},
GasUsed: "0x5508", GasUsed: "0x5508",
@ -1855,6 +1857,7 @@ func TestSimulateV1(t *testing.T) {
}, },
Data: hexutil.Bytes(common.BigToHash(big.NewInt(50)).Bytes()), Data: hexutil.Bytes(common.BigToHash(big.NewInt(50)).Bytes()),
BlockNumber: hexutil.Uint64(11), BlockNumber: hexutil.Uint64(11),
BlockTimestamp: hexutil.Uint64(0x70),
}, { }, {
Address: transferAddress, Address: transferAddress,
Topics: []common.Hash{ Topics: []common.Hash{
@ -1864,6 +1867,7 @@ func TestSimulateV1(t *testing.T) {
}, },
Data: hexutil.Bytes(common.BigToHash(big.NewInt(100)).Bytes()), Data: hexutil.Bytes(common.BigToHash(big.NewInt(100)).Bytes()),
BlockNumber: hexutil.Uint64(11), BlockNumber: hexutil.Uint64(11),
BlockTimestamp: hexutil.Uint64(0x70),
Index: hexutil.Uint(1), Index: hexutil.Uint(1),
}}, }},
Status: "0x1", Status: "0x1",

View file

@ -53,15 +53,17 @@ type tracer struct {
count int count int
traceTransfers bool traceTransfers bool
blockNumber uint64 blockNumber uint64
blockTimestamp uint64
blockHash common.Hash blockHash common.Hash
txHash common.Hash txHash common.Hash
txIdx uint txIdx uint
} }
func newTracer(traceTransfers bool, blockNumber uint64, blockHash, txHash common.Hash, txIndex uint) *tracer { func newTracer(traceTransfers bool, blockNumber uint64, blockTimestamp uint64, blockHash, txHash common.Hash, txIndex uint) *tracer {
return &tracer{ return &tracer{
traceTransfers: traceTransfers, traceTransfers: traceTransfers,
blockNumber: blockNumber, blockNumber: blockNumber,
blockTimestamp: blockTimestamp,
blockHash: blockHash, blockHash: blockHash,
txHash: txHash, txHash: txHash,
txIdx: txIndex, txIdx: txIndex,
@ -119,6 +121,7 @@ func (t *tracer) captureLog(address common.Address, topics []common.Hash, data [
Topics: topics, Topics: topics,
Data: data, Data: data,
BlockNumber: t.blockNumber, BlockNumber: t.blockNumber,
BlockTimestamp: t.blockTimestamp,
BlockHash: t.blockHash, BlockHash: t.blockHash,
TxHash: t.txHash, TxHash: t.txHash,
TxIndex: t.txIdx, TxIndex: t.txIdx,

View file

@ -244,7 +244,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
callResults = make([]simCallResult, len(block.Calls)) callResults = make([]simCallResult, len(block.Calls))
receipts = make([]*types.Receipt, len(block.Calls)) receipts = make([]*types.Receipt, len(block.Calls))
// Block hash will be repaired after execution. // Block hash will be repaired after execution.
tracer = newTracer(sim.traceTransfers, blockContext.BlockNumber.Uint64(), common.Hash{}, common.Hash{}, 0) tracer = newTracer(sim.traceTransfers, blockContext.BlockNumber.Uint64(), blockContext.Time, common.Hash{}, common.Hash{}, 0)
vmConfig = &vm.Config{ vmConfig = &vm.Config{
NoBaseFee: !sim.validate, NoBaseFee: !sim.validate,
Tracer: tracer.Hooks(), Tracer: tracer.Hooks(),