Skip to content

Commit bb9edd9

Browse files
committed
update
1 parent 7030e92 commit bb9edd9

File tree

3 files changed

+103
-10
lines changed

3 files changed

+103
-10
lines changed

crates/flashblocks-rpc/src/flashblocks.rs

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ fn get_and_set_txs_and_receipts(
344344
// check if exists, if not update
345345
let existing_tx = cache.get::<OpTransactionSigned>(&transaction.tx_hash().to_string());
346346
if existing_tx.is_none() {
347-
println!(
348-
"setting transaction in cache: {:?}",
349-
transaction.tx_hash().to_string()
350-
);
351347
if let Err(e) = cache.set(&transaction.tx_hash().to_string(), &transaction, Some(10)) {
352348
error!("Failed to set transaction in cache: {}", e);
353349
continue;
@@ -382,6 +378,15 @@ fn get_and_set_txs_and_receipts(
382378
) {
383379
error!("Failed to set transaction sender in cache: {}", e);
384380
}
381+
382+
// also keep track of the block number of each transaction
383+
if let Err(e) = cache.set(
384+
&format!("tx_block_number:{}", transaction.tx_hash()),
385+
&block_number,
386+
Some(10),
387+
) {
388+
error!("Failed to set transaction sender in cache: {}", e);
389+
}
385390
}
386391
}
387392

@@ -602,6 +607,61 @@ mod tests {
602607
))
603608
.unwrap();
604609
assert_eq!(tx2_receipt.cumulative_gas_used(), 42000);
610+
611+
// verify tx_sender, tx_block_number, tx_idx
612+
let tx_sender = cache
613+
.get::<Address>(&format!(
614+
"tx_sender:{}",
615+
"0x3cbbc9a6811ac5b2a2e5780bdb67baffc04246a59f39e398be048f1b2d05460c"
616+
))
617+
.unwrap();
618+
assert_eq!(
619+
tx_sender,
620+
Address::from_str("0xb63d5fd2e6c53fe06680c47736aba771211105e4").unwrap()
621+
);
622+
623+
let tx_block_number = cache
624+
.get::<u64>(&format!(
625+
"tx_block_number:{}",
626+
"0x3cbbc9a6811ac5b2a2e5780bdb67baffc04246a59f39e398be048f1b2d05460c"
627+
))
628+
.unwrap();
629+
assert_eq!(tx_block_number, 1);
630+
631+
let tx_idx = cache
632+
.get::<u64>(&format!(
633+
"tx_idx:{}",
634+
"0x3cbbc9a6811ac5b2a2e5780bdb67baffc04246a59f39e398be048f1b2d05460c"
635+
))
636+
.unwrap();
637+
assert_eq!(tx_idx, 0);
638+
639+
let tx_sender2 = cache
640+
.get::<Address>(&format!(
641+
"tx_sender:{}",
642+
"0xa6155b295085d3b87a3c86e342fe11c3b22f9952d0d85d9d34d223b7d6a17cd8"
643+
))
644+
.unwrap();
645+
assert_eq!(
646+
tx_sender2,
647+
Address::from_str("0x6e5e56b972374e4fde8390df0033397df931a49d").unwrap()
648+
);
649+
650+
let tx_block_number2 = cache
651+
.get::<u64>(&format!(
652+
"tx_block_number:{}",
653+
"0xa6155b295085d3b87a3c86e342fe11c3b22f9952d0d85d9d34d223b7d6a17cd8"
654+
))
655+
.unwrap();
656+
assert_eq!(tx_block_number2, 1);
657+
658+
let tx_idx2 = cache
659+
.get::<u64>(&format!(
660+
"tx_idx:{}",
661+
"0xa6155b295085d3b87a3c86e342fe11c3b22f9952d0d85d9d34d223b7d6a17cd8"
662+
))
663+
.unwrap();
664+
assert_eq!(tx_idx2, 1);
605665
}
606666

607667
#[test]

crates/flashblocks-rpc/src/integration/integration_test.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ mod tests {
165165
.http_port(1238)
166166
.websocket_url("ws://localhost:1239");
167167

168-
framework.start("reth-flashblocks", &reth).await.unwrap();
168+
framework.start("base-reth-node", &reth).await.unwrap();
169169

170170
// Wait for some time to allow messages to be processed
171171
tokio::time::sleep(Duration::from_secs(3)).await;
@@ -224,6 +224,27 @@ mod tests {
224224
assert!(receipt.is_some());
225225
assert_eq!(receipt.unwrap().gas_used(), 24000); // 45000 - 21000
226226

227+
// check transaction by hash
228+
let tx = provider
229+
.get_transaction_by_hash(
230+
B256::from_str(
231+
"0x2be2e6f8b01b03b87ae9f0ebca8bbd420f174bef0fbcc18c7802c5378b78f548",
232+
)
233+
.unwrap(),
234+
)
235+
.await?;
236+
assert!(tx.is_some());
237+
238+
let tx = provider
239+
.get_transaction_by_hash(
240+
B256::from_str(
241+
"0xa6155b295085d3b87a3c86e342fe11c3b22f9952d0d85d9d34d223b7d6a17cd8",
242+
)
243+
.unwrap(),
244+
)
245+
.await?;
246+
assert!(tx.is_some());
247+
227248
// check balance
228249
// use curl command to get balance with pending tag, since alloy provider doesn't support pending tag
229250
let output = std::process::Command::new("curl")

crates/flashblocks-rpc/src/rpc.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<E> EthApiExt<E> {
100100
block_hash: Some(block.header.hash_slow()),
101101
block_number: Some(block.number),
102102
index: Some(idx as u64),
103-
base_fee: None,
103+
base_fee: block.base_fee_per_gas,
104104
};
105105
self.transform_tx(signed_tx_ec_recovered, tx_info)
106106
})
@@ -397,12 +397,24 @@ where
397397
.cache
398398
.get::<Address>(&format!("tx_sender:{}", tx_hash))
399399
.unwrap();
400+
let block_number = self
401+
.cache
402+
.get::<u64>(&format!("tx_block_number:{}", tx_hash))
403+
.unwrap();
404+
let block = self
405+
.cache
406+
.get::<OpBlock>(&format!("block:{:?}", block_number))
407+
.unwrap();
408+
let index = self
409+
.cache
410+
.get::<u64>(&format!("tx_idx:{}", &tx_hash.to_string()))
411+
.unwrap();
400412
let tx_info = TransactionInfo {
401413
hash: Some(tx.tx_hash()),
402-
index: None,
403-
block_hash: None,
404-
block_number: None,
405-
base_fee: None,
414+
block_hash: Some(block.header.hash_slow()),
415+
block_number: Some(block.number),
416+
index: Some(index),
417+
base_fee: block.base_fee_per_gas,
406418
};
407419
let tx = Recovered::new_unchecked(tx, sender);
408420
Ok(Some(self.transform_tx(tx, tx_info)))

0 commit comments

Comments
 (0)