Skip to content

Commit d91771b

Browse files
committed
Fix ChainGetEvents RPC method
1 parent 4111c81 commit d91771b

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/daemon/db_util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,11 @@ where
326326
.compute_tipset_state(Arc::new(ts), NO_CALLBACK, VMTrace::NotTraced)
327327
.await?;
328328
for events_root in state_output.events_roots.iter() {
329-
println!("Indexing events root @{}: {}", epoch, events_root);
329+
if let Some(cid) = events_root {
330+
println!("Indexing events root @{}: {}", epoch, cid);
330331

331-
state_manager.chain_store().put_index(events_root, &tsk)?;
332+
state_manager.chain_store().put_index(cid, &tsk)?;
333+
}
332334
}
333335
}
334336

src/interpreter/vm.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type ForestExecutorV4<DB> = DefaultExecutor_v4<ForestKernelV4<DB>>;
7777
pub type ApplyResult = anyhow::Result<(ApplyRet, Duration)>;
7878

7979
pub type ApplyBlockResult =
80-
anyhow::Result<(Vec<Receipt>, Vec<Vec<StampedEvent>>, Vec<Cid>), anyhow::Error>;
80+
anyhow::Result<(Vec<Receipt>, Vec<Vec<StampedEvent>>, Vec<Option<Cid>>), anyhow::Error>;
8181

8282
/// Comes from <https://github.com/filecoin-project/lotus/blob/v1.23.2/chain/vm/fvm.go#L473>
8383
pub const IMPLICIT_MESSAGE_GAS_LIMIT: i64 = i64::MAX / 2;
@@ -357,7 +357,7 @@ where
357357
) -> ApplyBlockResult {
358358
let mut receipts = Vec::new();
359359
let mut events = Vec::new();
360-
let mut events_roots = Vec::new();
360+
let mut events_roots: Vec<Option<Cid>> = Vec::new();
361361
let mut processed = HashSet::default();
362362

363363
for block in messages.iter() {
@@ -388,12 +388,8 @@ where
388388
let msg_receipt = ret.msg_receipt();
389389
receipts.push(msg_receipt.clone());
390390

391-
if let Some(events_root) = ret.msg_receipt().events_root() {
392-
events_roots.push(events_root);
393-
events.push(ret.events());
394-
} else {
395-
events.push(ret.events());
396-
}
391+
events_roots.push(ret.msg_receipt().events_root());
392+
events.push(ret.events());
397393

398394
// Add processed Cid to set of processed messages
399395
processed.insert(cid);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,13 @@ impl EthEventHandler {
374374
.tipset_state_events(tipset, Some(events_root))
375375
.await?;
376376

377+
ensure!(state_events.roots.len() == state_events.events.len());
378+
377379
let filtered_events = state_events
378380
.roots
379381
.into_iter()
380382
.zip(state_events.events)
381-
.filter(|(cid, _)| cid == events_root)
383+
.filter(|(cid, _)| cid.as_ref() == Some(&events_root))
382384
.map(|(_, v)| v);
383385

384386
let mut chain_events = vec![];

src/state_manager/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct StateOutput {
9292
pub state_root: Cid,
9393
pub receipt_root: Cid,
9494
pub events: Vec<Vec<StampedEvent>>,
95-
pub events_roots: Vec<Cid>,
95+
pub events_roots: Vec<Option<Cid>>,
9696
}
9797

9898
#[derive(Clone)]
@@ -124,7 +124,7 @@ impl From<StateOutput> for StateOutputValue {
124124
#[derive(Clone)]
125125
pub struct StateEvents {
126126
pub events: Vec<Vec<StampedEvent>>,
127-
pub roots: Vec<Cid>,
127+
pub roots: Vec<Option<Cid>>,
128128
}
129129

130130
// Various structures for implementing the tipset state cache
@@ -530,9 +530,11 @@ where
530530
.compute_tipset_state(Arc::clone(tipset), NO_CALLBACK, VMTrace::NotTraced)
531531
.await?;
532532
for events_root in state_output.events_roots.iter() {
533-
trace!("Indexing events root @{}: {}", tipset.epoch(), events_root);
533+
if let Some(cid) = events_root {
534+
trace!("Indexing events root @{}: {}", tipset.epoch(), cid);
534535

535-
self.chain_store().put_index(events_root, key)?;
536+
self.chain_store().put_index(cid, key)?;
537+
}
536538
}
537539
let ts_state = state_output.into();
538540
trace!("Completed tipset state calculation {:?}", tipset.cids());

src/tool/subcommands/index_cmd.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ impl IndexCommands {
9797
.compute_tipset_state(Arc::new(ts), NO_CALLBACK, VMTrace::NotTraced)
9898
.await?;
9999
for events_root in state_output.events_roots.iter() {
100-
println!("Indexing events root @{}: {}", epoch, events_root);
100+
if let Some(cid) = events_root {
101+
println!("Indexing events root @{}: {}", epoch, cid);
101102

102-
chain_store.put_index(events_root, &tsk)?;
103+
chain_store.put_index(cid, &tsk)?;
104+
}
103105
}
104106
}
105107

0 commit comments

Comments
 (0)