Commit graph

72 commits

Author SHA1 Message Date
Calin Culianu
d7338d5b87
Moved a lock up to top in addBlock 2019-12-15 09:14:56 +02:00
Calin Culianu
bfbe86a795
Added saving of undo data to db
The save is done for the last 10 blocks before latest tip.

We also have to unconditionally issue Delete commands to the db for all
block heights >10 blocks ago.  So far the unconditional issuance of the
delete command does not seem to impact performance.

We could mitigate the Delete command by keeping track of the olders
header we know exists in the db -- but we don't bother for now.
2019-12-15 09:08:31 +02:00
Calin Culianu
627241cb08
Refactor: added the ShallowTmp and DeepCpy templates as QByteArray helpers
This will reduce typing and hopefully make it very explicit which type
of QByteArray is being created in the code as a defensive progarmming
measure to eliminate errors... because the QByteArray::FromRawData
static function doesn't capture its very unsafe nature in its name (and
the fact that it is a "contagious" property it brings to the
QByteArray).  The "ShallowTmp" naming captures this.
2019-12-14 12:22:40 +02:00
Calin Culianu
1d7163f099
Added UndoInfo Serialize/Deserialize and test 2019-12-14 11:42:26 +02:00
Calin Culianu
bd09a68d4d
Added saving platform wordsize (bits, eg 32, 64) to the meta db 2019-12-14 09:26:20 +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
590ba03a42 nit 2019-12-13 03:04:21 +02:00
Calin Culianu
ce018dd538
Finally got scripthash_unspent working with ok performance!
Yay!  And it doesn't even eat that much data on disk.  We are just using
an iterator in scripthash_history to get all the unspents.

We add/delete based on hashx + compacttxo_bytes.

Works like a charm!
2019-12-13 02:45:45 +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
c8803cf153 nit 2019-12-12 23:09:54 +02:00
Calin Culianu
3282c2a9be its kinda broken.. WIP 2019-12-12 20:38:56 +02:00
Calin Culianu
0320b42fd1 added CompactTXOVec and Ser/Deser of it 2019-12-12 16:58:31 +02:00
Calin Culianu
d409c3093f Compile fixups for MinGW G++ 2019-12-12 13:20:18 +02:00
Calin Culianu
e2b8e5af7e
Nits .. renamed a few data members to be clearer and added comments 2019-12-12 13:15:45 +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
f130c0450d Compile fixups for linux; rebuilt rocksdb for linux with USE_RTTI 2019-12-12 01:28:27 +02:00
Calin Culianu
608ba22231
added stats for merge calls for debugging 2019-12-12 00:23:19 +02:00
Calin Culianu
4dbc8e1b7d
Added scripthash_history update during sync
Requires the "merge operator" for performance. This ends up requiring a
lib recompile to use RTTI.
2019-12-12 00:07:29 +02:00
Calin Culianu
deda9fe583
Added preliminary BlkInfo saving to db
And checking on startup
2019-12-11 19:57:01 +02:00
Calin Culianu
90511e4f14
refactor nit in Storage.cpp 2019-12-11 18:52:33 +02:00
Calin Culianu
a68e9a5d86
More simplification in Storage.cpp templates
yay
2019-12-11 18:39:19 +02:00
Calin Culianu
e94bbbfd52
Nits and refactoring in Storage.cpp templates
Made the GenericDBGet and GenericDBPut more generic.  They rely on a new
C++17 stytle 'auto' return type template, ToSlice, which is very
generic. :)
2019-12-11 18:25:24 +02:00
Calin Culianu
c1d01fb029
Reduced CPU usage in addBlock -- we mark outputs spent in PreProcessedBlock now
This reduces the building of a set for each hashX in addBlock. Now we
flag the outputs that are safe to ignore for adding to utxo set (because
they were already spent) by flagging the OutPt directly in
PreProcessedBlock fill().

Should improve performance slightly as no more nested loops in
addBlock()
2019-12-11 17:02:42 +02:00
Calin Culianu
e4a723ccc3
Refactorings and nits in RecordFile.cpp code 2019-12-11 16:35:22 +02:00
Calin Culianu
07934e52cb
renamed file TxNum2TxHash to lowercase txnum2txhash 2019-12-11 12:28:01 +02:00
Calin Culianu
91b504b92a
comment nits 2019-12-11 12:13:47 +02:00
Calin Culianu
bfd697f9a2 nits 2019-12-11 11:49:45 +02:00
Calin Culianu
a4ca204dc9 Added recordfile use in storage.cpp, got rid of txnums table from db. this should be faster. 2019-12-11 11:32:46 +02:00
Calin Culianu
5cf40f5d20
nit 2019-12-11 08:52:38 +02:00
Calin Culianu
b6d248dfa7
Got rid of txHash -> txnum reverse mapping from db
this wasted gigs of space and likely won't be used.

Also refactored/optimized the db serialize to slice stuff to do less
copying when it's serializing a temporary to a slice.
2019-12-11 08:26:53 +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
262349f4ab
Test different maxBackLog backoff strategy, re-enabled write batching
Write batching reenabled for txnum <-> hash disk write
2019-12-09 15:39:39 +02:00
Calin Culianu
1ec001d95e
Save txNumNext to db, turn off batched writes in addBlock
batched writes in addBlock may be the reason we are seeing huge memory
consumption spikes when synching mainnet.  Turned off for now.
2019-12-09 13:42:11 +02:00
Calin Culianu
01f1ebd62c
Got rid of in-memory utxo set.. will rely on db
RocksDB is super fast. Keeping it in memory was a waste of memory.  This
is much faster and reduced memory consumption significantly.

TODO: Maybe do the same thing for headers as well!

Also: We need to save txNum to DB. We're not saving it now resulting in
correctness errors on subsequent reloads of same db.
2019-12-09 12:10:59 +02:00
Calin Culianu
4c6cc629ca addBlock: fix to prevent redundant add/removal of txo's spent in same block 2019-12-09 10:04:30 +02:00
Calin Culianu
a61beb1f35 tweak 2019-12-09 01:11:34 +02:00
Calin Culianu
a749f16582 use robin hood flat map instead of set in compactifyUtxoSet 2019-12-08 23:48:58 +02:00
Calin Culianu
c6243c489d
some tweaks to conserve memory 2019-12-08 23:15:42 +02:00
Calin Culianu
cb2233c09e msg tweak when closing db and it's busy saving 2019-12-08 22:53:50 +02:00
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
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
509a7253c7 testing 2019-12-08 11:45:57 +02:00
Calin Culianu
8e4bed2817 more stabs at rocksdb memory usage 2019-12-08 05:20:40 +02:00
Calin Culianu
00d8139032 tweaks to rocksdb in an attempt to reduce memory usage 2019-12-08 05:02:46 +02:00
Calin Culianu
56dcd08781 reduced lru cache elasticity size in storage.cpp 2019-12-08 03:45:45 +02:00
Calin Culianu
ae3321f882 nit 2019-12-08 03:06:36 +02:00