Skip to content

Commit 9b61e60

Browse files
committed
chain/ethereum: Fix POI inconsistencies in receipt handling (#6200)
1 parent b8bd318 commit 9b61e60

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use std::time::Instant;
5858
use crate::adapter::EthereumRpcError;
5959
use crate::adapter::ProviderStatus;
6060
use crate::chain::BlockFinality;
61-
use crate::trigger::LogRef;
61+
use crate::trigger::{LogPosition, LogRef};
6262
use crate::Chain;
6363
use crate::NodeCapabilities;
6464
use crate::TriggerFilter;
@@ -1978,8 +1978,24 @@ pub(crate) fn parse_log_triggers(
19781978
.transaction_receipts
19791979
.iter()
19801980
.flat_map(move |receipt| {
1981-
receipt.logs.iter().enumerate().map(move |(index, _)| {
1982-
EthereumTrigger::Log(LogRef::LogPosition(index, receipt.cheap_clone()))
1981+
receipt.logs.iter().enumerate().map(move |(index, log)| {
1982+
let requires_transaction_receipt = log
1983+
.topics
1984+
.first()
1985+
.map(|signature| {
1986+
log_filter.requires_transaction_receipt(
1987+
signature,
1988+
Some(&log.address),
1989+
&log.topics,
1990+
)
1991+
})
1992+
.unwrap_or(false);
1993+
1994+
EthereumTrigger::Log(LogRef::LogPosition(LogPosition {
1995+
index,
1996+
receipt: receipt.cheap_clone(),
1997+
requires_transaction_receipt,
1998+
}))
19831999
})
19842000
})
19852001
.collect()

chain/ethereum/src/trigger.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,43 @@ impl ToAscPtr for MappingTrigger {
222222
}
223223
}
224224

225+
#[derive(Clone, Debug)]
226+
pub struct LogPosition {
227+
pub index: usize,
228+
pub receipt: Arc<TransactionReceipt>,
229+
pub requires_transaction_receipt: bool,
230+
}
231+
225232
#[derive(Clone, Debug)]
226233
pub enum LogRef {
227234
FullLog(Arc<Log>, Option<Arc<TransactionReceipt>>),
228-
LogPosition(usize, Arc<TransactionReceipt>),
235+
LogPosition(LogPosition),
229236
}
230237

231238
impl LogRef {
232239
pub fn log(&self) -> &Log {
233240
match self {
234241
LogRef::FullLog(log, _) => log.as_ref(),
235-
LogRef::LogPosition(index, receipt) => receipt.logs.get(*index).unwrap(),
242+
LogRef::LogPosition(pos) => pos.receipt.logs.get(pos.index).unwrap(),
236243
}
237244
}
238245

246+
/// Returns the transaction receipt if it's available and required.
247+
///
248+
/// For `FullLog` variants, returns the receipt if present.
249+
/// For `LogPosition` variants, only returns the receipt if the
250+
/// `requires_transaction_receipt` flag is true, otherwise returns None
251+
/// even though the receipt is stored internally.
239252
pub fn receipt(&self) -> Option<&Arc<TransactionReceipt>> {
240253
match self {
241254
LogRef::FullLog(_, receipt) => receipt.as_ref(),
242-
LogRef::LogPosition(_, receipt) => Some(receipt),
255+
LogRef::LogPosition(pos) => {
256+
if pos.requires_transaction_receipt {
257+
Some(&pos.receipt)
258+
} else {
259+
None
260+
}
261+
}
243262
}
244263
}
245264

0 commit comments

Comments
 (0)