Commit graph

141 commits

Author SHA1 Message Date
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
Calin Culianu
68a3373bf2 initial data structures and hooks in addBlock for undo (reorg rewind) 2019-12-14 00:47:11 +02:00
Calin Culianu
a3b186eeb9
Fix: Connection lost/reconnect detection logic in Controller.cpp
There was a race condition before if the controller thread was very busy
it would not have time to reconnect the "wait for auth" signal and as
such would end up in a state where it kept spamming "waiting for
bitcoind" to the log incessantly.

This has been handled by keeping the gotFirstGoodConnection signal
always connected and only reacting to it if the "lostConn" flag is
latched (latched by allConnectionsLost signal).

The gotFirstGoodConnection signal is only emitted when the first good
connection is made anyway so it's not spammed.  It was not ideal that we
didn't have it always connected.

This fix hopefully fixes the race condition we saw when synching mainnet
on my slow windows box.
2019-12-13 18:54:30 +02:00
Calin Culianu
8db5ee50c7
Added blocks/sec and io/sec to progress display
yay!
2019-12-13 18:23:24 +02:00
Calin Culianu
1c89f60e12
Got scripthash_unspent working .. but block synch is painfully slow
We deleted the non-working merge operator for scripthash_unspent.. and
we do a read-modify-write for each new utxo/spend per scripthash.

It's very slow though.

I may have to defer updating this table until the very end from the utxo
set or something.  This is unacceptably bad...
2019-12-13 00:14:09 +02:00
Calin Culianu
735a67b2fa
comment & nit 2019-12-12 13:01:31 +02:00
Calin Culianu
b799dfb2a8
Scripthash history fix. Oops!
we weren't adding the right txidx to the history.  Good thing I also
added debug code to this commit to check history.

Fixed!

Also various other nits and tweaks.  Added the /debug endpoint for
sending params for debugging to the server.
2019-12-12 12:15:06 +02:00
Calin Culianu
608ba22231
added stats for merge calls for debugging 2019-12-12 00:23:19 +02:00
Calin Culianu
bd583bf18b
added code to test concurrent read of recordfile on windows especially 2019-12-11 12:02:41 +02:00
Calin Culianu
bb532db895
Tweaks to backoff time for download tasks that are ahead of backlog
Also made max backlog be < 1000 for block heights towards the end of the
chain.

Made the max backlog be chain specific as well, with it getting as small
as 100 towards the end of mainnet and/or testnet
2019-12-11 00:57:52 +02:00
Calin Culianu
4d62d612cc
Simplified the progress display code
Made it print the progress of the latest processed block rather than the
latest downloaded block (which may be 1000 blocks ahead).
2019-12-11 00:21:08 +02:00
Calin Culianu
8c3b42f1c5
Tweaks and fixups in storage class -- refactored some stuff
We no longer store the headers in memory. We keep them in the db.  We
don't need them that often and clients can just read them from the db
if/when needed. Hopefully rocksdb is peppy enough.  We can cache them if
it's a problem.

Also refactored some stuff around and simplified the storage code a
little bit.
2019-12-11 00:05:16 +02:00
Calin Culianu
f837999fb4 Optimized locking a little bit
There was no need to grab the smLock for ppBlkHtNext since that is
already an atomic value. This should improve throughput imperceptibly.
2019-12-09 16:13:12 +02:00
Calin Culianu
d4ddc83865 added chain stats to controler 2019-12-09 15:45:52 +02:00