Commit Graph

14059 Commits

Author SHA1 Message Date
Jason Rhinelander 76908d9d5d
Add missing header
This was previously being included via oaes_lib.h.
2022-07-22 14:18:24 -03:00
Jason Rhinelander d28c24a176
Rename oaes_lib to oaes_lib_expand
Since all it is now is just the key expansion from oaes_lib
2022-07-21 21:16:17 -03:00
Jason Rhinelander b450affb1a
Slim down oaes_lib
The only thing we use from it is the aes key expansion, so just delete
everything else and change the interface to just do key expansion.
2022-07-21 21:11:44 -03:00
Jason Rhinelander f6080918b4
Merge pull request #1580 from jagerman/upgrade-db-fix
Avoid failure if the trigger doesn't exist
2022-07-20 11:20:00 -03:00
Jason Rhinelander 3015683511
Avoid failure if the trigger doesn't exist
I'm not entirely sure how this happens, but I came across a node that
was failing here because the trigger didn't exist -- possibly from a
partial upgrade?

In any case, the `IF EXISTS` makes it more lenient.
2022-07-19 22:47:57 -03:00
Jason Rhinelander 46f0fd025c
Merge pull request #1576 from jagerman/better-print-locked-stakes
CLI wallet: improve print_locked_stakes
2022-07-11 22:56:24 -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 f87dfd0d51
Overhaul print_locked_stakes output
The CLI wallets `print_locked_stakes` was buggy, overly verbose, and
missing pertinent information.  This overhauls it.

Details are below; the quick differences:
- show the staking requirement
- make key image output optional with a +key_images flag on the command
- fix various bugs such as just showing the first contribution as the
  "total" contribution
- add the wallet address of extra contributions, rather than just the
  key image with no other info.
- put your own contributions first, and mark them as such
- show totals of other contributors
- sort service nodes to put unlocking nodes first; among unlocking and
  non-unlocking nodes we sort by hex pubkey string.
- sort locked dereg outputs by unlock height
- considerable reformatting of how things are displayed

---

Output now looks like this:

First we have 1-2 lines of general info:

    Service Node: abcdef123456...
    Unlock Height: 1234567         (omitted if not unlocking)

If there are other contributors then we print a total line such as:

    Total Contributions: 15000 OXEN of 15000 OXEN required

For our own contribution, when we have a single contribution, we use one of:

    Your Contribution: 5000 OXEN (Key image: abcdef123...)
    Your Contribution: 5000 OXEN of 15000 OXEN required (Key image: abcdef123...)

(the second one applies if we are the only contributor so far).

If we made multiple contributions then:

    Your Contributions: 5000 OXEN in 2 contributions:
    Your Contributions: 5000 OXEN of 15000 OXEN required in 2 contributions:

(the second one if we are the only contributor so far).

This is followed by the individual contributions:

        ‣ 4000.5 OXEN (Key image: abcdef123...)
        ‣ 999.5 OXEN (Key image: 789cba456...)

If there are other contributors then we also print:

    Other contributions: 10000 OXEN from 2 contributors:
        • 1234.565 OXEN (T6U7YGUcPJffbaF5p8NLC3VidwJyHSdMaGmSxTBV645v33CmLq2ZvMqBdY9AVB2z8uhbHPCZSuZbv68hE6NBXBc51Gg9MGUGr)
          Key image 123456789...
        • 8765.435 OXEN (T6Tpop5RZdwE39iBvoP5xpJVoMpYPUwQpef9zS2tLL8yVgbppBbtGnzZxzkSp53Coi88wbsTHiokr7k8MQU94mGF1zzERqELK)
          ‣ 7530 OXEN (Key image: 23456789a...)
          ‣ 1235.435 OXEN (Key image: 3456789ab...)

If we aren't showing key images then all the key image details get omitted.

---

Locked key images get overhauled too; it wasn't at all clear from the
output *why* these are locked (i.e. these are locked contributions of
failed SNs):

    Locked Stakes due to Service Node Deregistration:
        ‣ 234.567 OXEN (Unlock height 1234567; Key image: abcfed999...)
        ‣ 5000 OXEN (Unlock height 123333; Key image: cbcfef989...)
2022-07-11 17:21:17 -03:00
Jason Rhinelander efebe83225
Fix empty lines in `print_locked_stakes` output
Fixes #1575

We were appending a newline for every locked stake rather than just this
wallet's locked stakes.
2022-07-11 14:38:56 -03:00
Jason Rhinelander 7145cdae6e
Bump version for next point update 2022-07-07 18:23:13 -03:00
Jason Rhinelander bee13a319c
Merge pull request #1569 from darcys22/pop-blocks-investigation
Pop blocks investigation
2022-07-07 18:20:19 -03:00
Jason Rhinelander cd90b1bf0d
Merge pull request #1571 from jagerman/negative-emissions
Fix negative coinbase emissions
2022-07-07 18:20:01 -03:00
Jason Rhinelander 147cda59fa
Merge pull request #1570 from darcys22/nanosp-pid
nano s plus HID pid
2022-07-07 18:06:06 -03:00
Jason Rhinelander 815b7bdc1f
Fix negative coinbase emissions
With batching, individual blocks can have a negative coinbase emission
because the tx fee gets added to the batch rewards database and not paid
out immediately, which then results in an negative overflow to a value
close to 2^64.  Thus a block with no payout and a tx fee will have an
erroneous huge positive coinbase emission when queried via
`get_coinbase_tx_sum`.  For example block 1094068 queried with:

    {"jsonrpc":"2.0","id":"0","method":"get_coinbase_tx_sum","params":{"height": 1094068, "count": 1}}

returns:

    {
      "jsonrpc": "2.0",
      "id": "0",
      "result": {
        "burn_amount": 0,
        "emission_amount": 18446744073699378616,
        "fee_amount": 10173000,
        "status": "OK"
      }
    }

This commit fixes it by making the values signed (and also serves as an
example of why unsigned integers are usually the wrong choice):

    {
      "jsonrpc": "2.0",
      "id": "0",
      "result": {
        "burn_amount": 0,
        "emission_amount": -10173000,
        "fee_amount": 10173000,
        "status": "OK"
      }
    }
2022-07-05 10:24:08 -03:00
Sean Darcy 8566f8b973 nano s plus HID pid 2022-06-29 15:27:22 +10:00
Sean Darcy ed605fc1ac handle big pops 2022-06-23 16:37:21 +10:00
Sean Darcy fa88a104d4 keep add block and pop block for batching database in sync with service node list 2022-06-21 15:14:04 +10:00
Jason Rhinelander d826fbee03
Merge pull request #1568 from darcys22/sync-batching-keep-snl-state
Keep SNL state correct during resyncing of sqlite submodule
2022-06-19 14:31:58 -03:00
Jason Rhinelander ec00efc887
Bump release version 2022-06-19 12:42:03 -03: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 0f918f46d4
Downgrade upgrade info message 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
Jason Rhinelander 0ed150012e
Fix batch timing reporting; reduce block processing size
Batch timing was being reported as 0s, even though it is taking up the
vast majority of the time as of the HF block.

Reduce the block processing size to 500 blocks at a time rather than
1000.

Change when we print status updates to print once duration passes a 10s
threshold rather than every 10*1000 blocks.

This latter change probably also makes oxend more reliable on
low-powered servers because it also guards the systemd status update
message (which is needed to give us more watchdog time).
2022-06-19 12:34:56 -03:00
Sean Darcy b324193dc3
Keep SNL state correct during resyncing of sqlite submodule
When the sqlite batching database is resyncing it is dependant on the
service node list state being correct at the time the block is added to
the batching database. When syncing a singular module this sometimes is
not the case as the service node list state may be ahead or behind. This
patch simply ensures that when the batching database is behind the
service node list is reset back to that point in time.
2022-06-19 12:34:56 -03:00
Jason Rhinelander 502f88cdc4
Merge pull request #1565 from jagerman/next-height-is-now
Next height is now
2022-06-19 12:34:24 -03:00
Jason Rhinelander 3520507ac6
Merge pull request #1567 from jagerman/sqlite3-min-version
Make sure we have sqlite 3.24.0+
2022-06-19 12:34:15 -03:00
Jason Rhinelander f87c9990a2
Merge pull request #1564 from jagerman/remove-log-error
Remove wallet debugging errors
2022-06-19 12:33:57 -03:00
Jason Rhinelander cf4c8aaf85
Merge pull request #1566 from jagerman/suppress-zero-balances
Suppress zero balances
2022-06-19 12:33:34 -03:00
Jason Rhinelander 75b8af602d
Make sure we have sqlite 3.24.0+
Batching code relies on UPSERTs which were added in 3.24.

(This broke initial bionic debs, which needed a sqlite3 backport from
newer Ubuntu to address).
2022-06-16 21:40:36 -03:00
Jason Rhinelander e1c1677c0a
Don't include sub-atomic rows in get_all_accrued_earnings
The RPC call to return accrued balances currently returns some 0s,
because the database has sub-atomic (but non-zero) stored amounts.

This commit skips those when querying accrued earnings.
2022-06-16 13:45:43 -03:00
Jason Rhinelander b4062f37bb
Optimizations
- use pre-prepared queries
- avoid extra copy of addr/amount vectors in get_all_accrued_earnings
2022-06-16 13:43:31 -03:00
Jason Rhinelander f35c1b1707
Make next_payout_height return the next height >= current_height
wallet2 currently exposes a bug where it shows the next payout being +1
interval blocks from now one block too soon (i.e. if I earn a reward on
block 1234 then it should give me 1234 as my next payout height up until
we actually get block 1234 with the payout).

db_sqlite.cpp was already getting this behaviour by passing in height-1,
but that feels like a workaround for an off-by-one in the function
itself.  This fixes the function (and removes the -1 from
db_sqlite.cpp).
2022-06-13 16:58:04 -03:00
Jason Rhinelander 598c174c9c
Rewrite logic to avoid unsigned int overflow
- When calculating the offset the calculation here is overflowing; since
  they are `uint64_t`s where overflow is well-defined that doesn't
  actually break anything (the overflowed value overflows in the other
  direction when added, and works as the intended subtraction), but it
  feels a bit icky.  Rearranging the logic avoids it.

- If given a small height (e.g. 3) the next payout height would come out
  as a large positive number (close to uint64_t max).  The change above
  avoids this as well.
2022-06-13 16:52:36 -03:00
Jason Rhinelander 4bff414f94
Remove wallet debugging errors 2022-06-13 15:34:35 -03:00
Jason Rhinelander 946b182384
Version bump 2022-06-13 11:52:31 -03:00
Jason Rhinelander 441270b082
Merge pull request #1562 from darcys22/wallet2-batching
Adds batched amounts to simplewallet balances
2022-06-13 11:51:54 -03:00
Jason Rhinelander 7f384b99cc
Merge pull request #1563 from jagerman/empty-tx-warnings
Empty tx warnings
2022-06-13 11:51:36 -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 dd30873e19
Make epee okay with an std::array not being filled in
Unlike a vector, if a std::array doesn't exist in the response epee
chokes.  This fixes it to make it silently ignore it (and leave the
array values untouched), which just makes it consistent with what it
does for any other type of field.

This is particularly needed to be able to retrieve service_node_info
with the `service_node_version`, `lokinet_version`, and
`storage_server_version` fields omitted without getting a
deserialization failure from the omission.
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 e56bf13e55
Only request needed fields from SN info
This cuts the size of the response by about 75%.
2022-06-10 20:24:23 -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
Jason Rhinelander dedc7d351f
Make accruedBalance address parameter optional
If omitted it looks up the current wallet primary address (which is
usually what we want).
2022-06-10 17:18:58 -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 b39a118dae
Detect and don't try to parse empty txes
If we pass the blob into parse_and_validate_tx_from_blob we get
`deserialization or varint failed` error logs, which are harmless bug
annoying.  This catches the empty tx blob case earlier and logs at a
lesser severity.
2022-06-01 17:09:04 -03:00
Jason Rhinelander 4d91082acb
Detect on_transaction_relayed failure
If on_transaction_relayed fails to parse, it returns a null_hash, but
that wasn't being detected here.

Also eliminates calling `on_transaction_relayed(tx_blob)` twice.
2022-06-01 17:09:04 -03:00
Jason Rhinelander a6157fe0a9
Fail if tx blob is empty
Some node on the network apparently has a corrupted DB and is spewing
empty tx blobs onto the network.  Detect such a case rather than
broadcasting broken empty txes.
2022-06-01 15:44:24 -03:00
Jason Rhinelander e120075c37
Remove check for unbound
We don't use it anymore, but the top-level cmake was still looking for
it.
2022-05-30 19:24:24 -03:00