Commit Graph

1892 Commits

Author SHA1 Message Date
Sean Darcy 49766634a4 rename db_schema to walletdb 2023-03-24 00:10:09 +00:00
Sean Darcy a0211fd16c metadata table changed from 1xN to Nx1 2023-03-24 00:10:03 +00:00
Sean Darcy 8a577a4bc7 Introduces OMQ to cli and additional commands 2023-02-16 08:17:55 +11:00
Sean f8307ee34e
Merge pull request #1598 from darcys22/wallet3-test-fixes
fixes wallet3 test segfault, first test passing
2022-10-26 09:51:39 +11: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 43343f3b90
Fix ec_point sub-types not being formattable; fix crappy test code
Fixed a bug where ec_point subclasses were not getting formatted via
to_string(ec_point).

Also fixed the crappy test code that was incapable of reporting the
actual test failure.
2022-10-17 13:45:24 -03:00
Jason Rhinelander 463590ad5c
Eliminate most << output operators
Replace (nearly) everything with fmt formatting.  Some crap in wallet2
remains that I'm not going to bother with.
2022-10-17 13:45:24 -03:00
Jason Rhinelander c4f4bfc87e
Fix deprecated oxenmq::* usage
Some of this is just obsolete, some slipped in recent feature branches.
2022-10-17 13:45:24 -03:00
Sean Darcy 86dff557a5
trace noop in release build 2022-10-17 13:45:23 -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
Sean Darcy 9117f01736 Disable TX Signing test
This code might change soon so the test might not be relevant. revisit
this after further work on wallet3
2022-09-30 08:07:50 +10:00
Sean Darcy 75410dd675 transaction fees updated for blink, mock decoy selector was not being used previously 2022-09-29 16:47:47 +10:00
Sean Darcy 6146a88acd fixes wallet3 test segfault, first test passing 2022-09-28 16:52:29 +10:00
Thomas Winget 4b56bf4e4b all tests building now, not all passing 2022-09-07 19:34:52 -04:00
Sean Darcy 230a8185aa start of compiler errors 2022-09-02 15:38:21 -04:00
Jason Rhinelander 2bd874e0b5
Merge remote-tracking branch 'tewinget/wallet3' into dev 2022-09-01 18:56:14 -03:00
Thomas Winget ebbc0e5644 wallet3 changes and demo fixup
demo is vaguely presentable now.  syncing and basic tx send work.
change output was being sent to void (change address was unimplemented)
but that works now as well.
2022-08-30 19:58:51 -04:00
Thomas Winget e3726f520d wallet3 demo code and syncing bugfix 2022-08-25 17:48:08 -04:00
Thomas Winget d4b6f967fd Merge most recent dev and wallet3 branches
Fixes a few merge conflicts, several compilation errors, and
some behavioral incorrectness.  Still a few bugs with wallet3
but as far as I can tell wallet2 and daemon etc. should be working
correctly.
2022-08-22 19:25:49 -04:00
Jason Rhinelander 5f338c2492
Merge pull request #1585 from jagerman/fix-block-notify-race
Fix block notify race condition, and drain some of the swamp
2022-08-22 17:25:21 -03:00
Sean Darcy d6b8b2d036 fix for small contributor unlocks
The checking if the service node contributers are small miscalculated
atomic oxen. This brings in the correct figure for HF20 and in the
interim brings measures into the wallet and blink to prevent small
contributors from being to unlock in HF19.
2022-08-11 15:09:04 +10:00
Thomas Winget 9a7f7d6704 wallet3 send/receive works, more or less 2022-08-01 17:12:24 -04:00
Jason Rhinelander 0bc3c2f880
Rewrite trash tools::Notify
This was nasty.

Remove --block-rate-notify entirely; it's nearly useless on Oxen.

block and reorg notify remain, but now use a post-block hook rather than
shoving toxic Notify crap into cryptonote_core headers.
2022-07-27 17:25:48 -03:00
Jason Rhinelander f382c1971e
Replace hook virtual calls with std::function
- Instead of inheriting from a pure virtual base class, we know just use
  lambdas for hook callbacks.
- The signature of hooks also changes to take an info struct rather than
  a list of parameters, so that you don't have to change everything to
  ignore unwanted parameters if someone adds something to a hook.
2022-07-27 14:20:29 -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 b5a5d01b04
Optimization: reuse reward vector
Profiling shows noticeable CPU spend in allocating memory for this
vector (which makes sense, since we are looping through ~1700 nodes and
building a reward vector for each one).  Avoid it by reusing a single
vector that gets cleared (but not reallocated more than a handful of
times).

This reduces batching CPU time in a debug build by about 12%; curiously
I didn't find a noticeable reduction in a release build.
2022-06-19 12:36:40 -03:00
Jason Rhinelander 230b6bdc0d
128 bit optimizations
Use intrinsic 128-bit types when supported by the compiler; the
operations on them are a bit faster than the two-uint64_t
implementations we do not, and this shaves about 7% off the batch
processing time (which makes a lot of mul128_div64 calls).

Also removes a bunch of unused, useless epee crap from int-util.h.
2022-06-19 12:36:40 -03:00
Jason Rhinelander 33a0762563
Batching address string optimizations
Converting between internal addresses and string wallet addresses is
surprisingly expensive (partly because a keccak hash is involved);
normally on the blockchain that doesn't matter because string
conversions are rare, but batching exposed some code paths that do the
conversion a lot.

This makes two optimizations to considerably speed up batching
processing time:

1. Add an address string hash for batch addresses.  We don't see that
   many, but we tend to see the same addresses for *every* block.  By
   caching it we can considerably reduce the time needed to do the
   actual conversions.

2. In many places we don't really need strings at all: we can work just
   with the address_infos (which are cheap).  This eliminates some of
   the places we use addresses and pushes address_infos further through
   the code.

In total, this plus the previous optimization drop batch processing time
by this cuts batch processing CPU time by about 85%, roughly half from
this optimization and roughly half from the store-offsets optimization.

On a debug build, timing mainnet resyncing from just before HF19 to
current:

- neither optimization: 223.60s spent processing batch jobs (of 282s
  total recalculating subsystems).
- just offsets: 131s spent in batch processing
- both optimizations: 33s spent in batch processing (down to 60s total
  recalculating).

On a release build:
- before: 107.35s (4.73s snl; 95.55s batch)
- after: 28.27s (4.66s snl; 0.00s ons; 21.72s batch)
2022-06-19 12:36:40 -03:00
Jason Rhinelander 1ff341a7cf
Store payment_offset in batched_payments_accrued
This drastically increases the speed of processing new blocks because we
can select only the addresses we care about.
2022-06-19 12:36:40 -03:00
Sean Darcy 56504d35de change from portions to atomic amounts 2022-05-27 15:07:28 +10:00
Sean c5fbf96b7d
Merge pull request #1539 from darcys22/prevent-unlocks-small-holdings
Prevent unlocks small holdings
2022-05-27 11:15:29 +10:00
Sean Darcy 5387ca2cf4
test cases for batching 2022-05-26 15:08:32 -03:00
Jason Rhinelander 902d7afe55
Use an empty vector instead of optional<vector>
We don't do anything differently for a nullopt versus an empty vector,
so just return an empty vector for both not-at-the-hf and no-payments
cases.

(This also fixes a segfault and/or chainsync bug in the previous commit
because the optional is dereferenced without checking when on hf19).
2022-05-26 15:08:08 -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 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 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 e7c19d29a8
Move test subclass into tests/ 2022-05-25 20:57:31 -03:00
Jason Rhinelander 1fa71bcc2c
Rename hf19 -> hf19_reward_batching 2022-05-24 18:54:32 -03:00
Jason Rhinelander 6011a9b4e7
Remove debugging 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 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 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
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
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 f652aa09bc review notes 2022-05-12 10:32:57 +10:00
Sean Darcy 9edc2bb52d
Increase max number of contributors to 10
This requires the operator to still contribute 25% of the service node
but another 9 nodes will be allowed to stake to the node makeing 10
contributors total rather than our previous 4.
2022-05-10 18:48:20 -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
Thomas Winget e06537f384 testnet address in wallet test was wrong...somehow 2022-04-26 13:01:22 -04:00
Jason Rhinelander 63ede5ec4d
Make cryptonote::parse_amount return an optional
Replace a gross non-const uint64_t& argument + bool return with an
std::optional<uint64_t> return value.
2022-04-15 17:54:03 -03:00