Commit graph

58 commits

Author SHA1 Message Date
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
cf1c24d8e1
Added a mechanism to return the cached status has for .subscribe
If the SubsMgr knows the status has because it already announced it to
clients (other clients were subscribed), then this is returned.
Otherwise nothing is returned and client must, as before, grab the full
history to compute the status.
2019-12-30 22:29:29 +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
81b005aff0
nit 2019-12-30 10:42:10 +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
a9e68a4909
nit 2019-12-30 08:40:46 +02:00
Calin Culianu
14da10cf97
Nit 2019-12-30 02:07:22 +02:00
Calin Culianu
d876eecd0f
WIP 2019-12-29 22:57:04 +02:00
Calin Culianu
f074f84a31
Modified "New Client XXX" log print to be more readable
Also tells you how many extant connections total
2019-12-29 11:04:47 +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
8aa0d92bf8
Updated get_balance to include unconfirmed balance
This is from the mempool
2019-12-28 16:13:24 +02:00
Calin Culianu
75314137c4 wip 2019-12-28 15:10:07 +02:00
Calin Culianu
3a6e39288c
made 'new Client' message use loglevel Log for now 2019-12-24 17:42:50 +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
dfc5527591
Fixed notification for headers (we had to wrap it in a list) 2019-12-24 02:44:08 +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
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
3034cada1c
Added server.features
Also added a mechanism to query peer port, peer address, etc from
AbstractConnection instances.

Added genesisHash() public thread-safe function to Storage.
2019-12-23 11:12:29 +02:00
Calin Culianu
24e3873632
nits 2019-12-23 09:57:41 +02:00
Calin Culianu
d1300ce07b
comment nits 2019-12-23 09:55:27 +02:00
Calin Culianu
1f50fd6e5b
Added server.banne and server.donation_address stub implementations
Also removed some extraneous Trace() calls
2019-12-23 09:36:52 +02:00
Calin Culianu
3321d9f440
Prevented a potential deadlock in Merkle::Cache
Use byzantine code, get byzantine behavior.

This should be the last of the fixes hopefully.

Also in this commit: Some simplification in Servers.cpp and some comment
fixups and exception message cleanup.
2019-12-23 09:12:17 +02:00
Calin Culianu
0d72a6e408
Fully implemented blockchain.block.headers
Yay. All the cp_height stuff is out of the way. Now to focus on bigger
things.
2019-12-22 16:54:26 +02:00
Calin Culianu
0596f59bcf
Nits to the new merkleCache
Put it in a private area and access it via public methods in Storage to
preserve proper encapsulation.
2019-12-22 02:11:16 +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
5df823f351
Some tweaks to cp_height parsing 2019-12-21 19:51:33 +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
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
5e5d0b5375
Slight performance tweak/nit: Cache/return block hashes in bitcoind memorder
This is in Storage.cpp's txHashesForBlock, which has been renamed to
txHashesForBlockInBitcoindMemoryOrder since it is the only function that
returns results in this memory order. We do it this way so we may cache
the reversed results and return them quickly the next time, thereby
hopefully reducing the performance cost on cache hits.
2019-12-20 20:42:45 +02:00
Calin Culianu
21ad53eadb
nit 2019-12-20 19:59:50 +02:00
Calin Culianu
5ae8a88dd4
Oops. Bug in getMerkle for blocks with 1 tx. Fixed. 2019-12-20 19:43:25 +02:00
Calin Culianu
2e9c2dab63
Using our new Merkle.cpp, fully implemented 2 of the transaction methods
blockchain.transaction.id_from_pos is now fully implemented, as is
blockchain.transaction.get_merkle.

They both use a cache to store the txHashes for a particular block, and
resort to reading from the disk file if not found in cache.

This cache stores the txHashes for 500 of the most recently queried
blocks.  In the worst pathological circumstances of 64k tx's per block,
the cache would use about 1.5GB of memory at worst.  In practice it will
use much less as blocks are empty.
2019-12-20 19:12:05 +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
41f32c4ebf
Implemented more protocol methods partially
We can test stuff now. Yay.  It's fast.

Still missing:

- merkle related stuff
- scripthash subscription methanism (and notifications)
- mempool related stuff
- figure out how the scheme will work for submitting requests to
bitcoind (bitcoindmgr->submitRequest seems ready to go for this and can
be called from Client instances).
2019-12-19 14:29:48 +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
48aac4c4d5
Added blockchain.block.headers, various small nits 2019-12-18 13:04:40 +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
6df916565a
Made app only start listening for client connections after initial sync
Also in this commit various nits and subtle bugs prevented.

Refactored the 'Stats' mechanism to return a generic QVariant rather
than QVariantMap, which is more flexible.

Misc. other nits.
2019-11-27 14:07:09 +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
9e07f32e95
Added more stats 2019-11-17 12:38:36 +02:00
Calin Culianu
7e16244609
Nits: Runtime check that classes deriving from QObjectMixin are ok.
added some asserts, plus -DNDEBUG to release build to disable asserts
for release.
2019-11-17 10:59:50 +02:00
Calin Culianu
ca9db3fc8d
Refactored stats stuff into a mixin class, StatsMixin
This makes it so that subobjects that return stats get the "statsSafe()"
function for free (which does a Util::LambdaOnObject).
2019-11-17 00:18:44 +02:00
Calin Culianu
bb7732adec
Some nits 2019-11-16 23:33:40 +02:00
Calin Culianu
dc8d95ee69
Refactoring; made all AbstractConnection inherit TimersByNameMixin
Also wrote a virtual methd 'getStats()' for AbstractConnection which
puts some basic stats into a QVariantMap for the /stats endpoint.

Subclasses can call the base implementation and add their own stats to
the returned map.

Also in this commit: misc refactoring and nits
2019-11-16 22:28:27 +02:00
Calin Culianu
a34585da1b
Added BitcoinD classes.. lord help me.
Also "upgraded" the universal ID we use for all objects to use quint64
(unsigned) rather than signed, and the "NO_ID" is 0.
2019-11-12 22:14:04 +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
7a5f12dcd5
Added some checking to prevent memory exhaustion attacks from EX clients 2019-11-12 00:12:05 +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