Skip to content

Commit 477ee58

Browse files
deffrians1na
andauthored
internal/ethapi: add timestamp to logs in eth_simulate (#32831)
Adds blockTimestamp to the logs in response of eth_simulateV1. --------- Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent 1e4b39e commit 477ee58

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

internal/ethapi/api_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,10 +1327,11 @@ func TestSimulateV1(t *testing.T) {
13271327
validation = true
13281328
)
13291329
type log struct {
1330-
Address common.Address `json:"address"`
1331-
Topics []common.Hash `json:"topics"`
1332-
Data hexutil.Bytes `json:"data"`
1333-
BlockNumber hexutil.Uint64 `json:"blockNumber"`
1330+
Address common.Address `json:"address"`
1331+
Topics []common.Hash `json:"topics"`
1332+
Data hexutil.Bytes `json:"data"`
1333+
BlockNumber hexutil.Uint64 `json:"blockNumber"`
1334+
BlockTimestamp hexutil.Uint64 `json:"blockTimestamp"`
13341335
// Skip txHash
13351336
//TxHash common.Hash `json:"transactionHash" gencodec:"required"`
13361337
TxIndex hexutil.Uint `json:"transactionIndex"`
@@ -1677,10 +1678,11 @@ func TestSimulateV1(t *testing.T) {
16771678
Calls: []callRes{{
16781679
ReturnValue: "0x",
16791680
Logs: []log{{
1680-
Address: randomAccounts[2].addr,
1681-
Topics: []common.Hash{common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},
1682-
BlockNumber: hexutil.Uint64(11),
1683-
Data: hexutil.Bytes{},
1681+
Address: randomAccounts[2].addr,
1682+
Topics: []common.Hash{common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},
1683+
BlockNumber: hexutil.Uint64(11),
1684+
BlockTimestamp: hexutil.Uint64(0x70),
1685+
Data: hexutil.Bytes{},
16841686
}},
16851687
GasUsed: "0x5508",
16861688
Status: "0x1",
@@ -1853,18 +1855,20 @@ func TestSimulateV1(t *testing.T) {
18531855
addressToHash(accounts[0].addr),
18541856
addressToHash(randomAccounts[0].addr),
18551857
},
1856-
Data: hexutil.Bytes(common.BigToHash(big.NewInt(50)).Bytes()),
1857-
BlockNumber: hexutil.Uint64(11),
1858+
Data: hexutil.Bytes(common.BigToHash(big.NewInt(50)).Bytes()),
1859+
BlockNumber: hexutil.Uint64(11),
1860+
BlockTimestamp: hexutil.Uint64(0x70),
18581861
}, {
18591862
Address: transferAddress,
18601863
Topics: []common.Hash{
18611864
transferTopic,
18621865
addressToHash(randomAccounts[0].addr),
18631866
addressToHash(fixedAccount.addr),
18641867
},
1865-
Data: hexutil.Bytes(common.BigToHash(big.NewInt(100)).Bytes()),
1866-
BlockNumber: hexutil.Uint64(11),
1867-
Index: hexutil.Uint(1),
1868+
Data: hexutil.Bytes(common.BigToHash(big.NewInt(100)).Bytes()),
1869+
BlockNumber: hexutil.Uint64(11),
1870+
BlockTimestamp: hexutil.Uint64(0x70),
1871+
Index: hexutil.Uint(1),
18681872
}},
18691873
Status: "0x1",
18701874
}},

internal/ethapi/logtracer.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ type tracer struct {
5353
count int
5454
traceTransfers bool
5555
blockNumber uint64
56+
blockTimestamp uint64
5657
blockHash common.Hash
5758
txHash common.Hash
5859
txIdx uint
5960
}
6061

61-
func newTracer(traceTransfers bool, blockNumber uint64, blockHash, txHash common.Hash, txIndex uint) *tracer {
62+
func newTracer(traceTransfers bool, blockNumber uint64, blockTimestamp uint64, blockHash, txHash common.Hash, txIndex uint) *tracer {
6263
return &tracer{
6364
traceTransfers: traceTransfers,
6465
blockNumber: blockNumber,
66+
blockTimestamp: blockTimestamp,
6567
blockHash: blockHash,
6668
txHash: txHash,
6769
txIdx: txIndex,
@@ -115,14 +117,15 @@ func (t *tracer) onLog(log *types.Log) {
115117

116118
func (t *tracer) captureLog(address common.Address, topics []common.Hash, data []byte) {
117119
t.logs[len(t.logs)-1] = append(t.logs[len(t.logs)-1], &types.Log{
118-
Address: address,
119-
Topics: topics,
120-
Data: data,
121-
BlockNumber: t.blockNumber,
122-
BlockHash: t.blockHash,
123-
TxHash: t.txHash,
124-
TxIndex: t.txIdx,
125-
Index: uint(t.count),
120+
Address: address,
121+
Topics: topics,
122+
Data: data,
123+
BlockNumber: t.blockNumber,
124+
BlockTimestamp: t.blockTimestamp,
125+
BlockHash: t.blockHash,
126+
TxHash: t.txHash,
127+
TxIndex: t.txIdx,
128+
Index: uint(t.count),
126129
})
127130
t.count++
128131
}

internal/ethapi/simulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
244244
callResults = make([]simCallResult, len(block.Calls))
245245
receipts = make([]*types.Receipt, len(block.Calls))
246246
// Block hash will be repaired after execution.
247-
tracer = newTracer(sim.traceTransfers, blockContext.BlockNumber.Uint64(), common.Hash{}, common.Hash{}, 0)
247+
tracer = newTracer(sim.traceTransfers, blockContext.BlockNumber.Uint64(), blockContext.Time, common.Hash{}, common.Hash{}, 0)
248248
vmConfig = &vm.Config{
249249
NoBaseFee: !sim.validate,
250250
Tracer: tracer.Hooks(),

0 commit comments

Comments
 (0)