Commit graph

88 commits

Author SHA1 Message Date
Calin Culianu
8bb60fcb0d tweak 2019-12-08 22:48:48 +02:00
Calin Culianu
83e11bfd0b
Added some logic to cut down on cost of saving on first synch
On first synch we don't keep track of the difference set for the utxo
set. This should reduce memory consumption.  We just build the working
set.  After first save we then need to keep track of the difference set.

We also reduced the save interval to be infrequent -- every 500000
blocks.  This should also hopefully keep the controller task from
falling behind.

We do save on task end / ctrl-c though.
2019-12-08 22:31:17 +02:00
Calin Culianu
d982252adf nits 2019-12-08 22:16:52 +02:00
Calin Culianu
0c35c4a9fc
Added 'setSaveInterval' to specify save interval, redid backoff logic
The backoff logic on backlogs now favors the closer blocks to present
and delays the father away ones more.

Added the save interval as a programmable constant to storage.  We set
it to 100,000 on full downloads.
2019-12-08 22:07:01 +02:00
Calin Culianu
e1bfa52822
a comment added 2019-12-08 19:54:26 +02:00
Calin Culianu
cff923b3d5
Regined the backlog avoidance mechanism slightly
Tightened the lock and made it a shared_lock to hopefully stall the dl
tasks less waitng for it.

Also moved all logic for it into the method that decides if throttling
is necessary.

This mechanism is still very awkward. TODO: figure out something more
elegant.  It's just a PoC for now.
2019-12-08 19:45:00 +02:00
Calin Culianu
0491a9ab55 wip testing 2019-12-08 19:14:05 +02:00
Calin Culianu
a9408e1bf6
Some tweaks for correctness and memory consumption + lru cache perf
- Added compactifyUtxoSet to periodically reduce all instances of dupe
QByteArrays to point to the same underlying shared object. This runs
every 33,000 blocks on synch.

- Merged the Hdr and UtxoSet save flags into a single flag, "Blocks"
which means they get saved together. This is crucial for correctness.
Before it could be the case that a different height would be saved for
headers vs utxo set because of the way it worked.

- made the two lru caches try and keep the same key/value pairs
(hopefully shared copies)

- made the LRU::Cache class not use an exception internally on tryGet()
-- this seems to have a positive impact on performance as this function
is called a lot.  Instead, it calls into an internal common function now
called get_nolock_nothrow, upon which everything else is based.

It appears these efforts have reduced memory consumption a bit.  Our
UTXOSet is still pretty heavy.  More work to be done...
2019-12-08 17:21:39 +02:00
Calin Culianu
8b3f67cd32 wip 2019-12-07 23:30:07 +02:00
Calin Culianu
fa504bd6fb wip 2019-12-07 20:34:19 +02:00
Calin Culianu
ae753e22fc
Refactor the chaintip/chainheight stuff into a single call in the storage
Just a little bit cleaner...
2019-12-07 15:54:56 +02:00
Calin Culianu
f279e484b7 got rid of the ProcessedBlock stuff. The txNum optimization will be opaque to the rest of the app. Rest of app will deal in TxHash natively. 2019-12-07 15:04:45 +02:00
Calin Culianu
34e5e35a1c
Redid the hashXAggregated structure in BlockProc
It's now an unordered_node_map, keyed off of HashX.  This should be more
useful down the processing pipeline.  What we had before was confusing and
difficult to use.. its only advantage was it preserved order of HashX's
in a block.

We can reproduce the order though on-demand if it turns out we need it
by adding a method to construct an array keyed off the in/out index per
hashX.

So this map approach is sufficient and likely more useful.
2019-12-05 18:19:55 +02:00
Calin Culianu
082fb42af5
Switched to using robin_hood::unordered_flat_map
This is so much faster than unordered_map it's silly.  Also supposed to
use less memory. AND it's a single-header lib!  Very exciting.  W00.
2019-12-05 13:02:43 +02:00
Calin Culianu
ac8137e03d
nit 2019-12-05 12:38:52 +02:00
Calin Culianu
409feb1994
Ok, fixed the utxoset bug
Turns out our custom HashX class was doing some funny things when a
HashX had a \0 byte.  Likely QByteArray isn't really intended to be
inherited from.  Rather than investigate what was going on -- I just
decided it's sufficient to do: using HashX = QByteArray and be done with
it.

Now our utxo set is working correctly.

We still need to figure out how to store everything.. but this is
progress.
2019-12-05 12:07:27 +02:00
Calin Culianu
bf5eebaa65 wip -- it's kinda broken still.. :( 2019-12-04 23:53:45 +02:00
Calin Culianu
7f6d025be2 nit: made GetBlockHeaderSize() return int because that's more useful to us 2019-12-03 21:53:32 +02:00
Calin Culianu
b0f1876fde
nits to pct display 2019-12-03 06:52:38 +02:00
Calin Culianu
dfaa36cc13
DB format change: added SerializeScalar/DeserializeScalar
This is to support writing raw ints directly to db keys / db values as a
space saving measure.  QDataStream, while platform neutral, adds its own
marker/size bytes to the serialization which we do not need always.

Our DB format is now endian and architecture-specific, but that's ok.
Users can resynch if they switch machine architectures.
2019-12-03 06:38:19 +02:00
Calin Culianu
b1ff399790
tweaks headers renamed to blocks in mesaging 2019-12-02 16:27:42 +02:00
Calin Culianu
6acf393de9
tweaks and hopefully fixups 2019-12-02 16:21:22 +02:00
Calin Culianu
e82d98d68a tweaks to stop event spam, modified download progress pct to be progress of total blockchain 2019-12-02 14:11:02 +02:00
Calin Culianu
0556caf0f4 wip -- mostly works. task end has some spurious events that need removing but works well 2019-12-02 13:50:18 +02:00
Calin Culianu
26fda19b8d
Got rid of the download task retry mechanism. Hopefully we won't need it
We plan on synching in real time as the download proceeds.. so it won't
be needed.  It also simplified the code significantly to remove it.
2019-12-02 11:46:34 +02:00
Calin Culianu
4f1470fc99 wip 2019-12-02 11:42:10 +02:00
Calin Culianu
4a68eaaeaa
nit 2019-12-02 10:00:22 +02:00
Calin Culianu
7c63bba5d0 nits 2019-12-02 09:43:03 +02:00
Calin Culianu
76d0505323
Nits, refactorings, and tweaks
Cleaned up the code for BlockProc and created the HashX class

Plus made some of the PreProcessedBlock fields be more type-safe (using
std::optional)
2019-12-02 01:29:24 +02:00
Calin Culianu
e9d3991ded
WIP - added PreProcessedBlock
The PreProcessedBlock is intended to be a somewhat munged/mogrified form
of a CBlock which is somewhat ready for a db insert.

This data will get passed onto the Controller thread which will set
everything up to commit the SH history, header, etc to the db.

Did some initial testing and it's pretty fast and also.. I think it's
correct (as in I'm collating the data correctly).

TODO: Some more testing.
2019-12-01 22:36:19 +02:00
Calin Culianu
16a2e195c4
Nits/refactoring for the BTC::Deserialize* functions
I made them all less boilerplatey and use templates.  yay!
2019-12-01 15:22:12 +02:00
Calin Culianu
4c8f5d0f9b tweaks 2019-12-01 01:10:54 +02:00
Calin Culianu
06ab90b157 nits 2019-12-01 00:50:42 +02:00
Calin Culianu
a8e6703c38 tweaks 2019-12-01 00:43:03 +02:00
Calin Culianu
06cbe1321b tweaks / wip 2019-12-01 00:20:15 +02:00
Calin Culianu
c3091c0d99 tweaks 2019-11-30 23:33:30 +02:00
Calin Culianu
cbaea7a276 went back to getblockheader header dl for testing 2019-11-30 22:18:12 +02:00
Calin Culianu
5c9ecd9c08 Implemented different parallelism: stride style breakup of the download space between tasks 2019-11-30 22:07:35 +02:00
Calin Culianu
bea420355b wip 2019-11-30 12:29:32 +02:00
Calin Culianu
a7293a9939
Potential bug fixed: Added protection from connecting to wrong bitcoind
We now save the "chain" variable to the meta table.  We also panic if
the headers we are reading from bitcoind are behind what we have (todo:
handle this elegantly if there actually was a reorg?)
2019-11-30 01:33:27 +02:00
Calin Culianu
5842c44a79
Nits, refactorings + added shared HeaderVerifier that lives in Storage 2019-11-30 00:42:33 +02:00
Calin Culianu
46b670d813 storage wip 2019-11-29 14:42:17 +02:00
Calin Culianu
e9d432f5e7
C++ template magic - newTask factory function
Templates are fun.  Decided to reduce boilerplate by making task
creation inside the Controller class be done by a template member
function which acts like a task factory.  It surrounds the construction
of the task with some boilerplate (namely, inserting the task in the
tasks map, connecting an optional errored signal, and starting the
task).
2019-11-27 20:32:50 +02:00
Calin Culianu
c499e1a1b3
Made the "upToDate" slot that creates srvmgr fire only once
Via shared_ptr tricks, it only fires once in the interests of
efficiency. After the server is created the connection is disconnected.
2019-11-27 14:46:17 +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
0bf3d4e2ae
refactor ChainInfo into its own struct 2019-11-27 12:12:16 +02:00
Calin Culianu
bb1d371d2e
Use getblockchaininfo rather than getblockcount, and more
We now query more information initially when synching, which can be
useful.

We also deal with initial block download by retrying every minute

and other miscellany
2019-11-27 12:03:12 +02:00
Calin Culianu
1743a4728e
Some nits. Use of an unordered_map and static_assert, simplified map.emplace, show hdr dl pct 2019-11-27 02:38:39 +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
d9f335f1d4
memory/vector usage nits 2019-11-26 12:29:27 +02:00