Commit graph

387 commits

Author SHA1 Message Date
Jason Rhinelander 443c5e8cea Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.

This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).

This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate.  I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.

Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.

Other notable changes:

- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.

- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-07-02 12:52:13 -03:00
Jason Rhinelander 05f0572155 Replace loki::clamp_u64 backport with std::clamp 2020-07-02 12:52:13 -03:00
Jason Rhinelander 49c693d0a9 Split up common/util.h
common/util.h has become something of a dumping ground of random
functions.  This splits them up a little by moving the filesystem bits
to common/file.h, the sha256sum functions to common/sha256sum.h, and the
(singleton) signal handler to common/signal_handler.h.
2020-07-02 12:52:12 -03:00
Jason Rhinelander e7d056edf1 boost::variant -> std::variant
A huge amount of this is repetitive:

- `boost::get<T>(variant)` becomes `std::get<T>(variant)`
- `boost::get<T>(variant_ptr)` becomes `std::get_if<T>(variant_ptr)`
- `variant.type() == typeid(T)` becomes `std::holds_alternative<T>(variant)`

There are also some simplifications to visitors using simpler stl
visitors, or (simpler still) generic lambdas as visitors.

Also adds boost serialization serializers for std::variant and
std::optional.
2020-07-02 12:52:12 -03:00
Jason Rhinelander a506790f1c Serialization (part2): application 2020-07-02 12:52:12 -03:00
Jason Rhinelander 96354a0e0f boost::optional -> std::optional 2020-07-02 12:52:12 -03:00
Doyle 469e6bc583 output_blacklist: Remove redundant return, report exception 2020-06-02 15:50:27 +10:00
Doyle abb8dfc48e Merge commit 'c4f75fe' into MergeUpstream3 2020-05-28 15:29:00 +10:00
Doyle 8080f3548c Merge commit 'd7aeb5a' into MergeUpstream3 2020-05-27 15:30:50 +10:00
Doyle cec06636d9 Merge commit 'e51ce47' into MergeUpstream3 2020-05-27 15:06:09 +10:00
Doyle 39d74a0b38 Merge commit '48d8475b6ea77c6cc9670c9c312f3b7684b12a2c' into MergeUpstream3 2020-05-21 13:37:57 +10:00
Doyle 1d1b618872 Merge branch 'master' into MergeMasterToDev 2020-05-15 14:17:25 +10:00
Doyle ed35bb5418
recalculate_difficulty: Batch work, avoid LMDB paging error (#1150)
* recalculate_difficulty: Batch work, avoid LMDB paging error

F Uncaught exception! Failed to get block info in recalculate difficulty: MDB_TXN_FULL: Transaction has too many dirty pages - transaction too big

* recaluculate_difficulty: Reduce batch to 10k, rewrite num_batches
2020-05-15 14:16:32 +10:00
Doyle ec049b11ca Merge commit 'e3de4aa' into MergeUpstream 2020-04-07 15:21:50 +10:00
Doyle 048ecaede3 Merge commit '9d7107c870d88885f43a8fd65739b1b70a5af668' into MergeUpstream 2020-04-06 15:47:49 +10:00
Maxim Shishmarev 5cdf090539
Add storage server lokimq port (#1056)
* Add storage server lokimq port

* Don't hash storage lmq port until HF15

* Parse storage lmq port from ping
2020-03-11 12:35:36 +11:00
Interchained c61abf87c0 remove empty statements
Cleaning up a little around the code base.
2020-02-17 11:55:15 -05:00
Alexander Blair 8eedc8a390
Merge pull request #6140
08635a08 blockchain: speedup fetching pruned contiguous tx blobs (moneromooo-monero)
2020-01-25 16:55:18 -08:00
Alexander Blair e51ce477db
Merge pull request #6157
402dd207 db_lmdb: guard against non NUL terminated keys (moneromooo-monero)
2020-01-24 20:07:37 -08:00
Doyle c4309edf33 Regenerate the checkpoint table in lmdb
Updating the checkpoint table in place, something must have been done
incorrectly or some bug, such that querying MDB_LAST on the checkpoint
table returns not the latest expected checkpoint.

Pulling out all the old checkpoints, generating a new table and
reinserting them resolves this.
2020-01-10 15:23:55 +11:00
Doyle e44acab3aa Detect unaligned entries via record size, static assert record sizes 2020-01-07 11:10:13 +11:00
Doyle 04150fc9a1 Migrate old checkpoints to new aligned checkpoints data structure 2020-01-06 18:58:45 +11:00
Doyle 3589ed1f69
Byte calc for signatures uses post-endian converted number (#997) 2020-01-06 15:15:57 +11:00
Jason Rhinelander 8ddaf49d24 Disambiguate write txn error message
There's no way to know which of this was fired (the one above, in the
same function, has identical wording).
2019-12-26 12:26:03 -04:00
Jason Rhinelander 78ded3af70 Do txn handling via TXN_BLOCK_PREFIX macro (#982)
The macro handles the case where we can be called from either inside or
outside a block batch transaction.
2019-12-16 08:44:53 +10:00
Jason Rhinelander ed0adc3b69 Simplify service_node_proof_serialized ctor
Also import boost::endian namespace because the boost::endian's
throughout the file were needlessly verbose (the little_to_native calls
are already obvious).
2019-12-09 22:27:33 -04:00
Jason Rhinelander 9797a6a30e Take mdb_block_info pointer in 64bit value helper
This renames mdb_block_info_3 to mdb_block_info so that _1 and _2 are
the old versions (you can't predeclare a typedef), and use it rather
than a void pointer in the 64bit block value fetcher.
2019-12-09 22:26:41 -04:00
Jason Rhinelander b3d6150fa9 Store uptime proof data separately from states
This extracts uptime proof data entirely from service node states,
instead storing (some) proof data as its own first-class object in the
code and backed by the database.  We now persistently store:

- timestamp
- version
- ip & ports
- ed25519 pubkey

and update it every time a proof is received.  Upon restart, we load all
the proofs from the database, which means we no longer lose last proof
received times on restart, and always have the most recently received ip
and port information (rather than only having whatever it was in the
most recently stored state, which could be ~12 blocks ago).  It also
means we don't need to spam the network with proofs for up to half an
hour after a restart because we now know when we last sent (and
received) our own proof before restarting.

This separation required some restructuring: most notably changing
`state_t` to be constructed with a `service_node_list` pointer, which it
needs both directly and for BlockchainDB access.  Related to this is
also eliminating the separate BlockchainDB pointer stored in
service_node_list in favour of just accessing it via m_blockchain (which
now has a new `has_db()` method to detect when it has been initialized).
2019-12-09 22:26:38 -04:00
Jason Rhinelander 446173a3d2 LMDB - code improvements
Various code improvements to LMDB code (no logic changes):

- compile less code by moving the cursor macros (which are used often)
  into local functions

- removes the TXN_POSTFIX_RDONLY macro because it does exactly nothing

- remove useless `inline` from various functions in C++ only has one
  purpose: to tell the compiler that it's okay to have multiple
  definitions (and just throw the extra away when linking).  It is not
  used by any modern C++ compiler to actually decide when to inline, and
  so has no use in a .cpp file.  (Suspect this was written by a C
  programmer who doesn't fully understand C++).

- Remove the C `typedef struct blah { ... } blah;` idiom which has no
  purpose in C++.

- Use inheritance on the nearly-duplicate `mdb_block_info_{1,2,3}
  structs rather than repeating all the field in each one.  This also
  removed a completely unneeded offsetof into them that was being used
  to avoid having to learn C++.  (Also adds a static_assert in case
  anyone ever changes some contained type and breaks things).

- Fix bi_weight comment about why it is really uin64_t

- Add a missing method `override`.

- Replace "22" buried in the code with a constant indicating what it is
  for.  (Oh, reader, you wanted to know what it's used for?  It's the
  number of different databases allowed in the LMDB)

- Move `m_cur_whatever` macros into the .cpp file, and avoid using them
  in any code we've added in loki.  These are incredibly useless
  macros: they are basically just defined to slightly shorten a name.
  I'm guessing that, at some point, these members got moved and rather
  than fix the remaining code someone defined a bunch of macros to deal
  with the rename.  Yuck.

  (Getting rid of *all* of them (i.e. replacing all `m_cur_whatever`
  with `m_cursors->whatever` would be preferable, but would make future
  merge conflicts more painful, so I left the macros as is for the
  upstream databases but removed our service_node_data one.)

- Rename `mdb_txn_cursors` members to drop the leading `m_txc_` prefix.
  When the struct is nothing more than a POD collection of values the
  prefix makes no sense at all.  This allows us the write
  `m_cursors->service_node_data` instead of
  `m_cursors->m_txc_service_node_data` (or the horrible macro, above,
  which seems designed to just macro around this naming horror).
2019-12-09 22:25:44 -04:00
Jason Rhinelander 91d53ebfef big-endian fix - can't inplace convert a const value
Also simplifies the vector insertion a bit by inserting directly from
the begin/end pointers.
2019-12-03 00:51:18 -04:00
Jason Rhinelander 9727f72fec Add ability to fetch multiple tx heights at once
This allows fetching multiple tx heights in a single tx rather than
needing to call multiple times and incur the overhead of a transaction.

This devirtualizes the singular version and reimplements it as a simple
wrapper around the vector version.
2019-11-27 14:29:49 -04:00
Jason Rhinelander 7a5604ac06 Removing unneeded (and possibly harmful) packing
These structures will always end up packed anyway (everything in them is
8-byte aligned and a multiple of 8 bytes), but the pack pragma also
changes their alignment which isn't good (and causes warnings).  This
just static_asserts that they are padding-free instead, which is the
intention.
2019-11-27 14:08:57 -04:00
moneromooo-monero 402dd2078c
db_lmdb: guard against non NUL terminated keys 2019-11-19 11:12:49 +00:00
moneromooo-monero 08635a0875
blockchain: speedup fetching pruned contiguous tx blobs
About twice as fast, very roughly
2019-11-15 13:23:30 +00:00
Lee Clagett 5d7ae2d279 Adding support for hidden (anonymity) txpool 2019-11-02 20:36:03 +00:00
Doyle c6cbb5bc65 Remove endian swap on non-integral type enum struct blob_type 2019-10-18 15:30:25 +11:00
moneromooo-monero 37cccb8cfb
db_lmdb: an empty prunable data record means the tx is not pruned
as opposed to an absent record
2019-10-17 17:39:05 +00:00
moneromooo-monero 8330e772f1
monerod can now sync from pruned blocks
If the peer (whether pruned or not itself) supports sending pruned blocks
to syncing nodes, the pruned version will be sent along with the hash
of the pruned data and the block weight. The original tx hashes can be
reconstructed from the pruned txes and theur prunable data hash. Those
hashes and the block weights are hashes and checked against the set of
precompiled hashes, ensuring the data we received is the original data.
It is currently not possible to use this system when not using the set
of precompiled hashes, since block weights can not otherwise be checked
for validity.

This is off by default for now, and is enabled by --sync-pruned-blocks
2019-09-27 00:10:37 +00:00
Doyle 4b7b134b30
Include the tip of the chain when recalculating difficulty (#847) 2019-09-19 17:38:34 +10:00
Jason Rhinelander 5b67df6f55 Silence gcc 9 warnings & fix potential unaligned access
Silences:

    src/blockchain_db/lmdb/db_lmdb.cpp: In member function ‘virtual void cryptonote::BlockchainLMDB::open(const string&, cryptonote::network_type, int)’:
    src/blockchain_db/lmdb/db_lmdb.cpp:1473:63: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
     1473 |     if (db_version > static_cast<decltype(db_version)>(VERSION))
          |                                                               ^
    src/blockchain_db/lmdb/db_lmdb.cpp:1480:68: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
     1480 |     else if (db_version < static_cast<decltype(db_version)>(VERSION))
          |                                                                    ^

which happens because the `decltype()` here is const, and gcc apparently
now apparently warns on a cast to a const cast result.

While here I also noticed and fixed what looks like an unaligned access
that could be a potential problem on non-x86 architectures.
2019-09-15 23:10:55 -03:00
Doyle ce85eccf72
Rescan difficulty periodically, fix incorrect timestamps/difficulties in rescan (#835)
* Rescan difficulty periodically, fix incorrect timestamps/difficulties in rescan

* Code review
2019-09-13 15:46:15 +10:00
Doyle 1db5eedb63 Add static assert on blob_header to check for alignment 2019-09-11 15:38:21 +10:00
Doyle ea3bd74cd0 Update for_alt_blocks to support checkpoint blobs 2019-09-11 10:19:19 +10:00
Doyle 3fd0face4e Store alt checkpoints into the db to be applied on reorg 2019-09-10 17:59:17 +10:00
Doyle 5ca1d075d8 Only use greater pow alt chain if it has more checkpoints
Add migratory code for new alt_block_data_t.checkpointed field

Code review

Redo switch to alt chain logic to handle PoW properly

We always switch to the chain with prevailing checkpoints. If an old
chain reappears with more checkpoints it will be rebroadcasted and at
that point we will switch over then. So here we restore the old
behaviour regarding keeping alt chains around or not depending on the
scenario that caused the chain switch
2019-09-10 10:24:34 +10:00
moneromooo-monero 4672b5cea9
db_lmdb: print percentages as percentages, not ratios 2019-09-04 14:53:59 +00:00
Doyle add6051a8f
make get_checkpoints_range faster by using lmdb cursor as iterator (#819)
* make get_checkpoints_range faster by using lmdb cursor as iterator

* Update clamp to be more compliant with convention
2019-08-30 13:54:49 +10:00
Howard Chu 50ec40ea16
Increase max_dbs from 20 to 32
We've added a lot of new indices recently, and 20 isn't enough for them plus
new DBs opened during format migrations.
2019-08-18 17:10:45 +01:00
Doyle 83f69a791c Serialize long term storage separate from short term 2019-08-17 14:55:42 +10:00
Doyle ce150e43e9
Merge pull request #796 from Doy-lee/CheckpointReview
Checkpoints: Avoid race updating checkpoint with a potentially older checkpoint
2019-08-15 16:09:17 +10:00