Commit graph

40 commits

Author SHA1 Message Date
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
6056c7aced
Bumped the max extant job limit to 1000
It turns out it does spike sometimes when synching huge wallets.  I
still think 1000 might be too low.  TODO: Characterize this fully.
2019-12-24 13:34:01 +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
d73e96e1df
Added more stubs, tweaks to be able to test with EC
- Turns out EC doesn't send the "jsonrpc" key in its requests. Grr. So
we fudge it to support EC.
- Various other tweaks and protocol stub impl.'s added to get EC to
like us and talk to us.
- Increased the side of the lruHeight2Hashes cache for testing.  We need
to replace this cache altogether with a memcost-based cache though, so
we can set 100MB or something as the maximum cache size and just have at
it. Right now we cannot do that as the LRU::Cache is "size" based (and
each block may have 1 tx or 64000 tx's, both having 1 entry in the
cache!!).
2019-12-24 02:01:55 +02:00
Calin Culianu
fe3c0ae35f
Some defensive nits in the ThreadPool worker system
Keep a weak ref to the context object and check in a paranoid fashion
when executing in the run() method whether it was deleted so that we may
avoid calling potentially expensive work() functions when interested
Clients are already disconnected.
2019-12-21 21:21:02 +02:00
Calin Culianu
22608edac6
Massive refactoring for Severs.cpp and fixup to RPC.cpp
Servers.cpp now is much simplified. Writing RPC methods should be far
easier and less boilerplatey now.  We throw RPCError internally now when
we want to indicate an error -- this reduces the boilerplace
significantly.

Also we wrote a generic bitcoind_async function for submitting requests
to bitcoind which takes care of some of the boilerplate involved and
handles errors, etc, automatically (can be overridden by caller).

Also a bugfix to the ThreadPool -- if it caught an exception
completion() would still be called (which is not what we want).

Now it calls failure() appropriately at the right time on exception, and
does not call completion().

Also RPC.cpp had the sendResult() take a "method" argument which was
ignored.  Deleted the argument to simplify usage.

So far the code is looking good.
2019-12-21 18:55:48 +02:00
Calin Culianu
edb57e9822
comment nit 2019-12-21 15:26:04 +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
48aac4c4d5
Added blockchain.block.headers, various small nits 2019-12-18 13:04:40 +02:00
Calin Culianu
17b85ba47f
Some comment nits 2019-12-16 23:52:35 +02:00
Calin Culianu
46b670d813 storage wip 2019-11-29 14:42:17 +02:00
Calin Culianu
7f13c60ece
nits 2019-11-26 22:43:30 +02:00
Calin Culianu
cc8ce73c5a
Made bitcoind communication more efficient by use of ParseHexFast
When reading data from bitcoind, we can assume the hex data it gives us
is good and there is no need to validate on a per-character basis.

Thus, we use ParseHexFast to shave off cpu cycles (it's like 6x faster
than Qt's fromHex()).

This, along with the Util::ToHexFast() (which is 60% faster than
QByteArray::toHex()), will be used in performance critical code.
2019-11-26 22:04:45 +02:00
Calin Culianu
50ee0510f3
Added ParseHexFast() to the Util namespace
This hex parser is 5-6x faster than what we were using before, although
it does no real verification that the input is hex digits.  Usable with
results returned from bitcoind, which is never going to be
malicious/malformed and thus we can rely on this non-checking hex
parser for the performance it offers (at the expense of verification).
2019-11-26 21:01:31 +02:00
Calin Culianu
b8f5ff5fa2 Compile fixup for windows 2019-11-25 23:13:06 +02:00
Calin Culianu
0eb50606b9
Added "CtlTask" mechanism to Controller class, plus nits & refactoring
This is more complex than what we had before -- but is more concurrent
and is more production-ready -- it can deal with failures better and now
we also poll bitcoind for new headers.

Still probably can be optimized somehwat -- but getting there!
2019-11-25 22:34:11 +02:00
Calin Culianu
d7e0ba16db
fixup for error parsing integer id: 1000000.. oops. 2019-11-19 10:44:51 +02:00
Calin Culianu
45e12158db
Added process function to controller, and hooks for bitcoind when ready
Also added the "Fatal" logging class which logs as Error but then
schedules an app exit when invoked.  Only to be used for truly terrible
errors.
2019-11-18 08:29:33 +02:00
Calin Culianu
c0ea7f75a0
Refactored things, added "Controller" class
Controller will manage BitcoinD and perhaps synching to bitcoind. It can
"see" all the servers as well as bitcoind.

Also refactored things a little bit and added some more startup sanity
checks.
2019-11-18 00:21:34 +02:00
Calin Culianu
7a00bb94fb
Added some preliminary skeleton of message processing
Still not sure how I will design this..
2019-11-13 01:52:15 +02:00
Calin Culianu
7c5cfb8993
More nits and cleanup.
I'm getting a little OCD here..  but it's good. :)
2019-11-12 11:29:45 +02:00
Calin Culianu
c0ad6ebefe
more C++ template wizardry 2019-11-12 04:37:34 +02:00
Calin Culianu
46c569ff97 some c++ wizardry to try out packaged_task and futures 2019-11-12 03:04:49 +02:00
Calin Culianu
0d0f41c2f5
Changed the way timestamps are printed in the log 2019-11-11 11:55:10 +02:00
Calin Culianu
b2b2509f25
Got HttpConnection working and talking to bitcoind
It works!  I still haven't figured out how to provoke the dreaded
"Workdepth exceeded" error .. but we pretty much drop the connection
anyway on anything too unexpected from bitcoind.

When the bitcoind manager class is written it will back off and try
again if too many disconnects happen.

For now though, the code we have is fast and works well against
bitcoind.
2019-11-11 00:22:31 +02:00
Calin Culianu
45daaf6e91
some nits 2019-11-09 21:14:07 +02:00
Calin Culianu
cd643e7323
Made Message::Id type a std::variant
I restricted the possible underlying types it can contain down to
qint64, QString, and nullptr_t. This should make it more type safe since
we don't want it to inadvertently end up holding lists or maps
(previously it was a straight up QVariant).

It has a conversion to QVariant so it should work nicely.
2019-11-09 01:55:48 +02:00
Calin Culianu
386383d6d4 Made our JSON-RPC 2.0 implementation more closely match the spec
- It's still a little more restrictive than the spec allows -- doesn't
like non-positive-int 'id'
- We not made the shuffle.spec status report back 'notifications' to the
client rather than repeated 'result' messages (as those would be out of
spec). The first response to a 'shuffle.spec' request is either
result="pending", result="accepted", or an error response
- Subsequent shuffle.spec status changes come as a method notification
for "shuffle.spec" with params=["accepted"] or params=["some error
message"]

Overall I think our bare bones JSON-RPC will at least not break now as
interop with other impls.
2019-05-06 14:34:42 +03:00
Calin Culianu
31b891c006 hooked controller object in to app startup 2019-05-04 06:00:01 +03:00
Calin Culianu
2547dc35cb Added SysLogger for -S option which actually uses unix syslog()
On Windows it still prints to console, however (without timestamps).

Note that syslog mode doesn't produce any debug output even if -d is
specified (at least on macOS) -- probably the sysadmin needs to
enable debug logging.
2019-04-27 16:00:58 +03:00
Calin Culianu
5ccef909af Nits and refactoring of RunInThreads app exit handling 2019-04-27 14:55:10 +03:00
Calin Culianu
3f49dce1db Added some small goodies
- Util::RunInThread to run a lambda in a thread
- App exit handling cleanup
- EXMgr uses an id for clients now
- EXMgr keeps track of lagging clients
- EXMgr more aggressive with reconnects if no valid exclients
- Nits and refactorings and misc. cleanup
2019-04-27 12:38:50 +03:00
Calin Culianu
2477a7a8a3 Added initial TcpServer stub implementation
- Already supports listening on as many sockets as you wish
- Each listening server has its own thread
- Will implement later: SSL server

Also refactored code a bit, created the generic "Controller" class, made
EXMgr and SrvMgr inherit from it.

ToDo: Figure out workflow for connections and clients, model client
sessions, etc.
2019-04-26 08:47:46 +03:00
Calin Culianu
5b9161baba Fixed a crash if using Debug() and no qApp 2019-04-25 10:33:38 +03:00
Calin Culianu
d3cc2ff830 Tweaks
- Only send server.ping on idle >1min (previously we sent
unconditionally once a minute)

- Added __attrubute__ format stuff to the printf-like log functions

- Small nit
2019-04-24 12:44:01 +03:00
Calin Culianu
57148960c4 Added some command line options and a command line parser 2019-04-23 23:26:07 +03:00
Calin Culianu
4637012e22 Added more EXClient stuff 2019-04-23 12:36:51 +03:00
Calin Culianu
62101beeac Initial revision. Just laying out a skeleton to build on. 2019-04-23 02:33:16 +03:00