Skip to content

Commit f45a010

Browse files
authored
Merge pull request aeonix#37 from stoffu/aeon-fill-template-fix
tx_pool.fill_block_template: fix miscalculation of total size and fee
2 parents 3150946 + 7208080 commit f45a010

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/cryptonote_core/tx_pool.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,8 @@ namespace cryptonote
11891189
}
11901190

11911191
bool is_nofake_tx = false;
1192+
bool can_nofake_tx_be_simply_added = false;
1193+
bool can_nofake_tx_replace_existing_tx = false;
11921194
if (tx.vin.size() > 0)
11931195
{
11941196
if (version >= 2)
@@ -1251,7 +1253,6 @@ namespace cryptonote
12511253

12521254
LOG_PRINT_L2("We have currently " << nofake_txs_taken << " non-private transactions out of " << n << " transactions in the block");
12531255

1254-
bool can_nofake_tx_be_simply_added = false;
12551256
if (nofake_txs_taken + 1 <= rational_ceil((n + 1) * NOFAKE_TXS_TO_TOTAL_TXS_PERCENT, 100))
12561257
{
12571258
LOG_PRINT_L2("Checking if this tx can be simply added");
@@ -1267,7 +1268,6 @@ namespace cryptonote
12671268
}
12681269
}
12691270

1270-
bool can_nofake_tx_replace_existing_tx = false;
12711271
if (!can_nofake_tx_be_simply_added && n > nofake_txs_taken && nofake_txs_taken + 1 <= rational_ceil(n * NOFAKE_TXS_TO_TOTAL_TXS_PERCENT, 100))
12721272
{
12731273
LOG_PRINT_L2("Checking if this tx can replace an already added tx");
@@ -1279,9 +1279,6 @@ namespace cryptonote
12791279
{
12801280
LOG_PRINT_L2(" replacing existing tx " << bl.tx_hashes.back() << " with this tx would increase coinbase to " << print_money(coinbase));
12811281
can_nofake_tx_replace_existing_tx = true;
1282-
bl.tx_hashes.pop_back();
1283-
tx_sizes.pop_back();
1284-
tx_fees.pop_back();
12851282
}
12861283
}
12871284
}
@@ -1350,6 +1347,16 @@ namespace cryptonote
13501347
tx_sizes.insert(tx_sizes.begin(), meta.blob_size); // not really needed, just to make these two arrays in correspondence with bl.tx_hashes
13511348
tx_fees.insert(tx_fees.begin(), meta.fee);
13521349

1350+
if (can_nofake_tx_replace_existing_tx)
1351+
{
1352+
// remove the least profitable tx at the back of the array
1353+
bl.tx_hashes.pop_back();
1354+
total_size -= tx_sizes.back();
1355+
fee -= tx_fees.back();
1356+
tx_sizes.pop_back();
1357+
tx_fees.pop_back();
1358+
}
1359+
13531360
nofake_txs_taken++;
13541361
}
13551362
else

0 commit comments

Comments
 (0)