2
2
// SPDX-License-Identifier: Apache-2.0, MIT
3
3
4
4
use cid:: Cid ;
5
- use fil_actors_runtime:: actor_error;
6
5
use fil_actors_runtime:: {
7
6
actor_error, make_empty_map, make_map_with_root_and_bitwidth, ActorError , AsActorError ,
8
7
FIRST_NON_SINGLETON_ADDR ,
@@ -72,37 +71,45 @@ impl State {
72
71
store : & BS ,
73
72
addr : & Address ,
74
73
f4addr : & Address ,
75
- ) -> anyhow :: Result < ActorID >
74
+ ) -> Result < ActorID , ActorError >
76
75
where
77
76
BS : Blockstore ,
78
77
{
79
- let mut map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH ) ?;
78
+ let mut map = make_map_with_root_and_bitwidth ( & self . address_map , store, HAMT_BIT_WIDTH )
79
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to load address map" ) ?;
80
80
81
81
// Assign a new ID address, or use the one currently mapped to the f4 address. We don't
82
82
// bother checking if the target actor is an embryo here, the FVM will check that when we go to create the actor.
83
83
let f4addr_key = f4addr. to_bytes ( ) . into ( ) ;
84
- let id: u64 = match map. get ( & f4addr_key) ? {
84
+ let id: u64 = match map
85
+ . get ( & f4addr_key)
86
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to lookup f4 address in map" ) ?
87
+ {
85
88
Some ( id) => * id,
86
89
None => {
87
90
let id = self . next_id ;
88
91
self . next_id += 1 ;
89
- map. set ( f4addr_key, id) ?;
92
+ map. set ( f4addr_key, id)
93
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to set f4 address in map" ) ?;
90
94
id
91
95
}
92
96
} ;
93
97
94
98
// Then go ahead and assign the f2 address.
95
- let is_new = map. set_if_absent ( addr. to_bytes ( ) . into ( ) , id) ?;
99
+ let is_new = map
100
+ . set_if_absent ( addr. to_bytes ( ) . into ( ) , id)
101
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to set map key" ) ?;
96
102
if !is_new {
97
103
// this is impossible today as the robust address is a hash of unique inputs
98
104
// but in close future predictable address generation will make this possible
99
- return Err ( anyhow ! ( actor_error!(
105
+ return Err ( actor_error ! (
100
106
forbidden,
101
107
"robust address {} is already allocated in the address map" ,
102
108
addr
103
- ) ) ) ;
109
+ ) ) ;
104
110
}
105
- self . address_map = map. flush ( ) ?;
111
+ self . address_map =
112
+ map. flush ( ) . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to store address map" ) ?;
106
113
107
114
Ok ( id)
108
115
}
@@ -141,8 +148,11 @@ impl State {
141
148
& self ,
142
149
store : & BS ,
143
150
cid : & Cid ,
144
- ) -> anyhow:: Result < bool > {
145
- let installed: Vec < Cid > = match store. get_cbor ( & self . installed_actors ) ? {
151
+ ) -> Result < bool , ActorError > {
152
+ let installed: Vec < Cid > = match store
153
+ . get_cbor ( & self . installed_actors )
154
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to load installed actor list" ) ?
155
+ {
146
156
Some ( v) => v,
147
157
None => Vec :: new ( ) ,
148
158
} ;
@@ -155,13 +165,18 @@ impl State {
155
165
& mut self ,
156
166
store : & BS ,
157
167
cid : Cid ,
158
- ) -> anyhow:: Result < ( ) > {
159
- let mut installed: Vec < Cid > = match store. get_cbor ( & self . installed_actors ) ? {
168
+ ) -> Result < ( ) , ActorError > {
169
+ let mut installed: Vec < Cid > = match store
170
+ . get_cbor ( & self . installed_actors )
171
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to load installed actor list" ) ?
172
+ {
160
173
Some ( v) => v,
161
174
None => Vec :: new ( ) ,
162
175
} ;
163
176
installed. push ( cid) ;
164
- self . installed_actors = store. put_cbor ( & installed, Code :: Blake2b256 ) ?;
177
+ self . installed_actors = store
178
+ . put_cbor ( & installed, Code :: Blake2b256 )
179
+ . context_code ( ExitCode :: USR_ILLEGAL_STATE , "failed to save installed actor list" ) ?;
165
180
Ok ( ( ) )
166
181
}
167
182
}
0 commit comments