Commit Graph

14059 Commits

Author SHA1 Message Date
Jason Rhinelander a2eb8690ba
Reformatting 2022-05-26 15:08:07 -03:00
Jason Rhinelander e7a6deaf6c
Do more calculations in thousanths
We were converting to thousanths too late; this does it earlier, to
reduce numerical imprecision during reward calculations.
2022-05-26 15:08:07 -03:00
Jason Rhinelander 9584a14b3a
Refactor/DRY reward calculation code
The reward calculation code when adding or subtracting is identical;
this dries it out into a single helper method.
2022-05-26 15:08:05 -03:00
Jason Rhinelander bbdd91a3bb
const lvalue refs
Avoid copying vector arguments
2022-05-26 15:06:38 -03:00
Jason Rhinelander ac26747529
Rename a_b_over_c to mul128_div64
Also uses it in various places that were writing out separate mul128 +
div128_64's.
2022-05-26 15:06:38 -03:00
Jason Rhinelander d3684f6b44
Add iterable `prepared_results<T...>`
This gives back an iterator that lets you step through results as
tuples without having to executeStep() + get<...> yourself.
2022-05-26 15:06:12 -03:00
Jason Rhinelander 02d8e0aefc
Improve prepared interface; fix test suite bug
Add a `prepared_bind` that lets you get a prepared statement and bind
parameters to it in one shot.

Add comments to the prepared_* methods.

Fix test suite bug in sqlite testing wrapper added in the earlier
prepared statement commit: it was selecting values from the current
(new, empty) database rather than the passed-in one.
2022-05-26 13:57:01 -03:00
Jason Rhinelander 7d392dad01
Merge pull request #1540 from darcys22/decom-grace-period
Decom grace period
2022-05-26 11:37:19 -03:00
Jason Rhinelander b6e859a104
Merge pull request #1551 from jagerman/add-hf-to-get_info
Add hard_fork to get_info rpc request
2022-05-26 11:30:46 -03:00
Sean Darcy 47a9802f83 Rename miner_reward to coinbase_payouts and fix minor bug
After the batching HF we now have a "reward" field in the block header
which is confusingly different to "miner_reward". This renames
miner_reward to coinbase_payouts to clarify that this amount is the
amount actually paid out in the coinbase vs the reward accumulated into
the batching DB.

Also fixes a minor bug where the reward would only show the reward of
the first vout instead of summing all the vouts.
2022-05-26 13:09:04 +10:00
Jason Rhinelander b6fdd9d90f
Add hard_fork to get_info rpc request
It's simple to add and saves a call to HARD_FORK_INFO when all you care
about is the hf number (and not the other hard fork details).
2022-05-25 23:30:28 -03:00
Jason Rhinelander e7c19d29a8
Move test subclass into tests/ 2022-05-25 20:57:31 -03:00
Sean Darcy 76a585eb41 Add a grace period to deregistrations after a hardfork
It is not uncommon to have nodes get decommissioned after a hardfork,
either due to lack of updating or issues with the release. This
implements a 7 day grace period where nodes that do get decommissioned
will not progress into a deregistration (and being hit with the 30 day
funds locked penalty).
2022-05-25 14:07:55 +10:00
Jason Rhinelander 9a395be641
Make sure we error if given a non-existant payment address 2022-05-24 18:54:52 -03:00
Jason Rhinelander 7b331131d9
Remove debugging 2022-05-24 18:54:52 -03:00
Jason Rhinelander bf1915bd46
SQLite: use prepared statements
Using SQLite::Statement directly requires sqlite to re-prepare the
statement every time it is executed; going via our `prepared_st` wrapper
caches (per thread) and reuses previously prepared statements for better
performance.

(It also, in some cases, simplifies the code a bit).
2022-05-24 18:54:52 -03:00
Jason Rhinelander d59ccbf82c
Bump version 2022-05-24 18:54:32 -03:00
Jason Rhinelander 1fa71bcc2c
Rename hf19 -> hf19_reward_batching 2022-05-24 18:54:32 -03:00
Jason Rhinelander 2b94af71a9
Add static_assert for hf numeric values 2022-05-24 17:36:24 -03:00
Jason Rhinelander 6011a9b4e7
Remove debugging 2022-05-24 17:36:24 -03:00
Jason Rhinelander bac9c05162
Fix debug compilation 2022-05-24 17:36:24 -03:00
Jason Rhinelander 34ef746c95
prepare_registration fixes for multi contributors
Adds two slightly different versions of prepare_registration: one that
works with the existing 4-person registrations (used up to the hard
fork), and one that produces HF19 amount-based registrations.

This also overhauls the questions to be a bit nicer to input;
specifically:

- allow "max" and "min" as stake amount options, and make "max" the
  default.
- eliminate the "do you want to contribute the whole stake?" question
  entirely.  We instantly figure that out if you choose "max" (or enter
  the 15000 manually).
- eliminate the "how many contributors?" question.  Instead we just keep
  taking additional contributors until you stop entering them.
- move the fee to later, after you've provided contributor info (if not
  a full stake).

There is, unfortunately, a *huge* amount of duplication here: I copy and
pasted the entire HF18 registration code and just eliminated the
portions parts of it.  This is temporary: as soon as we are into HF19 we
can eliminate the HF18 version entirely.
2022-05-24 17:36:24 -03:00
Jason Rhinelander 377cfecb09
Atomic staking amounts
This adds a new tx registration interpretation for HF19+ by repurposing
the fields of the registration:

- `expiration` becomes `hf_or_expiration`; for "new" registrations it
  contains the hardfork number (e.g. 19 for HF19), but the data layout
  on chain doesn't change: essentially we determine whether it's a new
  registration based on whether the field is <= 255 (interpret as HF) or
  not (interpret as expiration).

Changes in "new" registrations:
- stake amounts are atomic OXEN rather than portions.  This lets us skip
  a whole bunch of fiddling around with amounts that was necessary to
  deal with integer truncation when converting between amounts and
  portions.

- the fee in the registration data is now a value out of 10000 instead
  of a portion (i.e. value out of 2^64-4).  This limits fee precision to
  a percentage with two decimal places instead of ~17 decimal places.
  Internally we still convert this to a portion when processing the
  registration for service_node_states, but this makes the registration
  itself much simpler and easier to work with (as a human).

- HF19+ registrations no longer have an expiry timestamp (though they do
  depend on the hardfork, so they "expire" whenever the next hard fork).
  The expiry timestamp was really only there to avoid a registration
  amount decreasing too much from the dropping staking requirement.

- Both types are registration are still permitted for HF19, but because
  registrations with more than 4 contributors expose bugs in the portion
  transfer code (that results in registrations become invalid),
  old-style registrations are still limited to 4 contributors.

- HF19 will allow both old and new registrations, so that registrations
  generated before the HF will still work, and so that we don't break
  testnet which has various "old" registrations on it.
2022-05-24 17:36:24 -03:00
Jason Rhinelander 5b25671c4f
Split up sqlitedb into a compiled unit
Lessens the compilation load of various things that include the header,
and lets us avoid having to include all of fmt when we include it.
2022-05-24 17:36:24 -03:00
Jason Rhinelander 636ee3f622
Replace boost::endian conversion with oxenc 1.0.3
1.0.3 got some endian fixes that lets us avoid boost::endian everywhere.
2022-05-24 17:35:59 -03:00
Jason Rhinelander 6f6505278c
Merge pull request #1548 from jagerman/skipping-cn-variant2-sqrt
Speed up test_variant2_int_sqrt tests by skipping most values
2022-05-24 17:33:29 -03:00
Jason Rhinelander 6bb83316dd
Merge pull request #1546 from jagerman/remove-major-ge-minor
Remove minor >= major block requirement for HF19+
2022-05-24 16:04:48 -03:00
Jason Rhinelander 1e41a55542
Merge pull request #1547 from jagerman/remove-ftime
Remove use of deprecated ftime
2022-05-24 16:04:36 -03:00
Jason Rhinelander be332d3772
Avoid integer truncation in decoy selection
There is a (correct) warning in the calculation that divides by this
value that this code is doing integer division, but then storing in a
float.  This fixes the warning, and the intention.
2022-05-24 16:04:08 -03:00
Jason Rhinelander 0b722fbd8a
Skip most stupidly test_variant2_int_sqrt values
This test uses 3.5 billion iterations, and takes multiple minutes --
effectively just as long as all other test suite tests combined.

This is dumb.

Reduce the "optimized" version to increment by 83 instead of 1, the same
as the "reference" version, but add a V2_INT_SQRT_FULL_TEST=1
environment variable you can set if you really want to test your CPU
cooler.
2022-05-24 15:56:37 -03:00
Jason Rhinelander 1bfa4e64d4
Remove use of deprecated ftime 2022-05-24 11:14:35 -03:00
Jason Rhinelander c3759c67de
Remove minor >= major block requirement for HF19+
Monero perverted the minor version many forks ago; this returns it to
being a minor version, making the blocks reflect our actual minor
version.
2022-05-24 11:07:06 -03:00
Sean dce39ec8ee
Merge branch 'dev' into batching-rpc-endpoints 2022-05-24 11:29:49 +10:00
Sean Darcy 741affa403 Enforce a minimum time period before small contributors can unlock stake
This PR defines contributors to a service node as a small contributor if
they contribute <25% of the nodes locked contributions. If a contributor
is small then they are prevented from unlocking their stake for 30 days
after the node is registered. This was in response to operators getting
frustrated with small contributors immediately unlocking after a node
was registered.

If you imagine the following node contribution structure:

Operator: 25%
Contributor 1: 65%
Contributor 2: 10%
Total: 100%

Node is registered on day 0. On Day 1 both the operator and Contributor
1 will be able to unlock their stake and the node begins its 15 day
unlock period.

Contributor 2 however will be prevented from unlocking until day 30.
At this point they will be able to unlock and begin the nodes 15 day
unlock period.
2022-05-24 10:55:26 +10:00
Thomas Winget 8783349f43 remove erroneous check from wallet3 tx constructor 2022-05-23 19:44:23 -04:00
Thomas Winget a8f4584578 wallet3: fix tx construction (sorted inputs) 2022-05-23 19:44:23 -04:00
Thomas Winget d716b1fde5 cleanup some wallet daemon comms error handling 2022-05-23 19:44:19 -04:00
Thomas Winget f3c0bd79a4 fix wallet3 db overall output count 2022-05-23 19:24:42 -04:00
Thomas Winget 6ed5bba739 small status/error message change 2022-05-23 19:23:40 -04:00
Thomas Winget 8b85d6b850 do not silently allow empty tx input indices 2022-05-23 19:17:50 -04:00
Sean Darcy f45d0588ae Adds RPC endpoint for accrued batching balances
This allows a user to query the daemon and ask for the accrued balance
of oxen rewards that have been batched but not yet paid out.

The endpoint takes in an array of addresses (Strings) and returns an
array of atomic oxen amounts (integers) that reflect the current
database balances for those requested addresses.

For example an address has accrued 2x batch payments of 16.5 oxen but
has not yet been paid out will show 33000000000 being the atomic amount
in the database.
2022-05-23 08:47:18 +10:00
Jason Rhinelander c7deef4ac3
Merge pull request #1545 from jagerman/deblobdata
Remove stupid typedef
2022-05-21 10:36:05 -03:00
Jason Rhinelander 26869869aa
Remove stupid typedef 2022-05-20 18:30:55 -03:00
majestrate 1dccbcd8c9
Merge pull request #1541 from jagerman/remove-config-macros
Remove cryptonote_config.h macros
2022-05-20 16:43:27 -04: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
Jason Rhinelander c8d5dfa597
Remove unused macros 2022-05-16 15:16:26 -03:00
Jason Rhinelander 8014cf6a6c
Undo 19.1 version for Session testing 2022-05-13 01:25:11 -03:00
Jason Rhinelander dd814da1ad
Reword registration command to include the operator wallet 2022-05-12 15:32:45 -03:00
Jason Rhinelander 4dad19fb7d
Add pubkey to prepare_registration summary 2022-05-12 15:20:58 -03:00
Jason Rhinelander fd020fcd83
Fix min operator amount, rejigger math
A fixed 3750 amount won't work on testnet (and also was set to 3750
atomic units instead of 3750 coins).

This refactor the math a bit so that the amount falls out of the portion
constant when making a registration.
2022-05-12 13:47:49 -03:00