@@ -247,6 +247,7 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
247247 };
248248
249249 while (!m_flag_interrupt_sv2) {
250+ uint256 prev_hash;
250251 if (!block_template) {
251252 LogPrintLevel (BCLog::SV2, BCLog::Level::Trace, " Generate initial block template for client id=%zu\n " ,
252253 client_id);
@@ -269,7 +270,7 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
269270 LogPrintLevel (BCLog::SV2, BCLog::Level::Trace, " Assemble template: %.2fms\n " ,
270271 Ticks<MillisecondsDouble>(SteadyClock::now () - time_start));
271272
272- uint256 prev_hash{ block_template->getBlockHeader ().hashPrevBlock } ;
273+ prev_hash = block_template->getBlockHeader ().hashPrevBlock ;
273274 {
274275 LOCK (m_tp_mutex);
275276 if (prev_hash != m_best_prev_hash) {
@@ -280,7 +281,7 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
280281
281282 // Add template to cache before sending it, to prevent race
282283 // condition: https://github.com/stratum-mining/stratum/issues/1773
283- m_block_template_cache.insert ({template_id,block_template});
284+ m_block_template_cache.insert ({template_id,std::make_pair (prev_hash, block_template) });
284285 }
285286
286287 {
@@ -327,7 +328,6 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
327328 client_id);
328329 }
329330
330- uint256 old_prev_hash{block_template->getBlockHeader ().hashPrevBlock };
331331 std::shared_ptr<BlockTemplate> tmpl = block_template->waitNext (options);
332332 // The client may have disconnected during the wait, check now to avoid
333333 // a spurious IPC call and confusing log statements.
@@ -343,7 +343,7 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
343343
344344 {
345345 LOCK (m_tp_mutex);
346- if (new_prev_hash != old_prev_hash ) {
346+ if (new_prev_hash != prev_hash ) {
347347 LogPrintLevel (BCLog::SV2, BCLog::Level::Trace, " Tip changed, client id=%zu\n " ,
348348 client_id);
349349 future_template = true ;
@@ -356,7 +356,7 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id)
356356
357357 // Add template to cache before sending it, to prevent race
358358 // condition: https://github.com/stratum-mining/stratum/issues/1773
359- m_block_template_cache.insert ({m_template_id,block_template});
359+ m_block_template_cache.insert ({m_template_id, std::make_pair (new_prev_hash, block_template) });
360360 }
361361
362362 {
@@ -403,7 +403,7 @@ void Sv2TemplateProvider::RequestTransactionData(Sv2Client& client, node::Sv2Req
403403
404404 return ;
405405 }
406- block = (*cached_block->second ).getBlock ();
406+ block = (*cached_block->second . second ).getBlock ();
407407 }
408408
409409 {
@@ -478,7 +478,7 @@ void Sv2TemplateProvider::SubmitSolution(node::Sv2SubmitSolutionMsg solution)
478478 * on the network. In case of a reorg the node will be able to switch
479479 * faster because it already has (but not fully validated) the block.
480480 */
481- block_template = cached_block_template->second ;
481+ block_template = cached_block_template->second . second ;
482482 }
483483
484484 // Submit the solution to construct and process the block
@@ -536,7 +536,7 @@ void Sv2TemplateProvider::PruneBlockTemplateCache()
536536 // If the blocks prevout is not the tip's prevout, delete it.
537537 uint256 prev_hash = m_best_prev_hash;
538538 std::erase_if (m_block_template_cache, [prev_hash] (const auto & kv) {
539- if (kv.second -> getBlockHeader (). hashPrevBlock != prev_hash) {
539+ if (kv.second . first != prev_hash) {
540540 return true ;
541541 }
542542 return false ;
0 commit comments