4
4
use std:: convert:: TryInto ;
5
5
6
6
use cid:: Cid ;
7
- use fil_actors_runtime:: { ActorDowncast , Array } ;
7
+ use fil_actors_runtime:: { ActorContext , ActorDowncast , ActorError , Array } ;
8
8
use fvm_ipld_amt:: Error as AmtError ;
9
9
use fvm_ipld_bitfield:: BitField ;
10
10
use fvm_ipld_blockstore:: Blockstore ;
@@ -19,12 +19,16 @@ pub struct BitFieldQueue<'db, BS> {
19
19
}
20
20
21
21
impl < ' db , BS : Blockstore > BitFieldQueue < ' db , BS > {
22
- pub fn new ( store : & ' db BS , root : & Cid , quant : QuantSpec ) -> Result < Self , AmtError > {
22
+ pub fn new ( store : & ' db BS , root : & Cid , quant : QuantSpec ) -> Result < Self , AmtError < BS :: Error > > {
23
23
Ok ( Self { amt : Array :: load ( root, store) ?, quant } )
24
24
}
25
25
26
26
/// Adds values to the queue entry for an epoch.
27
- pub fn add_to_queue ( & mut self , raw_epoch : ChainEpoch , values : & BitField ) -> anyhow:: Result < ( ) > {
27
+ pub fn add_to_queue (
28
+ & mut self ,
29
+ raw_epoch : ChainEpoch ,
30
+ values : & BitField ,
31
+ ) -> Result < ( ) , ActorError > {
28
32
if values. is_empty ( ) {
29
33
// nothing to do.
30
34
return Ok ( ( ) ) ;
@@ -50,15 +54,15 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
50
54
& mut self ,
51
55
epoch : ChainEpoch ,
52
56
values : impl IntoIterator < Item = u64 > ,
53
- ) -> anyhow :: Result < ( ) > {
57
+ ) -> Result < ( ) , ActorError > {
54
58
self . add_to_queue ( epoch, & BitField :: try_from_bits ( values) ?)
55
59
}
56
60
57
61
/// Cut cuts the elements from the bits in the given bitfield out of the queue,
58
62
/// shifting other bits down and removing any newly empty entries.
59
63
///
60
64
/// See the docs on `BitField::cut` to better understand what it does.
61
- pub fn cut ( & mut self , to_cut : & BitField ) -> anyhow :: Result < ( ) > {
65
+ pub fn cut ( & mut self , to_cut : & BitField ) -> Result < ( ) , ActorError > {
62
66
let mut epochs_to_remove = Vec :: < u64 > :: new ( ) ;
63
67
64
68
self . amt
@@ -70,22 +74,20 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
70
74
} else {
71
75
* * bitfield = bf;
72
76
}
73
-
74
- Ok ( ( ) )
75
77
} )
76
- . map_err ( |e| e . downcast_wrap ( "failed to cut from bitfield queue" ) ) ?;
78
+ . context ( "failed to cut from bitfield queue" ) ?;
77
79
78
80
self . amt
79
81
. batch_delete ( epochs_to_remove, true )
80
- . map_err ( |e| e . downcast_wrap ( "failed to remove empty epochs from bitfield queue" ) ) ?;
82
+ . context ( "failed to remove empty epochs from bitfield queue" ) ?;
81
83
82
84
Ok ( ( ) )
83
85
}
84
86
85
87
pub fn add_many_to_queue_values (
86
88
& mut self ,
87
89
values : impl IntoIterator < Item = ( ChainEpoch , u64 ) > ,
88
- ) -> anyhow :: Result < ( ) > {
90
+ ) -> Result < ( ) , ActorError > {
89
91
// Pre-quantize to reduce the number of updates.
90
92
let mut quantized_values: Vec < _ > = values
91
93
. into_iter ( )
@@ -110,19 +112,19 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
110
112
111
113
/// Removes and returns all values with keys less than or equal to until.
112
114
/// Modified return value indicates whether this structure has been changed by the call.
113
- pub fn pop_until ( & mut self , until : ChainEpoch ) -> anyhow :: Result < ( BitField , bool ) > {
115
+ pub fn pop_until ( & mut self , until : ChainEpoch ) -> Result < ( BitField , bool ) , ActorError > {
114
116
let mut popped_values = BitField :: new ( ) ;
115
117
let mut popped_keys = Vec :: < u64 > :: new ( ) ;
116
118
117
119
self . amt . for_each_while ( |epoch, bitfield| {
118
120
if epoch as ChainEpoch > until {
119
121
// break
120
- return Ok ( false ) ;
122
+ return false ;
121
123
}
122
124
123
125
popped_keys. push ( epoch) ;
124
126
popped_values |= bitfield;
125
- Ok ( true )
127
+ true
126
128
} ) ?;
127
129
128
130
if popped_keys. is_empty ( ) {
0 commit comments