Commit graph

154 commits

Author SHA1 Message Date
Calin Culianu
f63eea29f4
Added config options for workqueue and worker_threads
These control the number of jobs that may be enqueued before error, and
the number of concurrent threads to process jobs, respectively.

Also renamed 'misc' subdir to 'doc'

Also added some /stats: show all the configured global Options as they
came in from conf file/CLI. ("Config" subdict in /stats JSON).
2020-01-07 10:36:41 +02:00
Calin Culianu
d579a41cb3
Nit: Made all of the shared_ptr<Options> -> shared_ptr<const Options>
Except for in App.cpp, which is the place where they are created and the
only place the options may be modified (at app startup as a result of
parsing config).

Otherwise the options are const, which ensures they are immutable on the
type level (and thus don't need to be guarded with locks and can be
accessed by multiple threads for reading).
2020-01-06 08:57:24 +02:00
Calin Culianu
120f29b68b
Fixed some misplaced call args for callOnTimerSoon
Mistakenly passed a Qt::TimerType for the bool "force" arg.  Luckily
this didn't cause any problems with existing code.
2020-01-05 03:26:40 +02:00
Calin Culianu
6a7db8b5e8
Fee histogram method is implemented 2020-01-05 03:03:03 +02:00
Calin Culianu
647e2db4c8
Fee historgram testing 2020-01-05 02:49:42 +02:00
Calin Culianu
0f25722fb0
wip 2020-01-05 02:16:02 +02:00
Calin Culianu
1da2834612 Config file: added support for banner and donation variables.
Banner still needs variable substitution.
2020-01-04 13:26:25 +02:00
Calin Culianu
adbf65eed3
Initial impl. of config file mechanism. Works!
Next up: Support multiple tcp, ssl, stats args in the conf file.
2020-01-03 23:28:57 +02:00
Calin Culianu
18b20a1228
Bugfix for Linux: It turns out timer events always arrive after signals
This is on Linux only.  Who knew?  Thanks for Jt for finding this bug.

We had to go ahead and get rid of the Util::AsyncOnObject() call in
putBlock and lieu of a signal/slot connection (putBlock connected to
protected on_putBlock).

This fixes the race condition observed on Linux only whereby blocks
would be done downloading but the download task would get deleted before
the blocks could get processed by the Controller.

By making all of the events the Controller listens for arrive via
signals now, we avoid any out-of-order issues since signals themselves
always get delivered in order (whereas it appears timers get processed
AFTER the signals but only on Linux! On windows and macos they do not!).
2020-01-02 15:32:21 +02:00
Calin Culianu
2fc37d4e09
Paranoia nit about Debug("%s", __FUNCTION)..
Had issues with that when building in debug mode due to possible
compiler bugs. Switched to stream-style.
2020-01-01 22:51:56 +02:00
Calin Culianu
149e60eb0b
explicitly set maximum load factor for tx->hashXs to 1.0 for mempool 2020-01-01 17:27:56 +02:00
Calin Culianu
a9e6f00f90
Small memory footpring tweak for Mempool.h data and Controller.cpp
management of mempool data

rehash the fixed sized maps/sets to their fixed size to make load factor
as close to 1.0 as possible (thus not wasting space).
2020-01-01 17:10:20 +02:00
Calin Culianu
f4b4f95eec
Performance, efficiency and nit fixups for Controller and Mempool
We enforce re-use of the same underlying memory for all scriptHashes as
we update the mempool. This should significantly save memory in
pathological/large mempool situations where many of the tx's involve
the same address.

We also compactified the mempool data structure a bit, removed unused
data members (depends, spentBy), and decided to calculate fee ourselves
by doing ins - outs.  (This avoids potential problems we may have seen
where doubles cause off-by-one errors for sats).

Also cleaned up Controller::process a little bit to have a well-defined
state when "waiting for chain info".
2020-01-01 13:54:48 +02:00
Calin Culianu
4ae2b684ca Linux compile fixups and Qt 5.11 fixups 2019-12-31 19:29:48 +02:00
Calin Culianu
ae4820e717
Bumped the mempool stats printer to once per minute 2019-12-31 17:45:47 +02:00
Calin Culianu
3ba9a40b9d
Fixups to Mempool data structure (maintained by Controller.cpp)
Made the txos be a vector, rather than a slow-ish/bloated map. This
should be much faster.

Also various other small tune-ups.

Added "Broadcast tx.." message to log on broadcast.

More to come!
2019-12-31 16:22:52 +02:00
Calin Culianu
9b351f29ae
More efficiencies added to mempool synch, plus ENABLED NOTIFICATIONS
Cleaned up the code a bit.  Still a WIP and needs performance tuning.
2019-12-31 13:14:27 +02:00
Calin Culianu
a37d623ca2
Initial steps in making the mempool use less memory & CPU
- Made the hashXTxs mapped_type be a std::vector<TxRef> rather than a
std::set<TxRef>.  We manually maintain the uniqueness and sort invariant
as we process the mempool.  Vectors are much more compact memory-wise
and also have better insert characteristics, so we prefer them here.

Also, we never check for set membership, so the O log N lookup of the
set is not warranted.

We do however potentially build very large hashX -> TxRef arrays so a
std::vector is much better.

After this fix, we need to see what else in this data structure is
wasteful. I may get rid of the "txos" std::map<IONum, TXOInfo> in favor of a
simple and direct std::vector<TXOInfo>
2019-12-31 04:17:06 +02:00
Calin Culianu
fe8efd50b2
Nits in printMempoolStatusToLog 2019-12-31 00:50:51 +02:00
Calin Culianu
8ce34ca921
Nit fixups to some templates in Util.h: toList and toVec
Made them easier to use, leveraging C++17 type deduction.
2019-12-30 17:37:59 +02:00
Calin Culianu
4c8647c2ae
Added subs totals per-client, as well as per-sh + stats port
- Totals kept track of on sub per-client, as well as app-wide.
- Also added the /stats enpoint debug/stats info for the SubsMgr
2019-12-30 14:58:16 +02:00
Calin Culianu
532f11e95d
Fixed crash bug in SubsMgr::removeZombies + redid ownership of SubsMgr
- The crash bug was due to misuse of
robin_hood::unordered_flat_map::erase (it's still kind of bizarre that
it would crash the way it did, but I suppose the next iterator was
invalidated somehow).  We instead grab the next returned by .erase() and
now it works ok.

- We redid the ownership model of SubsMgr.  Rather than having
Controller own it and pass it all the way down to the Server instances,
we instead have Storage create & own it.  This is needed because in the
future Storage may need to invalidate cached sub statuses as blocks are
undone in undoLatestBlock, and/or it may need to atomically add
notifications as blocks are added.  So it makes sense for Storage to own
the SubsMgr (as it also owns the Mempool, which has similar ephemeral
qualities).
2019-12-30 10:33:35 +02:00
Calin Culianu
79e810dc0d
Fixed crash bug
Not sure why it was crashing in debug mode in ~CtlTask but I think it
was due to a compiler bug using __FUNCTION__ + Debug(printf_format).  We
switched it up and it no longer crashes.
2019-12-30 01:58:54 +02:00
Calin Culianu
d876eecd0f
WIP 2019-12-29 22:57:04 +02:00
Calin Culianu
e2ca3fdc1e
fixed bugs 2019-12-29 11:38:24 +02:00
Calin Culianu
2eb63fbbb6
bugfix 2019-12-29 11:27:12 +02:00
Calin Culianu
115acb7161
testing 2019-12-29 11:19:40 +02:00
Calin Culianu
32c68d18c9
Fixed bug with OP_RETURN in mempool 2019-12-29 10:33:22 +02:00
Calin Culianu
c57eeb5f01
nits 2019-12-29 10:21:19 +02:00
Calin Culianu
c298532058
Reduced the frequency of mempool status printing to the log
The rule is: debug mode prints every time it changes to debug logger.
Normal logger prints at most once every 30 seconds, and only if the
mempool is non-empty and if the size has changed, and if "up-to-date"
(in Controller).

The logic is a bit convoluted, but at least it doesn't print too often.
2019-12-29 09:47:46 +02:00
Calin Culianu
7b4514b412
Made poll interval be 2 seconds
Also got rid of some of the debug log spam for GetChainInfoTask and
SynchMempoolTask -- they only print stuff if new stuff is found.

misc other nits.
2019-12-29 00:45:09 +02:00
Calin Culianu
a831cce8ac
Modified license preamble to say "Bitcoin Cash" instead of "Electron Cash"
The hope is maybe people will adopt this with other wallets...
2019-12-28 23:48:24 +02:00
Calin Culianu
405335c173
Added LICENSE preamble to all top-level source files
GPL v3. YAY!
2019-12-28 23:46:05 +02:00
Calin Culianu
20da1f0c8b
Misc odds and ends
Added license to project, and other goodies. Added -T option for poll
timer. Misc other things added.
2019-12-28 23:26:16 +02:00
Calin Culianu
7269022c7a
nits 2019-12-28 16:34:50 +02:00
Calin Culianu
75314137c4 wip 2019-12-28 15:10:07 +02:00
Calin Culianu
2dd133806b
Set undo depth to 100 blocks.
Because.. why not? :)
2019-12-24 21:15:48 +02:00
Calin Culianu
090bd16ee7
Initial try at SSL support. Works.. mostly.
Not sure about the cert/key situation.  Seemed fragile on macos.
Hopefully windows works without too much library static linking
insanity.
2019-12-24 16:49:47 +02:00
Calin Culianu
1c81ad8b98
Replaced LRU::Cache with a cost-based cache for Height2TxHashes
We wrapped the QCache class which is a very light weight, cost-based LRU
cache.  It wasn't thread safe so we wrapped all its methods in
thread-safe versions.

Now we have a very accurate bound on memory usage for caching.  We may
want to replace the other height2txhash cache with this new class as
well since this new cost cache seems to be much more efficient.
2019-12-24 13:18:44 +02:00
Calin Culianu
7434754449
Misc. nits in Controller.cpp and Servers.cpp
Just paranoia/defensive programming.

Also added a check such that if the GetChainInfoTask fires multiple
times before a response comes in from bitcoind (in case bitcoind is out
to lunch for a few seconds), only the most recent request is
responded-to.
2019-12-23 18:36:36 +02:00
Calin Culianu
fe5d7ea5b9
Merkle yay!
Got the cp_height thing working for blockchain.block.header

Next up, the "headers" version. W00t! :D
2019-12-22 01:20:24 +02:00
Calin Culianu
55d8c79334
Increased parallelism!
Solved a problem that bugged me since the beginning: how to make latency
for the server as low as possioble and maximize CPU core usage.

We use a ThreadPool which gets invoked via generic_do_async() in
Servers.cpp for the more expensive rpc_* calls.  All the ones that may
hit the db and take a while, or may churn on the CPU (such as the
merkle-related ones) immediately go async and schedule their work on the
threadpool.

The rule will be only the most trivial rpc methods generate results
immediately, the rest schedule work via the threadpool.

This will help us scale and leverage as many cores as possible.  It also
allows us to have many many clients "living" in the server's thread
(thus reducing lock usage).

I'm excited about this design.
2019-12-21 15:09:02 +02:00
Calin Culianu
15d53f1760
Added Util::ThreadPool::SubmitWork mechanism
This allows for an app-global threadpool to be used for work that may
take a little while to complete.  The intended code that will use this
is the rpc server which will submit work that takes some time to
complete to the ThreadPool, so that the server's thread doesn't block
for very long while servicing client requests.

This ensures that the server remains responsive even if 1 or 2 clients
are issuing costly requests.

We plan on using this for get_history, listunspent, and the
merkle-related functions, to name a few.
2019-12-21 13:24:53 +02:00
Calin Culianu
b6b40cac5c
Added bitcoindmgr reference to Servers.cpp, added rpc methods
- blockchain.transaction.get is now fully implemented
- blockchain.transaction.broadcast is now fully implemented

Note we emulate electrumx's quirky/inconsistent behavior as much as
possible within reason until we can determine we can "do the right
thing" and it won't break existing clients.
2019-12-19 16:59:21 +02:00
Calin Culianu
4e3c893714
Added a bunch of RPC methods, etc
Yay! Getting there! :D
2019-12-18 17:53:16 +02:00
Calin Culianu
5436a14c8e
Modified RPC::Methods interface a little to be more useful
Also added shared_ptr to the storage object for accessing the database
from the "Server" instances.
2019-12-18 11:58:25 +02:00
Calin Culianu
17b85ba47f
Some comment nits 2019-12-16 23:52:35 +02:00
Calin Culianu
9ebe563cb0
some nits and comments 2019-12-15 23:40:52 +02:00
Calin Culianu
bbd96ff50b
Got undo working! Yay! We are getting closer to being a full real
server!

It still needs some testing but it appears to work.  We roll back
blocks. It's fast and good. Yay!
2019-12-15 20:52:21 +02:00
Calin Culianu
9a6073917b
Added more hooks and structure in preparation for undo code
Yay.
2019-12-15 12:33:02 +02:00