Commit graph

347 commits

Author SHA1 Message Date
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
Doyle c6cbb5bc65 Remove endian swap on non-integral type enum struct blob_type 2019-10-18 15:30:25 +11: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
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
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
Doyle d973d42250 Lock blockchain when quorum cop attempts to update checkpoint 2019-08-14 15:32:49 +10:00
Doyle b6f24d7fb0
Fix checkpoint regression, must accept alt blocks if they are < the first checkpoint (#792) 2019-08-13 15:33:20 +10:00
Doyle 4c73a9cf34
Immutable checkpoint api update (#773)
* Make immutable checkpoint function return the checkpoint

* Update test db immutable checkpoints prototype

* Handle the empty checkpoints_range case, remove unused variable

* Code review: simplify immutable detection logic

* Switch back to holding checkpoint ptrs to avoid copies
2019-08-09 10:01:12 +10:00
Doyle e7f44e4554 Increase the age of service node rollbacks we keep
Increase the range to mitigate frequent rescanning when reorganising,
technically with checkpointing we only need up to the 2nd oldest
checkpoint, but I'm sure there's some case we're forgetting that would
benefit from a larger rollback range.

Also considering there were only 160 events in the month with a mass
deregistration- keeping 2 days worth of rollbacks around is not going to
be too expensive.

Start storing service node list state for past blocks

Separate quorums and reduce storage to 1 days worth

Don't use pointer, declare m_state by value

Fix rebase to dev

Fix double serialise of service node state and expensive blob copy

std::move quorums into storage, reserve vector size

Don't +1 checkpoint finality height

Code review

Code review 2
2019-07-22 12:35:47 +10:00
Doyle 3cc5fd62ca
Difficulty workaround (#722)
* Recalculate difficulty on reorganisation workaround

* Gate difficulty workaround to only be on mainnet

* Make difficulty changes emit logs on diff delta only
2019-07-11 14:15:32 +10:00
Doyle d0fb04db46
Improved print_checkpoints + json_rpc get_checkpoints call (#708)
* Improved print_checkpoints

* Flesh out print checkpoints and associated RPC call

* Remove debug print checkpoints

* Update help text for print_checkpoints

* Rewrite to fix num_checkpoints != heights as a unit of measurement

* Use GET_ALL_CHECKPOINTS defined value in get_checkpoints_range

* Let T be deduced in parse_if_present, json_rpc_request not rpc_request
2019-07-05 09:34:51 +10:00
Jason Rhinelander 27252701ea Cap difficulty at 30MH/s for first 60 v12 blocks (#677)
We're going to be coming down off a ~300MH/s high, so add a difficulty
cap of 30MH/s for the first 60 blocks so that we don't end with
extremely long blocks.
2019-06-27 17:05:32 +10:00
Jason Rhinelander 94b5857a84 Merge remote-tracking branch 'LMDB/randomx' into randomx 2019-06-26 21:50:51 -03:00
Doyle 639d7456f7 Merge commit '1d5e8f4' into LokiMergeUpstream 2019-06-26 13:04:37 +10:00
Doyle 43084f7202
Merge pull request #659 from jagerman/relaxed-relax-dereg
Relaxed relax dereg (stripped)
2019-06-24 15:58:21 +10:00
Jason Rhinelander 6ce197478a lmdb size/endian fix (#660)
Fixes some potential architecture issues with the checkpoint lmdb:

- size_t is not a fixed size type (so 32-bit architectures and 64-bit
architectures would store a different amount of data here)
- add endian conversions to the integer fields before/after loading
(these are no-ops on little-endian architectures, i.e. in the vast
majority of the time).
2019-06-20 17:51:05 +10:00
Jason Rhinelander 4f721c0098 Make tx type and version scoped enums
This converts the transaction type and version to scoped enum, giving
type safety and making the tx type assignment less error prone because
there is no implicit conversion or comparison with raw integers that has
to be worried about.

This ends up converting any use of `cryptonote::transaction::type_xyz`
to `cryptonote::transaction::txtype::xyz`.  For version, names like
`transaction::version_v4` become `cryptonote::txversion::v4_tx_types`.

This also allows/includes various other simplifications related to or
enabled by this change:
- handle `is_deregister` dynamically in serialization code (setting
  `type::standard` or `type::deregister` rather than using a
  version-determined union)
- `get_type()` is no longer needed with the above change: it is now
  much simpler to directly access `type` which will always have the
  correct value (even for v2 or v3 transaction types).  And though there
  was an assertion on the enum value, `get_type()` was being used only
  sporadically: many places accessed `.type` directly.
- the old unscoped enum didn't have a type but was assumed castable
  to/from `uint16_t`, which technically meant there was potential
  undefined behaviour when deserializing any type values >= 8.
- tx type range checks weren't being done in all serialization paths;
  they are now.  Because `get_type()` was not used everywhere (lots of
  places simply accessed `.type` directory) these might not have been
  caught.
- `set_type()` is not needed; it was only being used in a single place
  (wallet2.cpp) and only for v4 txes, so the version protection code was
  never doing anything.
- added a std::ostream << operator for the enum types so that they can be
  output with `<< tx_type <<` rather than needing to wrap it in
  `type_to_string(tx_type)` everywhere.  For the versions, you get the
  annotated version string (e.g. 4_tx_types) rather than just the number
  4.
2019-06-19 17:47:03 -03:00
moneromooo-monero 0564da5fdc
ensure no NULL is passed to memcpy
NULL is valid when size is 0, but memcpy uses nonnull attributes,
so let's not poke the bear
2019-06-14 08:47:29 +00:00
Doyle 9f12ae0c0a
Service Node Checkpointing: More reliable transportation of votes, culling of old checkpoints (#632)
* Initial updates to allow syncing of checkpoints in protocol_handler

* Handle checkpoints in prepare_handle_incoming_blocks

* Debug changes for testing, cancel changes later

* Add checkpoint pruning code

* Reduce DB checkpoint accesses, sync votes for up to 60 blocks

* Remove duplicate lifetime variable

* Move parsing checkpoints to above early return for consistency

* Various integration test fixes

- Don't try participate in quorums at startup if you are not a service node
- Add lock for when potentially writing to the DB
- Pre-existing batch can be open whilst updating checkpoint so can't use
  DB guards
- Temporarily emit the ban message using msgwriter instead of logs

* Integration mode bug fixes

- Always deserialize empty quorums so get_testing_quorum only fails when
an actual critical error has occurred
- Cache the last culled height so we don't needlessly query the DB over
the same heights trying to delete already-deleted checkpoints
- Submit votes when new blocks arrive for more reliable vote
transportation

* Undo debug changes for testing

* Update incorrect DB message and stale comment
2019-06-13 18:01:08 +10:00
moneromooo-monero aed89cd99f
blockchain: keep alternative blocks in LMDB
Alternative blocks are cleared on startup unless --keep-alt-blocks
is passed on the command line
2019-06-01 21:40:46 +01:00
Doyle 8af377d2b8
Unify and move responsibility of voting to quorum_cop (#615)
* Unify checkpointing and uptime quorums

* Begin making checkpoints cull old votes/checkpoints

* Begin rehaul of service node code out of core, to assist checkpoints

* Begin overhaul of votes to move resposibility into quorum_cop

* Update testing suite to work with the new system

* Remove vote culling from checkpoints and into voting_pool

* Fix bugs making integration deregistration fail

* Votes don't always specify an index in the validators

* Update tests for validator index member change

* Rename deregister to voting, fix subtle hashing bug

Update the deregister hash derivation to use uint32_t as originally set
not uint64_t otherwise this affects the result and produces different
results.

* Remove un-needed nettype from vote pool

* PR review, use <algorithms>

* Rename uptime_deregister/uptime quorums to just deregister quorums

* Remove unused add_deregister_vote, move side effect out of macro
2019-05-31 11:06:42 +10:00
Doyle 47e5ab779c Merge branch 'master' into BackportVersion3Patch6ToDev 2019-05-27 10:16:13 +10:00
Doyle 71447e7877
Add flag to recalculate difficulty per block (#598)
* Beging adding functions to recalculate difficulty

* Add command line args to utility for recalculating difficulty

* Exception safety for recalculating difficulty

* Update help text for recalc difficulty

* Add recalc flag on the daemon

* Make context be const, signify intent for var++ to 1
2019-05-12 09:40:57 +10:00
moneromooo-monero e980938210
fix wide difficulty conversion with some versions of boost 2019-05-01 19:58:09 +00:00
Doyle f19e937a05 Merge commit '46c477a' into LokiMergeUpstream 2019-05-01 17:32:57 +10:00
Doyle 455129c8ca Merge branch 'dev' into LokiMergeUpstream 2019-05-01 16:31:54 +10:00
Doyle 73e8ac0343
Service Node Checkpoint Storage (#579)
* Add functions for storing checkpoints to the DB

* Allocate the DB entry on the stack instead of heap

* Add virtual overrides for new checkpoint functions

* Clean up for pull request, simplify some logic

* Revise API to include height in checkpoint header

* Move log to top of function even if early exit

* Begin moving checkpoints to db

* Allow storing of checkpoints to DB

* Cleanup for code reviewer, fix unit tests

* Fix tests, fix casting issues

* Don't use DUPSORT, use height->checkpoint mapping in DB

* Remove if 0 disabling checkpoint vote, we already check HF12

* Fix unit test infinite loop

* Update db schemas to match blk_checkpoint_header

* Code review
2019-05-01 15:57:41 +10:00
moneromooo-monero 5e673c03fe
blockchain_db: fix db txn ending too early
The db txn in add_block ending caused the entire overarching
batch txn to stop.
Also add a new guard class so a db txn can be stopped in the
face of exceptions.

Also use a read only db txn in init when the db itself is
read only, and do not save the max tx size in that case.
2019-04-14 08:35:38 +00:00
Doyle 4778d862c9 Merge commit 'bd42903' into LokiMergeUpstream 2019-04-12 18:37:56 +10:00
Doyle b985a05dd3 Merge commit 'cd776b1' into LokiMergeUpstream 2019-04-12 16:23:54 +10:00
Doyle 892469ded1 Update monero copyright to 2019 pre-emptively to make merge simpler 2019-04-12 14:36:43 +10:00
Doyle 8d7d90c374 Merge commit 'ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77' into LokiMergeUpstream 2019-04-11 15:08:26 +10:00
Doyle 4f0a729533 Merge commit '4466f4504e8bc41d353a6becce0526df8272bc1d' into LokiMergeUpstream 2019-04-10 09:59:38 +10:00
Doyle 0458a4849e Merge commit '55305559c1ce10ec5d5d5a1c5d31e5056b8a9dd6' into LokiMergeUpstream 2019-04-09 18:57:11 +10:00
moneromooo-monero 089c7637a6
cryptonote: rework block blob size sanity check
Use the actual block weight limit, assuming that weight is always
greater or equal to size
2019-04-05 09:35:19 +00:00
moneromooo-monero 91f4c7f45f
Make difficulty 128 bit instead of 64 bit
Based on Boolberry work by:
  jahrsg <jahr@jahr.me>
  cr.zoidberg <crypto.zoidberg@gmail.com>
2019-03-24 21:03:19 +00:00
Riccardo Spagni 5ac46c5310
Merge pull request #5256
4b21d38d blockchain: speed up getting N blocks weights/long term weights (moneromooo-monero)
2019-03-21 14:48:40 +02:00
moneromooo-monero 4b21d38dfd
blockchain: speed up getting N blocks weights/long term weights 2019-03-08 12:04:14 +00:00
binaryFate 1f2930ce0b Update 2019 copyright 2019-03-05 22:05:34 +01:00
Riccardo Spagni e65221d690
Merge pull request #5119
f024a10b db_lmdb: make mdb_block_info format conversion more future proof (moneromooo-monero)
2019-03-05 14:12:24 +02:00