Commit graph

988 commits

Author SHA1 Message Date
Doyle
35817a7473 temp: Remove devnet resetting code 2020-09-18 13:50:06 -03:00
Doyle
6c4ab79977 Restart devnet from scratch 2
- We avoid generating outputs if the amount is 0 (0 miner rewards in
HF16, alternative rounds with no tx's have 0 fees awarded)

- Adjust the time catch/delay mechanism for Pulse from 15s to 30s.
2020-09-18 13:50:06 -03:00
Doyle
111fe26fa6 Pulse: get_round_timings needs to work with alt blocks
- Make it stop relying on the block and instead the user must pass in
the correct information
2020-09-18 13:50:05 -03:00
Doyle
268c0d5b63 Pulse: Fix off by one round timings, remove unused block timings fn
- Fix cached blocks using too old timestamps
2020-09-18 13:50:05 -03:00
Doyle
65cd0faaf2 Pulse: Handle alternative block reorg with Pulse blocks
- Alternative pulse blocks must be verified against the quorum they belong to.
  This updates alt_block_added hook in Service Node List to check the new Pulse
  invariants and on passing allow the alt block to be stored into the DB until
  enough blocks have been checkpointed.

- New reorganization behaviour for the Pulse hard fork. Currently reorganization
  rules work by preferring chains with greater cumulative difficulty and or
  a chain with more checkpoints. Pulse blocks introduces a 'fake' difficulty to
  allow falling back to PoW and continuing the chain with reasonable difficulty.

  If we fall into a position where we have an alt chain of mixed Pulse blocks
  and PoW blocks, difficulty is no longer a valid metric to compare blocks (a
  completely PoW chain could have much higher cumulative difficulty if hash
  power is thrown at it vs Pulse chain with fixed difficulty).

  So starting in HF16 we only reorganize when 2 consecutive checkpoints prevail
  on one chain. This aligns with the idea of a PoS network that is
  governed by the Service Nodes. The chain doesn't essentially recover until
  Pulse is re-enabled and Service Nodes on that chain checkpoint the chain
  again, causing the PoW chain to switch over.

- Generating Pulse Entropy no longer does a confusing +-1 to the height dance
  and always begins from the top block. It now takes a block instead of a height
  since the blocks may be on an alternative chain or the main chain. In the
  former case, we have to query the alternative DB table to grab the blocks to
  work.

- Removes the developer debug hashes in code for entropy.

- Adds core tests to check reorganization works
2020-09-18 13:50:05 -03:00
Doyle
20cb89679e Pulse: Verify alt blocks from pulse 2020-09-18 13:50:05 -03:00
Doyle
832127215c blockchain: rename get_next_difficulty_for_alternative_chain
- Change get_next_difficulty_for_alternative_chain to
get_difficulty_for_alternative_chain to match
get_difficulty_for_next_block. This was an annoying function to find
because of the irregular naming scheme was different from the canonical
difficulty function.
2020-09-18 13:50:05 -03:00
Doyle
d0b743d667 Pulse: Pull blocks by header in rescan, avoid extra copies 2020-09-18 13:50:05 -03:00
Doyle
eec517d7df Pulse: Fix difficulty = 0 in pulse, adjust fill timestamps 2020-09-18 13:50:05 -03:00
Doyle
79ae34e361 Pulse: Setup the mainnet to work around difficulty
- Pulse blocks will forcibly get the difficulty set to
  1'000'000 * TARGET_BLOCK_TIME throughout time
- When PoW is required again, the past window of blocks will use these
  difficulties, i.e. setup the chain for mining at 1'000'000 difficulty
  which is easily mineable to continue the network and continue to pull
  difficulties from the new-er mined blocks until the network is ready
  for Pulse again.
- Difficulty is still necessary for falling back to mining when Pulse
  fails. Switching between the two systems seamlessly can be done by
  continuing to set the difficulty for Pulse blocks.
2020-09-18 13:50:05 -03:00
Doyle
ffb29989c7 Pulse: Prepare difficulty disabling for Pulse 2020-09-18 13:50:05 -03:00
Doyle
fc951c57ff Pulse: Separate more PoW from Pulse verification 2020-09-18 13:50:05 -03:00
Doyle
b585adf9f5 Pulse: Undo 'if 0' in create_block_template 2020-09-18 13:50:05 -03:00
Doyle
7d5ab17500 blockchain: Fix regressions with factoring basic_block_checks 2020-09-18 13:47:16 -03:00
Doyle
a13d06c2b9 Pulse: Move round/validator bitset into create_next_pulse_block 2020-09-18 13:47:16 -03:00
Doyle
20ab3c2ac9 blockchain: DRY basic block verification main/alt chain 2020-09-18 13:47:16 -03:00
Doyle
d65b952b70 Pulse: DRY block PoW calculation 2020-09-18 13:47:16 -03:00
Doyle
d181604535 Pulse: Move checkpoint verification out of PoW check 2020-09-18 13:47:16 -03:00
Doyle
bc318cf5dd Pulse: Don't verify PoW for Pulse Blocks 2020-09-18 13:47:16 -03:00
Doyle
d65479fea0 temp: Remove ghost 'success' variable 2020-09-18 13:47:16 -03:00
Doyle
ecff118600 temp: Global logs in block verify on blockchain side 2020-09-18 13:47:16 -03:00
Doyle
62fe4db413 config: Convert DIFFICULTY_BLOCKS_V2 to TARGET_BLOCK_TIME 2020-08-18 11:59:53 +10:00
Doyle
a62ff316e3 Pulse: Queue Block Gen code review
- Rename find_named_argument -> find_prefixed_value
- Update get_current_blockchain_height() comment to specify ability to lock
- Update memcmp(address1, address2) to address1 == address2
- Make create_next_miner_block_template call create_miner_block_template
- Update LMQ x25519 keys only when key has changed
- construct_miner_tx: Use C++17 features
- Pulse: Add log category "Pulse"
- Pulse: Check shutdown before blockchain height
- Pulse: Use get_human_readable_timespan
- Pulse: Switch to MINFO, enable with --log-level +pulse:DEBUG
- Pulse: Add height into context
- Pulse: Remove some default switch cases hiding compiler warnings
- SN: Update hardcoded '9' literals to network_version_9_service_nodes
- Core: Use using namespace std::literals
- Miner: Change num_blocks availability to debug
- RPC: Gate test rpc commands to != MAINNET
- Wallet: Store wallet before deinitialization instead of refresh
2020-08-18 11:59:53 +10:00
Doyle
9ebebec7d2 Pulse: Fix most common bitset selection 2020-08-18 11:59:53 +10:00
Doyle
73ea959c8d blockchain: Add optional lock when querying height 2020-08-18 11:59:53 +10:00
Doyle
5c2c35c0d6 Pulse: Make create block template have pulse/miner variants 2020-08-18 11:59:53 +10:00
Doyle
a6e1f82f7a Pulse: Make active snodes info public, disambiguate next_block_template
- Make active snods info public for Pulse to query the list to allow
  Pulse quorums to be generated outside of the Service Node List.
2020-08-18 11:59:53 +10:00
Doyle
457fd4d027 Pulse: Change queued_winner->block_leader, verify alt round rewards
Changes naming scheme
 - Block Producer: The Service Node/Miner reponsible for generating the block
 - Block Leader: The Service Node that is at the top of the Service Node
   List queue. They are also by default on pulse round 0, the block producer.
   If that round fails, then the block producer is changed as per the LIP-6
   with multi-block seeding.

This commit also re-writes validate miner TX to repeat some of the
verification code. This appears to be clearer than having multiple
variables that change the verification loop in small ways which was more
error prone than I'd like to tolerate.
2020-08-18 11:59:53 +10:00
Doyle
95a2ae88bc service_nodes: Rename block_winner to payouts
With Service Node List now generating 2 coinbase rewards, block_winner
is ambiguous, so, distinguish the reward generated for nodes at the top
of the queued list as- queued_winner.
2020-08-18 11:59:53 +10:00
Doyle
4c3e12c6cc Pulse: validate_miner_tx pass in block to service_node_list 2020-08-18 11:59:53 +10:00
Doyle
9312bedba1 Pulse: Undo merging of payout entries
Merging payout entries can be done when batching is implemented instead
of drilling down too deep in implementation too early before the other
parts of Pulse are fleshed out.
2020-08-18 11:59:53 +10:00
Doyle
8938003027 Pulse: Setup miner_tx to handle pulse/miner block producers 2020-08-18 11:59:53 +10:00
Doyle
254e6aa80d Code review
- Remove PoW/Difficulty information for Pulse Block printout
- Use unary + to co-erce char's in ostreams
- Avoid epee::string_tools::pod_to_hex for lokimq equivalent
- Express validator bitmask in terms of PULSE_QUORUM_NUM_VALIDATORS
- Fix bug in generating Pulse Quorum, avoiding the use of the 0th
  service node in pulse_candidates
- Switch to std::any for void * context
2020-08-18 11:59:53 +10:00
Doyle
63ba795c7e Pulse: DRY quorum signature verification
- By merging the quorum verification with pre-existing checkpointing
code, checkpoints votes are currently being sorted by the vote index
order. This was also enforced on the pulse signatures.
2020-08-18 11:59:53 +10:00
Doyle
96bf8f757e tests: Switch to CN Turtle for speed 2020-08-18 11:59:53 +10:00
Doyle
80552293a3 blockchain: set verification failed in subsystem, check validator bit masks 2020-08-18 11:59:53 +10:00
Doyle
59f7531151 Blockchain: Check loki subsystem block added failure 2020-08-18 11:59:53 +10:00
Doyle
475ed74b28 Pulse: Move verification to block. Add support to core tests.
Verification needs to go to the block, not the header to ensure it does
not get included in the block hash.
2020-08-18 11:59:53 +10:00
Doyle
b80bf5cbe9 Blockchain: Remove unused handle_block_to_main_chain(...) overload 2020-08-18 11:59:53 +10:00
Jason Rhinelander
02b928f49e Simplify generate_genesis_block() parameters
Take the network_type and use it to get_config(), rather than making the
caller pass in multiple things from get_config().
2020-08-17 02:54:45 -03:00
Jason Rhinelander
8bf3f00c03 RPC block & transaction improvements
- Add opt-in tx-extra parsing to `get_transactions`; this now lets you
  get most tx details (including service node tx info) via the RPC.
- Add ability for RPC block header requests to include a list of tx
  hashes contained in the block.
- remove long-deprecated txs_as_hex from `get_transactions`: this
  essentially doubled the length of requests since txs[i].as_hex has the
  exact same data.  Despite this being the "new" format for several
  years, wallet code was still relying on the "old" format.  Since 8.x
  already breaks the RPC, this seems a good time to remove it.
- Significantly cleaned up and documented how pruned transactions
  results are returned in GET_TRANSACTIONS.  Previously it was fairly
  uncertain when you'd get a pruned or unpruned transaction.  (See
  comments added in core_rpc_server_commands_defs.h)
- Stop returning the transaction data hex values when you ask for
  `decode_as_json`.  The documentation already implied you don't get
  it, but you do, and this is virtually always just wasted extra data
  when you're asking for the json-decoded value.
- fix miner txes being treated in the RPC as pruned transactions (they
  aren't: they just have no prunable data).
- Made a bunch of `get_transactions` fields (including virtually all of
  the new parsed tx-extras fields) into std::optional's so that the keys
  aren't included when the values are empty.
- Fix bug in `get_transactions` that raised an exception if *some* (but
  not all) of the requested transactions were missed.  Previously you
  could only get all-missed, all-found, or an exception.
2020-08-17 02:47:43 -03:00
Jason Rhinelander
06f5f3ee82 cryptonote_config.h: use inline constexpr
Currently all the variables in here need to be added into every
compilation unit; C++17 inline constexpr avoids that by throwing away
the duplicates at link time, plus lets the compiler optimize things
away.

Also eliminates a side effect in `get_config()` that mutated the
variable (so that one `get_config()` would end up changing the data of a
previous `get_config()`).  Instead `get_config()` is now always constant
and doesn't care about the hard fork version; instead there is a
convenience method to get the governance wallet_address which takes the
hf version.
2020-07-21 21:53:27 -03:00
Jason Rhinelander
443c5e8cea Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.

This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).

This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate.  I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.

Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.

Other notable changes:

- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.

- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-07-02 12:52:13 -03:00
Jason Rhinelander
5a27030ff8 Replace thread "pool" with a single thread
When you have a comment just before your thread pool initialization that
reads:

    // we only need 1

that is a pretty good indicator that you don't need a thread *pool* for
the thing you are doing.

Replace it with a single std::thread.
2020-07-02 12:52:13 -03:00
Jason Rhinelander
86986bd703 Replace boost::bind with lambdas 2020-07-02 12:52:13 -03:00
Jason Rhinelander
7584a6c3b8 sha256sum_str - fix recursion in string_views
Reorder and SFINAE the non-char string_view code to avoid infinite
recursion with a plain string_view.
2020-07-02 12:52:12 -03:00
Jason Rhinelander
49c693d0a9 Split up common/util.h
common/util.h has become something of a dumping ground of random
functions.  This splits them up a little by moving the filesystem bits
to common/file.h, the sha256sum functions to common/sha256sum.h, and the
(singleton) signal handler to common/signal_handler.h.
2020-07-02 12:52:12 -03:00
Jason Rhinelander
975305998e Simplify and avoid boost::adaptors 2020-07-02 12:52:12 -03:00
Jason Rhinelander
e7d056edf1 boost::variant -> std::variant
A huge amount of this is repetitive:

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

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

Also adds boost serialization serializers for std::variant and
std::optional.
2020-07-02 12:52:12 -03:00
Jason Rhinelander
19ca0e21ee Replace a few boost::bind's with lambda 2020-07-02 12:52:12 -03:00