MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CalculateBumpFees

Method CalculateBumpFees

src/node/mini_miner.cpp:309–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309std::map<COutPoint, CAmount> MiniMiner::CalculateBumpFees(const CFeeRate& target_feerate)
310{
311 if (!m_ready_to_calculate) return {};
312 // Build a block template until the target feerate is hit.
313 BuildMockTemplate(target_feerate);
314
315 // Each transaction that "made it into the block" has a bumpfee of 0, i.e. they are part of an
316 // ancestor package with at least the target feerate and don't need to be bumped.
317 for (const auto& txid : m_in_block) {
318 // Not all of the block transactions were necessarily requested.
319 auto it = m_requested_outpoints_by_txid.find(txid);
320 if (it != m_requested_outpoints_by_txid.end()) {
321 for (const auto& outpoint : it->second) {
322 m_bump_fees.emplace(outpoint, 0);
323 }
324 m_requested_outpoints_by_txid.erase(it);
325 }
326 }
327
328 // A transactions and its ancestors will only be picked into a block when
329 // both the ancestor set feerate and the individual feerate meet the target
330 // feerate.
331 //
332 // We had to convince ourselves that after running the mini miner and
333 // picking all eligible transactions into our MockBlockTemplate, there
334 // could still be transactions remaining that have a lower individual
335 // feerate than their ancestor feerate. So here is an example:
336 //
337 // ┌─────────────────┐
338 // │ │
339 // │ Grandparent │
340 // │ 1700 vB │
341 // │ 1700 sats │ Target feerate: 10 s/vB
342 // │ 1 s/vB │ GP Ancestor Set Feerate (ASFR): 1 s/vB
343 // │ │ P1_ASFR: 9.84 s/vB
344 // └──────▲───▲──────┘ P2_ASFR: 2.47 s/vB
345 // │ │ C_ASFR: 10.27 s/vB
346 // ┌───────────────┐ │ │ ┌──────────────┐
347 // │ ├────┘ └────┤ │ ⇒ C_FR < TFR < C_ASFR
348 // │ Parent 1 │ │ Parent 2 │
349 // │ 200 vB │ │ 200 vB │
350 // │ 17000 sats │ │ 3000 sats │
351 // │ 85 s/vB │ │ 15 s/vB │
352 // │ │ │ │
353 // └───────────▲───┘ └───▲──────────┘
354 // │ │
355 // │ ┌───────────┐ │
356 // └────┤ ├────┘
357 // │ Child │
358 // │ 100 vB │
359 // │ 900 sats │
360 // │ 9 s/vB │
361 // │ │
362 // └───────────┘
363 //
364 // We therefore calculate both the bump fee that is necessary to elevate
365 // the individual transaction to the target feerate:
366 // target_feerate × tx_size - tx_fees

Callers 3

BOOST_FIXTURE_TEST_CASEFunction · 0.80
mini_miner.cppFile · 0.80

Calls 9

findMethod · 0.80
emplaceMethod · 0.80
GetSizeWithAncestorsMethod · 0.80
endMethod · 0.45
eraseMethod · 0.45
GetFeeMethod · 0.45
GetModifiedFeeMethod · 0.45
GetTxSizeMethod · 0.45

Tested by 1

BOOST_FIXTURE_TEST_CASEFunction · 0.64