@@ -7,7 +7,7 @@ use fil_actors_runtime::cbor::serialize_vec;
7
7
use fil_actors_runtime:: runtime:: { ActorCode , Runtime , Syscalls } ;
8
8
use fil_actors_runtime:: {
9
9
actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_id_addr, ActorContext ,
10
- ActorDowncast , ActorError , Map , INIT_ACTOR_ADDR ,
10
+ ActorError , Map , INIT_ACTOR_ADDR ,
11
11
} ;
12
12
use fvm_ipld_blockstore:: Blockstore ;
13
13
use fvm_ipld_encoding:: RawBytes ;
@@ -97,10 +97,9 @@ impl Actor {
97
97
return Err ( actor_error ! ( illegal_argument; "negative unlock duration disallowed" ) ) ;
98
98
}
99
99
100
- let empty_root =
101
- make_empty_map :: < _ , ( ) > ( rt. store ( ) , HAMT_BIT_WIDTH ) . flush ( ) . map_err ( |e| {
102
- e. downcast_default ( ExitCode :: USR_ILLEGAL_STATE , "Failed to create empty map" )
103
- } ) ?;
100
+ let empty_root = make_empty_map :: < _ , ( ) > ( rt. store ( ) , HAMT_BIT_WIDTH )
101
+ . flush ( )
102
+ . context ( "Failed to create empty map" ) ?;
104
103
105
104
let mut st: State = State {
106
105
signers : resolved_signers,
@@ -146,12 +145,8 @@ impl Actor {
146
145
return Err ( actor_error ! ( forbidden, "{} is not a signer" , proposer) ) ;
147
146
}
148
147
149
- let mut ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) ) . map_err ( |e| {
150
- e. downcast_default (
151
- ExitCode :: USR_ILLEGAL_STATE ,
152
- "failed to load pending transactions" ,
153
- )
154
- } ) ?;
148
+ let mut ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) )
149
+ . context ( "failed to load pending transactions" ) ?;
155
150
156
151
let t_id = st. next_tx_id ;
157
152
st. next_tx_id . 0 += 1 ;
@@ -164,19 +159,9 @@ impl Actor {
164
159
approved : Vec :: new ( ) ,
165
160
} ;
166
161
167
- ptx. set ( t_id. key ( ) , txn. clone ( ) ) . map_err ( |e| {
168
- e. downcast_default (
169
- ExitCode :: USR_ILLEGAL_STATE ,
170
- "failed to put transaction for propose" ,
171
- )
172
- } ) ?;
162
+ ptx. set ( t_id. key ( ) , txn. clone ( ) ) . context ( "failed to put transaction for propose" ) ?;
173
163
174
- st. pending_txs = ptx. flush ( ) . map_err ( |e| {
175
- e. downcast_default (
176
- ExitCode :: USR_ILLEGAL_STATE ,
177
- "failed to flush pending transactions" ,
178
- )
179
- } ) ?;
164
+ st. pending_txs = ptx. flush ( ) . context ( "failed to flush pending transactions" ) ?;
180
165
181
166
Ok ( ( t_id, txn) )
182
167
} ) ?;
@@ -201,12 +186,8 @@ impl Actor {
201
186
return Err ( actor_error ! ( forbidden; "{} is not a signer" , approver) ) ;
202
187
}
203
188
204
- let ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) ) . map_err ( |e| {
205
- e. downcast_default (
206
- ExitCode :: USR_ILLEGAL_STATE ,
207
- "failed to load pending transactions" ,
208
- )
209
- } ) ?;
189
+ let ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) )
190
+ . context ( "failed to load pending transactions" ) ?;
210
191
211
192
let txn = get_transaction ( rt, & ptx, params. id , params. proposal_hash ) ?;
212
193
@@ -241,21 +222,11 @@ impl Actor {
241
222
}
242
223
243
224
let mut ptx = make_map_with_root :: < _ , Transaction > ( & st. pending_txs , rt. store ( ) )
244
- . map_err ( |e| {
245
- e. downcast_default (
246
- ExitCode :: USR_ILLEGAL_STATE ,
247
- "failed to load pending transactions" ,
248
- )
249
- } ) ?;
225
+ . context ( "failed to load pending transactions" ) ?;
250
226
251
227
let ( _, tx) = ptx
252
228
. delete ( & params. id . key ( ) )
253
- . map_err ( |e| {
254
- e. downcast_default (
255
- ExitCode :: USR_ILLEGAL_STATE ,
256
- format ! ( "failed to pop transaction {:?} for cancel" , params. id) ,
257
- )
258
- } ) ?
229
+ . with_context ( || format ! ( "failed to pop transaction {:?} for cancel" , params. id, ) ) ?
259
230
. ok_or_else ( || {
260
231
actor_error ! ( not_found, "no such transaction {:?} to cancel" , params. id)
261
232
} ) ?;
@@ -273,12 +244,7 @@ impl Actor {
273
244
return Err ( actor_error ! ( illegal_state, "hash does not match proposal params" ) ) ;
274
245
}
275
246
276
- st. pending_txs = ptx. flush ( ) . map_err ( |e| {
277
- e. downcast_default (
278
- ExitCode :: USR_ILLEGAL_STATE ,
279
- "failed to flush pending transactions" ,
280
- )
281
- } ) ?;
247
+ st. pending_txs = ptx. flush ( ) . context ( "failed to flush pending transactions" ) ?;
282
248
283
249
Ok ( ( ) )
284
250
} )
@@ -481,29 +447,16 @@ impl Actor {
481
447
}
482
448
483
449
let st = rt. transaction ( |st : & mut State , rt| {
484
- let mut ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) ) . map_err ( |e| {
485
- e. downcast_default (
486
- ExitCode :: USR_ILLEGAL_STATE ,
487
- "failed to load pending transactions" ,
488
- )
489
- } ) ?;
450
+ let mut ptx = make_map_with_root ( & st. pending_txs , rt. store ( ) )
451
+ . context ( "failed to load pending transactions" ) ?;
490
452
491
453
// update approved on the transaction
492
454
txn. approved . push ( rt. message ( ) . caller ( ) ) ;
493
455
494
- ptx. set ( tx_id. key ( ) , txn. clone ( ) ) . map_err ( |e| {
495
- e. downcast_default (
496
- ExitCode :: USR_ILLEGAL_STATE ,
497
- format ! ( "failed to put transaction {} for approval" , tx_id. 0 ) ,
498
- )
499
- } ) ?;
456
+ ptx. set ( tx_id. key ( ) , txn. clone ( ) )
457
+ . with_context ( || format ! ( "failed to put transaction {} for approval" , tx_id. 0 , ) ) ?;
500
458
501
- st. pending_txs = ptx. flush ( ) . map_err ( |e| {
502
- e. downcast_default (
503
- ExitCode :: USR_ILLEGAL_STATE ,
504
- "failed to flush pending transactions" ,
505
- )
506
- } ) ?;
459
+ st. pending_txs = ptx. flush ( ) . context ( "failed to flush pending transactions" ) ?;
507
460
508
461
// Go implementation holds reference to state after transaction so this must be cloned
509
462
// to match to handle possible exit code inconsistency
@@ -544,26 +497,11 @@ where
544
497
545
498
rt. transaction ( |st : & mut State , rt| {
546
499
let mut ptx = make_map_with_root :: < _ , Transaction > ( & st. pending_txs , rt. store ( ) )
547
- . map_err ( |e| {
548
- e. downcast_default (
549
- ExitCode :: USR_ILLEGAL_STATE ,
550
- "failed to load pending transactions" ,
551
- )
552
- } ) ?;
500
+ . context ( "failed to load pending transactions" ) ?;
553
501
554
- ptx. delete ( & txn_id. key ( ) ) . map_err ( |e| {
555
- e. downcast_default (
556
- ExitCode :: USR_ILLEGAL_STATE ,
557
- "failed to delete transaction for cleanup" ,
558
- )
559
- } ) ?;
502
+ ptx. delete ( & txn_id. key ( ) ) . context ( "failed to delete transaction for cleanup" ) ?;
560
503
561
- st. pending_txs = ptx. flush ( ) . map_err ( |e| {
562
- e. downcast_default (
563
- ExitCode :: USR_ILLEGAL_STATE ,
564
- "failed to flush pending transactions" ,
565
- )
566
- } ) ?;
504
+ st. pending_txs = ptx. flush ( ) . context ( "failed to flush pending transactions" ) ?;
567
505
Ok ( ( ) )
568
506
} ) ?;
569
507
}
@@ -583,12 +521,7 @@ where
583
521
{
584
522
let txn = ptx
585
523
. get ( & txn_id. key ( ) )
586
- . map_err ( |e| {
587
- e. downcast_default (
588
- ExitCode :: USR_ILLEGAL_STATE ,
589
- format ! ( "failed to load transaction {:?} for approval" , txn_id) ,
590
- )
591
- } ) ?
524
+ . with_context ( || format ! ( "failed to load transaction {:?} for approval" , txn_id, ) ) ?
592
525
. ok_or_else ( || actor_error ! ( not_found, "no such transaction {:?} for approval" , txn_id) ) ?;
593
526
594
527
if !proposal_hash. is_empty ( ) {
0 commit comments