Skip to content

Commit f4494a9

Browse files
committed
use undo data for prevouts
Completely untested.
1 parent ec4633f commit f4494a9

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/bitcoin-coinjoins.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <util/signalinterrupt.h>
3232
#include <util/task_runner.h>
3333
#include <util/translation.h>
34+
#include <undo.h>
3435
#include <validation.h>
3536
#include <validationinterface.h>
3637

@@ -171,16 +172,19 @@ int main(int argc, char* argv[])
171172
LOCK(chainman.GetMutex());
172173
current_block = chainman.ActiveChain()[block_height];
173174
}
174-
CCoinsViewCache &view = chainman.ActiveChainstate().CoinsTip();
175175
std::cout << "AFTER VIEW" << std::endl;
176176
std::cout << "BEFORE LOOP" << std::endl;
177177

178178
while (current_block) {
179179
std::cout << "TEST" << std::endl;
180180

181181
CBlock block;
182-
chainman.m_blockman.ReadBlockFromDisk(block, *current_block);
183-
CFeeRate fee_rate = GetMedianFeeRateFromBlock(block, view);
182+
CBlockUndo undo;
183+
bool read_success = false;
184+
read_success = chainman.m_blockman.ReadBlockFromDisk(block, *current_block);
185+
read_success &= chainman.m_blockman.UndoReadFromDisk(undo, *current_block);
186+
assert(read_success);
187+
CFeeRate fee_rate = GetMedianFeeRateFromBlock(block, undo);
184188
// the get feerate function
185189

186190
for (const CTransactionRef& tx : block.vtx) {

src/util/coinjoins.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <coins.h>
77
#include <consensus/validation.h>
88
#include <util/coinjoins.h>
9+
#include <undo.h>
910

1011
bool WhirlpoolTransactions::isWhirlpool(const CTransactionRef& tx) {
1112
if (tx->vin.size() == 5 && tx->vout.size() == 5) {
@@ -29,15 +30,17 @@ bool WhirlpoolTransactions::isWhirlpool(const CTransactionRef& tx) {
2930
return false;
3031
}
3132

32-
CFeeRate GetMedianFeeRateFromBlock(const CBlock& block, CCoinsViewCache &view) {
33+
CFeeRate GetMedianFeeRateFromBlock(const CBlock& block, const CBlockUndo &undo) {
3334
// calculate median fee rate
3435
std::vector<CFeeRate> feeRates;
35-
for (const auto& tx : block.vtx) {
36+
// Skip coinbase
37+
for(size_t txindex = 1; txindex < block.vtx.size(); txindex++) {
38+
const auto& tx = block.vtx[txindex];
39+
// vtxundo is offset by 1 because the coinbase tx is not present.
40+
const auto& undotx = undo.vtxundo[txindex - 1];
3641
CAmount value_in = 0;
37-
for (auto &v : tx->vin) {
38-
const COutPoint &prevout = v.prevout;
39-
const Coin& coin = view.AccessCoin(prevout);
40-
value_in += coin.out.nValue;
42+
for (const auto& prevout : undotx.vprevout) {
43+
value_in += prevout.out.nValue;
4144
}
4245
CAmount value_out = tx->GetValueOut();
4346
size_t txSize = GetTransactionWeight(*tx);

src/util/coinjoins.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class Tx0s {
5555
return tx0_set.size();
5656
}
5757
};
58-
59-
CFeeRate GetMedianFeeRateFromBlock(const CBlock& block, CCoinsViewCache &view);
58+
class CBlockUndo;
59+
CFeeRate GetMedianFeeRateFromBlock(const CBlock& block, const CBlockUndo& undo);
6060

6161
class WhirlpoolTransactions {
6262
Tx0s tx0s;

0 commit comments

Comments
 (0)