@@ -86,53 +86,58 @@ impl Miner {
86
86
let progress_bar = progress_bar. clone ( ) ;
87
87
let mut memory = equix:: SolverMemory :: new ( ) ;
88
88
move || {
89
- let res = core_affinity:: set_for_current ( i) ;
90
- if res {
91
- let timer = Instant :: now ( ) ;
92
- let mut nonce =
93
- u64:: MAX . saturating_div ( cores) . saturating_mul ( i. id as u64 ) ;
94
- let mut best_nonce = nonce;
95
- let mut best_difficulty = 0 ;
96
- let mut best_hash = Hash :: default ( ) ;
97
- loop {
98
- // Create hash
99
- if let Ok ( hx) = drillx:: hash_with_memory (
100
- & mut memory,
101
- & proof. challenge ,
102
- & nonce. to_le_bytes ( ) ,
103
- ) {
104
- let difficulty = hx. difficulty ( ) ;
105
- if difficulty. gt ( & best_difficulty) {
106
- best_nonce = nonce;
107
- best_difficulty = difficulty;
108
- best_hash = hx;
109
- }
89
+ // Return if core should not be used
90
+ if ( i. id as u64 ) . ge ( & cores) {
91
+ return ( 0 , 0 , Hash :: default ( ) ) ;
92
+ }
93
+
94
+ // Pin to core
95
+ if !core_affinity:: set_for_current ( i) {
96
+ return ( 0 , 0 , Hash :: default ( ) ) ;
97
+ }
98
+
99
+ // Start hashing
100
+ let timer = Instant :: now ( ) ;
101
+ let mut nonce = u64:: MAX . saturating_div ( cores) . saturating_mul ( i. id as u64 ) ;
102
+ let mut best_nonce = nonce;
103
+ let mut best_difficulty = 0 ;
104
+ let mut best_hash = Hash :: default ( ) ;
105
+ loop {
106
+ // Create hash
107
+ if let Ok ( hx) = drillx:: hash_with_memory (
108
+ & mut memory,
109
+ & proof. challenge ,
110
+ & nonce. to_le_bytes ( ) ,
111
+ ) {
112
+ let difficulty = hx. difficulty ( ) ;
113
+ if difficulty. gt ( & best_difficulty) {
114
+ best_nonce = nonce;
115
+ best_difficulty = difficulty;
116
+ best_hash = hx;
110
117
}
118
+ }
111
119
112
- // Exit if time has elapsed
113
- if nonce % 100 == 0 {
114
- if timer. elapsed ( ) . as_secs ( ) . ge ( & cutoff_time) {
115
- if best_difficulty. ge ( & min_difficulty) {
116
- // Mine until min difficulty has been met
117
- break ;
118
- }
119
- } else if cores == 0 {
120
- progress_bar. set_message ( format ! (
121
- "Mining... ({} sec remaining)" ,
122
- cutoff_time. saturating_sub( timer. elapsed( ) . as_secs( ) ) ,
123
- ) ) ;
120
+ // Exit if time has elapsed
121
+ if nonce % 100 == 0 {
122
+ if timer. elapsed ( ) . as_secs ( ) . ge ( & cutoff_time) {
123
+ if best_difficulty. ge ( & min_difficulty) {
124
+ // Mine until min difficulty has been met
125
+ break ;
124
126
}
127
+ } else if cores == 0 {
128
+ progress_bar. set_message ( format ! (
129
+ "Mining... ({} sec remaining)" ,
130
+ cutoff_time. saturating_sub( timer. elapsed( ) . as_secs( ) ) ,
131
+ ) ) ;
125
132
}
126
-
127
- // Increment nonce
128
- nonce += 1 ;
129
133
}
130
134
131
- // Return the best nonce
132
- ( best_nonce, best_difficulty, best_hash)
133
- } else {
134
- ( 0 , 0 , Hash :: default ( ) )
135
+ // Increment nonce
136
+ nonce += 1 ;
135
137
}
138
+
139
+ // Return the best nonce
140
+ ( best_nonce, best_difficulty, best_hash)
136
141
}
137
142
} )
138
143
} )
0 commit comments