@@ -859,62 +859,43 @@ typedef struct accounts_hash accounts_hash_t;
859
859
static ulong
860
860
fd_accounts_sorted_subrange_count ( fd_funkier_t * funk ,
861
861
uint range_idx ,
862
- uint range_cnt ,
863
- fd_spad_t * runtime_spad ) {
862
+ uint range_cnt ) {
864
863
865
864
fd_wksp_t * wksp = fd_funkier_wksp ( funk );
866
865
ulong num_pairs = 0UL ;
867
866
ulong range_len = ULONG_MAX /range_cnt ;
868
867
ulong range_min = range_len * range_idx ;
869
868
ulong range_max = (range_idx + 1U < range_cnt ) ? (range_min + range_len - 1U ) : ULONG_MAX ;
870
869
871
- FD_SPAD_FRAME_BEGIN ( runtime_spad ) {
870
+ fd_funkier_all_iter_t iter [1 ];
871
+ for ( fd_funkier_all_iter_new ( funk , iter );
872
+ !fd_funkier_all_iter_done ( iter );
873
+ fd_funkier_all_iter_next ( iter ) ) {
874
+ fd_funkier_rec_t const * rec = fd_funkier_all_iter_ele_const ( iter );
872
875
873
- /* Thread-safe iteration as described in the documentation of fd_map_para.c */
874
- fd_funkier_rec_map_t rec_map = fd_funkier_rec_map ( funk , wksp );
875
- ulong lock_cnt = fd_funkier_rec_map_chain_cnt ( & rec_map );
876
- ulong * lock_seq = fd_spad_alloc ( runtime_spad , alignof(ulong ), sizeof (ulong ) );
877
- for ( ulong lock_idx = 0UL ; lock_idx < lock_cnt ; lock_idx ++ ) lock_seq [ lock_idx ] = lock_idx ;
878
-
879
- fd_funkier_rec_map_iter_lock ( & rec_map , lock_seq , lock_cnt , FD_MAP_FLAG_BLOCKING );
880
-
881
- for ( ulong lock_idx = 0UL ; lock_idx < lock_cnt ; lock_idx ++ ) {
882
- /* Process chains in the order they were locked */
883
- ulong chain_idx = lock_seq [ lock_idx ];
884
-
885
- for ( fd_funkier_rec_map_iter_t iter = fd_funkier_rec_map_iter ( & rec_map , chain_idx );
886
- !fd_funkier_rec_map_iter_done ( iter );
887
- iter = fd_funkier_rec_map_iter_next ( iter ) ) {
888
- fd_funkier_rec_t const * rec = fd_funkier_rec_map_iter_ele_const ( iter );
889
-
890
- if ( !fd_funkier_key_is_acc ( rec -> pair .key ) || /* not a solana record */
891
- (rec -> flags & FD_FUNKIER_REC_FLAG_ERASE ) || /* this is a tombstone */
892
- (rec -> pair .xid -> ul [0 ] | rec -> pair .xid -> ul [1 ]) != 0 /* not root xid */ ) {
893
- continue ;
894
- }
895
-
896
- ulong n = __builtin_bswap64 ( rec -> pair .key -> ul [0 ] );
897
- if ( n < range_min || n > range_max ) {
898
- continue ;
899
- }
900
-
901
- fd_account_meta_t * metadata = (fd_account_meta_t * )fd_funkier_val_const ( rec , wksp );
902
- int is_empty = (metadata -> info .lamports == 0 );
903
- if ( is_empty ) {
904
- continue ;
905
- }
876
+ if ( !fd_funkier_key_is_acc ( rec -> pair .key ) || /* not a solana record */
877
+ (rec -> flags & FD_FUNKIER_REC_FLAG_ERASE ) || /* this is a tombstone */
878
+ (rec -> pair .xid -> ul [0 ] | rec -> pair .xid -> ul [1 ]) != 0 /* not root xid */ ) {
879
+ continue ;
880
+ }
906
881
907
- if ( (metadata -> info .executable & ~1 ) != 0 ) {
908
- continue ;
909
- }
882
+ ulong n = __builtin_bswap64 ( rec -> pair .key -> ul [0 ] );
883
+ if ( n < range_min || n > range_max ) {
884
+ continue ;
885
+ }
910
886
911
- num_pairs ++ ;
912
- }
887
+ fd_account_meta_t * metadata = (fd_account_meta_t * )fd_funkier_val_const ( rec , wksp );
888
+ int is_empty = (metadata -> info .lamports == 0 );
889
+ if ( is_empty ) {
890
+ continue ;
891
+ }
913
892
914
- /* Unlock incrementally */
915
- fd_funkier_rec_map_iter_unlock ( & rec_map , lock_seq + lock_idx , 1UL ) ;
893
+ if ( ( metadata -> info . executable & ~ 1 ) != 0 ) {
894
+ continue ;
916
895
}
917
- } FD_SPAD_FRAME_END ;
896
+
897
+ num_pairs ++ ;
898
+ }
918
899
919
900
return num_pairs ;
920
901
}
@@ -927,8 +908,7 @@ fd_accounts_sorted_subrange_gather( fd_funkier_t * funk,
927
908
fd_lthash_value_t * lthash_values_out ,
928
909
ulong n0 ,
929
910
fd_pubkey_hash_pair_t * pairs ,
930
- fd_features_t * features ,
931
- fd_spad_t * runtime_spad ) {
911
+ fd_features_t * features ) {
932
912
933
913
fd_wksp_t * wksp = fd_funkier_wksp ( funk );
934
914
ulong num_pairs = 0UL ;
@@ -938,69 +918,51 @@ fd_accounts_sorted_subrange_gather( fd_funkier_t * funk,
938
918
939
919
fd_lthash_value_t accum = {0 };
940
920
941
- FD_SPAD_FRAME_BEGIN ( runtime_spad ) {
942
-
943
- /* Thread-safe iteration as described in the documentation of fd_map_para.c */
944
- fd_funkier_rec_map_t rec_map = fd_funkier_rec_map ( funk , wksp );
945
- ulong lock_cnt = fd_funkier_rec_map_chain_cnt ( & rec_map );
946
- ulong * lock_seq = fd_spad_alloc ( runtime_spad , alignof(ulong ), sizeof (ulong ) );
947
- for ( ulong lock_idx = 0UL ; lock_idx < lock_cnt ; lock_idx ++ ) lock_seq [ lock_idx ] = lock_idx ;
948
-
949
- fd_funkier_rec_map_iter_lock ( & rec_map , lock_seq , lock_cnt , FD_MAP_FLAG_BLOCKING );
950
-
951
- for ( ulong lock_idx = 0UL ; lock_idx < lock_cnt ; lock_idx ++ ) {
952
- /* Process chains in the order they were locked */
953
- ulong chain_idx = lock_seq [ lock_idx ];
954
-
955
- for ( fd_funkier_rec_map_iter_t iter = fd_funkier_rec_map_iter ( & rec_map , chain_idx );
956
- !fd_funkier_rec_map_iter_done ( iter );
957
- iter = fd_funkier_rec_map_iter_next ( iter ) ) {
958
- fd_funkier_rec_t const * rec = fd_funkier_rec_map_iter_ele_const ( iter );
959
- if ( !fd_funkier_key_is_acc ( rec -> pair .key ) || /* not a solana record */
960
- (rec -> flags & FD_FUNKIER_REC_FLAG_ERASE ) || /* this is a tombstone */
961
- (rec -> pair .xid -> ul [0 ] | rec -> pair .xid -> ul [1 ]) != 0 /* not root xid */ ) {
962
- continue ;
963
- }
964
-
965
- ulong n = __builtin_bswap64 ( rec -> pair .key -> ul [0 ] );
966
- if ( n < range_min || n > range_max ) {
967
- continue ;
968
- }
969
- fd_account_meta_t * metadata = (fd_account_meta_t * )fd_funkier_val_const ( rec , wksp );
970
- int is_empty = (metadata -> info .lamports == 0 );
971
- if ( is_empty ) {
972
- continue ;
973
- }
974
-
975
- /* FIXME: remove magic number */
976
- uchar hash [32 ];
977
- fd_lthash_value_t new_lthash_value = {0 };
921
+ fd_funkier_all_iter_t iter [1 ];
922
+ for ( fd_funkier_all_iter_new ( funk , iter );
923
+ !fd_funkier_all_iter_done ( iter );
924
+ fd_funkier_all_iter_next ( iter ) ) {
925
+ fd_funkier_rec_t const * rec = fd_funkier_all_iter_ele_const ( iter );
926
+ if ( !fd_funkier_key_is_acc ( rec -> pair .key ) || /* not a solana record */
927
+ (rec -> flags & FD_FUNKIER_REC_FLAG_ERASE ) || /* this is a tombstone */
928
+ (rec -> pair .xid -> ul [0 ] | rec -> pair .xid -> ul [1 ]) != 0 /* not root xid */ ) {
929
+ continue ;
930
+ }
978
931
979
- fd_hash_account_current ( (uchar * )hash , & new_lthash_value , metadata , rec -> pair .key -> uc , fd_account_meta_get_data ( metadata ), FD_HASH_BOTH_HASHES , features );
980
- fd_lthash_add ( & accum , & new_lthash_value );
932
+ ulong n = __builtin_bswap64 ( rec -> pair .key -> ul [0 ] );
933
+ if ( n < range_min || n > range_max ) {
934
+ continue ;
935
+ }
936
+ fd_account_meta_t * metadata = (fd_account_meta_t * )fd_funkier_val_const ( rec , wksp );
937
+ int is_empty = (metadata -> info .lamports == 0 );
938
+ if ( is_empty ) {
939
+ continue ;
940
+ }
981
941
982
- fd_hash_t * h = (fd_hash_t * )metadata -> hash ;
983
- if ( FD_LIKELY ( (h -> ul [0 ] | h -> ul [1 ] | h -> ul [2 ] | h -> ul [3 ]) != 0 ) ) {
984
- if ( FD_UNLIKELY ( fd_acc_exists ( metadata ) && memcmp ( metadata -> hash , & hash , 32 ) != 0 ) ) {
985
- FD_LOG_WARNING (( "snapshot hash (%s) doesn't match calculated hash (%s)" , FD_BASE58_ENC_32_ALLOCA ( metadata -> hash ), FD_BASE58_ENC_32_ALLOCA ( & hash ) ));
986
- }
987
- } else {
988
- fd_memcpy ( metadata -> hash , & hash , sizeof (fd_hash_t ) );
989
- }
942
+ /* FIXME: remove magic number */
943
+ uchar hash [32 ];
944
+ fd_lthash_value_t new_lthash_value = {0 };
990
945
991
- if ( (metadata -> info .executable & ~1 ) != 0 ) {
992
- continue ;
993
- }
946
+ fd_hash_account_current ( (uchar * )hash , & new_lthash_value , metadata , rec -> pair .key -> uc , fd_account_meta_get_data ( metadata ), FD_HASH_BOTH_HASHES , features );
947
+ fd_lthash_add ( & accum , & new_lthash_value );
994
948
995
- fd_pubkey_hash_pair_t * pair = & pairs [num_pairs ++ ];
996
- pair -> rec = rec ;
997
- pair -> hash = (const fd_hash_t * )metadata -> hash ;
949
+ fd_hash_t * h = (fd_hash_t * )metadata -> hash ;
950
+ if ( FD_LIKELY ( (h -> ul [0 ] | h -> ul [1 ] | h -> ul [2 ] | h -> ul [3 ]) != 0 ) ) {
951
+ if ( FD_UNLIKELY ( fd_acc_exists ( metadata ) && memcmp ( metadata -> hash , & hash , 32 ) != 0 ) ) {
952
+ FD_LOG_WARNING (( "snapshot hash (%s) doesn't match calculated hash (%s)" , FD_BASE58_ENC_32_ALLOCA ( metadata -> hash ), FD_BASE58_ENC_32_ALLOCA ( & hash ) ));
998
953
}
954
+ } else {
955
+ fd_memcpy ( metadata -> hash , & hash , sizeof (fd_hash_t ) );
956
+ }
999
957
1000
- /* Unlock incrementally */
1001
- fd_funkier_rec_map_iter_unlock ( & rec_map , lock_seq + lock_idx , 1UL ) ;
958
+ if ( ( metadata -> info . executable & ~ 1 ) != 0 ) {
959
+ continue ;
1002
960
}
1003
- } FD_SPAD_FRAME_END ;
961
+
962
+ fd_pubkey_hash_pair_t * pair = & pairs [num_pairs ++ ];
963
+ pair -> rec = rec ;
964
+ pair -> hash = (const fd_hash_t * )metadata -> hash ;
965
+ }
1004
966
1005
967
sort_pubkey_hash_pair_inplace ( pairs , num_pairs );
1006
968
@@ -1015,7 +977,6 @@ struct fd_subrange_task_info {
1015
977
ulong num_lists ;
1016
978
fd_pubkey_hash_pair_list_t * lists ;
1017
979
fd_lthash_value_t * lthash_values ;
1018
- fd_spad_t * runtime_spad ;
1019
980
};
1020
981
typedef struct fd_subrange_task_info fd_subrange_task_info_t ;
1021
982
@@ -1028,7 +989,7 @@ fd_accounts_sorted_subrange_count_task( void *tpool,
1028
989
ulong m0 , ulong m1 FD_PARAM_UNUSED ,
1029
990
ulong n0 FD_PARAM_UNUSED , ulong n1 FD_PARAM_UNUSED ) {
1030
991
fd_subrange_task_info_t * task_info = (fd_subrange_task_info_t * )tpool ;
1031
- ulong num_pairs = fd_accounts_sorted_subrange_count ( task_info -> funk , (uint )m0 , (uint )task_info -> num_lists , task_info -> runtime_spad );
992
+ ulong num_pairs = fd_accounts_sorted_subrange_count ( task_info -> funk , (uint )m0 , (uint )task_info -> num_lists );
1032
993
task_info -> lists [m0 ].pairs_len = num_pairs ;
1033
994
}
1034
995
@@ -1043,7 +1004,7 @@ fd_accounts_sorted_subrange_gather_task( void *tpool,
1043
1004
fd_subrange_task_info_t * task_info = (fd_subrange_task_info_t * )tpool ;
1044
1005
fd_pubkey_hash_pair_list_t * list = task_info -> lists + m0 ;
1045
1006
fd_accounts_sorted_subrange_gather ( task_info -> funk , (uint )m0 , (uint )task_info -> num_lists ,
1046
- & list -> pairs_len , task_info -> lthash_values , n0 , list -> pairs , task_info -> features , task_info -> runtime_spad );
1007
+ & list -> pairs_len , task_info -> lthash_values , n0 , list -> pairs , task_info -> features );
1047
1008
}
1048
1009
1049
1010
int
@@ -1057,6 +1018,14 @@ fd_accounts_hash( fd_funkier_t * funk,
1057
1018
1058
1019
FD_LOG_NOTICE (("accounts_hash start" ));
1059
1020
1021
+ /* FIXME: this is not the correct lock to use, although in reality this is fine as we never modify
1022
+ accounts at the same time as hashing them. Once the hashing has been moved into tiles, we need to
1023
+ change it so that we partition by hash chains, and acquire the lock on the individual hash chains. */
1024
+ fd_wksp_t * wksp = fd_funkier_wksp ( funk );
1025
+ fd_funkier_rec_pool_t rec_pool = fd_funkier_rec_pool ( funk , wksp );
1026
+ fd_funkier_rec_pool_lock ( & rec_pool , 1 );
1027
+ fd_funkier_txn_start_read ( funk );
1028
+
1060
1029
if ( tpool == NULL || fd_tpool_worker_cnt ( tpool ) <= 1U ) {
1061
1030
ulong num_pairs = 0UL ;
1062
1031
fd_lthash_value_t * lthash_values = fd_spad_alloc ( runtime_spad , FD_LTHASH_VALUE_ALIGN , FD_LTHASH_VALUE_FOOTPRINT );
@@ -1066,7 +1035,7 @@ fd_accounts_hash( fd_funkier_t * funk,
1066
1035
FD_PUBKEY_HASH_PAIR_ALIGN ,
1067
1036
funk -> rec_max * sizeof (fd_pubkey_hash_pair_t ) );
1068
1037
1069
- fd_accounts_sorted_subrange_gather ( funk , 0 , 1 , & num_pairs , lthash_values , 0 , pairs , features , runtime_spad );
1038
+ fd_accounts_sorted_subrange_gather ( funk , 0 , 1 , & num_pairs , lthash_values , 0 , pairs , features );
1070
1039
if ( FD_UNLIKELY ( !pairs ) ) {
1071
1040
FD_LOG_ERR (( "failed to allocate memory for account hash" ));
1072
1041
}
@@ -1097,7 +1066,6 @@ fd_accounts_hash( fd_funkier_t * funk,
1097
1066
.num_lists = num_lists ,
1098
1067
.lists = lists ,
1099
1068
.lthash_values = lthash_values ,
1100
- .runtime_spad = runtime_spad ,
1101
1069
};
1102
1070
1103
1071
fd_tpool_exec_all_rrobin ( tpool , 0UL , num_lists , fd_accounts_sorted_subrange_count_task , & task_info ,
@@ -1126,6 +1094,9 @@ fd_accounts_hash( fd_funkier_t * funk,
1126
1094
} else
1127
1095
FD_LOG_NOTICE (( "accounts_hash %s" , FD_BASE58_ENC_32_ALLOCA ( accounts_hash -> hash ) ));
1128
1096
1097
+ fd_funkier_rec_pool_unlock ( & rec_pool );
1098
+ fd_funkier_txn_end_read ( funk );
1099
+
1129
1100
return 0 ;
1130
1101
}
1131
1102
0 commit comments