Commit Graph

426 Commits

Author SHA1 Message Date
Doyle 148531f199 Query state archive when processing state changes 2019-12-03 11:26:30 +11:00
Jason Rhinelander d7a2acf028 Promote SN state change errors to MERROR
These are quite serious: if they occur there's a good chance that the
local SN state data is wrong.  (At default logging they aren't printed
at all, and really should be).

This also fixes and adds more detail in the the "height is not stored"
error.
2019-12-02 18:21:16 -04:00
Jason Rhinelander 20c07f8e8d Promote SN state change errors to MERROR
These are quite serious: if they occur there's a good chance that the
local SN state data is wrong.  (At default logging they aren't printed
at all, and really should be).

This also fixes and adds more detail in the the "height is not stored"
error.
2019-12-02 18:19:39 -04:00
Jason Rhinelander 8090ee3481 Move randomness into new common/random.h
This adds a thread-local, pre-seeded rng at `tools::rng` (to avoid the
multiple places we are creating + seeding such an RNG currently).

This also moves the portable uniform value and generic shuffle code
there as well as neither function is specific to service nodes and this
seems a logical place for them.
2019-11-27 14:07:52 -04:00
Jason Rhinelander d66e6e9e3f Align hashable data structures
We don't impose any alignment on hashable types, but this means the
hashing function is doing invalid misaligned access when converting to a
size_t.  This aligns all of the primitive data types (crypto::hash,
public keys, etc.) to the same alignment as size_t.

That cascades into a few places in epee which only allow byte spanning
types that have byte alignment when what it really requires is just that
the type has no padding.  In C++17 this is exactly the purpose of
std::has_unique_object_representations, but that isn't available (or
even implementable) in C++14 so add specializations for the type that
need it to tell epee that we know those types are properly packed and
that it can safely use them as bytes.

Related to this, monero/epee also misuses `is_standard_layout` when the
purpose is actually `is_trivially_copyable`, so fixed that too.  (You
need the latter but don't need the former for a type to be safely
memcpy'able; the only purpose of `is_standard_layout` is when you need
to be sure your structs are compatible with C structs which is
irrelevant here).
2019-11-27 14:07:52 -04:00
Jason Rhinelander dd7a4104b5 Blink
This is the bulk of the work for blink.  There is two pieces yet to come
which will follow shortly, which are: the p2p communication of blink
transactions (which needs to be fully synchronized, not just shared,
unlike regular mempool txes); and an implementation of fee burning.

Blink approval, multi-quorum signing, cli wallet and node support for
submission denial are all implemented here.

This overhauls and fixes various parts of the SNNetwork interface to fix
some issues (particularly around non-SN communication with SNs, which
wasn't working).

There are also a few sundry FIXME's and TODO's of other minor details
that will follow shortly under cleanup/testing/etc.
2019-11-27 14:07:52 -04:00
Jason Rhinelander 5d28c9cf8d Switch service_node_keys to plain pointer instead of shared_ptr
The owning pointer is stashed in a unique_ptr so that it gets properly
destroyed; everything else gets a plain pointer to it.

(Ideally it would be std::optional instead, but that's not until C++17)
2019-11-27 14:07:52 -04:00
Jason Rhinelander d0573c11b3 Add blink quorums 2019-11-27 14:07:52 -04:00
Jason Rhinelander 8a276b362f Store loki version as std::array<u16,3> everywhere
Currently we store it as various different things: 3 separate ints, 2
u16s, 3 separate u16s, and a vector of u16s.  This unifies all version
values to a `std::array<uint16_t,3>`.

- LOKI_VERSION_{MAJOR,MINOR,PATCH} are now just LOKI_VERSION
- The previous LOKI_VERSION (C-string of the version) is now renamed
  LOKI_VERSION_STR

A related change included here is that the restricted RPC now returns
the major version in the get_info rpc call instead of an empty string
(e.g. "5" instead of "").  There is almost certainly enough difference
in the RPC results to distinguish major versions already so this doesn't
seem like it actually leaks anything significant.
2019-11-27 14:07:52 -04:00
Jason Rhinelander 1b5234e6a6 Rename `testing_quorum` class to just `quorum`
testing_quorum is a bit of a misnomer: it only does testing when used
for an obligations quorum, but it is also used for checkpointing and
soon Blink.
2019-11-27 14:07:52 -04:00
Jason Rhinelander 57e64b7d1c Add quorumnet comms
This adds vote relaying via quorumnet.

- The main glue between existing code and quorumnet code is in
  cryptonote_protocol/quorumnet.{h,cpp}
- Uses function pointers assigned at initialization to call into the
  glue without making cn_core depend on p2p
- Adds ed25519 and quorumnet port to uptime proofs and serialization.
- Added a second uptime proof signature using the ed25519 key to that
  SNs are proving they actually have it (otherwise they could spoof
  someone else's pubkey).
- Adds quorumnet port, defaulting to zmq rpc port + 1.  quorumnet
  listens on the p2p IPv4 address (but broadcasts the `public_ip` to the
  network).
- Derives x25519 when received or deserialized.
- Converted service_info_info::version_t into a scoped enum (with the
  same underlying type).
- Added contribution_t::version_t scoped enum.  It was using
  service_info_info::version for a 0 value which seemed rather wrong.

Random small details:
- Renamed internal `arg_sn_bind_port` for consistency
- Moved default stagenet ports from 38153-38155 to 38056-38058, and add the default stagenet
  quorumnet port at 38059 (this keeps the range contiguous; otherwise the next stagenet default port
  would collide with the testnet p2p port).
2019-11-27 14:07:45 -04:00
Doyle 0b8e21fb18
Aggegrate init service node info instead of setting members individually (#934)
* Aggegrate init service node info instead of setting members individually

* Initialise in header instead of aggregate
2019-11-27 14:40:56 +11:00
Jason Rhinelander 34480c6f23 Merge branch 'pk25519-rpc-interfaces' into lokinet-integration 2019-11-26 21:47:07 -04:00
1point21gigabytes 40946bd92f explicitly specify UTC (#931) 2019-11-25 15:30:12 +11:00
Jason Rhinelander f6bd747d94 Add optional get_n_sns RPC request; remove get_all_sn_pubkeys RPC
This allows a `"if_block_not_equal": "hash"` parameter to be given to
`get_n_service_nodes` which, if the given value matches the current
top block hash, skips building and returning a reply.

This is primarily aimed at lokinet which polls fairly frequenty for an
update but where the vast majority of those polls contain no new
information.

It also removes the get_all_service_nodes_public_keys RPC request
completely as lokinet was the only consumer of it (particularly unlikely
that anyone else was using this because it was returning the keys
base32z-encoded).
2019-11-08 03:01:08 -04:00
Jason Rhinelander a9294cdbef Remove boost::value_initialized and BOOST_FOREACH (#921)
Neither of these have a place in modern C++11; boost::value_initialized
is entirely superseded by `Type var{};` which does value initialization
(or default construction if a default constructor is defined).  More
problematically, each `boost::value_initialized<T>` requires
instantiation of another wrapping templated type which is a pointless
price to pay the compiler in C++11 or newer.

Also removed is the AUTO_VAL_INIT macro (which is just a simple macro
around constructing a boost::value_initialized<T>).

BOOST_FOREACH is a similarly massive pile of code to implement
C++11-style for-each loops. (And bizarrely it *doesn't* appear to fall
back to C++ for-each loops even when under a C++11 compiler!)

This removes both entirely from the codebase.
2019-11-01 09:26:58 +11:00
Doyle e949e15c6e
Remove hard-forking code on the boundary of 12 and 13 (#919) 2019-10-30 14:50:34 +11:00
Doyle 973f9de780
Merge pull request #901 from loki-project/dev
Merge v5.1.2 to master
2019-10-16 14:29:19 +10:00
Doyle 5fd673ae07
Guard against unexpected infinite loop, early out alt state cull (#896)
* Guard against unexpected infinite loop, early out alt state cull

* Remove unused code
2019-10-16 14:02:07 +10:00
Doyle 788603caaa Distinguish pop_blocks from reorg in detach hook 2019-10-16 10:25:04 +11:00
Jason Rhinelander 4b8c62b711 Fix version printing in info message
If major/minor are uint8_t then printing them tries to print characters
rather than numbers.  Changing them to uint16_t seems the easiest fix
(and agrees with the type we use for storing version parts in proofs).
2019-10-09 17:57:55 -03:00
Doyle fbd5c5eb60
Bump minor patch to 1 and enforce uptime proof minor version (#881)
* Bump minor patch to 1 in preparation for release

* Hardfork 13 date for mainnet
2019-10-09 12:54:16 +11:00
Jason Rhinelander 4edb53d317 Fix version_t count assert
Use an alias to simplify a little.
2019-10-08 01:21:22 -03:00
Jason Rhinelander 5f4b611d38 Delay SN info duplication
This required a bit of reworking - without the duplication we only have
a const iterator so can't reuse it later for a non-const iterator, so
store the found contributor by index instead.
2019-10-08 01:21:07 -03:00
Jason Rhinelander c00e8221cc Add SN ed25519/x25519 pubkeys + quorumnet port in proofs
This generates a ed25519 keypair (and from it derives a x25519 keypair)
and broadcasts the ed25519 pubkey in HF13 uptime proofs.

This auxiliary key will be used both inside lokid (starting in HF14) in
places like the upcoming quorumnet code where we need a standard
pub/priv keypair that is usable in external tools (e.g. sodium) without
having to reimplement the incompatible (though still 25519-based) Monero
pubkey format.

This pulls it back into HF13 from the quorumnet code because the
generation code is ready now, and because there may be opportunities to
use this outside of lokid (e.g. in the storage server and in lokinet)
before HF14.  Broadcasting it earlier also allows us to be ready to go
as soon as HF14 hits rather than having to wait for every node to have
sent a post-HF14 block uptime proof.

For a similar reason this adds a placeholder for the quorumnet port in
the uptime proof: currently the value is just set to 0 and ignored, but
allowing it to be passed will allow upgraded loki 6.x nodes to start
sending it to each other without having to wait for the fork height so
that they can start using it immediately when HF14 begins.
2019-10-07 22:09:17 -03:00
Jason Rhinelander 2c52c1c020 Add unified key container
This puts the SN pubkey/privkey into a single struct (which have
ed25519/x25519 keys added to it in the future), which simplifies various
places to just pass the struct rather than storing and passing the
pubkey and privkey separately.
2019-10-07 22:09:17 -03:00
Jason Rhinelander 45d62f1763 Code cleanup & minor reorganization
- Replace a bunch of repetitive proof rejection rules with a macro +
  HF requirement version loop.
- Remove mostly unused MAX_KEY_IMAGES_PER_CONTRIBUTOR variable.  It has
  always been set to 1 (and so doesn't actually do anything).  If we
  wanted to increase it at this point we'd have to add multiple
  HF-guarded versions of it and HF-version guard the code anyway, so
  seems simpler to just drop it.
- Simplify the max contributor/max contribution logic and merge it in
  with the existing contributor code (this is made easier by the above
  dropped variable).
2019-10-07 22:09:17 -03:00
Jason Rhinelander dd6de52378 Add --dev-allow-local-ip flag for allowing local network public-ip
This is very useful for testing.  Also adds a suitable scary warning at
startup when used.
2019-10-07 22:09:17 -03:00
Jason Rhinelander a3ebf5eba6 Reward fudge factor (#867)
* Add a 1 atomic unit fudge factor on reward calculations

If the thread's rounding mode is different (because RandomX changed it
in the current thread or in the thread that generated the block) then
the reward calculation can be up to 1 atomic unit off.  This lets those
pass rather than rejecting the block.

(I tested LOKI's reward calculations up to height 10M to verify that the
maximum error in reward values is never off by more than 1).

* Remove partial_block_reward

This variable is not actually used anywhere.

* Add 1ULP tolerance for SN reward checks

* Rewrite confusing logic and error

- fix the broken error message which was printing "base(base+fees)" instead
  of "total(base+fees)".
- improve the error message wording to actually indicate what the values
  signify.
- don't use base_reward as a temporary value (the intermediate value
  assigned to it is completely replaced later anyway).
- use some better variable names to describe what is happening here

* Add check for overflow
2019-10-04 13:57:14 +10:00
Doyle 127b505558 Make empty quorum if height is checkpointable but insufficient nodes
This is so that we can validly print an error in quorum_cop on the
heights that are actually not being stored in the daemon VS a service
node network that has insufficient nodes to form the quorum.

Update core test to enforce this constraint
2019-09-23 14:42:29 +10:00
Doyle f94328bf37
Switch to using validators for checkpoints (#850)
* Add temporary HF12/13 code to switch to validators for checkpointing

* Don't use target height for verifying vote age

You wouldn't have the quorum calculated to verify the vote in the first place.

* Update core tests to use validators for checkpoints
2019-09-20 15:54:00 +10:00
Doyle bcbaaeef93
Enforce checkpoint quorums min size and soft fork it for testnet (#842)
* Enforce checkpoint quorums min size from HF13 onwards

* Add core_test for checkpoint quorum min size
2019-09-20 12:46:34 +10:00
Doyle c41bfbdfe4 Add +detail to print_sn|print_n_status, display checkpoint and reachability 2019-09-19 17:42:19 +10:00
Doyle a94c1587d1 Remove sychronization check on receipt of uptime
If a peer views the destination peer as not synchronizing, then the
destination peer should just accept the uptime proof, rather than accept
it and then conditionally relay it depending on whether or not you are
synchronizing at the point of attempting to relay (which you could
transition into synchronizing state interim between accepting and
attempting to relay the proof).
2019-09-19 16:58:09 +10:00
Doyle 409cf4faee Relay proofs back to source, but don't relay your proof again
Otherwise we get into a ping-pong situation as follows
Node1 sends uptime ->
Node2 receives uptime and relays it back to Node1 for acknowledgement ->
Node1 receives it, handle_uptime_proof returns true to acknowledge ->
Node1 tries to resend to the same peers again

Instead, if we receive our own uptime proof, then acknowledge but don't
send on. If the we are missing an uptime proof it will have been
submitted automatically by the daemon itself instead of using my own
proof relayed by other nodes.
2019-09-18 15:37:32 +10:00
Doyle aedf023dc9 Add message on receipt of your own uptime proof from network 2019-09-18 15:21:59 +10:00
Doyle cbd22735d7
Add hard fork date for testnet to v13 (#833) 2019-09-13 16:31:58 +10:00
Doyle adc7c9aa02
Don't verify checkpoints until after HF13 (#834) 2019-09-13 13:13:40 +10:00
Doyle 54af5572ea
Don't allow duplicate ip changes for the same height (#831) 2019-09-11 16:14:24 +10:00
Doyle 50228e2a0e Merge branch 'dev' into AlternativeQuorums 2019-09-10 12:31:03 +10:00
Doyle 39987729ab
Update soft-forking checks to be effective HF13 (#825)
Code review

m_oldest_allowable_alternative_block -> m_immutable_height
2019-09-10 10:04:44 +10:00
Doyle 0b92e9ba89 Code review 2019-09-09 11:14:19 +10:00
Doyle 8cf7e0f5ca Add migration code for service node state format updates
Also gate some troublesome slow changes that slow down pre-hf12 changes
2019-09-06 14:41:55 +10:00
Doyle d2b619ea9a Revamp core_tests linear_chain_generator to support state_t
Remove using crypto, using cryptonote, using epee in chaingen

Add loki prefix to data structures, cleanup warts

Remove the need for get_static_keys(), remove useless functions and
attempt to remove some pointless function overloading that puts too many
levels of indirection and makes it harder to follow code execution.

Rehaul tests further, persist test generator when replaying through core

The class used to generate the testing events to replay through core is
now preserved. This subtle change simplifies a big chunk of core testing
in that we can remove the need for using callbacks to track events in
the events vector.

Add preliminary checkpoint/alt service node tests

Allow inlining of fail cases for test conditions

Add more checkpoint core tests

add_block in generator is parameterised with checkpoints

Add test to check chain with equal checkpoints

Add test for chain reorging when recieving enough votes for checkpoint
2019-09-06 14:41:55 +10:00
Doyle 35c84359d4 Handle quorums needing to be stored in the previous state_t 2019-09-06 14:41:55 +10:00
Doyle 62c0da64e3 Remove Blockchain dependency in service_node_list::state_t 2019-09-06 14:41:55 +10:00
Doyle b4efc82e6b Remove using select_winner twice in block reward check
Also promote the std::pair of <address, portions> to a struct for
readability.

Readjust block_winner to ensure test case passes
2019-09-06 14:41:55 +10:00
Doyle 4724a7436f Incorporate checkpoint validation into syncing step
Fix checkpoint verification check and add messages
2019-09-06 14:41:55 +10:00
Doyle 15ff209db0 Add alt block added hook
Move service node list methods to state_t methods

Add querying state from alt blocks and put key image parsing into function

Incorporate hash into state_t to find alt states

Add a way to query alternate testing quorums

Rebase cleanup
2019-09-06 14:41:55 +10:00
Maxim Shishmarev b91e690a62 Add storage server reachability field; test it with quorums (#820)
* Add storage server reachability field; test it with quorums

* Improve method names

* Address review comments
2019-09-02 13:06:15 +10:00
Doyle add6051a8f
make get_checkpoints_range faster by using lmdb cursor as iterator (#819)
* make get_checkpoints_range faster by using lmdb cursor as iterator

* Update clamp to be more compliant with convention
2019-08-30 13:54:49 +10:00
Doyle 9fe3097e4d
Separate long term service node state into archive from recent history set (#815) 2019-08-27 13:28:46 +10:00
Maxim Shishmarev 14881db565 Fix decommissioned snodes not leaving swarms (#812) 2019-08-22 13:14:25 +10:00
Doyle 35fa83a4dc
Merge pull request #803 from Doy-lee/ServiceNodeWinnerIncorrectFix
Service node winner incorrect fix
2019-08-17 15:07:03 +10:00
doyle 1905836c3a Code review
only_serialize_quorums should set only_store_quorums flag

Simplify detach logic since we don't need constants anymore

Move state storage comment to ::store

Fix off by one in detach on recent states
2019-08-17 14:59:45 +10:00
Doyle 83f69a791c Serialize long term storage separate from short term 2019-08-17 14:55:42 +10:00
Doyle f009d31b90 Don't version code because adding only_loaded_quorums breaks compat 2019-08-17 14:55:42 +10:00
Doyle 7ab6b16c6b Fix service node winner incorrect error
If we are re-deriving states we still also need the historical quorums
such that we can process incoming blocks with state changes. Without it,
state changes will be ignored and skipped causing inconsistent state in
the service node list.

This mandates a rescan and stores the most recent in state_ts, and only
just quorums for states preceeding 10k intervals. We can no longer store
the 1st most recent state in the DB as that will be missing quorums as
well for similar reason when rederiving on start-up.
2019-08-17 14:55:42 +10:00
Jason Rhinelander 24f26bd184 Fix 4.0.4 uptime proof transmission after recomm
When a node gets recommissioned in 4.0.4 we reset its timestamp to the
current time to delay obligations checks for newly recommissioned nodes,
but this reset caused problems:

- the code runs not only when a fresh block is received, but also when
  syncing or rescanning, and so time(NULL) gets used to update the
  node's timestamp even if it is an old record, and since proof info is
  shared across states, the affects the current state.

- as a result of the above, a just-rescanned node that has been
  decommissioned at some point in the past will think it has just sent a
  proof, and so won't send any proofs for an hour.

- A just-rescanned node won't accept or relay any proofs for any node
  that was recommissioned in its scan for the first half an hour, but this
  lack of relaying can cause chaos in getting uptime proofs out across the
  network, especially while we still have 4.0.3 nodes that need it.

To address the first issue, this switches the recommissioning to use the
block timestamp rather than the current timestamp.  This *will* be
slightly delayed in the case of current blocks (since a block timestamp
is the time the pool *started* working on the block, which is generally
the time the previous block was found on the network), but even with an
exceptionally long block delay (e.g. 20 minutes) we are still fending
off obligations checks for 1h40m.

That would partially fix issues 2 and 3, but we actually don't want a
recommissioning to look like a received uptime proof for a couple
reasons:

- When we haven't actually received an uptime proof it's confusing to
  report that we have (at the recommission time) and may mask an
  underlying issue of a node that isn't actually sending proofs for some
  reason (which might be more common for a node that has just been
  decommissioned/recommissioned).  There's also a related weird state
  here for nodes that have come on recently: they think the SN is
  active, but have 0's for IP and storage server port.

- 4.0.3 nodes don't get the updated timestamp and so really need the
  proof to come through even when the 4.0.4 nodes don't think it's
  important/acceptable.

So to also fix these, this commits adds an "effective_timestamp" to the
proof info: if it is larger than the actual timestamp field, we use it
instead of the actual one for obligations checking.  On a recommission,
we update only the effective field so that we can delay obligations
checking for a couple of hours without delaying actual proofs info going
over the network.
2019-08-16 15:04:49 -03:00
Doyle 5f1c18ab34 Remove rollback code and old serialization method, mandate rescan 2019-08-16 15:34:27 +10:00
Doyle 8fdf2a7819 Fix service node winner incorrect error
If we are re-deriving states we still also need the historical quorums
such that we can process incoming blocks with state changes. Without it,
state changes will be ignored and skipped causing inconsistent state in
the service node list.

This mandates a rescan and stores the most recent in state_ts, and only
just quorums for states preceeding 10k intervals. We can no longer store
the 1st most recent state in the DB as that will be missing quorums as
well for similar reason when rederiving on start-up.
2019-08-16 15:30:36 +10:00
Jason Rhinelander 0cea0970e9 Print good/bad winners in incorrect winner error 2019-08-15 20:29:35 -03:00
Doyle 9ab22f7404
Assert should be after info.is_active() is true (#799) 2019-08-15 16:03:32 +10:00
Doyle 84993544e1 Regression core tests, missing txs on fork, segfault on detach
We can't delete all state change TX's on blockchain increment incase the
state change came from an alternative block. We must keep them around
even if they would conflict with another state change because if we
switch chains, they need to be present for the block to still be
considered valid.

Add a .size() check when checking for is_migrated_from_v403 because when
reinitialise is true, m_state_history does not necessarily have any
elements (in tests atleast).
2019-08-13 13:31:14 +10:00
Jason Rhinelander 7bc764588b Fix storage states over-reserved size 2019-08-13 00:05:21 -03:00
Jason Rhinelander 59a2175f47 Use shared_ptr storage for service_node_info
This converts the stored service_node_info value into a
`shared_ptr<const service_node_info>` rather than a plain
`service_node_info`.  This yields a huge performance benefit by
significantly eliminating the vast majority of service_node_info
construction, destruction, and copying.

Most of the time when we copy a service_node_info nothing in it has
changed, which means we're storing exactly the same thing; this means an
extra construction for every SN info on every block *and* an extra
destruction when we cull old stored history.  By using a
shared_ptr, the vast majority of those constructions and destructions
are eliminated.

The immediately previous commit (upon which this one builds) already
reduced a full rescan from 180s to 171s; this commit further reduces
that time to 104s, or about 42% reduced from the rescan time required
before this pair of commits.  (All timings are from the dev.lokinet.org
box, tested over multiple runs with the entire lmdb cached in memory).

With the shared_ptr approach, we only make a copy when a change is
actually needed: because of infrequent (at the per-SN level) events like
a state_change, received reward, contribution, etc.  The contained
reference is deliberately `const` so that values are not changeable;
there's a new function that does an explicit copying duplication,
returning the new non-const and storing the const ref in the shared
pointer.

Related to this is a small change (and fix) to how proof info and
public_ip/storage_port are stored: rather than store the values in the
service_node_info struct itself, they now gets stored in a shared_ptr
inside the service_node_info that intentionally gets shared among all
copies of the service_node_info (that is, a SN info copy deliberately
copies the pointer rather than the values).  This also moves the ip/port
values into the proof struct, since that seemed much easier than
maintaining a separate shared_ptr for each value.

Previously, because these were stored as values in the service_node_info
they would actually get rolled back in the event of a reorg, but that
seems highly undesirable: you would end up rolling back to the old
values of the uptime proof and ip address (for example), but that should
not happen: those values are not dependent on the blockchain and so
should not be affected by a reorg/rollback.  With this change they
aren't since there is only one actual proof stored.

Note that the shared storage here only applies to in-memory states;
states loaded from the db will still be duplicated.
2019-08-11 22:35:00 -03:00
Jason Rhinelander d4635e5344 Optimizations and simplifications
This commit makes various simplifications and optimizations, mainly in
the service node list code.

All in all, this shaves about 5% of the CPU time used for re-processing
the entire service node list.

In particular:

- changed m_state_history from a std::vector to a std::set that sorts on
  height.  This is responsible for the bulk of the CPU reduction by
  significant reducing the amount of work required for checkpoint
  culling, which has to shuffle a lot of `state_t`s around when removing
  from the midde of a vector.

- the above also allows replacing the binary-search `std::lower_bound`
  complexity with a much simpler `find()`.

- since the history is now always sorted, removed the error messages
  related to sorting that either can't happen (on store) or don't matter
  (on load).

- Added some converting constructors to simplify code (for example, a
  `state_t` can now be very usefully constructed from an r-value
  `state_serialized`).

- Many construct + moves (and a couple construct + copy) were replaced
  with in-place constructions.

- removed some unused variables
2019-08-11 22:35:00 -03:00
Doyle 74ee386f6c
Make 4.0.4 service node blob backwards compatible (#786)
Ordinarily on shut down we would discard the quorum states that are
converted and serialised once on initial start up with the new software.
If this is lost, we would not be able to process incoming votes or any
state changes and essentially halt without forcing a way to rescan the
service node list back to a consistent state.
2019-08-12 09:53:05 +10:00
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 fcbe578067
Remove boundary HF12 uptime proof code (#785) 2019-08-09 12:52:39 +10:00
Doyle 17a0b7c381
Only store service node list every 10k AND Height-N blocks (#761)
* Store the oldest state in the MAX_SHORT_TERM_STATE_HISTORY window

Rederive the rest on startup, this way we only need to store states for
10k intervals + 1 state every block temporarily removing the overhead of
having to serialise 30+(every 10k interval) states every block which was
taking upto 15ms~ per block on mainnet.

* Store quorums into the state class

This is setup work to allow only storing one service node list state and
rederiving the rest of the state at runtime in memory without having to
waste space storing the extra 360 quorums every block which is the
biggest bottleneck with syncing the blockchain adding around ~15ms per
block after Service Nodes are activated.

* Derive quorums using correct state, record duration of scan

* Don't fail load if quorums empty, save progress on rescan

Storing quorums in quorum states is now optional because quorums are
stored with the state objects. Quorums are only stored in the dedicated
data structure if you requested to store quorum history so for most
users this will be empty.

* Store state upto quorum lifetime to match previous behaviour

* Make store every 10k states more robust

* Corectly use lower bound to find quorum

* Code review
2019-08-02 11:07:37 +10:00
Doyle 1155232048
Demote error message for missing quorum in handling non-standard txes (#769) 2019-07-31 12:22:07 +10:00
Doyle ead8997e21
Don't query the blockchain for hardfork which causes major slowdown (#764) 2019-07-27 00:55:39 +10:00
Doyle 05a7b97db1
Fix off by 1 when checking state_t heights causing sync failure (#759) 2019-07-25 14:35:36 +10:00
Doyle 234d2eeb16 Guard against invalid serialisation and change deque to vector 2019-07-22 15:16:29 +10:00
Doyle 4a30aecf36 Fix pop-blocks edge case before the first 10k interval 2019-07-22 14:21:35 +10:00
Doyle 7f9b5837ac ~5ms per block speed up, make serialised struct static
Avoid constant reallocation.
2019-07-22 12:36:14 +10:00
Doyle 707f43fe58 Store historical states for every 10k blocks and better detach 2019-07-22 12:36:12 +10:00
Doyle e7f44e4554 Increase the age of service node rollbacks we keep
Increase the range to mitigate frequent rescanning when reorganising,
technically with checkpointing we only need up to the 2nd oldest
checkpoint, but I'm sure there's some case we're forgetting that would
benefit from a larger rollback range.

Also considering there were only 160 events in the month with a mass
deregistration- keeping 2 days worth of rollbacks around is not going to
be too expensive.

Start storing service node list state for past blocks

Separate quorums and reduce storage to 1 days worth

Don't use pointer, declare m_state by value

Fix rebase to dev

Fix double serialise of service node state and expensive blob copy

std::move quorums into storage, reserve vector size

Don't +1 checkpoint finality height

Code review

Code review 2
2019-07-22 12:35:47 +10:00
Jason Rhinelander ae1adf38b2 Fix rebase mistake from #702 (#751) 2019-07-18 10:12:25 +10:00
Jason Rhinelander 5b819ba558 (Low priority) Add disabled-by-default quorum storage support (#702)
* Add disabled-by-default quorum storage support

This adds support for storing N blocks of recent expired quorum state
history in lokid (and dumping to/from the lmdb).

This isn't useful for regular nodes (and that's why we don't store it)
but is incredibly useful for the block explorer to be able to report
*which* node got deregistered/decommissioned/etc. by a given
state_change tx.

* Fix quorum states copy
2019-07-17 16:01:54 +10:00
Jason Rhinelander 0bac540cdf Push buffer subtraction into get_testing_quorum
As recent bugs have demonstrated, requiring the caller to have offset
the quorum by 11 is highly error prone.  This commit moves the offset
into `get_testing_quorum` itself so that any caller asking for the
quorum for vote height 12345 just asks for it rather than having to
remember to subtract 11 to get at the correct generating block.
2019-07-12 23:24:53 -03:00
Doyle 30fc4612b9 Move the refill of votes to recommission because we still update vote counts during decommission 2019-07-12 15:00:57 +10:00
Jason Rhinelander 22970cd51e Skip non-interval height checkpoints when loading
Because of how the serialization code works, these gets stored as
quorums with empty members, but we don't want them at all so just skip
loading them when the height says it should be empty.
2019-07-11 20:51:00 -03:00
Jason Rhinelander 846e2e03d6 Only create checkpoint quorum for heights divisible by CHECKPOINT_INTERVAL
This was causing mass checkpoint deregistrations for missed votes
because 3/4 of the checkpointing "quorums" being identified were not
(and not supposed to be) voted on.
2019-07-11 18:27:32 -03:00
Doyle fd0b2bb3db
Merge pull request #712 from Doy-lee/CheckpointingFixes
Switch to a circular buffer for recording checkpointing votes
2019-07-11 16:07:58 +10:00
Doyle 09ce929a91 Reset uptime to 0 on decommission, so node must submit uptime to recommission 2019-07-11 14:21:59 +10:00
Doyle 3571d9e524 Update softfork date for testnet quorum change 2019-07-11 14:21:59 +10:00
Doyle bdf8829f6b Switch to a circular buffer for recording checkpointing votes 2019-07-11 14:21:59 +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 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
Jason Rhinelander c64121f224 Fix segfault on exit with bad SN args (#690)
service_node_list::store() was called on destruction, but destruction
can happen before it is set up with the database pointer (hence the
segfault).  Fix it to just silently return if not set up yet.
2019-06-29 14:25:52 +10:00
Doyle e6b5ef558a
Service node checkpointing deregistration (#672)
* Add deregistration of checkpoints by checking how many votes are missed

Move uptime proofs and add checkpoint counts in the service_node_list
because we typically prune uptime proofs by time, but it seems we want
to switch to a model where we persist proof data until the node expires
otherwise currently we would prune uptime entries and potentially our
checkpoint vote counts which would cause premature deregistration as the
expected vote counts start mismatching with the number of received
votes.

* Revise deregistration

* Fix test breakages

* uint16_t for port, remove debug false, min votes to 2 in integration mode

* Fix integration build
2019-06-27 17:05:44 +10:00
Jason Rhinelander 91def132f1 Replace growable vector with fixed-size array
We don't really need to know the IP history; it's sufficient just to
know that there were at least two different recent IPs, so just store
two.
2019-06-26 23:25:52 -03:00
Jason Rhinelander 6130c1b976 Add penalty for switching IPs
This adds a new obligations quorum vote "ip_change_penalty" that gets
triggered if the quorum has received multiple IPs advertised in uptime
proofs from a service node in the past 24 hours.  Upon reception of such
a transaction the SN gets bumped to the bottom of the reward list.
2019-06-26 01:24:59 -03:00
Jason Rhinelander 661bfe3f1b Fix recommissioning not reinserting SN at the back of the reward list 2019-06-26 01:14:52 -03:00
Jason Rhinelander 3489ae1e72 Replace is_fully_funded() calls with is_active()
The vast majority of the time `is_active()` is what we actually want.
Most of these are just a name change, but there is also one important
fix here to the next-winner list which needs to use active, not
fully-funded.
2019-06-26 01:14:52 -03: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
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
Maxim Shishmarev 0c23035562 Incorporate service node ip address into uptime proofs (#622)
* Incorporate service node ip address into uptime proofs; expose them using rpc

* Check that storage server port is specified in service-node mode

* Remove problematic const, rename argument name for storage port, update comments

* Validate ip address when receive uptime proof

* Better argument names and descriptions
2019-06-04 14:15:16 +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
Doyle 47e5ab779c Merge branch 'master' into BackportVersion3Patch6ToDev 2019-05-27 10:16:13 +10:00
Doyle 62a5d7abe5 Merge branch 'master' into dev 2019-05-27 10:05:14 +10:00
Doyle 170e841a12
Merge pull request #590 from Doy-lee/LokiMergeUpstream
Loki Merge Upstream 2019-05-07 2bf855e
2019-05-16 13:15:49 -04:00
Maxim Shishmarev 55c14bc672 sort sn list before applying updates; only assign swarms to fully funded snodes (#605) 2019-05-14 10:14:28 -04:00
Jason Rhinelander 27bc2aa11d Add more status messages when rescanning SNs (#603) 2019-05-12 10:07:52 +10:00
Doyle cbfb285630
Add key_image_unlock rollback event (#594)
* Add key_image_unlock rollback event

* Update printed text for failure to rollback image unlock
2019-05-09 18:25:45 +10:00
Doyle f19e937a05 Merge commit '46c477a' into LokiMergeUpstream 2019-05-01 17:32:57 +10:00
Doyle cc0d51078c Merge dev into upstream 2019-05-01 16:01:17 +10:00
Doyle 2715050afe Merge branch 'master' into dev 2019-04-26 13:56:40 +10:00
Doyle 0d4f2361ee
Ensure clear() also clears out the key image blacklist (#573) 2019-04-26 13:19:08 +10:00
Doyle 6024539e13
Allow storing multiple quorum types (#562) 2019-04-23 10:53:17 +10:00
Doyle 8d7d90c374 Merge commit 'ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77' into LokiMergeUpstream 2019-04-11 15:08:26 +10:00
sachaaaaa 18208cf138 Bufferless swarm assignment logic (#518)
* unit tests and core tests for new queueless swarm assignment logic

* new bufferless swarm assignment logic

* new lines

* Address reviews

* Improve node stealing logic

* unit tests for additional functions

* get_excess_pool to return early if the threshold is lower than MIN_SWARM_SIZE

* Address reviews

* another round of reviews

* Move new_swarm_vector inside loop

* Rebase changes: moved get_new_swarm_id to service_node_swarm.cpp

* reserve vector size for all_ids in get_new_swarm_id
2019-04-08 12:03:47 +10:00
Doyle f154d309e6
Merge pull request #535 from loki-project/master
Backport 3.0.3 + 3.0.4 changes to dev
2019-04-03 15:36:28 +11:00
Maxim Shishmarev cbd57e0f95 new algorithm for generating ids for new swarms (#546)
* new algorithm for generating ids for new swarms

* fixed typo

* simplify algorithm
2019-04-03 12:40:58 +11:00
sachaaaaa 2109f3bd46 Remove nested shadowed variables (#542) 2019-04-01 15:03:56 +11:00
Doyle 33d17607c0
Account for delayed portions subtraction in converted registration args (#531) 2019-03-28 19:22:16 +11:00
Doyle 1b07d10493
Prepare registration dust failure minimal fix (#523)
* Add the minimal fix for prepare registration failing by dust amounts

* Add dust redistribution at final step

* Comment and clean up useless lines

* Add fudge factor for dust amounts

* Avoid possible overflow with portions if contributor 1 is insufficient
2019-03-28 18:18:23 +11:00
Doyle 75c521dd31
Merge pull request #516 from loki-project/master
Backport forced rescan on v3 change to dev
2019-03-21 16:32:13 +11:00
Doyle af66c7a847
Merge pull request #513 from Doy-lee/ForceRefresh
Force a rescan of the list
2019-03-21 13:47:41 +11:00
Doyle 57e6fe09f9 Force a rescan of the list 2019-03-21 13:46:32 +11:00
Doyle 24ac69fe36
Merge pull request #512 from loki-project/master
Backport master changes to dev
2019-03-21 12:55:40 +11:00
Doyle 9f232a159b Incorporate HF version into staking requirement algo change 2019-03-21 11:05:32 +11:00
Doyle 40c08391e1
Remove old line referring to autostake (not relevant) (#505) 2019-03-20 10:18:30 +10:00
Maxim Shishmarev aaa338838e core tests: update priority for service nodes selected as winners (#506) 2019-03-19 17:29:27 +10:00
Maxim Shishmarev 4be45d29cf Fix SN expirations and deregistrations in core tests (#493) 2019-03-18 09:48:50 +10:00
Doyle 29a793f9c0
Implement the relaxed contribution rules on the back end (#481)
* Implement the relaxed contribution rules on the back end

* Code review adjustments
2019-03-13 05:35:02 +00:00
Doyle 9ddba6de5f
Demote error messages not relevant to user to level 1 (#484) 2019-03-13 05:34:46 +00:00
Doyle bc47ecf05b Update version naming for infinite staking 2019-02-25 18:05:20 +11:00
Doyle 43436b081d
Infinite Staking Part 2 (#406)
* Cleanup and undoing some protocol breakages

* Simplify expiration of nodes

* Request unlock schedules entire node for expiration

* Fix off by one in expiring nodes

* Undo expiring code for pre v10 nodes

* Fix RPC returning register as unlock height and not checking 0

* Rename key image unlock height const

* Undo testnet hardfork debug changes

* Remove is_type for get_type, fix missing var rename

* Move serialisable data into public namespace

* Serialise tx types properly

* Fix typo in no service node known msg

* Code review

* Fix == to >= on serialising tx type

* Code review 2

* Fix tests and key image unlock

* Add command to print locked key images

* Update ui to display lock stakes, query in print cmd blacklist

* Modify print stakes to be less slow

* Remove autostaking code

* Refactor staking into sweep functions

It appears staking was derived off stake_main written separately at
implementation at the beginning. This merges them back into a common
code path, after removing autostake there's only some minor differences.

It also makes sure that any changes to sweeping upstream are going to be
considered in the staking process which we want.

* Display unlock height for stakes

* Begin creating output blacklist

* Make blacklist output a migration step

* Implement get_output_blacklist for lmdb

* In wallet output selection ignore blacklisted outputs

* Apply blacklisted outputs to output selection

* Fix broken tests, switch key image unlock

* Fix broken unit_tests

* Begin change to limit locked key images to 4 globally

* Revamp prepare registration for new min contribution rules

* Fix up old back case in prepare registration

* Remove debug code

* Cleanup debug code and some unecessary changes

* Fix migration step on mainnet db

* Fix blacklist outputs for pre-existing DB's

* Remove irrelevant note

* Tweak scanning addresses for locked stakes

Since we only now allow contributions from the primary address we can
skip checking all subaddress + lookahead to speed up wallet scanning

* Define macro for SCNu64 for Mingw

* Fix failure on empty DB

* Add missing error msg, remove contributor from stake

* Improve staking messages

* Flush prompt to always display

* Return the msg from stake failure and fix stake parsing error

* Tweak fork rules for smaller bulletproofs

* Tweak pooled nodes minimum amounts

* Fix crash on exit, there's no need to store on destructor

Since all information about service nodes is derived from the blockchain
and we store state every time we receive a block, storing in the
destructor is redundant as there is no new information to store.

* Make prompt be consistent with CLI

* Check max number of key images from per user to node

* Implement error message on get_output_blacklist failure

* Remove resolved TODO's/comments

* Handle infinite staking in print_sn

* Atoi->strtol, fix prepare_registration, virtual override, stale msgs
2019-02-14 12:12:57 +11:00
Doyle 1ad7658c77
Developer build target and minor static analysis (#409)
* Faster build target for development, some static analysis fixes

* Avoid linking wallet_rpc_server in dev build
2019-02-07 12:14:00 +11:00
doy-lee 0f560e0d62 Merge branch 'dev' into LokiMergeUpstream 2019-01-30 17:15:31 +11:00
doy-lee bebecbd0a6 Merge branch 'dev' into LokiMergeUpstream 2019-01-30 16:59:47 +11:00
doy-lee 590e4594fb Fix bulletproof broken tests 2019-01-30 14:44:00 +11:00
Doyle 8ae8d9804a
Fix assert compiled out in debug causing werror unused var (#405) 2019-01-29 11:34:33 +11:00
Doyle 3a7b6b59eb
Infinite Staking Part 1 (#387)
* Remove dead branches in hot-path check_tx_inputs

Also renames #define for mixins to better match naming convention

* Shuffle around some more code into common branches

* Fix min/max tx version rules, since there 1 tx v2 on v9 fork

* First draft infinite staking implementation

* Actually generate the right key image and expire appropriately

* Add framework to lock key images after expiry

* Return locked key images for nodes, add request unlock option

* Introduce transaction types for key image unlock

* Update validation steps to accept tx types, key_image_unlock

* Add mapping for lockable key images to amounts

* Change inconsistent naming scheme of contributors

* Create key image unlock transaction type and process it

* Update tx params to allow v4 types and as a result construct_tx*

* Fix some serialisation issues not sending all the information

* Fix dupe tx extra tag causing incorrect deserialisation

* Add warning comments

* Fix key image unlocks parsing error

* Simplify key image proof checks

* Fix rebase errors

* Correctly calculate the key image unlock times

* Blacklist key image on deregistration

* Serialise key image blacklist

* Rollback blacklisted key images

* Fix expiry logic error

* Disallow requesting stake unlock if already unlocked client side

* Add double spend checks for key image unlocks

* Rename get_staking_requirement_lock_blocks

To staking_initial_num_lock_blocks

* Begin modifying output selection to not use locked outputs

* Modify output selection to avoid locked/blacklisted key images

* Cleanup and undoing some protocol breakages

* Simplify expiration of nodes

* Request unlock schedules entire node for expiration

* Fix off by one in expiring nodes

* Undo expiring code for pre v10 nodes

* Fix RPC returning register as unlock height and not checking 0

* Rename key image unlock height const

* Undo testnet hardfork debug changes

* Remove is_type for get_type, fix missing var rename

* Move serialisable data into public namespace

* Serialise tx types properly

* Fix typo in no service node known msg

* Code review

* Fix == to >= on serialising tx type

* Code review 2

* Fix tests and key image unlock

* Add additional test, fix assert

* Remove debug code in wallet

* Fix merge dev problem
2019-01-25 14:15:52 +11:00
Doyle 101f1799eb
All Service Node Keys as Base32z RPC Call (#404)
* create get_service_node_list rpc call

currently does nothing, just a shell (that compiles)

* implement get_all_service_node_keys rpc call

* change get_all_service_node_keys rpc to use json rpc

also change the result to be vector of hex strings rather than binary keys

* Make nodes be plural, add hex to base32z for keys

Base32z for Lokinet internal usage

* Add option to return fully funded service nodes only

* Add nullptr check for conversion

* Add assert for incorrect usage of to base32z
2019-01-25 10:50:42 +11:00
Maxim Shishmarev 715f3d3698 allow less than 25% staking with large existing contributions (#339)
* allow less than 25% staking with large existing contributions

* remove readline depencency in wallet2
2019-01-22 10:44:30 +11:00
doy-lee cbd8193ba2 Fix destruction of service node list locking destroyed mutex 2019-01-18 16:16:23 +11:00
Maxim Shishmarev f9a1883ce2 Allow rpc call to get registration command to use human readable input (#343)
* Allow `prepare_registration` to work on command-line

This allows you to use `lokid prepare_registration` to generate a
registration command via RPC commands to the lokid, which is
particularly useful when the lokid is running non-interactively as a
system service.

Without this it is necessary to stop the lokid service, start it
manually, run the prepare_registration, then stop lokid and restart it
via the system service.

This also rewrites the description of the prepare_registration command to
remove the reference to saving to disk.

* make getting registration command more user-friendly via rpc

* better error message for get registration command rpc

* move get_service_node_registration_cmd into prepare_registration

* show error message on unsuccessful registration in simplewallet as well
2019-01-11 13:28:21 +11:00
doy-lee 7464673c64 Merge branch 'dev' into LokiMergeUpstream 2019-01-07 11:56:23 +11:00
Doyle baa100a345
Remove loki namespace and merge into service_nodes (#334) 2018-12-21 11:33:05 +11:00
doy-lee df347f23e0 Merge branch 'dev' into LokiMergeUpstream 2018-12-19 10:53:35 +11:00
Maxim Shishmarev 303ac6cdcb Add an rpc call for getting batched quorum states (#345)
* add rpc call for getting batched quorum states

* add rpc call to get all service nodes
2018-12-18 17:50:49 +11:00
doy-lee 5a4ca2c4b2 Replace gmtime calls with epee::misc_utils::get_gmt_time 2018-12-11 17:42:06 +11:00
doy-lee 40506127a4 Merge commit '7e957c1' into LokiMergeUpstream 2018-12-11 13:46:35 +11:00
Maxim Shishmarev d22055bfcd Implementation of swarms using a queue/buffer (#299)
* Added implementation of swarms using a buffer

* fixed bug in get_new_swarm_id

* use correct hf version

* removed comments
2018-11-16 10:32:56 +11:00
Maxim Shishmarev fdaa45a53a Add API for staking from GUI wallet (#315)
* Enable staking in GUI wallet

* Move more helper functions into service_node_rules.h

* Move validation of arguments for staking into wallet2

* call stake validation from within create_stake_tx
2018-11-15 13:22:14 +11:00
Doyle fad67eee46
Rotating Governance Schedule (#303)
* Add multiple governance keys

* Batch governance payments to every interval blocks

* Batching of gov rewards and fix breakages in tests

* Add changes to api for working with core tests

* Clean up left over debug stuff

* more cleanup

* Fix uninitialised batched governance value

* Remove dependency on blockchain in tx utils

* Remove redundant vector reserve
2018-11-12 14:02:21 +11:00
Doyle cd04e1efa3
Merge pull request #287 from Doy-lee/LokiMergeUpstreamUntil_20181010_77e1ebf
Loki merge upstream until 2018-10-10 #77e1ebf
2018-10-19 14:28:51 +11:00
Doyle ff8d3796fc
Make service node scan from hardfork 9 (#251)
* Make scanning code more robust and compliant with core_tests

* Fix incorrect call to get_hard_fork_version

* On clear, start height from hardfork 9 height.
2018-10-17 11:07:04 +11:00
Doyle 8a5480a2f5
Service Nodes Reregistration Grace Period (#290)
* Allow a grace period to re-register service nodes

* Guard feature behind hardfork 10

* Const iterator, guard rpc height result by hard fork 10
2018-10-16 10:32:35 +11:00
Maxim Shishmarev 87cfb05f55 use a recursive_mutex from boost in service node list (#289) 2018-10-15 12:22:46 +11:00
doy-lee b9fabc269f Merge branch 'dev' into LokiMergeUpstreamUntil_20181010_77e1ebf 2018-10-11 13:21:23 +11:00
Maxim Shishmarev 207c1fa89a Making service nodes list and quorum cop thread-safe (#285)
* Remove dependency on service node list in quorum cop

* making service node list therad-safe

* improve thread-safety of quorum cop
2018-10-10 16:24:01 +11:00
doy-lee 5805b72778 Merge commit '2a8fcb421bc41eb254f95379dd73238915dd509d' into LokiMergeUpstreamUntil_20180911_e6d36c1
Begin fixing broken bulletproof tests in Loki
2018-10-08 13:34:36 +11:00
doy-lee 4caffeff78 Merge branch 'dev' into LokiMergeUpstreamUntil_20180905_fad88e1 2018-10-01 16:48:40 +10:00
Doyle 2022767837
Disallow insufficient stake if you're not a pre-existing contributor (#274) 2018-09-29 19:37:04 +10:00
Doyle a71b7640d2
Service Nodes Improve Reliability & Feedback (#262)
* If unable to receive own uptime proof, switch to more granular pinging

* Uptime proof simpler solution to repeatedly ping on failure
2018-09-27 18:31:08 +10:00
doy-lee fea865537c Merge branch 'dev' into LokiMergeUpstream20180821 2018-09-19 13:29:43 +10:00
doy-lee 3a46efb488 Set m_height to 0, revert didn't revert this. 2018-09-19 13:24:37 +10:00
doy-lee 13d524ee02 Merge branch 'dev' into LokiMergeUpstream20180821 2018-09-19 13:23:56 +10:00
Doyle 2dc9f687ea
Backport master changes to dev (#248)
* updated checkpoints to remove early hardfork chainsplit

* Service Nodes Safe Guard (#246)

* Enforce stake and registration to always be atleast v3

* Scan from hardfork 9 height

* Remove get quorum state URI endpoint, use json rpc only (#199)
2018-09-18 12:14:11 +10:00
Maxim Shishmarev d8944cb5ca core_tests: more tests and some refactoring (#205)
* core_tests: test that deregister tx make it into full blocks

* correct derivation of the service nodes winner in core tests

* core_tests: check deregistrations with non-zero fee declined

* core_tests: linear chain generator refactoring

* core_tests: test deregister safety buffer

* fix build error with const elements

* remote unnecessary const from return type
2018-09-14 14:35:29 +10:00
doy-lee ca464be3bd Merge commit 'ed2c81e' into LokiMergeUpstream20180821 2018-09-13 18:42:49 +10:00
moneromooo-monero 8d769392d9 replace std::list with std::vector on some hot paths
also use reserve where appropriate
2018-09-13 18:31:35 +10:00
Maxim Shishmarev d934e5b4d5 unit tests: check portion amount validation (#214)
* unit tests: check portion amount validation

* unit tests: test service nodes rewards proportionate to contributions
2018-09-13 11:49:30 +10:00
Doyle 25292b3e86 Version 0.4.0 Release Candidate (#216)
* core: submit uptime proof immediately after registering

* Increase visibility of autostaking prompts

* quorum_cop: changed uptime proof prune timeout to 2 hours 10 minutes

* cleanup: removed scope limiting block

* check_tx_inputs: fix deregister double spend test to include deregisters from other heights

* config: new testnet network id, genesis tx, and version bump

* wallet2: fix testnet wallet blockheight approximation

* Fix change in address format in RPC which broke parsing and pooling contributors (#184)

* Fix service node endpoints for RPC to also use stdout (#185)

* fixed some further rct core tests (#180)

* Fix service node state by calling detached hooks on failure to switch to alt chain (#188)

* fixed block verification core tests (#186)

* fixed block verification core tests

* core tests: removed gen_block_miner_tx_out_is_small which is only relevant to hardfork version 1

*  Don't consider expired deregistrations when filling block template

* Add unit tests for getting staking requirement (#191)

* First service node test (#190)

* core_tests: added service node tests

* core_tests: check balance after registration tx

* Fix underflow for popping rollback events (#189)

* Move deregistration age check into check_tx_inputs

* Zero initialise rct_signatures member txnFee is a uint64_t and has uninit values

* Enforce that deregisters must be 0 fee since we skip checks

* Add unit tests for vote validation (#193)

* Add unit tests for deregistration validation (#194)

* Mainnet checkpoint 86535, testnet 3591, 4166

* Bump version number

* Add print_sr for getting staking requirement (#198)

* Misc bugfixes (#203)

* removed unnecessary cast to double during txfee+coinbase calculation

* simplewallet: increased autostaking interval from 2 minutes to 40

* Fix casting issues from uint to int (#204)

* core_tests: check service node registration and expiration (#195)

* core_tests: check service node registration and deregistration

* core_tests for service nodes:

- include service nodes rewards when calculating account's balance
- check that service nodes rewards have been received

* fixed namespace error; reduced the scope of staking requirement constants

* On blockchain inc/dec mark deregisters relayble based on age (#201)

* Service nodes restore only 1 rollback bug (#206)

* Fix restore 1 rollback event, ensure prevent rollback is always added

* Remove adding prevent_rollback event at init

It gets called in on block added generic anyway.

* Log db exception, fix relation operators for vote/deregister lifetime (#207)

* Filter relayable deregisters w/ check_tx_inputs instead of blockchain callbacks

* Bump version to 0.3.7-beta

* fix build with GCC 8.1.0 (#211)

* Add temp hardfork rule in testnet for deregister lifetimes (#210)

* Update testnet, remove testnet forks, remove checkpoints, update blockheight estimate (#212)

* Don't ban peers for a bad vote, just drop their connection (#213)

* Update to version 0.3.0 release candidate (#215)
2018-09-07 17:42:48 +10:00
Doyle a0e8229928
Service nodes restore only 1 rollback bug (#206)
* Fix restore 1 rollback event, ensure prevent rollback is always added

* Remove adding prevent_rollback event at init

It gets called in on block added generic anyway.
2018-09-04 18:27:13 +10:00
Maxim Shishmarev dfae8763da core_tests: check service node registration and expiration (#195)
* core_tests: check service node registration and deregistration

* core_tests for service nodes:

- include service nodes rewards when calculating account's balance
- check that service nodes rewards have been received

* fixed namespace error; reduced the scope of staking requirement constants
2018-09-04 11:41:05 +10:00
Doyle 2ef7d3b923
Fix underflow for popping rollback events (#189) 2018-08-29 16:03:45 +10:00
Maxim Shishmarev 93302c19ff First service node test (#190)
* core_tests: added service node tests

* core_tests: check balance after registration tx
2018-08-29 15:53:13 +10:00
Doyle 4846572f96
Add unit tests for getting staking requirement (#191) 2018-08-29 15:38:55 +10:00
Doyle a48749c699
Fix service node state by calling detached hooks on failure to switch to alt chain (#188) 2018-08-28 12:02:43 +10:00
jcktm 45a15d5a24 check_tx_inputs: fix deregister double spend test to include deregisters from other heights 2018-08-23 16:12:11 +10:00
jcktm 9eba9557fb version: bump version number and decrease service node logs 2018-08-22 15:29:39 +10:00
Doyle T db3bac912e Fix conditional jump on uninitialised valgrind warning 2018-08-20 18:33:23 +10:00
jcktm 939e194755 testnet: remove testnet forks for testnet relaunch 2018-08-20 14:20:48 +10:00
jcktm 78b7fccfbf service nodes: changed portions to 64 bits
also miner fixes to simplewallet behaviour and interactive registration
prompt
2018-08-20 14:20:37 +10:00
jcktm 245e1f769e
Merge pull request #158 from jcktm/autostaking
simplewallet: added autostaking
2018-08-17 17:11:28 +10:00
jcktm a29c3a8eb3 simplewallet: added autostaking 2018-08-17 16:21:03 +10:00
jcktm b417bf1f27 service nodes: add quorum states to db storage 2018-08-17 15:14:45 +10:00
jcktm 95079568dd service nodes: added service node list rescan message back in 2018-08-17 12:25:28 +10:00
Thomas Winget f9e195f09e
minor fixes to service node data storage 2018-08-16 00:13:57 -04:00
Thomas Winget 4f521b69b4 keep track of service node registration height separately 2018-08-15 23:38:06 -04:00
Thomas Winget 06b6c738a7 Revert "Revert "Store Service Node State to DB as Blob (#125)" (#127)"
This reverts commit c4988f5a1f.

This un-reverts the changes to store the service node info in the
database.  This could easily just be its own commit instead of a
revert, but doing a revert is amusing (and easier in this case).
2018-08-15 23:38:06 -04:00
Doyle f55b9b1b82
Service Nodes States Endpoint (#145)
* Add get_service_node_list_state command for analytics

* Update service_node_list_state to search particular pubkey

* Service node list state sorts display results by longest waiting

* Fix up leftover todos/unused data structures

* Change get_service_node_list_state to print_sn
2018-08-15 12:59:05 +10:00
jcktm 0891999d2b service nodes: add hardfork for testnet reservation calculation bug 2018-08-15 12:45:31 +10:00
sachaaaaa 063a6fa6a5 core: prepare_registration interactive prompt
Add new interactive daemon command "prepare_registration" that saves the registration parameters to a file.

Changes to interactive prompt + put contribution<25% last

clean up

changed everything to portions

added check for --service-node flag
2018-08-15 12:34:50 +10:00
jcktm 12ec5231f3
service nodes: fixed portion calculation to allow last contributor to have less than 25% (#140) 2018-08-14 16:40:30 +10:00
jcktm f2b5480f45 service nodes: fixed bug in reservation calculation (#138) 2018-08-14 16:18:40 +10:00
jcktm e19cdc0532 service nodes; added pubkey check before service node registration signature check (#139) 2018-08-14 16:12:42 +10:00
jcktm d58890fe8f service nodes: fixed the staking requirement (#141) 2018-08-14 16:04:30 +10:00
jcktm 9c6e8b042d service nodes: changed rescan to begin from start of blockchain instead of 30 days (#143) 2018-08-14 15:41:30 +10:00
jcktm 6657a8336a service nodes: switched to portable shuffle algorithm 2018-08-12 12:09:01 +10:00
jcktm dbe25f7a57 tests: change MAKE_TX test macros to use ring ct and bulletproofs; begin preparations for service node tests 2018-08-10 14:29:51 +10:00
jcktm c4988f5a1f Revert "Store Service Node State to DB as Blob (#125)" (#127)
This reverts commit 591fda78f0.
2018-08-08 18:51:14 +10:00
jcktm e2c8230f31 serivce nodes: initialized m_height to remove uninitialized variable errors 2018-08-08 16:43:41 +10:00
jcktm ec9e7c16b6 service nodes: update staking lock blocks requirements (#126) 2018-08-08 16:31:20 +10:00
jcktm 11b1b042ca service nodes: revert 30k limit in staking requirement 2018-08-08 16:31:20 +10:00
jcktm 79406a28a0 simplewallet: add sanity check to staking commands (#123) 2018-08-08 16:31:20 +10:00
Doyle 591fda78f0 Store Service Node State to DB as Blob (#125)
* store service node state as a blob in db

* add height to service node list storage
2018-08-08 16:31:20 +10:00
jcktm 7badc30e97 service nodes: added service node operator cut to registration 2018-08-07 17:01:39 +10:00
jcktm 62f86e837d constants: add some static asserts, and replace magic numbers with constants 2018-08-07 17:01:39 +10:00
jcktm 17152e4329 Fix bug in service node payout address duplication check 2018-08-07 17:01:39 +10:00
jcktm 0cb93a5b6f service node list: changed contributor map to vector 2018-08-07 17:01:39 +10:00
jcktm cc48990cdc new and improved contribution system 2018-08-07 17:01:39 +10:00
jcktm 54dece9691 fix change address and balance display for per-output unlock times 2018-08-05 03:08:51 +00:00
jcktm 8c5a5792cb added tx secret key field to tx extra 2018-08-03 18:34:49 +10:00
jcktm b81214ec6e wallet2: added staking transactions to create_transactions_2 2018-08-03 16:52:44 +10:00
jcktm d318cd702e service node list: added initial contribution field to prepare registration and registration arg parsing 2018-08-03 15:17:15 +10:00
Doyle T 5435e3327e Add RPC call for getting snode register command 2018-08-03 13:52:09 +10:00
jcktm bffd7c2d34
Per output unlock time rebased (#114)
* add per-output unlock time field to transaction class

* get output unlock time (and relevant const fixes)

* move output unlocked check to separate function

* tx unlocked -> output unlocked in Blockchain

* per output unlock in tx creation; needs fork rules and testing

* per output unlock in tx prefix so it is signed...

also fix a couple typos/goofs

* wallet: check if using per output unlock time

* add rules.h and rules.cpp.  git woopsie.

* update test for BlockchainDB changes

* Change tx v3 deregister to be a bool in tx header

* service_node_list: handle per output unlock times in contribution txs

* transaction: added verification of unlock_times.size()
2018-08-03 11:39:28 +10:00
jcktm cce04efb28 service_node_list: fixed initialization typo 2018-08-03 11:34:41 +10:00
jcktm ace26fc0cd quorum_cop: added quorum cop and service node keys to lokid
Submit deregistration autonomously, prune uptime_proofs

Move pruner to relayer, fix inf. loop, quorum participation bool return

find_if, fix reorg logic, make 2hrs check a variable

Add iterator assign on erase, adjust detached check

qacop: review iteration, changed warnings and std::find call

Accept proofs excluding the added time buffer
2018-08-02 18:58:19 +10:00
jcktm 25a424e696 service node registration: changed block reward from -1 to inf; misc bugfix, refactor 2018-07-31 15:18:37 +10:00
jcktm dcf1cc54d9 pooled staking: renamed contributor cut to portions 2018-07-31 15:18:37 +10:00
jcktm aab30bb9e0 service node registration: misc bugfixes and pooled registration contributions 2018-07-31 15:18:37 +10:00
jcktm 41103edbcd service node registration: add signatures from service node pubkey to registration 2018-07-28 10:49:56 +10:00
jcktm 003f0709b8 service_node_list: add multiple stakers, reward shares, etc 2018-07-20 14:16:26 +10:00
Doyle fb66b7e00b Service Node Deregister Part 5 (#89)
* Retrieve quorum list from height, reviewed

* Setup data structures for de/register TX

* Submit and validate partial/full deregisters

* Add P2P relaying of partial deregistration votes

* Code review adjustments for deregistration part 1

 - Fix check_tx_semantic
 - Remove signature_pod as votes are now stored as blobs. Serialization
   overrides don't intefere with crypto::signature anymore.

* deregistration_vote_pool - changed sign/verify interface and removed repeated code

* Misc review, fix sign/verify api, vote threshold

* Deregister/tx edge case handling for combinatoric votes

* core, service_node_list: separated address from service node pubkey

* Retrieve quorum list from height, reviewed

* Setup data structures for de/register TX

* Submit and validate partial/full deregisters

* Add P2P relaying of partial deregistration votes

* Code review adjustments for deregistration part 1

 - Fix check_tx_semantic
 - Remove signature_pod as votes are now stored as blobs. Serialization
   overrides don't intefere with crypto::signature anymore.

* deregistration_vote_pool - changed sign/verify interface and removed repeated code

* Misc review, fix sign/verify api, vote threshold

* Deregister/tx edge case handling for combinatoric votes

* Store service node lists for the duration of deregister lifetimes

* Quorum min/max bug, sort node list, fix node to test list

* Change quorum to store acc pub address, fix oob bug

* Code review for expiring votes, acc keys to pub_key, improve err msgs

* Add early out for is_deregistration_tx and protect against quorum changes

* Remove debug code, fix segfault

* Remove irrelevant check for tx v3 in blockchain, fix >= height for pruning quorum states

Incorrect assumption that a transaction can be kept in the chain if it could
eventually become invalid, because if it were the chain would be split and
eventually these transaction would be dropped. But also that we should not
override the pre-existing logic which handles this case anyway.
2018-07-18 12:42:47 +10:00
jcktm 89240e87b4 core, service_node_list: separated address from service node pubkey 2018-07-12 22:36:35 +10:00
jcktm 8a92407f5f
servicenodes: Added service node list 2018-06-29 14:47:00 +10:00