feat: fixed missing blocktimestamp in logs subscription (#16598)

This commit is contained in:
Ishika Choudhury
2025-06-03 14:33:29 +05:30
committed by GitHub
parent f2d1863485
commit 5f7fe6b9e2
4 changed files with 27 additions and 11 deletions

View File

@@ -358,6 +358,7 @@ mod tests {
block_receipts[0].0,
BlockReceipts {
block: block1.num_hash(),
timestamp: block1.timestamp,
tx_receipts: vec![(
// Transaction hash of a Transaction::default()
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),
@@ -443,6 +444,7 @@ mod tests {
block_receipts[0].0,
BlockReceipts {
block: old_block1.num_hash(),
timestamp: old_block1.timestamp,
tx_receipts: vec![(
// Transaction hash of a Transaction::default()
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),
@@ -459,6 +461,7 @@ mod tests {
block_receipts[1].0,
BlockReceipts {
block: new_block1.num_hash(),
timestamp: new_block1.timestamp,
tx_receipts: vec![(
// Transaction hash of a Transaction::default()
b256!("0x20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"),

View File

@@ -242,16 +242,25 @@ impl<N: NodePrimitives> Chain<N> {
N::SignedTx: Encodable2718,
{
let mut receipt_attach = Vec::with_capacity(self.blocks().len());
for ((block_num, block), receipts) in
self.blocks().iter().zip(self.execution_outcome.receipts().iter())
{
let mut tx_receipts = Vec::with_capacity(receipts.len());
for (tx, receipt) in block.body().transactions().iter().zip(receipts.iter()) {
tx_receipts.push((tx.trie_hash(), receipt.clone()));
}
let block_num_hash = BlockNumHash::new(*block_num, block.hash());
receipt_attach.push(BlockReceipts { block: block_num_hash, tx_receipts });
}
self.blocks_and_receipts().for_each(|(block, receipts)| {
let block_num_hash = BlockNumHash::new(block.number(), block.hash());
let tx_receipts = block
.body()
.transactions()
.iter()
.zip(receipts)
.map(|(tx, receipt)| (tx.trie_hash(), receipt.clone()))
.collect();
receipt_attach.push(BlockReceipts {
block: block_num_hash,
tx_receipts,
timestamp: block.timestamp(),
});
});
receipt_attach
}
@@ -400,6 +409,8 @@ pub struct BlockReceipts<T = reth_ethereum_primitives::Receipt> {
pub block: BlockNumHash,
/// Transaction identifier and receipt.
pub tx_receipts: Vec<(TxHash, T)>,
/// Block timestamp
pub timestamp: u64,
}
/// Bincode-compatible [`Chain`] serde implementation.

View File

@@ -16,6 +16,7 @@ use std::sync::Arc;
pub fn matching_block_logs_with_tx_hashes<'a, I, R>(
filter: &Filter,
block_num_hash: BlockNumHash,
block_timestamp: u64,
tx_hashes_and_receipts: I,
removed: bool,
) -> Vec<Log>
@@ -44,7 +45,7 @@ where
transaction_index: Some(receipt_idx as u64),
log_index: Some(log_index),
removed,
block_timestamp: None,
block_timestamp: Some(block_timestamp),
};
all_logs.push(log);
}

View File

@@ -333,6 +333,7 @@ where
let all_logs = logs_utils::matching_block_logs_with_tx_hashes(
&filter,
block_receipts.block,
block_receipts.timestamp,
block_receipts.tx_receipts.iter().map(|(tx, receipt)| (*tx, receipt)),
removed,
);