Post
Topic
Board Development & Technical Discussion
Merits 2 from 1 user
Re: How do miners solve the knapsack problem?
by
mikeywith
on 19/07/2024, 01:45:37 UTC
⭐ Merited by ABCbits (2)
To optimize their profits, do miners use software like Gurobi or other LP-solvers to solve the knapsack problem and select the most profitable transactions?
I'm only talking about honest miners who only want to maximize their profits.

I'd assume that most pools use Bitcoin Core's getblocktemplate function. The way it works is very simple and straightforward: it prioritizes high-fee transactions, taking into account transactions that depend on other transactions like CPFP transactions. You can go on GitHub and find the Core repo, look for the BlockAssembler class in miner.cpp.

getblocktemplate is obviously just a trial-and-error-and-hope-for-the-best solution to the knapsack problem. As mentioned above, since it's also NP-hard, you just can't tell what the best solution is. Also, given that most Bitcoin transactions have the same size, it makes the default greedy algorithm somewhat pretty efficient since the operation is just straightforward for most cases.

Obviously, other pools like Ocean have their own way of selecting transactions since they ban a dozen of them. Other pools like ViaBTC, which offers a transaction acceleration service, will prioritize their paid transactions when constructing a block. Except for Kano.is and CKsolo, I don't think anyone else makes anything that technical public.