Skip to content

Commit

Permalink
Add fee_est tool for debugging fee estimation code
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Mar 5, 2019
1 parent b1a0846 commit e233047
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 11 deletions.
40 changes: 39 additions & 1 deletion src/Makefile.test.include
Expand Up @@ -29,7 +29,11 @@ FUZZ_TARGETS = \
if ENABLE_FUZZ
noinst_PROGRAMS += $(FUZZ_TARGETS:=)
else
# Avoid link errors (multiple defintion of `main', undefined reference to
# `LLVMFuzzerTestOneInput') trying to build these binaries when fuzzing is
# enabled, by excluding them from the default make target.
bin_PROGRAMS += test/test_bitcoin
noinst_PROGRAMS += test/fee_est/fee_est
endif

TEST_SRCDIR = test
Expand Down Expand Up @@ -170,7 +174,7 @@ test_test_bitcoin_LDADD += $(BDB_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(RAPIDC
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static

if ENABLE_ZMQ
test_test_bitcoin_LDADD += $(ZMQ_LIBS)
test_test_bitcoin_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif

if ENABLE_FUZZ
Expand Down Expand Up @@ -532,6 +536,40 @@ test_fuzz_blocktransactionsrequest_deserialize_LDADD = \
test_fuzz_blocktransactionsrequest_deserialize_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
endif # ENABLE_FUZZ

# fee_est/fee_est binary #
test_fee_est_fee_est_SOURCES = test/fee_est/fee_est.cpp
test_fee_est_fee_est_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fee_est_fee_est_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fee_est_fee_est_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fee_est_fee_est_LDADD = \
$(LIBBITCOIN_SERVER)

if ENABLE_WALLET
test_fee_est_fee_est_LDADD += \
$(LIBBITCOIN_WALLET)
endif

test_fee_est_fee_est_LDADD += \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_CRYPTO_SSE41) \
$(LIBBITCOIN_CRYPTO_AVX2) \
$(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
$(LIBSECP256K1) \
$(LIBUNIVALUE) \
$(BDB_LIBS) \
$(BOOST_LIBS) \
$(CRYPTO_LIBS) \
$(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) \
$(MINIUPNPC_LIBS)

if ENABLE_ZMQ
test_fee_est_fee_est_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif
#

nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

$(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
Expand Down
38 changes: 38 additions & 0 deletions src/test/fee_est/README.md
@@ -0,0 +1,38 @@
src/test/fee_est -- Fee estimation offline testing tool
=======================================================

The `fee_est` tool is intended to help debug and test changes in bitcoin fee
estimation code using transaction data gathered from live bitcoin nodes.

Transaction data can be collected by running bitcoind with `-estlog` parameter
which will produce newline-delimited json file
([ndjson.org](http://ndjson.org/), [jsonlines.org](http://jsonlines.org/))
which logs relevant transaction information. The `fee_est` tool can parse the
log to produce graphs of fee estimation data and do some basic analysis of the
results. The implementation is intended to be simple enough that it can be
easily customized to do more specific analysis.

Example usage:

Run bitcoind collecting fee estimation data:

```
$ make -C src bitcoind test/fee_est/fee_est
$ src/bitcoind -estlog=est.log &
```

Run fee estimation tool producing graph of estimates:

```
$ src/test/fee_est/fee_est -ograph=graph.html est.log
$ chrome graph.html
```

Run fee estimation tool computing some basic statistics:

```
$ src/test/fee_est/fee_est -cross est.log
Non-test txs: 1407226
Test txs: 5603 total (4345 kept, 631 discarded unconfirmed, 627 discarded outliers)
Mean squared error: 71.0651
```

0 comments on commit e233047

Please sign in to comment.