3
3
4
4
use cid:: Cid ;
5
5
use fil_actors_runtime:: {
6
- actor_error, make_empty_map, make_map_with_root_and_bitwidth, AsActorError ,
6
+ actor_error, make_empty_map, make_map_with_root_and_bitwidth, ActorError , AsActorError ,
7
7
FIRST_NON_SINGLETON_ADDR ,
8
8
} ;
9
9
use fvm_ipld_blockstore:: Blockstore ;
@@ -22,7 +22,7 @@ pub struct State {
22
22
}
23
23
24
24
impl State {
25
- pub fn new < BS : Blockstore > ( store : & BS , network_name : String ) -> anyhow :: Result < Self > {
25
+ pub fn new < BS : Blockstore > ( store : & BS , network_name : String ) -> Result < Self , ActorError > {
26
26
let empty_map = make_empty_map :: < _ , ( ) > ( store, HAMT_BIT_WIDTH )
27
27
. flush ( )
28
28
. context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to create empty map" ) ?;
@@ -37,22 +37,26 @@ impl State {
37
37
& mut self ,
38
38
store : & BS ,
39
39
addr : & Address ,
40
- ) -> anyhow :: Result < ActorID > {
40
+ ) -> Result < ActorID , ActorError > {
41
41
let id = self . next_id ;
42
42
self . next_id += 1 ;
43
43
44
- let mut map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH ) ?;
45
- let is_new = map. set_if_absent ( addr. to_bytes ( ) . into ( ) , id) ?;
44
+ let mut map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH )
45
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to load address map" ) ?;
46
+ let is_new = map
47
+ . set_if_absent ( addr. to_bytes ( ) . into ( ) , id)
48
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to set map key" ) ?;
46
49
if !is_new {
47
50
// this is impossible today as the robust address is a hash of unique inputs
48
51
// but in close future predictable address generation will make this possible
49
- return Err ( anyhow ! ( actor_error!(
52
+ return Err ( actor_error ! (
50
53
forbidden,
51
54
"robust address {} is already allocated in the address map" ,
52
55
addr
53
- ) ) ) ;
56
+ ) ) ;
54
57
}
55
- self . address_map = map. flush ( ) ?;
58
+ self . address_map =
59
+ map. flush ( ) . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to store address map" ) ?;
56
60
57
61
Ok ( id)
58
62
}
@@ -71,14 +75,18 @@ impl State {
71
75
& self ,
72
76
store : & BS ,
73
77
addr : & Address ,
74
- ) -> anyhow :: Result < Option < Address > > {
78
+ ) -> Result < Option < Address > , ActorError > {
75
79
if addr. protocol ( ) == Protocol :: ID {
76
80
return Ok ( Some ( * addr) ) ;
77
81
}
78
82
79
- let map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH ) ?;
83
+ let map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH )
84
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to load address map" ) ?;
80
85
81
- Ok ( map. get ( & addr. to_bytes ( ) ) ?. copied ( ) . map ( Address :: new_id) )
86
+ let found = map
87
+ . get ( & addr. to_bytes ( ) )
88
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to get address entry" ) ?;
89
+ Ok ( found. copied ( ) . map ( Address :: new_id) )
82
90
}
83
91
}
84
92
0 commit comments