Commit Graph

51 Commits

Author SHA1 Message Date
tomFlowee 50af3dc02c [Refactor] rename FastBlock.{h|cpp} -> Block.* 2021-11-02 10:24:58 +01:00
tomFlowee 6ff0e7c0de [Refactor] FastBlock -> Block 2021-11-02 10:18:24 +01:00
tomFlowee 223cc61968 Remove dead code 2021-06-12 12:20:06 +02:00
tomFlowee 4f8f5ba739 blk file management: handle truncated files.
This makes it possible for the most recent file to not be the default
filesize but much smaller. This fixes us to writing outside of the
allocated membuffer and causing a kernel signal.
Additionally we start a new file for writes in that case.

This case is seen in the unit tests where we have a perfect-fitting file
in git which we then try to write to when adding a new block.
As such this is tested in the upcoming unit test.
2021-03-24 21:00:25 +01:00
tomFlowee 4e0acff905 Make reindex finding blocks massively faster.
The code that connects blocks together uses the block-hash (blockId) for
that, which we always just created on the fly.
Instead store the blockId on the state and in that way make adding
headers not entirely in-sequence be 10 times as fast.

Additionally, we wait with actual validation after a reindex until the
files are all found because otherwise we can't save the meta blocks.
2021-03-12 11:21:46 +01:00
tomFlowee ad7b81c17a Simplify and pick during reindex. 2021-03-12 10:28:27 +01:00
tomFlowee b1daf37b43 Make reindex find the metadata blocks. 2021-03-10 20:11:04 +01:00
tomFlowee a4351c2f95 Write the meta block to disk. 2021-03-10 20:11:04 +01:00
TomZ d430a4be8a Update all usages of boost create_directories
The API throws when the directories already exist, which is quite
unexpected.
This now changes the code to silently ignore these issues in the
knowledge that the immediately following opening of files will
fail with a nice error message.
2020-11-23 14:09:00 +01:00
TomZ 27e507cba0 Test and fix reconsiderBlock
This adds a unit test to see if the combination of invalidateBlock and
reconsiderBlock do what we expect to do.

The main issue was that we store an invalidated block in the UTXO and we
forgot to re-validate that on reconsider.

Additionally I avoid writing a lot of unchanged data to the block-index.
2020-11-18 22:08:00 +01:00
TomZ 67cf8955b0 Drop usage of old log-style. 2020-10-27 16:33:08 +01:00
TomZ 7e59d0c242 Remove loud log message 2020-08-16 14:53:13 +02:00
TomZ acd142a0e6 Fix logic wrt signed/unsigned
The typedef was an unsigned type, and comparisons failed.
2020-08-16 12:22:00 +02:00
TomZ 679374e923 Revert chain-switching idea
It becomes messy due to the usage of the compact form on block headers.
2020-08-16 12:03:19 +02:00
TomZ 750bd23b27 Work around badly picked default variable value.
A not yet saved file has file-index zero, which is valid...
Also check this state and allow deletion of rev zero.
2020-08-13 18:28:43 +02:00
TomZ 59c468decf We now check if a revert file has become useless and delete it
If we are past at least 2000 blocks of the items stored in a data file we
can delete the revert file and save a couple hundred megabytes of
on-disk storage for every blk file.
2020-08-13 13:32:01 +02:00
TomZ 90988c80a9 Fix reindex sometimes taking forever on a block file. 2020-08-13 11:45:02 +02:00
TomZ 84ebae427e Import ASERT DAA
This includes renaming some methods which makes the import look larger
than it really is.
2020-08-12 21:42:54 +02:00
TomZ 297a22dfa8 Move and fix partitionCheck()
Small refactor; move the partition check away from main and the obsolete
global variables we used to use, instead now just add it to the DB which
owns the data it works on.

This fixes the bug that in various cases we'd incorrectly get a warning
about no blocks being found in the last N hours.
2020-08-10 10:13:02 +02:00
TomZ 60f1864b74 API review. Use isClosingDown() 2020-05-21 19:33:13 +02:00
TomZ 01ff5ff1db Make writing to blk file not follow symlinks
To share the downloaded blocks between instances on Linux it is common
to sym-link the blk files from read-only storage.
The Hub would fail to write to the last file due to the file being on
read-only storage and the Hub would shut down.
This change makes sure we instead create a new file instead of trying to
write to a symlinked one.
2020-03-05 23:29:52 +01:00
TomZ a790b26133 Just warn about failing to write to a legacy blk
Boost throws an exception when the resize fails, which would cause
a total shutdown of the client. So make sure we catch it in the
scheduled task to avoid this problem.
2020-03-01 18:27:28 +01:00
TomZ 30927fe0b2 Fix reindexing sometimes failing due to read-only blocks
When reindexing we now always first try to open a file read-write because
the algo to only open the last file in a sequence as RW failed in such
situations where we don't know the amount of files yet.
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 42aaf08e6b Fixlet in comments grammar. 2019-11-25 23:23:00 +01: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 01459ec961 Refactor; move lastCommonAncestor to Blocks::Index ns
Out of the main.cpp and usable for a bigger audience.
2019-05-27 09:27:08 +02:00
TomZ 3f1fae0adb Fix case where indexDB inconsistency was not detected properly
When a block is expected to be on-disk, but we don't know where it is
this now no longer leads to a validation process hanging.
2019-02-18 18:31:17 +01:00
TomZ caff0b1ee2 Add block-maintainance cronjob
Every 15 minutes we check and take action should there be a need
to delete old revert files or truncate blk files.
2019-02-15 13:31:49 +01:00
TomZ c367278a1d Cleanup resizing code
We no longer resize blk / rev files, which was a premature optimization.
This means this code is obsolete.
2019-02-06 13:40:40 +01:00
TomZ 8998b0afaf Move slow unmapping to be done outside the mutex 2019-02-06 13:39:56 +01:00
TomZ 135bbb9a5f Cleanup BOOST_FOREACH -> for(:) 2018-12-30 15:33:11 +01:00
TomZ f89aa4598c Fix copy/paste error in chaintip-finding
and add some debug output on startup for the chaintips.
2018-11-21 12:49:18 +01:00
TomZ 8f9b160012 Make mapper close more agressive
I expect that it would be bettter to make this configurable
because it is based on what the rest of the system is used for.
2018-11-18 12:27:41 +01:00
TomZ 58a9baba3a On loading, calculate nChainWork 2018-11-18 12:12:38 +01:00
TomZ 7b76d177e8 Remove chain obfuscation misfeature. 2018-11-02 20:42:45 +01:00
TomZ 90f635e8ec Add a test for a cornercase of appendHeader and fix it. 2018-10-21 20:38:34 +02:00
TomZ a2928b91eb Simplify
On all mature operating systems and filesystems creation of a 1GB file
will not actually use that data, only when we start using blocks does
the disk space get used.
As such this is a premature optimization that Core added and I ported to
Flowee which this commit removes.

Additionally, increase the block file size to 1GiB
2018-10-05 20:49:44 +02:00
TomZ 7511b0e47f Have an upper limit for the amount of files we keep open 2018-10-05 20:27:42 +02:00
TomZ a22cae12ae Make having open mapped files more smart.
Instead of having a magic 10 open files, we now have a scheduled
run that closes all mapped files 30 seconds after last usage.
This allows many files to be opened with extremely low overhead and
cost (they are not actually loaded until needed, and even then only
per 4K page).
2018-09-25 18:22:57 +02:00
TomZ 9aec9e5eeb Merge branch 'master' into UnspentOutputDB 2018-09-24 21:25:34 +02:00
TomZ 1e9d9b3ea2 Fix system call, its in bytes not in ints 2018-09-24 21:23:27 +02:00
TomZ 371ac9849c Fix case where reindex thought it was done
After we extract all block-headers from the files and we then shut down
the node this makes sure that we avoid thinking we finished because
there are no more jobs.
This so that a restarting node has the opportunity to continue indexing.
2018-09-24 21:23:27 +02:00
TomZ 854544f33a Make scanned but not validated files also save to blockindex 2018-08-06 13:57:09 +02:00
TomZ ebde1fd457 When restarting a reindex, avoid doing double work. 2018-08-06 12:00:14 +02:00
TomZ 2fde96e54b Merge branch 'master' into UnspentOutputDB 2018-08-05 10:59:35 +02:00
TomZ c2cfea6b50 Notice exit faster.
This also makes the exit more stable and avoids hangs.
2018-08-05 10:58:19 +02:00
TomZ 1600086ede Updates to and start using the UnspentOutputDB
The new UnspentOutputDatabase classes are only very loosly a database, we
purely register and store unspent outputs there. But unline a DB we don't
allow modification (just insert and delete).

This replaces the coin-db (which was based on leveldb) and as first goal
this gives us a higher level of stability. The level-database was known
to give corruption issues.

Notice that users will need to do a manual reindex on first update.
2018-07-23 19:49:32 +02:00
TomZ 3690014f02 Fixes in signedness and usage of new C++ constructs 2018-06-12 19:26:26 +02:00
TomZ 53fb30d67e Make more readable. 2018-02-20 13:52:47 +01:00