Skip to content

Commit b649e03

Browse files
committed
Create new BlockPolicyEstimator for fee estimates
This class groups transactions that have been confirmed in blocks into buckets, based on either their fee or their priority. Then for each bucket, the class calculates what percentage of the transactions were confirmed within various numbers of blocks. It does this by keeping an exponentially decaying moving history for each bucket and confirm block count of the percentage of transactions in that bucket that were confirmed within that number of blocks. -Eliminate txs which didn't have all inputs available at entry from fee/pri calcs -Add dynamic breakpoints and tracking of confirmation delays in mempool transactions -Remove old CMinerPolicyEstimator and CBlockAverage code -New smartfees.py -Pass a flag to the estimation code, using IsInitialBlockDownload as a proxy for when we are still catching up and we shouldn't be counting how many blocks it takes for transactions to be included. -Add a policyestimator unit test
1 parent b6ea3bc commit b649e03

File tree

10 files changed

+1267
-424
lines changed

10 files changed

+1267
-424
lines changed

qa/rpc-tests/smartfees.py

Lines changed: 224 additions & 57 deletions
Large diffs are not rendered by default.

qa/rpc-tests/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ def check_json_precision():
3333
if satoshis != 2000000000000003:
3434
raise RuntimeError("JSON encode/decode loses precision")
3535

36-
def sync_blocks(rpc_connections):
36+
def sync_blocks(rpc_connections, wait=1):
3737
"""
3838
Wait until everybody has the same block count
3939
"""
4040
while True:
4141
counts = [ x.getblockcount() for x in rpc_connections ]
4242
if counts == [ counts[0] ]*len(counts):
4343
break
44-
time.sleep(1)
44+
time.sleep(wait)
4545

46-
def sync_mempools(rpc_connections):
46+
def sync_mempools(rpc_connections, wait=1):
4747
"""
4848
Wait until everybody has the same transactions in their memory
4949
pools
@@ -56,7 +56,7 @@ def sync_mempools(rpc_connections):
5656
num_match = num_match+1
5757
if num_match == len(rpc_connections):
5858
break
59-
time.sleep(1)
59+
time.sleep(wait)
6060

6161
bitcoind_processes = {}
6262

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ BITCOIN_CORE_H = \
105105
netbase.h \
106106
net.h \
107107
noui.h \
108+
policy/fees.h \
108109
pow.h \
109110
primitives/block.h \
110111
primitives/transaction.h \
@@ -181,6 +182,7 @@ libbitcoin_server_a_SOURCES = \
181182
miner.cpp \
182183
net.cpp \
183184
noui.cpp \
185+
policy/fees.cpp \
184186
pow.cpp \
185187
rest.cpp \
186188
rpcblockchain.cpp \

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ BITCOIN_TESTS =\
5656
test/multisig_tests.cpp \
5757
test/netbase_tests.cpp \
5858
test/pmt_tests.cpp \
59+
test/policyestimator_tests.cpp \
5960
test/pow_tests.cpp \
6061
test/rpc_tests.cpp \
6162
test/sanity_tests.cpp \

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
974974
CAmount nFees = nValueIn-nValueOut;
975975
double dPriority = view.GetPriority(tx, chainActive.Height());
976976

977-
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height());
977+
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), mempool.HasNoInputsOf(tx));
978978
unsigned int nSize = entry.GetTxSize();
979979

980980
// Don't accept it if it can't get into a block
@@ -1040,7 +1040,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
10401040
}
10411041

10421042
// Store transaction in memory
1043-
pool.addUnchecked(hash, entry);
1043+
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
10441044
}
10451045

10461046
SyncWithWallets(tx, NULL);
@@ -2042,7 +2042,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
20422042
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
20432043
// Remove conflicting transactions from the mempool.
20442044
list<CTransaction> txConflicted;
2045-
mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted);
2045+
mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted, !IsInitialBlockDownload());
20462046
mempool.check(pcoinsTip);
20472047
// Update chainActive & related variables.
20482048
UpdateTip(pindexNew);

0 commit comments

Comments
 (0)