Commit Graph

32 Commits

Author SHA1 Message Date
tomFlowee 4fe9d69e7b Use more specific define-guards 2024-01-24 21:03:58 +01:00
tomFlowee bc47a700a4 Refactor; wrap BufferPool in shared_ptr
As we moved most of the creation of a BufferPool to be via the
Streaming::pool() method, which uses a thread-local, it makes sense
to start cleaning up the design and make it more modern C++.
The above mentioned method would return a reference and you'd see
loads of places use `auto &pool =` which is less than ideal.

As the number of places where we actually instantiate a BufferPool
goes down, the usage of some sort of smart pointer makes more sense.

This now makes all APIs use BufferPool be wrapped in a shared_ptr.
2023-12-21 15:23:23 +01:00
tomFlowee 1b7b24ee9f Fixlets in API docs. Correct arg-name. 2023-10-24 20:24:59 +02:00
tomFlowee 30ac78807c API / docs updates 2023-07-15 11:36:19 +02:00
tomFlowee ebaccb6fee Move include to cpp file 2023-07-15 11:36:19 +02:00
tomFlowee ae78dd0bb8 Update email address 2021-06-20 22:44:44 +02: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 089145a3a6 Delete copy constructor 2020-11-17 16:04:45 +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 1141de5c13 Cleanups 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 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 4a6845ff76 Fixlets from static code inspector 2019-09-12 15:24:03 +02:00
TomZ 230611b98e Tweak the numbers to be better on IBD 2019-06-12 23:53:24 +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 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 31650b7340 Squashed commit of the utxo-lockfree-map branch
Replace the m_buckets unsorted map with a lock-free version
based on atomic pointers. (BucketMap)
remove the m_leafs and move those into the bucket struct.
Make the access to the jumptable transactional to avoid one big lock
over all datastructures.

On my threadripper 2990WX the entire 150GB BCH blockchain was
parsed and imported in under 3 hours.
2019-02-23 15:33:22 +01:00
TomZ c6297727b8 Change the inserting to be in batches 2018-11-21 20:20:31 +01:00
TomZ 71b45cd38c Merge branch 'dev/HFNov2018' 2018-11-15 23:40:56 +01:00
TomZ cdec1fa593 Implement CTOR validation 2018-11-15 23:35:43 +01:00
TomZ d55c7bfed8 Make UTXO write timebased as well
The current system writes based on the amount of changes, which is a bit
risky as long as we have small blocks as the amount of changes may for
hours be below the "lets write" limit.

So also write every 5 minutes, just to make sure we won't keep data in
memory longer than needed. Also this allows pruning to happen for people
that don't run their node all the time.
2018-11-11 16:47:54 +01:00
TomZ fdd693541e Make the UTXO have some limits "configurable"
This change makes the limits be static variables, which means they are
only settable once for a process. The only usecase so far is to use much
smaller limits in testing situations.
2018-10-21 13:21:24 +02:00
TomZ 3fbc2e89f1 Speed up UTXO, replace mutex with lock-free list 2018-10-08 22:30:21 +02:00
TomZ a28ffd18bb Write less txid's to the DB file and write shorter ones.
When pruning we sort leafs by txid / output and refrain from
writing the txid repeatedly for outputs of the same tx.
Additionally, use the fact that we only ever get to a leaf via
a bucket and since the first 64 bits of a txid is there, skip
repeating them when writing to disk.
Last, make pruning have different strategies.

This should shrink the utxo by about 40%
2018-09-24 21:24:28 +02:00
TomZ 6c68f9df12 Updates to UnspentOutputDatabase classes
* remove unused code
* reorg code to make the access to disk be outside the mutex
* add detection of slow disk-writes and slow down data coming in
* Update and fix the rmHint
2018-09-05 11:16:29 +02:00
TomZ 0bfa3cbb85 Introduce rollback() on UnspentOutputDB
together with blockFinished() as 'commit' this introduces the ability
to modify the in-memory utxo which can be rolled-back with ease.

This allows us to "modify" the utxo while validating a block in an
optimistic manner and only spend extra resources doing a rollback
should the block end up not being Ok.
2018-07-29 18:03:49 +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 f0f07153fa Remove unused tag 2018-05-10 01:25:50 +02:00
TomZ 886e921b89 Fix typo in methodname 2018-05-09 12:46:54 +02:00
TomZ c368c6ef77 Create new UTXO database library
The old was based on levelDB which has scalability issues and stability
issues. (most often cited problem is corrupted database..)

This unspent output database I wrote is based on the idea that we need
never actually update any rows, which makes most old fashioned databases
a bad fit.
All we do is create rows and we forget rows. So lets design a DB to fit
that pattern.
2018-05-09 10:48:16 +02:00