File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
internal/mithril-persistence/src/database
provider/cardano_transaction Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change
1
+ use anyhow:: Context ;
1
2
use sqlite:: Value ;
2
3
3
4
use mithril_common:: entities:: BlockNumber ;
@@ -36,18 +37,22 @@ impl<'conn> DeleteCardanoTransactionProvider<'conn> {
36
37
Self { connection }
37
38
}
38
39
39
- fn get_prune_condition ( & self , threshold : BlockNumber ) -> WhereCondition {
40
- let threshold = Value :: Integer ( threshold. try_into ( ) . unwrap ( ) ) ;
40
+ fn get_prune_condition ( & self , threshold : BlockNumber ) -> StdResult < WhereCondition > {
41
+ let threshold = Value :: Integer (
42
+ threshold
43
+ . try_into ( )
44
+ . with_context ( || format ! ( "Failed to convert threshold `{threshold}` to i64" ) ) ?,
45
+ ) ;
41
46
42
- WhereCondition :: new ( "block_number < ?*" , vec ! [ threshold] )
47
+ Ok ( WhereCondition :: new ( "block_number < ?*" , vec ! [ threshold] ) )
43
48
}
44
49
45
50
/// Prune the cardano transaction data below the given threshold.
46
51
pub fn prune (
47
52
& self ,
48
53
threshold : BlockNumber ,
49
54
) -> StdResult < EntityCursor < CardanoTransactionRecord > > {
50
- let filters = self . get_prune_condition ( threshold) ;
55
+ let filters = self . get_prune_condition ( threshold) ? ;
51
56
52
57
self . find ( filters)
53
58
}
Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ impl CardanoTransactionRepository {
297
297
. await ?
298
298
{
299
299
let provider = DeleteCardanoTransactionProvider :: new ( & self . connection ) ;
300
- let threshold = highest_block_range_start - number_of_blocks_to_keep;
300
+ let threshold = highest_block_range_start. saturating_sub ( number_of_blocks_to_keep) ;
301
301
provider. prune ( threshold) ?. next ( ) ;
302
302
}
303
303
@@ -897,6 +897,12 @@ mod tests {
897
897
let transaction_result = repository. get_all ( ) . await . unwrap ( ) ;
898
898
assert_eq ! ( cardano_transactions. len( ) , transaction_result. len( ) ) ;
899
899
900
+ // Pruning with a number of block to keep greater than the highest block range start should
901
+ // do nothing.
902
+ repository. prune_transaction ( 10_000_000 ) . await . unwrap ( ) ;
903
+ let transaction_result = repository. get_all_transactions ( ) . await . unwrap ( ) ;
904
+ assert_eq ! ( cardano_transactions, transaction_result) ;
905
+
900
906
// Since the highest block range start is 45, pruning with 20 should remove transactions
901
907
// with a block number strictly below 25.
902
908
repository. prune_transaction ( 20 ) . await . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments