Skip to content

Commit

Permalink
Have waitFeesChanged() frequently make a template
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Sep 30, 2024
1 parent ffc936d commit c0408d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class Mining
* Waits for fees in the next block to rise, a new tip or the timeout.
*
* @param[in] current_tip block hash that the most recent template builds on
* @param[in] fee_threshold how far total fees for the next block should rise (currently ignored)
* @param[in] fee_threshold how far total fees for the next block should rise
* @param[in] options currently ignored: options for creating the block, should match those
* passed to createNewBlock (currently ignored)
* passed to createNewBlock
*
* @returns true if fees increased, false if a new tip arrives or the timeout occurs
*/
Expand Down
18 changes: 15 additions & 3 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ class MinerImpl : public Mining

BlockAssembler::Options assemble_options{options};
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
// It's not necessary to verify the template, since we don't return it.
// This is also faster.
assemble_options.test_block_validity = false;

while (!chainman().m_interrupt) {
now = std::chrono::steady_clock::now();
Expand All @@ -977,9 +980,18 @@ class MinerImpl : public Mining
return false;
}

// TODO: when cluster mempool is available, actually calculate
// fees for the next block. This is currently too expensive.
if (context()->mempool->GetTransactionsUpdated() > last_mempool_update) return true;
// Did anything change at all?
if (context()->mempool->GetTransactionsUpdated() != last_mempool_update) {
auto block_template{BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(CScript())};

CAmount fees = 0;
for (CAmount fee : block_template->vTxFees) {
// Skip coinbase
if (fee < 0) continue;
fees += fee;
if (fees >= fee_threshold) return true;
}
}

std::this_thread::sleep_until(std::min(deadline, now + tick));
}
Expand Down

0 comments on commit c0408d6

Please sign in to comment.