Commit graph

503 commits

Author SHA1 Message Date
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 2dffb730b4 Expose accessor for service_node_list in core/blockchain
This adds direct access to the service node list via core/blockchain so
that it doesn't have to be passes around as reference in quite so many
places.
2019-11-27 14:07:52 -04:00
Jason Rhinelander dd230491db Uptime proof timer tweak + debug option
This tweaks uptime proofs to go out on the first timer tick in the
58.5-62.5 interval (rather than 60-65) which should result in proofs
usually being very close to the 60 minute mark.  (Currently a fair
percentage end up at the 65m mark because the timer fires just before
the 60m mark).

It also tweaks the first uptime proof to go out after 2 minutes instead
of 5 minutes, and uses separate constants
(UPTIME_PROOF_INITIAL_DELAY_SECONDS, UPTIME_PROOF_TIMER_SECONDS) for
times that were previously overloading the
UPTIME_PROOF_BUFFER_IN_SECONDS constant.

For debugging this also adds a cmake option LOKI_DEBUG_SHORT_PROOFS
that, when enabled, makes the whole proof cycle (sending and acceptance)
20x faster, which is very useful for local testnet debugging.
2019-11-27 14:07:52 -04:00
Jason Rhinelander a2727d5518 Blink WIP 2019-11-27 14:07:52 -04:00
Jason Rhinelander 2bc606fb89 Remove pointless check against already called 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
Jason Rhinelander 34480c6f23 Merge branch 'pk25519-rpc-interfaces' into lokinet-integration 2019-11-26 21:47:07 -04:00
Jason Rhinelander b64097a47e Add lokinet ping rpc endpoint
This abstracts much of the storage server ping code to work for both
storage server and lokinet.
2019-11-26 18:49:37 -04: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
Doyle c859a2ab96
Merge pull request #914 from Doy-lee/HandleTXRemoveUselessStep
Remove check_tx_syntax unused since forever
2019-11-07 16:30:43 +11:00
Doyle 1e46dd48c5
Merge pull request #920 from jagerman/tx-burning
Tx burning
2019-11-07 12:24:13 +11: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
Jason Rhinelander 1e496975b3 Add fee burning
This adds a tx extra field that specifies an amount of the tx fee that
must be burned; the miner can claim only (txnFee - burnFee) when
including the block.

This will be used for the extra, burned part of blink fees and LNS fees
and any other transaction that requires fee burning in the future.
2019-10-30 18:47:22 -03:00
Doyle e949e15c6e
Remove hard-forking code on the boundary of 12 and 13 (#919) 2019-10-30 14:50:34 +11:00
Doyle ba9a4d84ed Remove check_tx_syntax unused since 2015 2019-10-23 15:22:01 +11:00
Doyle 4db1f0ddd0
Merge pull request #872 from jagerman/qnet-backport
Backports from quorumnet branch for 5.x
2019-10-08 17:13:34 +11:00
Jason Rhinelander 13f7b7f11e Wait for storage server (#874)
* Fix elapsed time in storage server warning message

This was passing the time value rather than the number of seconds so
basically always printed "a long time" instead of the elapsed time.

* Removed pre-HF12 code

* Wait for storage server before sending proof

On startup we send a proof immediately, but this is misleading to the
operator - they may see a proof broadcast over the network suggesting
everything is good even when the storage server is still down.  This
makes lokid wait for a first ping before the first proof so that the
user doesn't get mislead.

It also adds the storage server last ping into the `lokid status`
message, such as:

    Height: 375634/375634 (100.0%) on mainnet, not mining, net hash 63.00 MH/s, v12, up to date, 1(out)+0(in) connections, uptime 0d 0h 0m 4s
    SN: f4558f60b1c4075e469a15411f12d5a747c1c62b44bcbc8523f1a90becc80475 not registered, s.server: NO PING RECEIVED

or:

    Height: 375663/375663 (100.0%) on mainnet, not mining, net hash 76.17 MH/s, v12, up to date, 1(out)+0(in) connections, uptime 0d 0h 0m 32s
    SN: f4558f60b1c4075e469a15411f12d5a747c1c62b44bcbc8523f1a90becc80475 not registered, s.server: last ping 11 seconds ago
2019-10-08 15:40:11 +11: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 c2f2c8306e Remove useless method.
Five years into the future this pointless method is still not used.
Time to go.
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
Howard Chu 3b8dd4b25b Updated RandomX integration from upstream
Support RandomX PoW algorithm
2019-09-25 17:12:23 -03:00
Doyle 705885af1b
Add testnet checkpoint & enable checkpoints from json (#851) 2019-09-20 17:06:12 +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 ce85eccf72
Rescan difficulty periodically, fix incorrect timestamps/difficulties in rescan (#835)
* Rescan difficulty periodically, fix incorrect timestamps/difficulties in rescan

* Code review
2019-09-13 15:46:15 +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 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
Jason Rhinelander d5f234477e Removed unused/always-obsolete macros
This removes a bunch of macros from cryptonote_config.h that either
aren't used at all, or have never applied to Loki, along with
removing/simplifying some of the dead code touching these macros.

A few of these are still used only in the test suite, so I moved them
there instead.

One of these sounds sort of scary -- ALLOW_DEBUG_COMMANDS -- but this
has *always* been forcibly enabled with no way to disable it going back
to the very first monero git commit.

DYNAMIC_FEE_PER_KB_BASE_FEE_V5 was defined in a very strange way that
doesn't make a lot of sense (including using a constant that is not
otherwise applied in loki), so I just replaced it with the expanded
value.
2019-08-22 21:42:10 -03:00
Doyle a6cbad1701 Enforce ordering of votes in HF13 2019-08-15 11:42:46 +10:00
Doyle f7e6c98e48
Merge pull request #788 from jagerman/opt-simp
Service node data optimizations and code cleanups/simplifications
2019-08-13 13:16:38 +10:00
Doyle 00284cfdcd
Don't relay service node votes or uptime proof if synchronising (#779)
* Don't relay service node votes or uptime proof if synchronising

* Only relay votes if state is > state_synchronizing

Not before. Handshake = no, synchronizing = no.

* Relay votes/uptime to all nodes including those on I2P/TOR.
2019-08-13 12:23:08 +10: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 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 c2ef3b413a Inline update_miner_block_template and remove from core header 2019-08-07 10:30:46 +10:00
Doyle de1d9ab53d Remove NOTIFY_NEW_DEREGISTER_VOTE code, deprecated by service node vote 2019-08-07 10:18:53 +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 25c8058a7c Don't send NOTIFY_NEW_SERVICE_NODE_VOTE before v12
They were being sent too early by upgraded lokids, resulting in "Unknown
command:2012" errors on 3.0.x mainnet nodes.
2019-07-11 16:30:17 -03: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 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 bdf8829f6b Switch to a circular buffer for recording checkpointing votes 2019-07-11 14:21:59 +10:00
Doyle afc86db4a9
Rollback chain when receiving conflicting checkpoints (#726) 2019-07-11 14:16:55 +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