Commit graph

730 commits

Author SHA1 Message Date
Doyle
f761ed6345 Merge commit '51766d0' into LokiMergeUpstream 2019-06-26 12:43:21 +10:00
Jason Rhinelander
36b06c52e7 Increase fee by 80x at Heimdall fork (#663)
* Increase fee by 80x at Heimdall fork

Loki's current fees are far too cheap, which makes a potential
deanonymization attack (whereby someone floods the network with
transactions that they later use to identify decoys) very cheap.

This commit increases the tx fee by 80x.  Transactions will still be
cheap (a typical tx will go from around 0.00052 LOKI to 0.04 LOKI, which
is around half a US cent at the time of this commit.

This also provides a better estimate for the FEE_PER_BYTE value (both
before and after the fork), which was using a wrong estimate from Monero
(which has 3 extra decimal places!)

Finally this commit removes some related constants from
cryptonode_config.h that have never applied to Loki.

* Remove Loki-impossible values from wallet code
2019-06-25 19:22:43 +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
Doyle
9f12ae0c0a
Service Node Checkpointing: More reliable transportation of votes, culling of old checkpoints (#632)
* Initial updates to allow syncing of checkpoints in protocol_handler

* Handle checkpoints in prepare_handle_incoming_blocks

* Debug changes for testing, cancel changes later

* Add checkpoint pruning code

* Reduce DB checkpoint accesses, sync votes for up to 60 blocks

* Remove duplicate lifetime variable

* Move parsing checkpoints to above early return for consistency

* Various integration test fixes

- Don't try participate in quorums at startup if you are not a service node
- Add lock for when potentially writing to the DB
- Pre-existing batch can be open whilst updating checkpoint so can't use
  DB guards
- Temporarily emit the ban message using msgwriter instead of logs

* Integration mode bug fixes

- Always deserialize empty quorums so get_testing_quorum only fails when
an actual critical error has occurred
- Cache the last culled height so we don't needlessly query the DB over
the same heights trying to delete already-deleted checkpoints
- Submit votes when new blocks arrive for more reliable vote
transportation

* Undo debug changes for testing

* Update incorrect DB message and stale comment
2019-06-13 18:01:08 +10:00
Doyle
ed0ef399db
Various integration test fixes (#628)
- Don't try participate in quorums at startup if you are not a service node
- Add lock for when potentially writing to the DB
- Pre-existing batch can be open whilst updating checkpoint so can't use
  DB guards
- Temporarily emit the ban message using msgwriter instead of logs
2019-06-06 14:44:57 +10:00
Doyle
3794dce241
Service Node Checkpointing Basic Syncing (#621)
* Initial updates to allow syncing of checkpoints in protocol_handler

* Handle checkpoints in prepare_handle_incoming_blocks

* Parse checkpoints sent by peer

* Fix rebase to dev referencing no longer valid argument
2019-06-04 13:50:31 +10:00
Doyle
ac796c7767
Enforce miner tx version (#623)
* Enforce tx version for coinbase transactions

* Gate coinbase version enforcement to HF12

* Remove min/max type/version check comment
2019-06-04 09:50:19 +10:00
Doyle
cc72791b9d
Remove unused txs member in NOTIFY_RESPONSE_GET_OBJECT (#619) 2019-06-03 14:04:43 +10:00
Riccardo Spagni
7e417dd408
Merge pull request #5571
35da33be blockchain: do not try to pop blocks down to the genesis block (moneromooo-monero)
4b51f9a3 core: do not commit half constructed batch db txn (moneromooo-monero)
2019-06-01 20:22:19 +02:00
Doyle
a23b553a31
Merge pull request #606 from Doy-lee/LokiMergeUpstream
Loki Merge Upstream #e8487fa 2019-05-17
2019-05-31 12:35:25 +10:00
Doyle
8af377d2b8
Unify and move responsibility of voting to quorum_cop (#615)
* Unify checkpointing and uptime quorums

* Begin making checkpoints cull old votes/checkpoints

* Begin rehaul of service node code out of core, to assist checkpoints

* Begin overhaul of votes to move resposibility into quorum_cop

* Update testing suite to work with the new system

* Remove vote culling from checkpoints and into voting_pool

* Fix bugs making integration deregistration fail

* Votes don't always specify an index in the validators

* Update tests for validator index member change

* Rename deregister to voting, fix subtle hashing bug

Update the deregister hash derivation to use uint32_t as originally set
not uint64_t otherwise this affects the result and produces different
results.

* Remove un-needed nettype from vote pool

* PR review, use <algorithms>

* Rename uptime_deregister/uptime quorums to just deregister quorums

* Remove unused add_deregister_vote, move side effect out of macro
2019-05-31 11:06:42 +10:00
moneromooo-monero
35da33bea9
blockchain: do not try to pop blocks down to the genesis block 2019-05-26 17:11:32 +00:00
moneromooo-monero
4b51f9a34f
core: do not commit half constructed batch db txn 2019-05-25 16:24:56 +00:00
Howard Chu
b6830db2d4
Fix #5553
Make sure the tip hash still matches the cached block
2019-05-19 03:02:33 +01:00
Doyle
2649eb79da Merge commit 'ebb1c03' into LokiMergeUpstream 2019-05-17 03:43:06 +10:00
Riccardo Spagni
f64f59627d
Merge pull request #5510
e9809382 fix wide difficulty conversion with some versions of boost (moneromooo-monero)
2019-05-07 17:36:27 +02:00
moneromooo-monero
a4c4a2d8aa
blockchain: keep a rolling long term block weight median 2019-05-02 09:47:01 +00:00
Doyle
d2d5b74b03 Merge commit '4609b36' into LokiMergeUpstream 2019-05-02 13:22:33 +10:00
Doyle
277586417a Merge commit '96696d1' into LokiMergeUpstream 2019-05-02 11:13:33 +10:00
moneromooo-monero
e980938210
fix wide difficulty conversion with some versions of boost 2019-05-01 19:58:09 +00:00
Doyle
f19e937a05 Merge commit '46c477a' into LokiMergeUpstream 2019-05-01 17:32:57 +10:00
Doyle
455129c8ca Merge branch 'dev' into LokiMergeUpstream 2019-05-01 16:31:54 +10:00
Doyle
cc0d51078c Merge dev into upstream 2019-05-01 16:01:17 +10:00
Doyle
73e8ac0343
Service Node Checkpoint Storage (#579)
* Add functions for storing checkpoints to the DB

* Allocate the DB entry on the stack instead of heap

* Add virtual overrides for new checkpoint functions

* Clean up for pull request, simplify some logic

* Revise API to include height in checkpoint header

* Move log to top of function even if early exit

* Begin moving checkpoints to db

* Allow storing of checkpoints to DB

* Cleanup for code reviewer, fix unit tests

* Fix tests, fix casting issues

* Don't use DUPSORT, use height->checkpoint mapping in DB

* Remove if 0 disabling checkpoint vote, we already check HF12

* Fix unit test infinite loop

* Update db schemas to match blk_checkpoint_header

* Code review
2019-05-01 15:57:41 +10:00
Doyle
47522768f0
Remove loading checkpoints from DNS (#570)
* Remove loading checkpoints from DNS code

* Remove DNS code from blockchain utilities

* Fix grammar in json checkpoint comments
2019-04-26 13:16:56 +10:00
Doyle
dee66d4556
Non-Enforced Transient Service Node Checkpointing (#566)
* Collect checkpoint votes and signatures

* Copy deregister vote and adapt for checkpoint vote

Monkey see, monkey do

Write boilerplate code for receiving and relaying votes

* Make current checkpoints service node aware

Fix not saving checkpoint hash for normal checkpoints

Simplify some of the checkpointing API

* Verify blocks against service node checkpoints

Remove checkpoint copy, make checkpoint at vote threshold

Fix null ptr dereferences, add debug print checkpoints

* Add simple node checkpointing w/no conflict resolution

* Use endl to flush output

* Add hash to vote

* Revise checkpoint rules

* Don't store checkpoints in a linked list

* Commit checkpoints on super majority of votes received

* Add locks since checkpoints is accessed in network thread

* Handle checkpoint vote conflicts better

* Comment out early exiting voting process for simplicity

* Clean up for code review

* Fix whitespacing

* More cleanup for review

* Remove debug changes, fix using upper_bound incorrectly, return points by value

* find_if uses == not < as the predicate

* Fix merge issues from rebasing multiple quorum types
2019-04-23 12:04:47 +10:00
Doyle
6024539e13
Allow storing multiple quorum types (#562) 2019-04-23 10:53:17 +10:00
Riccardo Spagni
68d131615e
Merge pull request #5448
d009f6dd rpc: fix get_block_hashes.bin from wallet on pruned blockchain (moneromooo-monero)
bb0ef5b1 blockchain: lock the blockchain while pruning (moneromooo-monero)
2019-04-16 22:47:36 +02:00
Riccardo Spagni
0d2aaac15b
Merge pull request #5414
e9fac29a unit_tests/long_term_block_weight: some tweaks that seem to make more sense (stoffu)
467f4c7e tests/block_weight: use integer division when computing median (stoffu)
815d08dc tests/block_weight: remove unused MULTIPLIER_SMALL (stoffu)
661f1fb8 blockchain: remove unused calc of short_term_constraint (stoffu)
2019-04-16 22:37:02 +02:00
moneromooo-monero
d009f6dd61
rpc: fix get_block_hashes.bin from wallet on pruned blockchain
We want to get all blocks here, even pruned ones
2019-04-15 22:27:15 +00:00
moneromooo-monero
bb0ef5b1f2
blockchain: lock the blockchain while pruning 2019-04-15 22:27:12 +00:00
moneromooo-monero
5e673c03fe
blockchain_db: fix db txn ending too early
The db txn in add_block ending caused the entire overarching
batch txn to stop.
Also add a new guard class so a db txn can be stopped in the
face of exceptions.

Also use a read only db txn in init when the db itself is
read only, and do not save the max tx size in that case.
2019-04-14 08:35:38 +00:00
Doyle
5653661258 Merge commit '9c77dbf' into LokiMergeUpstream 2019-04-12 19:04:00 +10:00
Doyle
721fd318d5 Merge commit '5db72d1' into LokiMergeUpstream 2019-04-12 18:41:07 +10:00
Doyle
4778d862c9 Merge commit 'bd42903' into LokiMergeUpstream 2019-04-12 18:37:56 +10:00
Doyle
c53bee7177 Merge commit '5dbcceb' into LokiMergeUpstream 2019-04-12 18:21:16 +10:00
Doyle
9d1df98f37 Merge commit '4308a2e' into LokiMergeUpstream 2019-04-12 18:00:11 +10:00
Doyle
403b6f6df8 Merge commit '30a3a73' into LokiMergeUpstream 2019-04-12 17:22:42 +10:00
Doyle
b985a05dd3 Merge commit 'cd776b1' into LokiMergeUpstream 2019-04-12 16:23:54 +10:00
Doyle
892469ded1 Update monero copyright to 2019 pre-emptively to make merge simpler 2019-04-12 14:36:43 +10:00
moneromooo-monero
064ab12340
functional_tests: add more blockchain related tests
Related to emission, reorgs, getting tx data back, output
distribution and histogram
2019-04-11 11:07:58 +00:00
Riccardo Spagni
915d9e5a1f
Merge pull request #5380
113e4877 blockchain_stats: fix sign in formatting function (moneromooo-monero)
adaea3ea various: remove unused variables (moneromooo-monero)
631ef00e blockchain: some debug info when adding txes-from-block fails (moneromooo-monero)
2019-04-11 13:02:59 +02:00
Riccardo Spagni
bd429033df
Merge pull request #5378
eda2661a Allow pruning before v10 (moneromooo-monero)
2019-04-11 13:02:35 +02:00
Riccardo Spagni
036daa3af9
Merge pull request #5373
aff80e70 blockchain: fix returned height in create_block_template (moneromooo-monero)
2019-04-11 13:00:55 +02:00
Riccardo Spagni
76fbcfe2dd
Merge pull request #5123
089c7637 cryptonote: rework block blob size sanity check (moneromooo-monero)
2019-04-11 12:41:07 +02:00
Doyle
33488c1723 Merge commit '503b2fd964342a63876a7d16539ae9ceb27b7b70' into LokiMergeUpstream 2019-04-11 17:36:24 +10:00
Doyle
8d7d90c374 Merge commit 'ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77' into LokiMergeUpstream 2019-04-11 15:08:26 +10:00
Doyle
e2a29bf490 Merge commit '927b2300b3f437787b5833aa011cf97525fac9ff' into LokiMergeUpstream 2019-04-10 09:36:50 +10:00
stoffu
661f1fb8b2
blockchain: remove unused calc of short_term_constraint 2019-04-09 19:39:24 +09:00