Commit Graph

96 Commits

Author SHA1 Message Date
TomZ 477a536e25 [UTXO] UnitTest rollback-to-checkpoint code 2020-11-17 20:57:32 +01:00
TomZ 089145a3a6 Delete copy constructor 2020-11-17 16:04:45 +01:00
TomZ 36a0bb10f2 Improve log info. 2020-11-10 17:28:40 +01:00
TomZ e9a2437c2d Add unit tests for UTXO and fixes
This fixes that the .info file is sometimes not written when nothing
changed in the db file.

This fixes that the info file with .1.info extension is reused again
and again, effectively reducing the usefulness of the snapshots.
This only really affects the indexer as pruning avoids this most
of the time.

Closes issue flowee-issues#6
2020-05-18 22:51:41 +02:00
TomZ e9ef907c1f Sync checkpoint save and index-db saveCaches
When the UTXO saved checkpoints this change makes sure we also store the
index-db changes.

Since we stopped saving simple state changes fromt the index-db, the
only real data we save is the 'undo-block-index', as such this will be
relatively cheap to save.
Without an undo block position we will currently fail to verify those
blocks and as such it is useful to save all at the same time to actually
have a state we can start from.
2020-03-05 23:29:53 +01:00
TomZ 4f077da5a6 remove assert(true) 2020-03-05 23:29:53 +01:00
TomZ bd58ac420a Avoid reuse (shadow) of variable 2020-03-05 23:29:53 +01:00
TomZ 8e269a2ea8 Fix initialization order 2020-03-05 23:29:53 +01:00
TomZ 02258d9dcd Make pruner use the new tags
This allows the pruner to be used on the 'tip' DB file, at which point it
will set the filesize to be the default 2GB one.
Previously pruning the tip would confuse the Hub with a smaller file
size.
2020-03-05 23:29:52 +01:00
TomZ d9604e3f33 Design a better detection for need of UTXO-GC
Doing a garbage collect of the Sha256 based databases means we remove
all the records that have been deleted from our file.
We also sort the file to have all the jump-tables at the end, making it
much cheaper on memory-locality to find (or not) items in the DB.

The downsides are that this prune step takes time, writes dozens of MBs
and that we lose checkpoints. The latter means we no longer can rollback
to a safe position, simply because we flushed those records.

So we want to do this often enough to avoid fragmentation but not too
often because it creates a greater risk on data consistency.

This algoritm checks the actual data and calculates the fragmentation of
the jump-tables to decide if we want to start a GC.

When we do GC, we try to do as many files as makes sense, to make sure we
can wait quite a long time before we need to do a new GC.
2020-03-05 23:29:52 +01:00
TomZ a5a2aef53e Increase the amount of checkpoints from 5 to 15.
Now we can revert much cheaper to an earlier checkpoint it becomes much
more important that we actually keep them around to be usable.
2020-03-05 23:18:42 +01:00
TomZ 1141de5c13 Cleanups 2020-02-28 00:34:12 +01:00
TomZ 9a3dde8400 Make sure the UTXO doesn't write a new info file when there are no changes 2020-02-28 00:34:12 +01:00
TomZ 60d371afa7 Make loading find a functional UTXO state
When, on loading, the blockindex and the UTXO don't agree then try to find an older UTXO
state where they do agree.
The most typical state issue is where a block stored in the blocksdb is not available in
the index due to corruption or similar.
2020-02-28 00:34:08 +01:00
TomZ f0e93708e1 Minor cleanups 2020-02-28 00:33:11 +01:00
TomZ 489a9a4859 Move nStatus of blockindex into the UTXO
To allow the UTXO to actually use the power of checkpoints we need to
make sure that the block-validation state is not stored separately from
it.
The goal is that when we have some curruption we can just go back to an
earlier state of the UTXO and re-validate the blocks to get to the
current tip. The often seen problem is that corruption will instead
leave the block-index (leveldb) with an incorrect state so the replay
fails.

This change solves that by no longer reading the block-validation-state
and no longer writing it on a state change.
2020-02-28 00:33:04 +01:00
TomZ 8057429dfa Re-do the UTXO garbage collect planning algo
The UTXO keeps outdated records around in an append-only file, which
means we need to do a garbage collect regularly.
This new algo uses the commulatative amount of changes since last GC
(aka prune) as an indicator to plan a new one.

The effect should be much smaller files to keep in memory and the data and
jump tables being much more localized which should result in higher
throughput.
2020-02-23 11:15:55 +01:00
TomZ 86d580463a Make selection of UTXO info files better
This avoids some cornercases.
2020-02-22 13:43:16 +01:00
TomZ 175096b2bd Refactor: move files
Move some files back to the server "library".
Merge the 'console' lib with server, as it doesn't really make sense with
just one file and nobody exclusively linking to it.

The server "libary" is not really a library, its the place we put all
the files shared by hub-qt hub-cli and hub.
We no longer depend on these files from other places (mostly due to
moving to the new logging framework) and as such we can move the files
back.
2019-11-13 19:09:24 +01:00
TomZ 4a6845ff76 Fixlets from static code inspector 2019-09-12 15:24:03 +02:00
TomZ 028fff30a2 Make clang happy 2019-09-07 20:26:53 +02:00
TomZ e7a7ada953 Cleanup dependencies a bit more.
This means that for apps like 'pos' no longer link against libSSL

The streams no longer zero-after-free, there are no secrets transported
in datastreams so this is useless and avoids linking in one OpenSSL
call.

The insecure_rand() method depended on the openssl code to seed it with
randomness. Now replaced with a proven current-time-milliseconds.
This is enough in those cases because it was always meant to be an
insecure random.
2019-08-24 22:25:10 +02:00
TomZ df7de2ecd2 Clean up the hairy ball of util.cpp
Move some globals and all stuff pulling in crypto to the
server/serverutil.cpp file

Remove dead code.

Move several items that were used in only one place to the respective
files using them.

Move the class WaitUntilFinishedHelper into its own file.

Made sure no header includes utils.h
remove a handfull of files including utils.h for nothing.
2019-08-24 22:25:09 +02:00
TomZ 2bb06afa9e Cleanup the link-lines 2019-08-24 22:25:09 +02:00
TomZ cf4eca26ba Merge branch '2019.06' 2019-06-22 13:02:11 +02:00
TomZ 21ce0163f7 Fix possible threading issue, use an atomic
The changecount integer was updated in two different threads,
so it needs to be an atomic to be safe.
2019-06-22 12:37:01 +02:00
TomZ 49b6f802a5 Make loglines less confusing
Now multiple different targets use this database, the messages
were confusing. Next to that "pruning" is not really correct
and it lead to confusing. More correct is the term GC.
2019-06-22 10:59:37 +02:00
TomZ c0752a944c Fix sometimes not being able to load a UTXO
In the rare case when we already created a new DB file, but never
managed to write a .info file, the constructor would end up rejecting
the whole DB.
This just drops off the last useless file and goes from there.
2019-06-19 21:49:04 +02:00
TomZ 110d7e8a39 Fix pruning of rather large files 2019-06-19 16:55:59 +02:00
TomZ 5ca03cddd5 Futher improve how often save is called
Realize that the changes made before committing are changes I'm
not allowed to save yet and as such move scheduling to the commit()
method.
2019-06-15 21:36:52 +02:00
TomZ 230611b98e Tweak the numbers to be better on IBD 2019-06-12 23:53:24 +02:00
TomZ 840cd5a913 Fix change-counting and saving in UTXO
Fix a bug that could make the wait between saves too long and now aim to
make the saving more often because this helps us determine in time that
the file is full so we don't go over the end.
2019-06-11 18:59:51 +02:00
TomZ 3fcd3536ed Clarify coinbase pos in block.
The first field after the header is the number of transactions. This
is a variable-width field of between 1 and 9 bytes.
Coinbase starts after that.
2019-06-11 17:38:30 +02:00
TomZ f9b01e2040 Fixlet in API docs 2019-06-10 21:02:15 +02:00
TomZ 6643059f2a Forgot to add copyright headers to these files 2019-06-04 21:40:12 +02:00
TomZ a1dfd1cde9 Work on installable headers 2019-06-03 10:59:33 +02:00
TomZ ac1a3db905 Write new variable to UTXO-DB info files
Write a changesSincePruning integer which has the following effects;
after a restart;
* We will do a prune faster and/or more often for nodes that are not
  running very long stretches of time.
* We will skip pruning files that don't need it.

Context; pruning of the UTXO is throwing away already spent outputs
that are still in our dirty files.
2019-04-10 23:59:10 +02:00
TomZ ef5dafe6e0 Add private header warnings 2019-04-06 12:28:34 +02:00
TomZ 6db08ef9f8 Also prune the first file 2019-04-03 14:33:56 +02:00
TomZ 67d2019434 Have a special exception for UTXO internal errors
This avoids an internal error from failing one block due
to a perceived missing input while the block may be fine
but other issues need looking at (for instance disk errors).
2019-04-02 18:40:56 +02:00
TomZ 3e3c4859fe minor bugfix
Make sure we count changes correctly (off-by-one)
2019-03-31 19:53:53 +02:00
TomZ 0264e56551 Second part of 'file full' utxo detection
Do checks during insertAll for those really large blocks.
2019-03-25 12:50:27 +01:00
TomZ 7e8ce613bb Fix regression, failure on shutdown 2019-03-24 21:39:41 +01:00
TomZ b0e57ffd7a Make UTXO able to handle much larger blocks.
Checking if my database file is full can not be assumed to only happen
on end-of-block if blocks get really large.
I'm taking a small performance hit to check this on insert and
flushSomeNodesToDisk on a more regular basis.
2019-03-24 10:23:52 +01:00
TomZ 54c565fdd8 DB files start at 1 2019-03-23 19:24:20 +01:00
TomZ cfe690320d Move various standalone simple classes into utils
The 'server' library has always been a catch-all and
ideally only the hub links it in (far future goal).
In line with this I move a list of files out of server
into the utils lib.
I choose 'utils' because all these are plain old data
objects that many crypto apps will find useful.

now in utils/primitives/
* CScript
* CPubKey
* CTransaction
* CBlock
* FastTransaction
* FastBlock
* CScript

streams.h is now in utils/streaming/
hash.h is now in utils/
2019-03-11 15:40:42 +01:00
TomZ 1f779a3d9b For the UTXO set the no-CoW flag
This is really only relevant for people using btrfs on Linux, we will
set the utxo dir to be no-copy-on-write which causes all new databases
to follow this flag and be faster due to lack of copying on write.
2019-03-06 15:11:42 +01:00
TomZ ef1aa4b4dd Use std::swap
this avoids a race condition.
2019-03-06 10:13:38 +01:00
TomZ a09339dc05 Applying lessons learned for lock-free programming
The reason there are no standard library versions of lock-free
containers is because you want to always take full advantage of
the details in question.
In this case (read millions of times for each modification) it makes
no sense to use anything other than a standard container, but put in
a copy-on-write block. Simple and easy.
2019-03-05 18:52:49 +01:00
TomZ bc53fe2d4b Make this a little less confusing; use BCH not BTC 2019-03-04 12:46:26 +01:00