Skip to content

Commit adbdf28

Browse files
authored
Fix Filecoin.ChainGetEvents method (#5593)
1 parent 286c214 commit adbdf28

File tree

7 files changed

+12
-18
lines changed

7 files changed

+12
-18
lines changed

scripts/tests/api_compare/filter-list

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
# They should be considered bugged, and not used until the root cause is resolved.
33
# Disable until next Lotus release with go-f3 0.8.0
44
!Filecoin.F3GetManifest
5-
# CustomCheckFailed in Forest: https://github.com/ChainSafe/forest/issues/5579
6-
!Filecoin.ChainGetEvents

scripts/tests/api_compare/filter-list-offline

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,3 @@
2727
!Filecoin.EthGetBlockByNumber
2828
!eth_getBlockByNumber
2929
!Filecoin.ChainSetHead
30-
# CustomCheckFailed in Forest: https://github.com/ChainSafe/forest/issues/5579
31-
!Filecoin.ChainGetEvents

src/daemon/db_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ where
325325
let state_output = state_manager
326326
.compute_tipset_state(Arc::new(ts), NO_CALLBACK, VMTrace::NotTraced)
327327
.await?;
328-
for events_root in state_output.events_roots.iter() {
328+
for events_root in state_output.events_roots.iter().flatten() {
329329
println!("Indexing events root @{}: {}", epoch, events_root);
330330

331331
state_manager.chain_store().put_index(events_root, &tsk)?;

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: 3 additions & 3 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
@@ -529,7 +529,7 @@ where
529529
let state_output = self
530530
.compute_tipset_state(Arc::clone(tipset), NO_CALLBACK, VMTrace::NotTraced)
531531
.await?;
532-
for events_root in state_output.events_roots.iter() {
532+
for events_root in state_output.events_roots.iter().flatten() {
533533
trace!("Indexing events root @{}: {}", tipset.epoch(), events_root);
534534

535535
self.chain_store().put_index(events_root, key)?;

src/tool/subcommands/index_cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl IndexCommands {
9696
let state_output = state_manager
9797
.compute_tipset_state(Arc::new(ts), NO_CALLBACK, VMTrace::NotTraced)
9898
.await?;
99-
for events_root in state_output.events_roots.iter() {
99+
for events_root in state_output.events_roots.iter().flatten() {
100100
println!("Indexing events root @{}: {}", epoch, events_root);
101101

102102
chain_store.put_index(events_root, &tsk)?;

0 commit comments

Comments
 (0)