Skip to content

Commit ad77eee

Browse files
committed
add empty check while fetching events and small fixes
1 parent cacf0c8 commit ad77eee

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/rpc/methods/eth/filter/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ impl EthEventHandler {
285285

286286
ensure!(
287287
messages.len() == events.len(),
288-
"Length of messages and events do not match"
288+
"Length of messages ({}) and events ({}) do not match",
289+
messages.len(),
290+
events.len(),
289291
);
290292

291293
let mut event_count = 0;
@@ -374,7 +376,12 @@ impl EthEventHandler {
374376
.tipset_state_events(tipset, Some(events_root))
375377
.await?;
376378

377-
ensure!(state_events.roots.len() == state_events.events.len());
379+
ensure!(
380+
state_events.roots.len() == state_events.events.len(),
381+
"State events roots ({}) and events length ({}) mismatch ",
382+
state_events.roots.len(),
383+
state_events.events.len(),
384+
);
378385

379386
let filtered_events = state_events
380387
.roots

src/state_manager/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use tracing::{error, info, instrument, trace, warn};
9191
pub use utils::is_valid_for_sending;
9292

9393
const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize);
94-
const EVENTS_AMT_BITWIDTH: u32 = 5;
94+
pub const EVENTS_AMT_BITWIDTH: u32 = 5;
9595

9696
/// Intermediary for retrieving state objects and updating actor states.
9797
type CidPair = (Cid, Cid);
@@ -567,18 +567,19 @@ where
567567
key,
568568
Box::new(move || {
569569
Box::pin(async move {
570-
// If the events are not in the cache, try to load them from the blockstore
571-
if let Some(events_root) = events_root
572-
&& let Ok(stamped_events) =
573-
StampedEvent::get_events(this.blockstore(), &events_root)
570+
// Try to load events directly from the blockstore
571+
if let Some(stamped_events) = events_root
572+
.as_ref()
573+
.and_then(|root| StampedEvent::get_events(this.blockstore(), root).ok())
574+
.filter(|events| !events.is_empty())
574575
{
575576
return Ok(StateEvents {
576577
events: vec![stamped_events],
577-
roots: vec![Some(events_root)],
578+
roots: vec![events_root],
578579
});
579580
}
580581

581-
// If the events are neither in the cache nor in the blockstore, compute them.
582+
// Fallback: compute the tipset state if events not found in the blockstore
582583
let state_out = this
583584
.compute_tipset_state(ts, NO_CALLBACK, VMTrace::NotTraced)
584585
.await?;

0 commit comments

Comments
 (0)