@@ -6,8 +6,8 @@ use std::collections::BTreeSet;
6
6
use fil_actors_runtime:: cbor:: serialize_vec;
7
7
use fil_actors_runtime:: runtime:: { ActorCode , Runtime , Syscalls } ;
8
8
use fil_actors_runtime:: {
9
- actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_id_addr, ActorDowncast ,
10
- ActorError , Map , INIT_ACTOR_ADDR ,
9
+ actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_id_addr, ActorContext ,
10
+ ActorDowncast , ActorError , Map , INIT_ACTOR_ADDR ,
11
11
} ;
12
12
use fvm_ipld_blockstore:: Blockstore ;
13
13
use fvm_ipld_encoding:: RawBytes ;
@@ -73,12 +73,8 @@ impl Actor {
73
73
let mut resolved_signers = Vec :: with_capacity ( params. signers . len ( ) ) ;
74
74
let mut dedup_signers = BTreeSet :: new ( ) ;
75
75
for signer in & params. signers {
76
- let resolved = resolve_to_id_addr ( rt, signer) . map_err ( |e| {
77
- e. downcast_default (
78
- ExitCode :: USR_ILLEGAL_STATE ,
79
- format ! ( "failed to resolve addr {} to ID addr" , signer) ,
80
- )
81
- } ) ?;
76
+ let resolved = resolve_to_id_addr ( rt, signer)
77
+ . with_context ( || format ! ( "failed to resolve addr {} to ID addr" , signer) ) ?;
82
78
if !dedup_signers. insert ( resolved. id ( ) . expect ( "address should be resolved" ) ) {
83
79
return Err (
84
80
actor_error ! ( illegal_argument; "duplicate signer not allowed: {}" , signer) ,
@@ -269,11 +265,8 @@ impl Actor {
269
265
return Err ( actor_error ! ( forbidden; "Cannot cancel another signers transaction" ) ) ;
270
266
}
271
267
272
- let calculated_hash = compute_proposal_hash ( & tx, rt) . map_err ( |e| {
273
- e. downcast_default (
274
- ExitCode :: USR_ILLEGAL_STATE ,
275
- format ! ( "failed to compute proposal hash for (tx: {:?})" , params. id) ,
276
- )
268
+ let calculated_hash = compute_proposal_hash ( & tx, rt) . with_context ( || {
269
+ format ! ( "failed to compute proposal hash for (tx: {:?})" , params. id)
277
270
} ) ?;
278
271
279
272
if !params. proposal_hash . is_empty ( ) && params. proposal_hash != calculated_hash {
@@ -299,12 +292,8 @@ impl Actor {
299
292
{
300
293
let receiver = rt. message ( ) . receiver ( ) ;
301
294
rt. validate_immediate_caller_is ( std:: iter:: once ( & receiver) ) ?;
302
- let resolved_new_signer = resolve_to_id_addr ( rt, & params. signer ) . map_err ( |e| {
303
- e. downcast_default (
304
- ExitCode :: USR_ILLEGAL_STATE ,
305
- format ! ( "failed to resolve address {}" , params. signer) ,
306
- )
307
- } ) ?;
295
+ let resolved_new_signer = resolve_to_id_addr ( rt, & params. signer )
296
+ . with_context ( || format ! ( "failed to resolve address {}" , params. signer) ) ?;
308
297
309
298
rt. transaction ( |st : & mut State , _| {
310
299
if st. signers . len ( ) >= SIGNERS_MAX {
@@ -336,12 +325,8 @@ impl Actor {
336
325
{
337
326
let receiver = rt. message ( ) . receiver ( ) ;
338
327
rt. validate_immediate_caller_is ( std:: iter:: once ( & receiver) ) ?;
339
- let resolved_old_signer = resolve_to_id_addr ( rt, & params. signer ) . map_err ( |e| {
340
- e. downcast_default (
341
- ExitCode :: USR_ILLEGAL_STATE ,
342
- format ! ( "failed to resolve address {}" , params. signer) ,
343
- )
344
- } ) ?;
328
+ let resolved_old_signer = resolve_to_id_addr ( rt, & params. signer )
329
+ . with_context ( || format ! ( "failed to resolve address {}" , params. signer) ) ?;
345
330
346
331
rt. transaction ( |st : & mut State , rt| {
347
332
if !st. is_signer ( & resolved_old_signer) {
@@ -374,12 +359,9 @@ impl Actor {
374
359
}
375
360
376
361
// Remove approvals from removed signer
377
- st. purge_approvals ( rt. store ( ) , & resolved_old_signer) . map_err ( |e| {
378
- e. downcast_default (
379
- ExitCode :: USR_ILLEGAL_STATE ,
380
- "failed to purge approvals of removed signer" ,
381
- )
382
- } ) ?;
362
+ st. purge_approvals ( rt. store ( ) , & resolved_old_signer)
363
+ . context ( "failed to purge approvals of removed signer" ) ?;
364
+
383
365
st. signers . retain ( |s| s != & resolved_old_signer) ;
384
366
385
367
Ok ( ( ) )
@@ -396,18 +378,10 @@ impl Actor {
396
378
{
397
379
let receiver = rt. message ( ) . receiver ( ) ;
398
380
rt. validate_immediate_caller_is ( std:: iter:: once ( & receiver) ) ?;
399
- let from_resolved = resolve_to_id_addr ( rt, & params. from ) . map_err ( |e| {
400
- e. downcast_default (
401
- ExitCode :: USR_ILLEGAL_STATE ,
402
- format ! ( "failed to resolve address {}" , params. from) ,
403
- )
404
- } ) ?;
405
- let to_resolved = resolve_to_id_addr ( rt, & params. to ) . map_err ( |e| {
406
- e. downcast_default (
407
- ExitCode :: USR_ILLEGAL_STATE ,
408
- format ! ( "failed to resolve address {}" , params. to) ,
409
- )
410
- } ) ?;
381
+ let from_resolved = resolve_to_id_addr ( rt, & params. from )
382
+ . with_context ( || format ! ( "failed to resolve address {}" , params. from) ) ?;
383
+ let to_resolved = resolve_to_id_addr ( rt, & params. to )
384
+ . with_context ( || format ! ( "failed to resolve address {}" , params. to) ) ?;
411
385
412
386
rt. transaction ( |st : & mut State , rt| {
413
387
if !st. is_signer ( & from_resolved) {
@@ -424,12 +398,9 @@ impl Actor {
424
398
// Add new signer
425
399
st. signers . push ( to_resolved) ;
426
400
427
- st. purge_approvals ( rt. store ( ) , & from_resolved) . map_err ( |e| {
428
- e. downcast_default (
429
- ExitCode :: USR_ILLEGAL_STATE ,
430
- "failed to purge approvals of removed signer" ,
431
- )
432
- } ) ?;
401
+ st. purge_approvals ( rt. store ( ) , & from_resolved)
402
+ . context ( "failed to purge approvals of removed signer" ) ?;
403
+
433
404
Ok ( ( ) )
434
405
} ) ?;
435
406
@@ -621,12 +592,8 @@ where
621
592
. ok_or_else ( || actor_error ! ( not_found, "no such transaction {:?} for approval" , txn_id) ) ?;
622
593
623
594
if !proposal_hash. is_empty ( ) {
624
- let calculated_hash = compute_proposal_hash ( txn, rt) . map_err ( |e| {
625
- e. downcast_default (
626
- ExitCode :: USR_ILLEGAL_STATE ,
627
- format ! ( "failed to compute proposal hash for (tx: {:?})" , txn_id) ,
628
- )
629
- } ) ?;
595
+ let calculated_hash = compute_proposal_hash ( txn, rt)
596
+ . with_context ( || format ! ( "failed to compute proposal hash for (tx: {:?})" , txn_id) ) ?;
630
597
631
598
if proposal_hash != calculated_hash {
632
599
return Err ( actor_error ! (
@@ -641,7 +608,10 @@ where
641
608
642
609
/// Computes a digest of a proposed transaction. This digest is used to confirm identity
643
610
/// of the transaction associated with an ID, which might change under chain re-orgs.
644
- pub fn compute_proposal_hash ( txn : & Transaction , sys : & dyn Syscalls ) -> anyhow:: Result < [ u8 ; 32 ] > {
611
+ pub fn compute_proposal_hash (
612
+ txn : & Transaction ,
613
+ sys : & dyn Syscalls ,
614
+ ) -> Result < [ u8 ; 32 ] , ActorError > {
645
615
let proposal_hash = ProposalHashData {
646
616
requester : txn. approved . get ( 0 ) ,
647
617
to : & txn. to ,
0 commit comments