Commit graph

9500 commits

Author SHA1 Message Date
Jason Rhinelander
0fa54cb507 Make operator_fee in millionths
This makes it consistent with the value returned in the tx extra details
in the get transactions rpc call.
2021-11-01 17:08:56 -04:00
Jason Rhinelander
61f87e42a6 RPC: HARD_FORK_INFO
Implements new RPC for hard_fork_info, which `oxend status` (most
notably, but there are others) requires.
2021-11-01 17:08:54 -04:00
Jason Rhinelander
7e6097d312 RPC: GET_TRANSACTION_POOL_STATS improvements/tweaks
- Take the "include_unrelayed" as a parameter instead of switching on on
  the admin context; there isn't likely to be anything sensitive there,
  and it makes little sense for a wallet to get *different* results just
  because it happens to be talking to a localhost oxend.
- Change the histogram code so that it always returns a fixed size
- Various improvements to histogram output; most notably printing a more
  useful indication of what the histogram outputs are (e.g. instead of:

             Age             Txes       Bytes
             now                0           0
       8.0 minutes ago          0           0
       16.1 minutes ago         0           0
       24.1 minutes ago         0           0
       32.2 minutes ago         0           0
       40.2 minutes ago         0           0
       48.3 minutes ago         0           0
       56.3 minutes ago         0           0
       64.3 minutes ago         0           0
       72.4 minutes ago         2        4559

  it now displays the ranges:

                  Age                Txes       Bytes
           now - 10.6min ago          0           0
       10.6min - 21.3min ago          0           0
       21.3min - 32.0min ago          0           0
       32.0min - 42.6min ago          0           0
       42.6min - 53.2min ago          0           0
       53.2min - 63.9min ago          0           0
       63.9min - 74.6min ago          0           0
       74.6min - 85.2min ago          0           0
       85.2min - 1.6hr ago            0           0
         1.6hr - 1.8hr ago            2        4559
2021-11-01 17:08:22 -04:00
Jason Rhinelander
7b871e97fc Add fmtlib::fmt backport of C++20 std::format
Because I'm tired of waiting for std::format.
2021-11-01 17:03:47 -04:00
Jason Rhinelander
0e260256b2 Push RPC response serialization down into handlers
Rather than serializing in the `invoke` call, we now return a variant
(bt, json, or string) from invoke and let the RPC server deal with it.

This significantly simplifies the JSON RPC interface because it lets us
move json objects around, which is particularly useful for building a
json_rpc response and lets us avoid the vector of strings hack that was
needed for epee json serialization.

This also lets the RPC caller decide what it wants to accept -- so the
OMQ RPC can deal with anything (bt, json, binary), while the http
json_rpc handler only accepts json, and the http/legacy binary handlers
accepts json or strings, but not bt_value.

This also fixes a but in the json_rpc handler that failed when given an
"id" value that wasn't a string (such as a number).
2021-11-01 16:59:01 -04:00
Jason Rhinelander
3415733996 RPC overhaul: SYNC_INFO 2021-11-01 16:59:01 -04:00
Jason Rhinelander
bdccca82dd Remove debugging & superfluous 'return;'s 2021-11-01 16:59:01 -04:00
Jason Rhinelander
5c413592aa Return tx pool hashes as potential binary
We can assign hashes directly now and get binary for bt-rpc, hex for
json.
2021-11-01 16:59:01 -04:00
Jason Rhinelander
8bb9d56f96 Fix mining status commands 2021-11-01 16:59:01 -04:00
Jason Rhinelander
6d7428b0e1 Add invoke_simple for invoking simple RPC calls
Simple here means no arguments and no return aside from the "status":
"OK" field.  For commands like stop_mining, stop_daemon, save_bc.
2021-11-01 16:58:59 -04:00
Jason Rhinelander
8ad7eb1509 Remove "support_flags" from p2p protocol
It does nothing.  This keeps a stub that returns zero so that other
nodes can still query us, which can be removed after the next HF.
2021-11-01 16:58:04 -04:00
Jason Rhinelander
c2f39b6541 RPC update: get_connections
- add documentation
- change download/upload speed values to B/s instead of KiB/s
- return times as milliseconds instead of seconds, and rename those
  fields from ..._time to ..._ms.
- Code cleanup of state strings
- remove completely unused peer state "idle"
2021-11-01 16:58:01 -04:00
Jason Rhinelander
ef3686ccf3 Remove hide_hr, show_hr commands, part 2 2021-11-01 14:59:27 -04:00
Jason Rhinelander
86a8de6403 Add generic concat and concat-with-delimiter string utils 2021-11-01 14:59:27 -04:00
Jason Rhinelander
7bb53551e3 Apply some lipstick to a pig
Some small random epee improvements.
2021-11-01 14:59:21 -04:00
Jason Rhinelander
ad79059b74 Move tx pool stats struct out of rpc code
It makes no sense for the definition to be there (except that it was
for epee serialization purposes), so move it into tx_memory_pool where
it belongs, and convert it to json on the fly for the rpc method that
wants it.
2021-11-01 14:54:21 -04:00
Jason Rhinelander
4c141e1e4a START_MINING fixes
- parse args
- make it compile
- fix the slow_mining parameter not being passed through to the miner
2021-11-01 14:54:21 -04:00
Jason Rhinelander
5dcb2c2b56 Remove parse_request() overloads for no-args endpoints
Inheriting from NO_ARGS lets you rely on the no-input
parse_request(NO_ARGS&, rpc_input) rather than needing to add an empty
one.
2021-11-01 14:54:21 -04:00
Jason Rhinelander
b9755af4b4 Remove useless junk from miner: autodetect, miner_conf.json
Autodetect is not that useful in the first place, even if we weren't
PoS, but is especially useless now.

miner_conf.json is this probably-never-used feature to load some extra
crap into the tx_extra.  Just kill it.

Remove the ability (and RPC endpoint) to print the hashrate periodically
to stdout because that is pretty dumb.
2021-11-01 14:54:21 -04: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
1f16daf109 Replace epee C date crap with C++20 date backport 2021-11-01 14:54:18 -04:00
Jason Rhinelander
63a6cd6a13 get_outputs - finish, backwards compat, add results as tuple
- Make it compile/work
- Take outputs as a list of output indices.  We never need "amount" in
  Oxen (it will always be 0).
- Add backwards compatibility to still take outputs as
  [{"amount":0,"index":n},...] when making a json request.
- Add an "as_tuple" bool parameter: if specified then you get results in
  a much denser tuple form rather than a dict, which can make a huge
  difference in the response size when requesting many outputs.
2021-11-01 14:53:56 -04:00
Jason Rhinelander
02f1b5b982 Add nlohmann-json submodule 2021-11-01 14:53:52 -04:00
Jason Rhinelander
2b568f02d2 Add support for loading from various container types
- Supports loading into tuples, std::arrays, std::pairs from a list of
  the correct size.
- Supports loading into vectors of arbitrary types (include vector,
  tuples, binary types, etc.)
- Removes system_clock type as we aren't using it (and because it won't
  be recursively handled nicely when nested, especially for json).
2021-11-01 14:53:10 -04:00
Sean Darcy
71fb298b3a parse params of get_outputs 2021-11-01 14:53:10 -04:00
Sean Darcy
533b319fff define parsers, returning correct types 2021-11-01 14:53:10 -04:00
Jason Rhinelander
a8b36efd4c Update doc formatting style
Use `- \p paramname Description` rather than `\arg \c paramname
Description`.

\arg is for compatibility with some particular doc format and is
equivalent to - except that - can be nested while \arg cannot.

\c and \p are equivalent, but \p is explicitly intended for parameters.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
9a0e23ca05 get_service_node *client* updates
Updates the internal callers of get_service_nodes to properly deal with
the new request format/fields.

Note that this also introduces some significant changes to the
`print_sn` output:

- contributor formats are more compact (one line per contributor), show
  reserved amounts (if != contributed amouont), and show the stake %.
- reworded "Operator Cut (% of Fee Reward)" to "Operator Fee"
- checkpoint/pulse vote format is completely overhauled to list voted
  and missed heights separately.
- pulse votes now show the pulse round for non-zero round results.
- timestamp checks renamed to Quorumnet tests
- qnet & timesync results now just print the number of successes/fails
  rather than a list of true/false values.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
ebc8bc79e5 RPC: GET_SERVICE_NODES & GET_SERVICE_NODE_STATUS
Converts request parsing and result generation for get_service_nodes and
get_service_node_status.

Note that there are some significant changes here (due to no longer
having to be under epee's output constraints) that significantly reduce
the size of an all-service-nodes request by nearly half, most notably in
a significantly more compact representation of vote/participation
results.

- added a "decomm_reasons" which decomposes the reason codes into string
  values such as:

    "decomm_reasons": {
        "all": ["uptime"],
        "some": ["pulse", "lokinet"]
    }
- reworded/fixed/expanded various field descriptions
- Various Loki currency references changed to OXEN
- added "operator_fee" which is a rounded operator fee expressed as
  thousanths of a percent (e.g.  100000 means 100%, 4567 means 4.567%).
  This is inaccurate but much easier to deal with than the raw
  portions_for_operator value (especially because the value *usually*
  exceeds what can be stored in a double, and thus is not safe with
  various JSON parsers).
- added "swarm" which is a hex string representation of the swarm_id,
  because swarm_id also isn't double-storage safe.
- reserved and total_reserved fields are now only included if they are
  actually different from the amount/total_contributed values.
- various uptime-proof-dependent values (like versions, public ip,
  ports) are now omitted if we haven't received an uptime proof yet.
- Flipped inverted descriptions of timestamp participation / synced
  values in the RPC documentation.
- checkpoint/pulse/timecheck/timesync participations data is completely
  redesigned to be less bloated; the names are now changed to
  "checkpoint_votes" and "pulse_votes" and information is returned much
  more compactly using lists of lists and/or plain values rather than
  lists of dicts that repeat a ton of fields.
- Renamed timestamp_participation in the RPC to quorumnet_tests since,
  although we're doing the test for time checking, the main purpose of
  the participation is to see that we can reach them.  As above, the
  result value is significantly more compact: [SUCCESS,FAILS] instead of
  an array of dicts.
- Similarly renamed timesync_status to timesync_tests ("status" was
  fine, but changing the value completely to [SUCCESS,FAILS] warrants a
  name change).
- dropped the "as_json" field because it is asking oxend to
  double-encode json, and that is retarded.
- also applies all the same refactoring to get_service_node_status
  (which is really just a shortcut for getting the current node's status
  out of get_service_nodes).
- overhauled how "fields" works to take a list of field names (the dict
  is name: bool values is still supported for backwards compatibility).
  Also extended fields to handle "locked_contributions" as a supported
  field (so that you can easily omit it, since it often isn't cared
  about).
2021-11-01 14:53:10 -04:00
Jason Rhinelander
4317feb7d6 Promote critical startup errors to MFATAL
At MERROR they don't print at the default --log-level=0, so you get
output such as:

    2021-08-06 18:04:08.073	I Starting up oxend services...
    2021-08-06 18:04:08.073	I Starting core
    2021-08-06 18:04:08.073	F Failed to start core
    2021-08-06 18:04:08.173	I Deinitializing daemon objects...

with no actual error displayed as to why it failed to start.  With this
change you get:

    2021-08-06 18:04:14.004	F Please specify an IPv4 public address which the service node & storage server is accessible from with: '--service-node-public-ip <ip address>'
    2021-08-06 18:04:14.004	F IMPORTANT: One or more required service node-related configuration settings/options were omitted or invalid; please fix them and restart oxend.
    2021-08-06 18:04:14.004	F Failed to start core
2021-11-01 14:53:10 -04:00
Jason Rhinelander
de3f9a103f Move json binary handling code; teach it about vectors
- Moves the json binary handling code into new rpc_binary.h

- Adds support for storing/loading vectors of binary types
  (crypto::hash, etc.), and vectors of strings.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
e8cbf6352d using nlohmann::json
Simplify things by not require full qualification everywhere.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
1ea9791ca4 Add a version of tools::join that also transforms
Also add a missing <cassert> header needed for elsewhere in the header.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
ea8292703f print_money: allow trimming unused decimals
This lets the caller get a value of 15000 or 4.56 instead of
15000.000000000 or 4.560000000 by passing a true second argument to
print_money().
2021-11-01 14:53:10 -04:00
Jason Rhinelander
5330069421 Remove dumb configurable decimal place support
*Nothing* calls `print_money()` with a decimal place value, for good
reason: it's a stupid thing to want to do.  Similarly nothing gives a
decimal places argument to `get_unit()`.

This removes the dumb unused decimal place argument.
2021-11-01 14:53:10 -04:00
Jason Rhinelander
a3547c8467 Simplify participation structures
- make checkpoint and pulse participation distinct types
- make the container act a little more like an stl container
- replace check_participation() with a failures() method that just
  returns the number of failures (so the caller can decide whether that
  is bad or not).
- As a consequence of the above, failures now trigger on N+1 failures,
  while previously they required N+1 failures *and* 8 total responses.
  There is no need to wait for all 8 as far as I can see since we will
  be failing no matter what the next 3 responses are.
- Removed the serialization code (hopefully this doesn't break
  everything outside the RPC code).
- Simplify/DRY the code that records participation
2021-11-01 14:53:10 -04:00
Jason Rhinelander
41c01efadf Add int-to-string converter (from storage server) 2021-11-01 14:53:10 -04:00
Sean Darcy
c7ab69b4f9 Convert RPC functions to new format:
MINING_STATUS, GET_TRANSACTION_POOL_HASHES, GET_TRANSACTION_POOL_BACKLOG, GET_TRANSACTION_POOL_STATS, GET_CONNECTIONS
2021-11-01 14:53:10 -04:00
Sean Darcy
434ca35c7e New RPC formats for STOP_MINING, SAVE_BC, STOP_DAEMON, GETBLOCKCOUNT 2021-11-01 14:53:10 -04:00
Sean Darcy
ced01dfb16 START_MINING and GET_OUTPUTS to new RPC format 2021-11-01 14:53:09 -04:00
Sean Darcy
b3f125bfdf GET_NET_STATS - To new RPC format 2021-11-01 14:53:09 -04:00
Jason Rhinelander
d350e2a664 Remove old code 2021-11-01 14:53:09 -04:00
Jason Rhinelander
4a8023ade6 Make RPC more flexible & add bt-encoding
The bt-encoding, in particular, is aimed at more efficient wallet3 rpc
interactions with a daemon.

This removes the rigidity from RPC request responses, making it easier
to return useful constructs that the current epee code doesn't support
(like lists of lists), and also adds support for bt-encoded RPC requests
(intended to eventually replace the ".bin" endpoints with Monero NIH
binary encoding).

Instead endpoints now set a nlohmann::json response object with whatever
arbitrary values they want without having to add a bunch of limited epee
serialization macro hell.

So, for example, to set the value "foo" to 20, you use:

    rpc.response["height"] = 20;

Binary values (for things like hashes) are handled by going through a proxy object:

    rpc.response_hex["hash"] = hash; // hash is a crypto::hash

which, for json, is equivalent to:

    rpc.response["hash"] = tools::type_to_hex(hash);

but when the response is to be bt-encoded it leaves it as binary for
more efficient transfers.

There is also a `response_b64` that converts json-destined values to
base64 instead of hex (and again leaves bt-destined values as binary).

Parsing of incoming requests now moves to a new
core_rpc_server_command_parser file, which does free-form parsing from a
nlohmann::json or bt_dict_consumer, and has various templated helper
functions to make this easier.

This is preliminary: this builds the basic infrastucture for handling
requests, and converts three endpoints:

- get_info
- get_height
- ons_resolve

Currently only `make daemon` builds (there is code in the wallet that
hasn't been updated yet), and the other RPC interfaces are disabled by
this commit (until they get converted to the new style).
2021-11-01 14:53:05 -04:00
Jason Rhinelander
d66e72fcea friendly_duration: show 0s for exactly 0 rather than 0ns 2021-11-01 14:19:27 -04:00
Jason Rhinelander
0ff6d3f491 Minor api improvement: return pair instead of two output params 2021-11-01 14:19:27 -04:00
Jason Rhinelander
c3c90a48f7 Code simplification 2021-11-01 14:19:27 -04:00
Jason Rhinelander
e312e30f12
Merge pull request #1494 from tewinget/sqlitedb
fix bugs in initial implementation of sqlitedb abstraction
2021-10-19 12:34:33 -03:00
Jason Rhinelander
5a73ec194a
Merge pull request #1495 from jagerman/remove-uselessness
Remove useless atomic calculations
2021-10-19 12:33:35 -03:00
Jason Rhinelander
340c99b524 Set up aes flags properly for cn-turtle compilation 2021-10-18 22:23:01 -03:00
Thomas Winget
a255889286 minor fixups in sqlitedb wrapper 2021-10-16 22:32:32 -04:00