@@ -38,7 +38,6 @@ fd_store_new( void * shmem, ulong fec_max, ulong part_cnt ) {
38
38
}
39
39
40
40
fd_memset ( shmem , 0 , footprint );
41
- fec_max = fd_ulong_pow2_up ( fec_max ); /* required by map_chain */
42
41
43
42
/* This seed value is very important. We have fec_max chains in the
44
43
map, which means the size of each partition of buckets should be
@@ -66,6 +65,10 @@ fd_store_new( void * shmem, ulong fec_max, ulong part_cnt ) {
66
65
store -> root = null ;
67
66
68
67
fd_store_pool_t pool = fd_store_pool ( store );
68
+ if ( FD_UNLIKELY ( !fd_store_pool_new ( shpool ) ) ) {
69
+ FD_LOG_WARNING (( "fd_store_pool_new failed" ));
70
+ return NULL ;
71
+ }
69
72
fd_store_pool_reset ( & pool , 0 );
70
73
71
74
FD_COMPILER_MFENCE ();
@@ -115,7 +118,8 @@ fd_store_leave( fd_store_t const * store ) {
115
118
}
116
119
117
120
void *
118
- fd_store_delete ( void * store ) {
121
+ fd_store_delete ( void * shstore ) {
122
+ fd_store_t * store = shstore ;
119
123
120
124
if ( FD_UNLIKELY ( !store ) ) {
121
125
FD_LOG_WARNING (( "NULL store" ));
@@ -127,6 +131,15 @@ fd_store_delete( void * store ) {
127
131
return NULL ;
128
132
}
129
133
134
+ if ( FD_UNLIKELY ( store -> magic != FD_STORE_MAGIC ) ) {
135
+ FD_LOG_WARNING (( "bad magic" ));
136
+ return NULL ;
137
+ }
138
+
139
+ FD_COMPILER_MFENCE ();
140
+ FD_VOLATILE ( store -> magic ) = 0UL ;
141
+ FD_COMPILER_MFENCE ();
142
+
130
143
return store ;
131
144
}
132
145
@@ -207,14 +220,14 @@ fd_store_publish( fd_store_t * store,
207
220
any descendants of those ancestors. */
208
221
209
222
while ( FD_LIKELY ( head ) ) {
210
- fd_store_fec_t * child = fd_store_pool_ele ( & pool , head -> child ); /* left-child */
223
+ fd_store_fec_t * child = fd_store_pool_ele ( & pool , head -> child ); /* left-child */
211
224
while ( FD_LIKELY ( child ) ) { /* iterate over children */
212
225
if ( FD_LIKELY ( child != newr ) ) { /* stop at new root */
213
226
tail -> next = fd_store_map_idx_remove ( map , & child -> key , null , fec0 ); /* remove node from map to reuse `.next` */
214
- tail = fd_store_pool_ele ( & pool , tail -> next ); /* push onto BFS queue (so descendants can be pruned) */
227
+ tail = fd_store_pool_ele ( & pool , tail -> next ); /* push onto BFS queue (so descendants can be pruned) */
215
228
tail -> next = null ; /* clear map next */
216
229
}
217
- child = fd_store_pool_ele ( & pool , child -> sibling ); /* right-sibling */
230
+ child = fd_store_pool_ele ( & pool , child -> sibling ); /* right-sibling */
218
231
}
219
232
fd_store_fec_t * next = fd_store_pool_ele ( & pool , head -> next ); /* pophead */
220
233
int err = fd_store_pool_release ( & pool , head , BLOCKING ); /* release */
@@ -231,12 +244,18 @@ fd_store_publish( fd_store_t * store,
231
244
232
245
fd_store_t *
233
246
fd_store_clear ( fd_store_t * store ) {
247
+
234
248
fd_store_map_t * map = fd_store_map ( store );
235
249
fd_store_pool_t pool = fd_store_pool ( store );
236
250
fd_store_fec_t * fec0 = fd_store_fec0 ( store );
237
251
238
252
fd_store_fec_t * head = fd_store_root ( store );
239
253
fd_store_fec_t * tail = head ;
254
+
255
+ # if FD_STORE_USE_HANDHOLDING
256
+ if ( FD_UNLIKELY ( !head ) ) { FD_LOG_WARNING (( "calling clear on an empty store" )); return store ; }
257
+ # endif
258
+
240
259
for ( fd_store_map_iter_t iter = fd_store_map_iter_init ( map , fec0 );
241
260
!fd_store_map_iter_done ( iter , map , fec0 );
242
261
iter = fd_store_map_iter_next ( iter , map , fec0 ) ) {
@@ -283,6 +302,8 @@ fd_store_verify( fd_store_t * store ) {
283
302
return -1 ;
284
303
}
285
304
}
305
+ fd_store_pool_t pool = fd_store_pool_const ( store );
306
+ if ( FD_UNLIKELY ( fd_store_pool_verify ( & pool )== -1 ) ) return -1 ;
286
307
return fd_store_map_verify ( map , store -> fec_max , fec0 );
287
308
}
288
309
@@ -296,7 +317,7 @@ print( fd_store_t const * store, fd_store_fec_t const * fec, int space, const ch
296
317
297
318
if ( space > 0 ) printf ( "\n" );
298
319
for ( int i = 0 ; i < space ; i ++ ) printf ( " " );
299
- printf ( "%s%s" , prefix , FD_BASE58_ENC_32_ALLOCA ( & fec -> key ) );
320
+ printf ( "%s%s" , prefix , FD_BASE58_ENC_32_ALLOCA ( & fec -> key . mr ) );
300
321
301
322
fd_store_fec_t const * curr = fd_store_pool_ele_const ( & pool , fec -> child );
302
323
char new_prefix [1024 ]; /* FIXME size this correctly */
0 commit comments