Commit Graph

1815 Commits

Author SHA1 Message Date
Jason Rhinelander 13409ad00e
run clang format 2023-04-13 17:15:12 -03:00
Jason Rhinelander 9dc312b0d9
Move gross single-macro-only "header" into wallet2
This header is stupid and gross and is only used from wallet2.  Remove
it from common/ to contain the damage within wallet2.

simplewallet.cpp includes it just for fun, but never actually uses it,
because why not?
2023-01-12 19:51:36 -04:00
Jason Rhinelander 8a16ab664c
Handle missing total_reserved
Like reserved, it is omitted when not different than total_contributed.
2023-01-11 19:29:34 -04:00
Jason Rhinelander 0b746215d3
Fix wallet2 staking
`get_service_nodes` no longer includes the `"reserved"` field if there
is no unfilled reservation, but wallet2 was expecting it.

This makes it okay with not having it.

Along the way this converts various `[]` to `.at()` to throw proper
exceptions when the key being accessed doesn't exist.
2023-01-11 19:07:11 -04:00
Jason Rhinelander a3ecb3cfa6
Revert wallet2 output blacklist retrieval
Wallet2 needs to keep using the binary endpoint as we don't have (or,
really, want) a non-binary version for wallet2 to use.
2023-01-11 16:09:06 -04:00
Jason Rhinelander 6122164735
Change ["key"] -> .at("key")
So that we throw when the key doesn't exist.
2023-01-10 23:14:34 -04:00
Jason Rhinelander bb111c3959
Fix get_service_nodes rpc node proxy query
Also fixes the wrong error message being shown when it fails.
2023-01-10 22:43:31 -04:00
Jason Rhinelander 78192856ab
Small string_view optimizations
Using string_view is slightly faster as it lets us get a view directly
into nlohmann's string value, rather than making an intermediate copy
into a temporary string.
2023-01-10 22:26:28 -04:00
Jason Rhinelander 64fbdb8c7f
Fix locked_contributions not included in cached SN list
Not having it broke wallet2 that was expecting it to exist; this fixes
it and also changes the `[]` usage to `.at()` to throw on non-existent
keys.
2023-01-10 22:25:03 -04: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 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 0cf55f3945
Add garbage to make it work on a garbage OS
- Don't touch <fmt/std.h> because it touches std::filesystem which makes
  macOS throw a hissy fit and refuse to compile.
- int_to_string is broken on macOS because it uses std::to_chars which
  makes macos throw a hissy fit like a cranky old female cat seeing a
  kitten if it sees it.
- wallet3 was using std::filesystem and std::visit, both of which make
  macos throw a hissy fit.  (There is a pattern here).  Apply the dumb
  fs::path and var::visit workarounds needed to appease this garbage OS.
- use var::get (from oxenc/variant.h) instead of std::get because, oh
  yeah, we need to support a garbage OS that Apple themselves don't even
  properly support.  Yay!
2022-10-17 13:45:24 -03:00
Jason Rhinelander 9e4e4976fa
Remove unnecessary move
gcc is (rightly) warning: the value here is already a temporary, so
moving doesn't do anything useful (but also prevents copy elision).
2022-10-17 13:45:23 -03:00
Jason Rhinelander 5806fd7825
Change simple fmt::format calls to new "..."_format(...) 2022-10-17 13:45:22 -03:00
Jason Rhinelander 085e9ba963
Unwrap fmt::format with a style argument
oxen::logging handles a style argument now (it is also safer e.g. if the
final formatted string itself intentionally contains {}).
2022-10-17 13:41:45 -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
Jason Rhinelander 2bd874e0b5
Merge remote-tracking branch 'tewinget/wallet3' into dev 2022-09-01 18:56:14 -03: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 d955607306
Merge pull request #1588 from darcys22/create-hwdev-file-by-default-for-hw-devices
Create HWDEV file by default for hardware wallets
2022-08-22 17:27:11 -03: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 9ae474eb76 Create HWDEV file by default for hardware wallets
This modifies the current behaviour from only creating the hwdev.txt
file, when a new wallet is created if content is specified as an
argument to always creating the file. This file is used by the GUI
wallet to detect if the device is a hardware device and the CLI wallet
behaviour is kept the same to keep behavious consistent between CLI and
RPC wallets.
2022-08-19 15:28:17 +10: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
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
Thomas Winget 0b17bb9adb fix build after merge
still need to make tests build and fix up some behavior
correctness around RPC (and maybe other areas)
2022-07-25 22:22:49 -04: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 4bff414f94
Remove wallet debugging errors 2022-06-13 15:34:35 -03:00
Jason Rhinelander f487affdd9
Show total staked and unlocking amounts in cli balance
E.g.:

    [wallet T6TSSZ (has locked stakes)]: balance
    Currently selected account: [0] Primary account
    Tag: (No tag assigned)
    Balance: 73541.719401728, unlocked balance: 72339.332202963 (23 block(s) to unlock)
    Total staked: 919.987654321, 0.000000000 unlocking
    Pending SN rewards: 49.419920278,  (next payout: block 10433, in about 26 minutes)
2022-06-10 22:21:13 -03:00
Jason Rhinelander b13b55de98
Simplify; add check for mismatched vector lengths 2022-06-10 22:21:04 -03:00
Jason Rhinelander 53f53f2a51
Expose next payout height via wallet2
wallet2_api needs to provide a way to to get at this.

Also changed the existing wallet_rpc_server and simplewallet code to use
the new wallet2 method.
2022-06-10 19:40:57 -03:00
Sean Darcy 90cc745987 Adds batched amounts to wallet2 rpc and simplewallet
This adds detail to the balance command of the CLI wallet to show how
much has been batched for each address and also summarises when the next
payout is.

It also includes additional fields to get_balance rpc endpoint on the
oxen-wallet-rpc so the user can check on the status of their accrued
funds.
2022-06-10 14:15:19 +10:00
Jason Rhinelander d229bc77ed
Merge pull request #1486 from jagerman/wallet-csv-export-fixes
Wallet csv export fixes
2022-05-29 20:30:55 -03:00
Jason Rhinelander 76f5a9a33c
Add ifdef'd code to scan the genesis block
This code is virtually never needed, except when we reset
testnet/devnet, but is useful to have on hand for such cases.
2022-05-27 16:44:28 -03:00
Jason Rhinelander f12bb8b3f9
Merge compilation fix 2022-05-27 15:28:54 -03:00
Jason Rhinelander e9e8e93669
Fix wrong change value in outputs sent to self
We figure out, when parsing a blockchain-confirmed transaction, what the
change is but never properly set that in the new
confirmed_transfer_details entry that we create from the
unconfirmed_transfer_details, and the latter only has the *actual*
change but doesn't know about outputs we sent to ourself.

This commit fixes it by updating the change value when such a case
occurs, which fixes a wrong output & running total bug in csv exports.
2022-05-27 15:28:54 -03:00
Jason Rhinelander 69300f0a15
Fix invalid balance in view wallet csv export with imported key images
Received inputs were being handled incorrectly when importing key
images: only the *first* payment received was being removed, but it
can easily happen that we have multiple payments to ourselves in the
same wallet (for example, if we send a fixed amount to ourselves then
almost always send two non-zero amounts to ourself: the amount + the
change).

This would result in (n-1) "in" outputs for the transaction still
showing up in the output, along with the "out" transaction (which
contains the overall net transfer amount).  For example:

- Alice sends 100 + 12.3 change to herself.
- Bob has Alice's view keys, opens a view-only wallet, sees 100 and 12.3
  as two separate inputs from the same transaction.
- Alice provides a key image export to Bob to verify the account
- Bob imports.

Bob's export would now show:

    in 12.3
    out 0

(The inputs of the same transaction are apparently ordered randomly, so
it could also be 'in 100'/'out 0')

and the running total would be 12.3 too high (or 100 too high if the 100
got left instead of the 12.3).

This fixes it by removing *all* matching payments when we import key
images instead of just the first one.
2022-05-27 15:28:54 -03:00
Jason Rhinelander 70954ff373
CSV export-related code and output cleanups
Cleans up some messy code.

Reformats the CSV output to be a little cleaner (in both code and
result), using fmt:
- change second "amount" field to "sent_amount"
- don't unnecessarily quote the subaddr indices field (only quote when
  more than one need to be listed as comma-separated).
- change "checkpoint" field output to "yes"/"no" rather than
  "checkpointed"/"no".
- Adds spacing between fields which makes it a little easier to read and
  should still parse identically.
- Date format also changes somewhat (because fmt is now formatting it)
  and includes " UTC" to clarify.
2022-05-27 15:28:54 -03:00
Jason Rhinelander 184d61bb80
wallet2 code simplifications and cleanups
Miscellanous crap that I couldn't help but cleanup while working in
wallet2 to solve the export csv issues:

- To celebrate the 10 year anniversary of god inventing `auto` we
  replace some obtuse code that was trying to make itself look bigger by
  typing out massive obvious types.
- Remove the single remaining tab in wallet2.cpp to get wallet2.cpp from
  being 99.9993% tab-free too 100.0000000% tab free.
- Fix THROW_WALLET_EXCEPTION_IF calls that checked for not-found *after*
  another check that already dereferenced the iterator.
- Make `get_attribute` interface less stupid by returning an optional
  string instead of a bool with an out string argument.
- Simplify various std::holds_alternative + var::get combinations with a
  single std::get_if.
- Optimize and DRY hex conversion of payment id in make_transfer_view.
  The existing code was duplicated 4 times but also was inefficiently
  performing extra string allocations via multiple substr calls.
- Loki -> Oxen in a wallet error message.
- Initialize confirmed_transfer_details members inline rather than using
  an obtuse constructor.
- Apply some C++17 `if` initializer syntatic sugar.
- Don't use `0 != pointer` to test for null
- Don't use a linear scan of a std::vector to do what an unordered_set
  is meant to to.
- Replace NULL with nullptr
- eliminate boost::format from wallet2
- eliminate boost::lexical_cast from wallet2
2022-05-27 15:28:54 -03:00
Sean 7161f42c64
Merge pull request #1472 from jagerman/avoid-integer-truncation
Avoid integer truncation in decoy selection
2022-05-27 11:16:54 +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
Jason Rhinelander 1fa71bcc2c
Rename hf19 -> hf19_reward_batching 2022-05-24 18:54:32 -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 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
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 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
Jason Rhinelander d9f19ca463
Include SN status info info list_current_stakes()
Adds unlock height, funded, and decommissioned info to returned stake
info.
2022-04-21 18:27:45 -03:00