Skip to content

Commit a7a7720

Browse files
committed
PR review: make block range root interval retrieval fail on inconsistent state
Before it only yielded that no work was needed
1 parent 112d43b commit a7a7720

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

mithril-aggregator/src/database/repository/cardano_transaction_repository.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::ops::Range;
22
use std::sync::Arc;
33

4-
use anyhow::Context;
4+
use anyhow::{anyhow, Context};
55
use async_trait::async_trait;
6-
use slog_scope::warn;
76

87
use mithril_common::crypto_helper::MKTreeNode;
98
use mithril_common::entities::{
@@ -213,13 +212,11 @@ impl TransactionStore for CardanoTransactionRepository {
213212
(_, None) => Ok(None),
214213
(None, Some(end)) => Ok(Some(0..(end + 1))),
215214
(Some(start), Some(end)) if end < start => {
216-
warn!(
217-
"Last computed block range is higher than the last transaction block number. \
218-
This should not happen. Did you forgot to prune the `block_range_root` table \
219-
after pruning the `cardano_tx` table ?";
220-
"start" => start, "end" => end
221-
);
222-
Ok(None)
215+
Err(anyhow!(
216+
"Inconsistent state: \
217+
Last block range root block number ({start}) is higher than the last transaction block number ({end}). \
218+
Did you forgot to prune obsolete `block_range_root` after a transaction rollback ?"
219+
))
223220
}
224221
(Some(start), Some(end)) => Ok(Some(start..(end + 1))),
225222
},
@@ -647,21 +644,22 @@ mod tests {
647644

648645
assert_eq!(None, interval);
649646
}
650-
// Highest transaction block number is below the last computed block range, this may happen
651-
// if the latest transactions were pruned from DB (whatever the reason for this pruned was).
647+
// Inconsistent state: Highest transaction block number is below the last computed block range
652648
{
653649
let last_transaction_block_number = last_block_range.end - 10;
654650
repository
655651
.create_transaction("tx-1", last_transaction_block_number, 50, "block-1", 99)
656652
.await
657653
.unwrap();
658654

659-
let interval = repository
655+
let res = repository
660656
.get_block_interval_without_block_range_root()
661-
.await
662-
.unwrap();
657+
.await;
663658

664-
assert_eq!(None, interval);
659+
assert!(
660+
res.is_err(),
661+
"Inconsistent state should raise an error, found:\n{res:?}"
662+
);
665663
}
666664
}
667665

mithril-signer/src/database/repository/cardano_transaction_repository.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,11 @@ impl TransactionStore for CardanoTransactionRepository {
212212
(_, None) => Ok(None),
213213
(None, Some(end)) => Ok(Some(0..(end + 1))),
214214
(Some(start), Some(end)) if end < start => {
215-
warn!(
216-
"Last computed block range is higher than the last transaction block number. \
217-
This should not happen. Did you forgot to prune the `block_range_root` table \
218-
after pruning the `cardano_tx` table ?";
219-
"start" => start, "end" => end
220-
);
221-
Ok(None)
215+
Err(anyhow!(
216+
"Inconsistent state: \
217+
Last block range root block number ({start}) is higher than the last transaction block number ({end}). \
218+
Did you forgot to prune obsolete `block_range_root` after a transaction rollback ?"
219+
))
222220
}
223221
(Some(start), Some(end)) => Ok(Some(start..(end + 1))),
224222
},
@@ -582,21 +580,22 @@ mod tests {
582580

583581
assert_eq!(None, interval);
584582
}
585-
// Highest transaction block number is below the last computed block range, this may happen
586-
// if the latest transactions were pruned from DB (whatever the reason for this pruned was).
583+
// Inconsistent state: Highest transaction block number is below the last computed block range
587584
{
588585
let last_transaction_block_number = last_block_range.end - 10;
589586
repository
590587
.create_transaction("tx-1", last_transaction_block_number, 50, "block-1", 99)
591588
.await
592589
.unwrap();
593590

594-
let interval = repository
591+
let res = repository
595592
.get_block_interval_without_block_range_root()
596-
.await
597-
.unwrap();
593+
.await;
598594

599-
assert_eq!(None, interval);
595+
assert!(
596+
res.is_err(),
597+
"Inconsistent state should raise an error, found:\n{res:?}"
598+
);
600599
}
601600
}
602601

0 commit comments

Comments
 (0)