Commit graph

91 commits

Author SHA1 Message Date
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
Sean Darcy 8023b59867 rebrand lns -> ons 2021-04-12 10:27:57 +10:00
Sean Darcy 928ad2c668 Enable ONS mapping type=wallet and resolve ONS wallet addresses 2021-04-12 10:27:57 +10:00
Sean Darcy 0396698ee7 initial loki -> oxen pass 2021-01-04 11:09:45 +11:00
Jason Rhinelander 3d4d6ba916 Inline get_unlock_time to resolve build dep issue
device_ledger needs to call it, but can't link against
cryptonote_basic, so provide an inline version.
2020-12-14 13:54:05 -04:00
Jason Rhinelander 1f03bb41b7 Test suite: add tx version hack and remove broken tests
This adds a variable hack into loki-core that lets us disable the
transaction hard fork requirement so that the test suite can still
generate transactions under older tx rules even though the transactions
will be modern CLSAG txes.

These are sort of bastardized txes that can never occur on the proper
mainnet, but let us keep tests that apply to v2/v3 transactions even
though we can't actually generate proper v2/v3 transactions anymore.

A few tests got removed here because they are testing for old invalid
bulletproof formats that don't matter anymore because they will never be
accepted on the current chain anyway.
2020-12-13 21:42:10 -04:00
Jason Rhinelander 33242dff47 Replace keypair::generate with a keypair constructor taking a hwdev
This makes it a bit nicer, and allows in-place construction rather than
needing to construct-and-copy.
2020-12-08 22:31:54 -04:00
Jason Rhinelander 0450f3dad6 De-inline cryptonote_basic
Moves a bunch of inline methods out into a new cryptonote_basic.cpp
compilation unit.  (Given how widely cryptonote_basic.h gets included it
seems desirable to have as little code needing compilation as possible).
2020-12-08 22:28:37 -04:00
Jason Rhinelander d60548ac0a Move txversion/txtype outside of cryptonote_basic.h
This is simply enough that it can be used from device (which is above
cryptonote_basic in the deps hierarchy).
2020-12-06 23:11:23 -04:00
Jason Rhinelander e8a340e9be Make RingCT and RangeProof types type-safe enum classes 2020-11-30 00:47:12 -04:00
Jason Rhinelander b627b3b4bb Move epee includes under "epee/..."
This ends epee's include pollution.
2020-10-24 12:46:27 -03:00
Jason Rhinelander b7dd5e8911 Target macos 10.12
When targetting macos <10.14 macos won't allow use of anything from
C++17 that throws, such as:
- std::get on a variant
- std::visit
- std::optional::value()
- std::any_cast

This avoids all of these.

For std::get, we either replace with std::get_if (where appropriate), or
else use a `var::get` implementation of std::get added to lokimq (also
updated here).  (This `var` namespace is just an `std` alias everywhere
*except* old target macos).

For std::visit, likewise lokimq adds an var::visit implementation for
old macos that we use.

std::optional::value() uses weren't useful anyway as everywhere it calls
them we've already checked that the option has a value, in which case we
can use `*opt` (which doesn't check for contents and throw).

std::any just has to be avoided as far as I can tell, but the one place
we used it is only ever a block, so I just replaced it with a `const
block*`.
2020-10-18 11:18:08 -03:00
Jason Rhinelander b608d6027d
Fix JSON serialization of pulse block data (#1286)
There was a missing call to nested the values in an object, so the
resulting json ended up as:

    "pulse":,"random_value":"b01b8d1290cbac40917a23a08b343bec","round":0,"validator_bitset":2047,

instead of:

    "pulse":{"random_value":"b01b8d1290cbac40917a23a08b343bec","round":0,"validator_bitset":2047},

Modernize it to avoid macros, and fix it by beginning an object.

(This won't affect binary serialization; object serialization only has
an effect on json serialization and is a no-op for binary
serialization).
2020-09-27 13:56:37 +10:00
Jason Rhinelander f549f9d6d6 Feex speeling mistack and remove dead code
- cash != cache

- The ENABLE_HASH_CASH_INTEGRITY_CHECK is some left over debugging that
  is never enabled and broken code anyway (it compares the resulting
  hash value to uninitialized memory, and for the block hash case, is
  checking something for false that can only ever return true).  Just
  delete it.
2020-09-18 20:25:48 -03:00
Jason Rhinelander 3f67de11df network_version_16 += _pulse 2020-09-18 16:39:50 -03:00
Doyle 86aff9765e Pulse: Move block verification outside of validate_miner_tx 2020-09-18 13:43:51 -03:00
Jason Rhinelander 1ba69c9a77
Fix json serialization of pulse sigs (#1234)
This was producing invalid json:

    "signatures":[,"voter_index":0,"signature":"...",,"voter_index":1,"signature":"...",,

This change corrects it to:

    "signatures":[{"voter_index":0,"signature":"..."},{"voter_index":1,"signature":"..."},{
2020-08-19 15:31:41 +10:00
Doyle cd1c3a206f Pulse: Remove unused operator== 2020-08-18 11:59:54 +10:00
Doyle a62ff316e3 Pulse: Queue Block Gen code review
- Rename find_named_argument -> find_prefixed_value
- Update get_current_blockchain_height() comment to specify ability to lock
- Update memcmp(address1, address2) to address1 == address2
- Make create_next_miner_block_template call create_miner_block_template
- Update LMQ x25519 keys only when key has changed
- construct_miner_tx: Use C++17 features
- Pulse: Add log category "Pulse"
- Pulse: Check shutdown before blockchain height
- Pulse: Use get_human_readable_timespan
- Pulse: Switch to MINFO, enable with --log-level +pulse:DEBUG
- Pulse: Add height into context
- Pulse: Remove some default switch cases hiding compiler warnings
- SN: Update hardcoded '9' literals to network_version_9_service_nodes
- Core: Use using namespace std::literals
- Miner: Change num_blocks availability to debug
- RPC: Gate test rpc commands to != MAINNET
- Wallet: Store wallet before deinitialization instead of refresh
2020-08-18 11:59:53 +10:00
Doyle 601e9f77e1 Pulse: Rename participation to validator_bitset 2020-08-18 11:59:53 +10:00
Doyle 80273cd7fe Remove unused ring_signature typedef 2020-08-18 11:59:53 +10:00
Doyle 63ba795c7e Pulse: DRY quorum signature verification
- By merging the quorum verification with pre-existing checkpointing
code, checkpoints votes are currently being sorted by the vote index
order. This was also enforced on the pulse signatures.
2020-08-18 11:59:53 +10:00
Doyle 475ed74b28 Pulse: Move verification to block. Add support to core tests.
Verification needs to go to the block, not the header to ensure it does
not get included in the block hash.
2020-08-18 11:59:53 +10:00
Doyle a1c658d814 Pulse: Verify incoming pulse blocks 2020-08-18 11:59:53 +10:00
Doyle ae29ecb335 Code review, keep nonce, remove HF_VERSION..
- Keep none for blocks
- Remove HF_VERSION_PULSE and prefer network_version_16 for big features
  - Keep HF_VERSION_... for smaller feature flags
- Add operator< for pulse_sort_key
- Avoid erase() in validators gen loop for pulse
2020-08-18 11:59:53 +10:00
Doyle d869c592b8 Pulse: Support generating 1-time quorums for a block 2020-08-18 11:59:53 +10:00
Jason Rhinelander 4bb46b96c7 Fix "rct_signatures" key being serialized without a value
This was resulting in invalid tx json for txes with no vins (such as
deregs) because the json would contain:

        ...
        "rct_signatures":
    }
2020-08-17 02:44:17 -03:00
Jason Rhinelander e7d056edf1 boost::variant -> std::variant
A huge amount of this is repetitive:

- `boost::get<T>(variant)` becomes `std::get<T>(variant)`
- `boost::get<T>(variant_ptr)` becomes `std::get_if<T>(variant_ptr)`
- `variant.type() == typeid(T)` becomes `std::holds_alternative<T>(variant)`

There are also some simplifications to visitors using simpler stl
visitors, or (simpler still) generic lambdas as visitors.

Also adds boost serialization serializers for std::variant and
std::optional.
2020-07-02 12:52:12 -03:00
Jason Rhinelander a506790f1c Serialization (part2): application 2020-07-02 12:52:12 -03:00
Doyle 0112974dda LNS: Store wallet addresses to DB
- Renames generic_key->generic_owner
- Move generic_owner and generic_signature out of crypto.h because they
aren't really crypto items, rather composition of crypto primitives.
generic_owner also needs access to account_public_address, while that is
just 2 public keys, I've decided to include cryptonote_basic.h into
tx_extra.h instead of crypto.h.
- Some generic_owner helper functions were moved into
cryptonote_basic/format_utils as they need to avoid circular
dependencies between cryptonote_core/cryptonote_basic had I included
generic_owner/generic_signature into loki_name_system.h
- Utilise the normal serialize macros since tx_extra.h already includes
the serializing headers.
2020-03-13 16:07:14 +11:00
Doyle f47efd713a Introduce LNS update transaction to update the underlying value mapping 2020-02-20 09:34:25 +11:00
Doyle a22157862b Update txtype activation hardforks 2020-02-13 11:07:46 +11:00
Doyle 632f6a6e83 Rebase fix, blink_lns -> blink, v15 and reserve types for protocol 2020-02-13 11:07:46 +11:00
Doyle dc69d237e6 Add support for Loki Name Service on the backend 2020-02-13 11:07:46 +11:00
Jason Rhinelander 292a3b11d0 Blink RPC updates & fixes
Blink txes were not being properly passed in/out of the RPC wallet.
This adds the necessary bits both to submit a blink and to get a blink
submission status back from the daemon.
2019-12-26 12:29:05 -04:00
Doyle 1eb45e523e Build/core test fixes, incoporate staking changes from LNS
- Fix assert to use version_t::_count in service_node_list.cpp
- Incoporate staking changes from LNS which revamp construct tx to
  derive more of the parameters from hf_version and type. This removes
  extraneous parameters that can be derived elsewhere.

  Also delegate setting loki_construct_tx_params into wallet2 atleast,
  so that callers into the wallet logic, like rpc server, simplewallet
  don't need bend backwards to get the HF version whereas the wallet has
  dedicated functions for determining the HF.
2019-12-04 15:17:55 +11:00
Jason Rhinelander 99572b2397 Fix block ctors
The move constructors were not actually working (they defaulted to
deleted, which clang helpfully warned about).
2019-12-03 00:51:18 -04:00
Jason Rhinelander f4eaadd4e8 Remove default from get_{min,max}_version_for_hf
The MAINNET default here doesn't make sense: not specifying the network
type in the call (and relying on the MAINNET default) seems likely to be
a bug.
2019-11-27 14:23:56 -04:00
Jason Rhinelander cd06b3c5f1 Make block movable
There is a vector in `block` that can benefit from moving, and with the
copy constructors explicitly defined there are no default implicit move
ctors.
2019-11-27 14:07:52 -04:00
Jason Rhinelander 0350ccfc9a Switch to per-byte + per-output fees, reduce max multiplier
This switches loki 5.x to use a fee formula of

    SIZE * PER_BYTE + OUTPUTS * PER_OUTPUT

where we reduce the PER_BYTE fee back to what it was in 3.x; and with
the PER_OUTPUT fee set to 0.02 LOKI.  This compares to the 4.x fee of:

    SIZE * PER_BYTE * 80

(the *80 multiple was introduced in 4.x).

It also reduces the multiplier for the maximum priority level to 125
instead of 1000 because 1000 produced uselessly high tx fees.  The new
multipliers go up 5x at each level: {1, 5, 25, 125} while previously
they went {1, 5, 25, 1000}.

As for the base change: we added the *80 multiplier in 4.x because we
wanted to make a theoretical de-anonymizing tx spam attack more costly.
The unanticipated consequence was that we also made *large* transactions
(such as sweeps) considerably more costly despite the fact that these
transactions typically only create 2 outputs.

This better captures what we meant to do in 4.x (making output creation
relatively more expensive) without making large txes (e.g. sweeps
required for staking) highly expensive.

The end effect is that the fee for a minimum-sized, 1-input/2-output
transaction should stay roughly the same (slightly over 0.04 LOKI),
while a 100-input/2-output transction (a typical spend or sweep from a
wallet with lots of smaller rewards) will drop in fee by somewhere
around 95%.

The most efficient theoretical deanonymizing tx spamming of this sort
was a 1-input/16-output transaction which will become about 2.5x as
expensive as currently the case in v4.x.
2019-08-26 17:42:30 -03:00
Doyle 3aab77c258
Set minimum miner tx version to 4 (#683)
* Set minimum miner tx version to 4

* Don't set tx minimum version to 4 for hf11

* Use min version to maintain backwards compat in tests when generating staking TX
2019-06-28 13:12:01 +10:00
Doyle 212b859a66 Merge branch 'dev' into LokiMergeUpstream 2019-06-26 15:46:06 +10:00
Doyle fdc340b0ee
Service node checkpointing: rebased on relaxed deregistration (#662)
* core: do not commit half constructed batch db txn

* Add defer macro

* Revert dumb extra copy/move change

* Fix pop_blocks not calling hooks, fix BaseTestDB missing prototypes

* Merge ServiceNodeCheckpointing5 branch, syncing and integration fixes

* Update tests to compile with relaxed-registration changes

* Get back to feature parity pre-relaxed registration changes

* Remove debug changes noticed in code review and some small bugs
2019-06-26 14:00:05 +10:00
Doyle 26080045b6
Decrease the miner tx version minimum to v2 (#669) 2019-06-26 13:36:58 +10:00
Doyle 639d7456f7 Merge commit '1d5e8f4' into LokiMergeUpstream 2019-06-26 13:04:37 +10:00
Jason Rhinelander 6d6541670e Relax deregistration rules
The replaces the deregistration mechanism with a new state change
mechanism (beginning at the v12 fork) which can change a service node's
network status via three potential values (and is extensible in the
future to handle more):

- deregistered -- this is the same as the existing deregistration; the
SN is instantly removed from the SN list.
- decommissioned -- this is a sort of temporary deregistration: your SN
remains in the service node list, but is removed from the rewards list
and from any network duties.
- recommissioned -- this tx is sent by a quorum if they observe a
decommissioned SN sending uptime proofs again.  Upon reception, the SN
is reactivated and put on the end of the reward list.

Since this is broadening the quorum use, this also renames the relevant
quorum to a "obligations" quorum (since it validates SN obligations),
while the transactions are "state_change" transactions (since they
change the state of a registered SN).

The new parameters added to service_node_rules.h control how this works:

    // Service node decommissioning: as service nodes stay up they earn "credits" (measured in blocks)
    // towards a future outage.  A new service node starts out with INITIAL_CREDIT, and then builds up
    // CREDIT_PER_DAY for each day the service node remains active up to a maximum of
    // DECOMMISSION_MAX_CREDIT.
    //
    // If a service node stops sending uptime proofs, a quorum will consider whether the service node
    // has built up enough credits (at least MINIMUM): if so, instead of submitting a deregistration,
    // it instead submits a decommission.  This removes the service node from the list of active
    // service nodes both for rewards and for any active network duties.  If the service node comes
    // back online (i.e. starts sending the required performance proofs again) before the credits run
    // out then a quorum will reinstate the service node using a recommission transaction, which adds
    // the service node back to the bottom of the service node reward list, and resets its accumulated
    // credits to 0.  If it does not come back online within the required number of blocks (i.e. the
    // accumulated credit at the point of decommissioning) then a quorum will send a permanent
    // deregistration transaction to the network, starting a 30-day deregistration count down.

This commit currently includes values (which are not necessarily
finalized):
- 8 hours (240 blocks) of credit required for activation of a
decommission (rather than a deregister)
- 0 initial credits at registration
- a maximum of 24 hours (720 blocks) of credits
- credits accumulate at a rate that you hit 24 hours of credits after 30
days of operation.

Miscellaneous other details of this PR:

- a new TX extra tag is used for the state change (including
deregistrations).  The old extra tag has no version or type tag, so
couldn't be reused.  The data in the new tag is slightly more
efficiently packed than the old deregistration transaction, so it gets
used for deregistrations (starting at the v12 fork) as well.

- Correct validator/worker selection required generalizing the shuffle
function to be able to shuffle just part of a vector.  This lets us
stick any down service nodes at the end of the potential list, then
select validators by only shuffling the part of the index vector that
contains active service indices.  Once the validators are selected, the
remainder of the list (this time including decommissioned SN indices) is
shuffled to select quorum workers to check, thus allowing decommisioned
nodes to be randomly included in the nodes to check without being
selected as a validator.

- Swarm recalculation was not quite right: swarms were recalculated on
SN registrations, even if those registrations were include shared node
registrations, but *not* recalculated on stakes.  Starting with the
upgrade this behaviour is fixed (swarms aren't actually used currently
and aren't consensus-relevant so recalculating early won't hurt
anything).

- Details on decomm/dereg are added to RPC info and print_sn/print_sn_status

- Slightly improves the % of reward output in the print_sn output by
rounding it to two digits, and reserves space in the output string to
avoid excessive reallocations.

- Adds various debugging at higher debug levels to quorum voting (into
all of voting itself, vote transmission, and vote reception).

- Reset service node list internal data structure version to 0.  The SN
list has to be rescanned anyway at upgrade (its size has changed), so we
might as well reset the version and remove the version-dependent
serialization code.  (Note that the affected code here is for SN states
in lmdb storage, not for SN-to-SN communication serialization).
2019-06-23 22:37:53 -03:00
Jason Rhinelander 4f721c0098 Make tx type and version scoped enums
This converts the transaction type and version to scoped enum, giving
type safety and making the tx type assignment less error prone because
there is no implicit conversion or comparison with raw integers that has
to be worried about.

This ends up converting any use of `cryptonote::transaction::type_xyz`
to `cryptonote::transaction::txtype::xyz`.  For version, names like
`transaction::version_v4` become `cryptonote::txversion::v4_tx_types`.

This also allows/includes various other simplifications related to or
enabled by this change:
- handle `is_deregister` dynamically in serialization code (setting
  `type::standard` or `type::deregister` rather than using a
  version-determined union)
- `get_type()` is no longer needed with the above change: it is now
  much simpler to directly access `type` which will always have the
  correct value (even for v2 or v3 transaction types).  And though there
  was an assertion on the enum value, `get_type()` was being used only
  sporadically: many places accessed `.type` directly.
- the old unscoped enum didn't have a type but was assumed castable
  to/from `uint16_t`, which technically meant there was potential
  undefined behaviour when deserializing any type values >= 8.
- tx type range checks weren't being done in all serialization paths;
  they are now.  Because `get_type()` was not used everywhere (lots of
  places simply accessed `.type` directory) these might not have been
  caught.
- `set_type()` is not needed; it was only being used in a single place
  (wallet2.cpp) and only for v4 txes, so the version protection code was
  never doing anything.
- added a std::ostream << operator for the enum types so that they can be
  output with `<< tx_type <<` rather than needing to wrap it in
  `type_to_string(tx_type)` everywhere.  For the versions, you get the
  annotated version string (e.g. 4_tx_types) rather than just the number
  4.
2019-06-19 17:47:03 -03:00
moneromooo-monero 1387549e90
serialization: check stream good flag at the end
just in case
2019-06-14 08:47:23 +00:00
Doyle 4778d862c9 Merge commit 'bd42903' into LokiMergeUpstream 2019-04-12 18:37:56 +10:00
Doyle 892469ded1 Update monero copyright to 2019 pre-emptively to make merge simpler 2019-04-12 14:36:43 +10:00