Skip to content

Commit 878bb44

Browse files
committed
fix missing ancestor ts
1 parent 487c1a1 commit 878bb44

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/chain/store/index.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ impl<DB: Blockstore> ChainIndex<DB> {
120120

121121
/// Find tipset at epoch `to` in the chain of ancestors starting at `from`.
122122
///
123-
/// Returns [`None`] when the chain walk from `from` does not contain a
124-
/// matching epoch (including when parent links are missing in the store).
125-
/// Returns an error if `to` is greater than `from.epoch()`, or for
126-
/// blockstore/genesis failures.
123+
/// On success, returns [`Some`] tipset wrapped in [`Ok`]. Returns an error if `to`
124+
/// is greater than `from.epoch()`, if the walk completes without resolving `to`
125+
/// (including when ancestor tipsets are missing), or for blockstore/genesis failures.
127126
///
128127
/// # Why pass in the `from` argument?
129128
///
@@ -228,7 +227,9 @@ impl<DB: Blockstore> ChainIndex<DB> {
228227
}
229228
}
230229
}
231-
Ok(None)
230+
Err(Error::Other(format!(
231+
"Tipset with epoch={to} does not exist"
232+
)))
232233
}
233234

234235
/// Finds the latest beacon entry given a tipset up to 20 tipsets behind
@@ -358,7 +359,7 @@ mod tests {
358359
}
359360

360361
#[test]
361-
fn tipset_by_height_not_on_chain_returns_none() {
362+
fn tipset_by_height_broken_ancestor_chain_returns_error() {
362363
let db = Arc::new(MemoryDB::default());
363364
let genesis = genesis_tipset();
364365
// Epoch 3 header points at a parent key we never persist — `Tipset::chain` stops
@@ -370,9 +371,8 @@ mod tests {
370371
let index = ChainIndex::new(db);
371372
assert!(
372373
index
373-
.tipset_by_height(2, epoch3.clone(), ResolveNullTipset::TakeOlder)
374-
.unwrap()
375-
.is_none()
374+
.tipset_by_height(2, epoch3, ResolveNullTipset::TakeOlder)
375+
.is_err()
376376
);
377377
}
378378
}

src/rpc/methods/chain.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,21 +1232,16 @@ impl ChainGetTipSetFinalityStatus {
12321232
-1
12331233
}
12341234
};
1235-
let ec_finality_epoch = (head.epoch() - ctx.chain_config().policy.chain_finality).max(0);
1236-
let finalized = if depth >= 0 {
1237-
match ctx.chain_index().tipset_by_height(
1235+
let finalized = if depth >= 0
1236+
&& let Ok(Some(ts)) = ctx.chain_index().tipset_by_height(
12381237
(head.epoch() - depth).max(0),
12391238
head.shallow_clone(),
12401239
ResolveNullTipset::TakeOlder,
1241-
)? {
1242-
Some(ts) => Some(ts),
1243-
None => ctx.chain_index().tipset_by_height(
1244-
ec_finality_epoch,
1245-
head,
1246-
ResolveNullTipset::TakeOlder,
1247-
)?,
1248-
}
1240+
) {
1241+
Some(ts)
12491242
} else {
1243+
let ec_finality_epoch =
1244+
(head.epoch() - ctx.chain_config().policy.chain_finality).max(0);
12501245
ctx.chain_index().tipset_by_height(
12511246
ec_finality_epoch,
12521247
head,

0 commit comments

Comments
 (0)