Commit Graph

97 Commits

Author SHA1 Message Date
Jason Rhinelander 13409ad00e
run clang format 2023-04-13 17:15:12 -03:00
Jason Rhinelander 6aa9db9538
Overhaul and fix crypto::{public_key,ec_point,etc.} types
- Remove implicit `operator bool` from ec_point/public_key/etc. which
  was causing all sorts of implicit conversion mess and bugs.
- Change ec_point/public_key/etc. to use a `std::array<unsigned char,
  32>` (via a base type) rather than a C-array of char that has to be
  reinterpret_cast<>'ed all over the place.
- Add methods to ec_point/public_key/etc. that make it work more like a
  container of bytes (`.data()`, `.size()`, `operator[]`, `begin()`,
  `end()`).
- Make a generic `crypto::null<T>` that is a constexpr all-0 `T`, rather
  than the mishmash `crypto::null_hash`, crypto::null_pkey,
  crypto:#️⃣:null(), and so on.
- Replace three metric tons of `crypto::hash blahblah =
  crypto::null_hash;` with the much simpler `crypto::hash blahblah{};`,
  because there's no need to make a copy of a null hash in all these
  cases.  (Likewise for a few other null_whatevers).
- Remove a whole bunch of `if (blahblah == crypto::null_hash)` and `if
  (blahblah != crypto::null_hash)` with the more concise `if
  (!blahblah)` and `if (blahblah)` (which are fine via the newly
  *explicit* bool conversion operators).
- `crypto::signature` becomes a 64-byte container (as above) but with
  `c()` and `r()` to get the c() and r() data pointers.  (Previously
  `.c` and `.r` were `ec_scalar`s).
- Delete with great prejudice CRYPTO_MAKE_COMPARABLE and
  CRYPTO_MAKE_HASHABLE and all the other utter trash in
  `crypto/generic-ops.h`.
- De-inline functions in very common crypto/*.h files so that they don't
  have to get compiled 300 times.
- Remove the disgusting include-a-C-header-inside-a-C++-namespace
  garbage from some crypto headers trying to be both a C and *different*
  C++ header at once.
- Remove the toxic, disgusting, shameful `operator&` on ec_scalar, etc.
  that replace `&x` with `reinterpret_cast x into an unsigned char*`.
  This was pure toxic waste.
- changed some `<<` outputs to fmt
- Random other small changes encountered while fixing everything that
  cascaded out of the above changes.
2022-10-17 22:20:54 -03:00
Jason Rhinelander c9934b9f5f
Change most oxen::log::whatever to log::whatever
oxen::log::info(...), etc. are a bit too verbose; this simplifies them
to just `log::info(...)`, etc. by aliasing the `oxen::log` namespace
into most of the common namespaces we use in core.

This result is usage that is shorter but also reads better:

    oxen::log::info(logcat, "blah: {}", 42);

    log::info(logcat, "blah: {}", 42);
2022-10-17 13:41:43 -03:00
Sean Darcy d7992b5940
Logging Refactor
This replaces the current epee logging system with our oxen::log
library. It replaces the easylogging library with spdlog, removes the
macros and replaces with functions and standardises how we call the
logs.
2022-10-17 13:41:10 -03:00
Thomas Winget 1311a20e9f merge dev branch with RPC/wallet3 changes
Incomplete, many things to fix, some annotated with
a comment MERGEFIX
2022-07-11 20:40:50 -04:00
Jason Rhinelander 26869869aa
Remove stupid typedef 2022-05-20 18:30:55 -03:00
Jason Rhinelander dfe566480b
Remove cryptonote_config macros
- Replace all cryptonote_config macros with constexpr variables.  Some
  become integer types, some become chrono types.
  - generally this involved removing a "CRYPTONOTE_" prefix since the
    values are now in the `cryptonote` namespace
  - some constants are grouped into sub-namespaces (e.g.
    cryptonote::p2p)
  - deprecated constants (i.e. for old HFs) are in the `cryptonote::old`
    namespace.
  - all the magic hash key domain separating strings are now in
    cryptonote::hashkey::WHATEVER.
- Move some economy-related constants to oxen_economy.h instead
- Replaced the BLOCKS_EXPECTED_IN_DAYS constexpr functions with more
  straightforward `BLOCKS_PER_DAY` value (i.e.  old
  `BLOCKS_EXPECTED_IN_DAYS(10)` is now `BLOCKS_PER_DAY * 10`.
- Replaced `network_version` unscoped enum with a scoped enum
  `cryptonote::hf`, replacing all the raw uint8_t values where it was
  currently accepted with the new `hf` type.
- Made `network_type` a scoped enum so that it now has to be qualified
  (network_type::TESTNET) and can't be arbitrarily/unintentionally
  converted to/from an int.
- HARDFORK_WHATEVER macros have become cryptonote::feature::WHATEVER
  constexpr hf values.
- Add `revision` to rpc hard_fork_info response
- Don't build trezor code at all (previously we were pointlessly
  building an empty dummy lib).
2022-05-16 20:37:07 -03:00
Sean Darcy 866691d9d8 Batching of service node rewards
This updates the coinbase transactions to reward service nodes
periodically rather than every block. If you recieve a service node
reward this reward will be delayed x blocks, if you receive another
reward to the same wallet before those blocks have been completed it
will be added to your total and all will be paid out after those x
blocks has passed.

For example if our batching interval is 2 blocks:

Block 1 - Address A receives reward of 10 oxen - added to batch
Block 2 - Address A receives reward of 10 oxen - added to batch
Block 3 - Address A is paid out 20 oxen.

Batching accumulates a small reward for all nodes every block

The batching of service node rewards allows us to drip feed rewards
to service nodes. Rather than accruing each service node 16.5 oxen every
time they are pulse block leader we now reward every node the 16.5 /
num_service_nodes every block and pay each wallet the full amount that
has been accrued after a period of time (Likely 3.5 days).

To spread each payment evenly we now pay the rewards based on the
address of the recipient. This modulus of their address determines which
block the address should be paid and by setting the interval to our
service_node_batching interval we can guarantee they will be paid out
regularly and evenly distribute the payments for all wallets over this
2022-04-29 09:51:14 +10:00
Jason Rhinelander 109b7b81e4 Eviscerate epee timing garbage
Removes a bunch of epee garbage and replaces it with std::chrono.

In particular:

- TIME_MEASURE_* macros are gone because they are garbage.
- epee::get_tick_count() is gone because it is garbage.
- epee::get_ns_count() is gone because it is garbage.
- TIME_MEASURE_NS_* macros are gone because they are unused and garbage.
- PROFILE_FUNC_* macros are gone because they are unused and garbage.
- profile_tools::local_call_account is gone because it is unused and
  garbage.
- various places passing around ints (which could be seconds,
  milliseconds, or nanoseconds) changed to pass std::chrono duration
  types.
2021-11-01 14:54:21 -04:00
Jason Rhinelander 7b00cb251b Add snode revision soft forks & drop hard fork voting code
Snode revisions are a secondary version that let us put out a mandatory
update for snodes that isn't a hardfork (and so isn't mandatory for
wallets/exchanges/etc.).

The main point of this is to let us make a 9.2.0 release that includes
new mandatory minimums of future versions of storage server (2.2.0) and
lokinet (0.9.4) to bring upgrades to the network.

This slightly changes the HF7 blocks to 0 (instead of 1) because,
apparently, we weren't properly checking the HF value of the
pre-first-hf genesis block at all before.  (In practice this changes
nothing because genesis blocks are v7 anyway).

This also changes (slightly) how we check for hard forks: now if we skip
some hard forks then we still want to know the height when a hard fork
triggers.  For example, if the hf tables contains {7,14} then we still
need to know that the HF14 block height also is the height that
activates HF9, 10, etc.
2021-06-19 15:13:57 -03:00
Sean Darcy 432dc319a9 executable names changed 2021-01-04 14:19:42 +11:00
Jason Rhinelander b627b3b4bb Move epee includes under "epee/..."
This ends epee's include pollution.
2020-10-24 12:46:27 -03:00
Jason Rhinelander 78833f9d69 Remove deprecated epee code 2020-10-24 12:46:26 -03:00
Jason Rhinelander b7dd5e8911 Target macos 10.12
When targetting macos <10.14 macos won't allow use of anything from
C++17 that throws, such as:
- std::get on a variant
- std::visit
- std::optional::value()
- std::any_cast

This avoids all of these.

For std::get, we either replace with std::get_if (where appropriate), or
else use a `var::get` implementation of std::get added to lokimq (also
updated here).  (This `var` namespace is just an `std` alias everywhere
*except* old target macos).

For std::visit, likewise lokimq adds an var::visit implementation for
old macos that we use.

std::optional::value() uses weren't useful anyway as everywhere it calls
them we've already checked that the option has a value, in which case we
can use `*opt` (which doesn't check for contents and throw).

std::any just has to be avoided as far as I can tell, but the one place
we used it is only ever a block, so I just replaced it with a `const
block*`.
2020-10-18 11:18:08 -03:00
Doyle 72700383ce rescan_diffic: Simplify params, update cli arg in blockchain_import 2020-09-30 11:17:12 +10:00
Jason Rhinelander 3f67de11df network_version_16 += _pulse 2020-09-18 16:39:50 -03:00
Doyle 4ceefe4d76 Pulse: Avoid miner, sn coinbase outputs when reward < 0
- Avoid generating any outputs on an alternative round, for the
alternative block producer if the total tx fee was 0.

- Remove the 1 atomic loki awarded to the miner in HF16 (previously kept
to 1 for making sure tests work, whilst implementing the new block
reward split)
2020-09-18 13:50:06 -03:00
Doyle 111fe26fa6 Pulse: get_round_timings needs to work with alt blocks
- Make it stop relying on the block and instead the user must pass in
the correct information
2020-09-18 13:50:05 -03:00
Doyle d0b743d667 Pulse: Pull blocks by header in rescan, avoid extra copies 2020-09-18 13:50:05 -03:00
Doyle eec517d7df Pulse: Fix difficulty = 0 in pulse, adjust fill timestamps 2020-09-18 13:50:05 -03:00
Doyle 79ae34e361 Pulse: Setup the mainnet to work around difficulty
- Pulse blocks will forcibly get the difficulty set to
  1'000'000 * TARGET_BLOCK_TIME throughout time
- When PoW is required again, the past window of blocks will use these
  difficulties, i.e. setup the chain for mining at 1'000'000 difficulty
  which is easily mineable to continue the network and continue to pull
  difficulties from the new-er mined blocks until the network is ready
  for Pulse again.
- Difficulty is still necessary for falling back to mining when Pulse
  fails. Switching between the two systems seamlessly can be done by
  continuing to set the difficulty for Pulse blocks.
2020-09-18 13:50:05 -03:00
Jason Rhinelander c30526adf1 Replace boost::adaptors::reverse with reverse iterators
Using boost brings in a bunch of header code, and yet doesn't make the
code any simpler compared to just using a built-in reverse iterator.
2020-07-02 12:52:13 -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
Doyle 1391f35ef0 Merge commit 'dc64fcb8a6c046c6e30665a6217b8fb6ec2471bc' into MergeUpstream3 2020-05-22 11:25:15 +10:00
Jason Rhinelander 52838aa5b2 "Remove namespace pollution" << ENDL
Removes all "using namespace epee;" and "using namespace std;" from the
code and fixes up the various crappy places where unnamespaced types
were being used.

Also removes the ENDL macro (which was defined to be `std::endl`)
because it is retarded, and because even using std::endl instead of a
plain "\n" is usually a mistake (`<< std::endl` is equivalent to `<<
"\n" << std::flush`, and that explicit flush is rarely desirable).
2020-05-11 18:44:45 -03: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
Jesus Ramirez f9b3f6ef3b Removed Berkeley DB and db switching logic 2019-09-16 16:18:05 +02: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 b6f24d7fb0
Fix checkpoint regression, must accept alt blocks if they are < the first checkpoint (#792) 2019-08-13 15:33:20 +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
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
Doyle f19e937a05 Merge commit '46c477a' into LokiMergeUpstream 2019-05-01 17:32:57 +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 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 1b1b942bb8 Add overrides to calm warnings on GUI, make is_open in header 2019-03-19 18:14:31 +11:00
binaryFate 1f2930ce0b Update 2019 copyright 2019-03-05 22:05:34 +01:00
moneromooo-monero b044d03a51
Avoid repeated (de)serialization when syncing 2019-03-05 11:57:55 +00:00
moneromooo-monero b8787f4302
ArticMine's new block weight algorithm
This curbs runaway growth while still allowing substantial
spikes in block weight

Original specification from ArticMine:

here is the scaling proposal
Define: LongTermBlockWeight
Before fork:
LongTermBlockWeight = BlockWeight
At or after fork:
LongTermBlockWeight = min(BlockWeight, 1.4*LongTermEffectiveMedianBlockWeight)
Note: To avoid possible consensus issues over rounding the LongTermBlockWeight for a given block should be calculated to the nearest byte, and stored as a integer in the block itself. The stored LongTermBlockWeight is then used for future calculations of the LongTermEffectiveMedianBlockWeight and not recalculated each time.
Define:   LongTermEffectiveMedianBlockWeight
LongTermEffectiveMedianBlockWeight = max(300000, MedianOverPrevious100000Blocks(LongTermBlockWeight))
Change Definition of EffectiveMedianBlockWeight
From (current definition)
EffectiveMedianBlockWeight  = max(300000, MedianOverPrevious100Blocks(BlockWeight))
To (proposed definition)
EffectiveMedianBlockWeight  = min(max(300000, MedianOverPrevious100Blocks(BlockWeight)), 50*LongTermEffectiveMedianBlockWeight)
Notes:
1) There are no other changes to the existing penalty formula, median calculation, fees etc.
2) There is the requirement to store the LongTermBlockWeight of a block unencrypted in the block itself. This  is to avoid possible consensus issues over rounding and also to prevent the calculations from becoming unwieldy as we move away from the fork.
3) When the  EffectiveMedianBlockWeight cap is reached it is still possible to mine blocks up to 2x the EffectiveMedianBlockWeight by paying the corresponding penalty.

Note: the long term block weight is stored in the database, but not in the actual block itself,
since it requires recalculating anyway for verification.
2019-03-04 09:33:58 +00:00
moneromooo-monero 6cc35100f9 ArticMine's new block weight algorithm
This curbs runaway growth while still allowing substantial
spikes in block weight

Original specification from ArticMine:

here is the scaling proposal
Define: LongTermBlockWeight
Before fork:
LongTermBlockWeight = BlockWeight
At or after fork:
LongTermBlockWeight = min(BlockWeight, 1.4*LongTermEffectiveMedianBlockWeight)
Note: To avoid possible consensus issues over rounding the LongTermBlockWeight for a given block should be calculated to the nearest byte, and stored as a integer in the block itself. The stored LongTermBlockWeight is then used for future calculations of the LongTermEffectiveMedianBlockWeight and not recalculated each time.
Define:   LongTermEffectiveMedianBlockWeight
LongTermEffectiveMedianBlockWeight = max(300000, MedianOverPrevious100000Blocks(LongTermBlockWeight))
Change Definition of EffectiveMedianBlockWeight
From (current definition)
EffectiveMedianBlockWeight  = max(300000, MedianOverPrevious100Blocks(BlockWeight))
To (proposed definition)
EffectiveMedianBlockWeight  = min(max(300000, MedianOverPrevious100Blocks(BlockWeight)), 50*LongTermEffectiveMedianBlockWeight)
Notes:
1) There are no other changes to the existing penalty formula, median calculation, fees etc.
2) There is the requirement to store the LongTermBlockWeight of a block unencrypted in the block itself. This  is to avoid possible consensus issues over rounding and also to prevent the calculations from becoming unwieldy as we move away from the fork.
3) When the  EffectiveMedianBlockWeight cap is reached it is still possible to mine blocks up to 2x the EffectiveMedianBlockWeight by paying the corresponding penalty.
2019-02-20 18:57:58 +11:00
Doyle 43436b081d
Infinite Staking Part 2 (#406)
* Cleanup and undoing some protocol breakages

* Simplify expiration of nodes

* Request unlock schedules entire node for expiration

* Fix off by one in expiring nodes

* Undo expiring code for pre v10 nodes

* Fix RPC returning register as unlock height and not checking 0

* Rename key image unlock height const

* Undo testnet hardfork debug changes

* Remove is_type for get_type, fix missing var rename

* Move serialisable data into public namespace

* Serialise tx types properly

* Fix typo in no service node known msg

* Code review

* Fix == to >= on serialising tx type

* Code review 2

* Fix tests and key image unlock

* Add command to print locked key images

* Update ui to display lock stakes, query in print cmd blacklist

* Modify print stakes to be less slow

* Remove autostaking code

* Refactor staking into sweep functions

It appears staking was derived off stake_main written separately at
implementation at the beginning. This merges them back into a common
code path, after removing autostake there's only some minor differences.

It also makes sure that any changes to sweeping upstream are going to be
considered in the staking process which we want.

* Display unlock height for stakes

* Begin creating output blacklist

* Make blacklist output a migration step

* Implement get_output_blacklist for lmdb

* In wallet output selection ignore blacklisted outputs

* Apply blacklisted outputs to output selection

* Fix broken tests, switch key image unlock

* Fix broken unit_tests

* Begin change to limit locked key images to 4 globally

* Revamp prepare registration for new min contribution rules

* Fix up old back case in prepare registration

* Remove debug code

* Cleanup debug code and some unecessary changes

* Fix migration step on mainnet db

* Fix blacklist outputs for pre-existing DB's

* Remove irrelevant note

* Tweak scanning addresses for locked stakes

Since we only now allow contributions from the primary address we can
skip checking all subaddress + lookahead to speed up wallet scanning

* Define macro for SCNu64 for Mingw

* Fix failure on empty DB

* Add missing error msg, remove contributor from stake

* Improve staking messages

* Flush prompt to always display

* Return the msg from stake failure and fix stake parsing error

* Tweak fork rules for smaller bulletproofs

* Tweak pooled nodes minimum amounts

* Fix crash on exit, there's no need to store on destructor

Since all information about service nodes is derived from the blockchain
and we store state every time we receive a block, storing in the
destructor is redundant as there is no new information to store.

* Make prompt be consistent with CLI

* Check max number of key images from per user to node

* Implement error message on get_output_blacklist failure

* Remove resolved TODO's/comments

* Handle infinite staking in print_sn

* Atoi->strtol, fix prepare_registration, virtual override, stale msgs
2019-02-14 12:12:57 +11:00
doy-lee ac4d0469bf Merge commit '4a0e4c7' into LokiMergeUpstream 2019-01-30 12:04:20 +11:00
moneromooo-monero b750fb27b0
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.

No other data is currently pruned.

There are three ways to prune a blockchain:

- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility

The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.

The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.

Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2019-01-22 20:30:51 +00:00
doy-lee 9eefb869f8 Merge commit '69e8567' into LokiMergeUpstream 2019-01-17 15:57:30 +11:00
moneromooo-monero ce594f5af7
blockchain_db: allocate known size vector only once 2018-12-05 21:13:18 +00:00
doy-lee c1da4f690d Merge commit '5ffb2ff' into LokiMergeUpstreamUntil_20180911_e6d36c1 2018-10-09 12:31:08 +11:00
doy-lee 3f85a1b716 Merge commit '89645ec' into LokiMergeUpstream20180821 2018-09-25 17:50:49 +10:00
doy-lee 319a2c3299 Upstream merge necessary changes to work with Loki 2018-09-19 19:15:03 +10:00
doy-lee bfa4f75e5c Merge commit '21afa71' into LokiMergeUpstream20180821 2018-09-19 14:05:10 +10:00