Commit graph

754 commits

Author SHA1 Message Date
Doyle
a0c327bcdf
Handle multi state changes in the pool (#781)
* Update state transition check to account for height and universally set timestamp on recommission

Reject invalidated state changes by their height after HF13

* Prune invalidated state changes on blockchain increment

Simplify check_tx_inputs for state_changes by using service node list

Instead of querying the last 60 historical blocks for every transaction,
use the service node list and determine the state of the service node
and if it can transition to its new state.

We also now enforce at hardfork 13, that the network cannot commit
transactions to the network if they would have been invalidated by
a newer state change that already is already on the blockchain.

This is backwards compatible all the way back to hardfork 9.

Greatly simplify state change tx pruning on block added

Use the new stricter rules for pruning state changes in the txpool

We can do so because pruning the TX pool won't cause issues at the
protocol level, but the more people we can upgrade the better network
behaviour we get in terms of propagating more intrinsically correct
ordering of state changes to other peers.

* Don't generate state changes if not valid, disallow voting if node is non-votable
2019-08-12 09:48:47 +10:00
Doyle
8060f00428
Add progress meter to pop_blocks (#770) 2019-08-07 11:43:39 +10:00
Doyle
8dca820ed7
Service node checkpointing soft fork for mainnet (#719)
* Add soft forking for checkpointing on mainnet

* Clear checkpoints on softfork on mainnet

* Move softfork date until we're ready, fix test results and modulo addition

* Only round up delete_height if it's not a multiple of CHECKPOINT_INTERVAL

* Remove unused variable soft fork in service_node_rules (replaced by cryptonote_config)
2019-07-11 16:16:16 +10:00
Doyle
afc86db4a9
Rollback chain when receiving conflicting checkpoints (#726) 2019-07-11 14:16:55 +10:00
Doyle
3cc5fd62ca
Difficulty workaround (#722)
* Recalculate difficulty on reorganisation workaround

* Gate difficulty workaround to only be on mainnet

* Make difficulty changes emit logs on diff delta only
2019-07-11 14:15:32 +10:00
Doyle
ca37156c38
Allow state changes if non conflicting states (#718)
* Only dupe check state changes against the latest valid change

* Check the service node info for dupe state change

* Gate dupe state changes behind HF12

* Actually properly gate dupe state change and revert breaking changes

* Use is_decommissioned() to get service node state, change msg log level
2019-07-09 13:59:42 +10:00
Doyle
3deeaf2c67 Don't discard alt-chains if they have a checkpoint
Technically the alt chain can still be re-orged due to checkpointing
since the last 2 Service Node checkpoints can be undone with sufficient
valid blocks on an alt chain.
2019-07-05 14:24:04 +10:00
Doyle
17ba8d88cf
Resolve pubkeys from state change in dupe check in the tx_pool (#707)
* Resolve public keys from state changes for the TX pool to avoid dupes

* Update copy pasted error message for quorum index OOB

* Code review
2019-07-04 17:25:02 +10:00
Doyle
1b0780b34e
Merge pull request #691 from jagerman/fix-relayable-votes
P2P network fix
2019-07-01 13:14:09 +10:00
Jason Rhinelander
3bc4f1ac13 Extend height tolerance to state_change tx "verifivation" 2019-06-30 23:18:33 -03:00
Jason Rhinelander
c509198c00 Silence unused variable warnings (#692)
These all produce compilation warnings and look perfectly safe to
remove.
2019-07-01 10:10:03 +10: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
2393843ec2
Move miner.h to fix cn basic referencing core and core referencing basic (#679) 2019-06-27 19:15:58 +10:00
Jason Rhinelander
27252701ea Cap difficulty at 30MH/s for first 60 v12 blocks (#677)
We're going to be coming down off a ~300MH/s high, so add a difficulty
cap of 30MH/s for the first 60 blocks so that we don't end with
extremely long blocks.
2019-06-27 17:05:32 +10:00
Doyle
66da3b605f
Merge branch 'dev' into randomx 2019-06-27 17:04:48 +10:00
Doyle
d6c5b5d783
Hefty Heimdall, version tag, add checkpoints, add dates (#668)
* Hefty Heimdall v4.0.0, add checkpoint and hardfork dates

* Add 1 day to testnet, stagenet fork days
2019-06-27 17:00:44 +10:00
Jason Rhinelander
94b5857a84 Merge remote-tracking branch 'LMDB/randomx' into randomx 2019-06-26 21:50:51 -03: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
7f00012c7b Revert "Remove unused txs member in NOTIFY_RESPONSE_GET_OBJECT (#619)"
This reverts commit cc72791b9d.
2019-06-26 13:09:15 +10:00
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
Howard Chu
043894fb62
Proposed tweak for issue with finding seedblock hash
This patch isn't needed if we always restrict block-sync-size to <= SEEDHASH_EPOCH_LAG.
But otherwise, this will allow syncing with larger block-sync-sizes.
2019-06-01 21:42:20 +01:00
Howard Chu
cfe0e9c7c5
RandomX integration
Support RandomX PoW algorithm
2019-06-01 21:40:55 +01:00
moneromooo-monero
aed89cd99f
blockchain: keep alternative blocks in LMDB
Alternative blocks are cleared on startup unless --keep-alt-blocks
is passed on the command line
2019-06-01 21:40:46 +01: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