Skip to content

Commit 5f7fe6b

Browse files
authored
feat: fixed missing blocktimestamp in logs subscription (#16598)
1 parent f2d1863 commit 5f7fe6b

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

crates/chain-state/src/notifications.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ mod tests {
358358
block_receipts[0].0,
359359
BlockReceipts {
360360
block: block1.num_hash(),
361+
timestamp: block1.timestamp,
361362
tx_receipts: vec![(
362363
// Transaction hash of a Transaction::default()
363364
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),
@@ -443,6 +444,7 @@ mod tests {
443444
block_receipts[0].0,
444445
BlockReceipts {
445446
block: old_block1.num_hash(),
447+
timestamp: old_block1.timestamp,
446448
tx_receipts: vec![(
447449
// Transaction hash of a Transaction::default()
448450
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),
@@ -459,6 +461,7 @@ mod tests {
459461
block_receipts[1].0,
460462
BlockReceipts {
461463
block: new_block1.num_hash(),
464+
timestamp: new_block1.timestamp,
462465
tx_receipts: vec![(
463466
// Transaction hash of a Transaction::default()
464467
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),

crates/evm/execution-types/src/chain.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,25 @@ impl<N: NodePrimitives> Chain<N> {
242242
N::SignedTx: Encodable2718,
243243
{
244244
let mut receipt_attach = Vec::with_capacity(self.blocks().len());
245-
for ((block_num, block), receipts) in
246-
self.blocks().iter().zip(self.execution_outcome.receipts().iter())
247-
{
248-
let mut tx_receipts = Vec::with_capacity(receipts.len());
249-
for (tx, receipt) in block.body().transactions().iter().zip(receipts.iter()) {
250-
tx_receipts.push((tx.trie_hash(), receipt.clone()));
251-
}
252-
let block_num_hash = BlockNumHash::new(*block_num, block.hash());
253-
receipt_attach.push(BlockReceipts { block: block_num_hash, tx_receipts });
254-
}
245+
246+
self.blocks_and_receipts().for_each(|(block, receipts)| {
247+
let block_num_hash = BlockNumHash::new(block.number(), block.hash());
248+
249+
let tx_receipts = block
250+
.body()
251+
.transactions()
252+
.iter()
253+
.zip(receipts)
254+
.map(|(tx, receipt)| (tx.trie_hash(), receipt.clone()))
255+
.collect();
256+
257+
receipt_attach.push(BlockReceipts {
258+
block: block_num_hash,
259+
tx_receipts,
260+
timestamp: block.timestamp(),
261+
});
262+
});
263+
255264
receipt_attach
256265
}
257266

@@ -400,6 +409,8 @@ pub struct BlockReceipts<T = reth_ethereum_primitives::Receipt> {
400409
pub block: BlockNumHash,
401410
/// Transaction identifier and receipt.
402411
pub tx_receipts: Vec<(TxHash, T)>,
412+
/// Block timestamp
413+
pub timestamp: u64,
403414
}
404415

405416
/// Bincode-compatible [`Chain`] serde implementation.

crates/rpc/rpc-eth-types/src/logs_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::sync::Arc;
1616
pub fn matching_block_logs_with_tx_hashes<'a, I, R>(
1717
filter: &Filter,
1818
block_num_hash: BlockNumHash,
19+
block_timestamp: u64,
1920
tx_hashes_and_receipts: I,
2021
removed: bool,
2122
) -> Vec<Log>
@@ -44,7 +45,7 @@ where
4445
transaction_index: Some(receipt_idx as u64),
4546
log_index: Some(log_index),
4647
removed,
47-
block_timestamp: None,
48+
block_timestamp: Some(block_timestamp),
4849
};
4950
all_logs.push(log);
5051
}

crates/rpc/rpc/src/eth/pubsub.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ where
333333
let all_logs = logs_utils::matching_block_logs_with_tx_hashes(
334334
&filter,
335335
block_receipts.block,
336+
block_receipts.timestamp,
336337
block_receipts.tx_receipts.iter().map(|(tx, receipt)| (*tx, receipt)),
337338
removed,
338339
);

0 commit comments

Comments
 (0)