Commit graph

85 commits

Author SHA1 Message Date
Sean Darcy
0396698ee7 initial loki -> oxen pass 2021-01-04 11:09:45 +11:00
Jason Rhinelander
b627b3b4bb Move epee includes under "epee/..."
This ends epee's include pollution.
2020-10-24 12:46:27 -03:00
Jason Rhinelander
125662b74b trace message display fix 2020-10-12 03:53:30 -03:00
Doyle
f91f018b09 Pulse: Use the latest round when querying quorums via rpc 2020-10-12 11:42:54 +11:00
Doyle
6931356091 Pulse: Log failure to generate valid block template 2020-09-26 13:52:39 +10:00
Doyle
30bb239d64 Pulse: Don't query HF16 blocks too early 2020-09-23 15:15:16 +10:00
Doyle
c986888fcf Pulse: Record Pulse participation globally on network
- Instead of the Pulse quorums validators recording participation
between each other- so failures may not manifest in a decommission until
the several common nodes align and agree to vote off the node.

Voting now occurs when blocks arrives, validators participating in the
generation of the block are marked. This is shared information between
all nodes syncing the chain so decommissions are more readily agreeable
and acted upon in the Obligation quorums immediately.
2020-09-23 15:15:16 +10:00
Jason Rhinelander
928b4ac796 More efficient get-block-by-height lookups
Currently where we need to look up a block by height we do:

1. get block hash for the given height
2. look up block by hash

This hits the lmdb layer and does:

3. look up height from hash in hashes-to-height table
4. look up block from height in blocks table

which is pointless.  This commit adds a `get_block_by_height()` that
avoids the extra runaround, and converts code doing height lookups to
use the new method.
2020-09-18 20:25:48 -03:00
Jason Rhinelander
3f67de11df network_version_16 += _pulse 2020-09-18 16:39:50 -03:00
Jason Rhinelander
6e5c5c113e Disable flakey pulse test code 2020-09-18 13:50:06 -03:00
Jason Rhinelander
ef5f4d0d81 Make pulse test failure only half the time
This updates failures to come in batches of 10 followed by 10
should-be-good blocks.

Blocks with an odd 2nd-last digit (xxx1x, xxx3x, etc.) are the ones
where we add failures.
2020-09-18 13:50:06 -03:00
Doyle
648ca37562 Pulse: Add testing code for making nodes malfunction 2020-09-18 13:50:06 -03:00
Doyle
676b1db917 Pulse: Only check self participation if you're a validator 2020-09-18 13:50:06 -03:00
Doyle
ec6642e36f Pulse: On alt rounds, allocate tx fee to alt producer 2020-09-18 13:50:05 -03:00
Doyle
e0a81c5bdf Pulse: Persist past round data for late messages
- Late messages that arrive fail signature validation and log an error.
In reality this is not always an error, it means the Pulse node finished
the round or realised the round was going to fail earlier than another
node.

The late arriving messages refer to the previous round or block and
might actually validate ok, but just be late. This commit stores the
round history so that we can still validate these old messages and
silently ignore instead of printing errors.
2020-09-18 13:50:05 -03:00
Doyle
8aadc36faa Pulse: On signed block message, provide 2 signatures
- Previously we just submitted 1 signature that signed the contents of
the final block that required us to delay signature verification,
because, if we received the message before we were in the final stage we
would have to delay the verification because we have insufficient data
to verify the signature.

This means that when someone in the quorum receives and relays the
message, they can tamper the message and make it invalid (by changing
the round to something invalid for example) and cause other nodes in the
quorum to reject it, eventually, recording that the Service Node didn't
participate in the round and bias Service Nodes to decommissioning.

Instead of taking the shortcut and providing only 1 signature, we do the
same thing we do with all the other messages,

1. We signed the contents of the message- this proves that the message
originated from the Service Node it claims to have come from (preventing
any tampering).

2. The 2nd signature actually is the signature that signs the final
block and is included in the block for propagation in the network.

Doing so patches up the ability for intermediate relay nodes from tampering
the message.
2020-09-18 13:50:05 -03:00
Doyle
1a613e1b8c Pulse: Verify participation against the bitset not the count
- A non-participating node might be able to leak his way through
a stage and influence the receive count and cause participating nodes to
progress and (but) eventually fail and report some non-sensical error
that all messages were received but still failed.
2020-09-18 13:50:05 -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
7760255454 Pulse: When not participating in block but should be, sleep
- If a node is in the pulse quorum- but in the
locked in bitset (that indicates the nodes that are locked in to
participate in the round) does not include the node, go to sleep.

Previously the node would continue through the pulse rounds, but
messages would be ignored by everyon else in the quorums.
2020-09-18 13:50:05 -03:00
Doyle
31b9fbff91 Pulse: Record pulse participation and issue decommission 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
d49dfc5a17 Pulse: Fix pulse round timings querying wrong top block 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
67deb672a4 Pulse: Revise signature hash and checking pulse round 2020-09-18 13:50:05 -03:00
Doyle
d02d3fa2a1 Pulse: Remove TODO for producer checks
- We could do it earlier, but we need info for producing the payouts.
Adding it earlier and shuffling around more state to store is not worth
it just for early return to sleep, when we still have to wait for the next
round to start anyway.
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
64fa0c1425 Pulse: Redo documentation for the state machine 2020-09-18 13:47:16 -03:00
Doyle
282a1a4824 Pulse: Use time printer that displays mins & seconds 2020-09-18 13:47:16 -03:00
Doyle
23294561b1 Pulse: Don't churn pulse rounds when non-participant
- When not a participant in a pulse round, nodes will iterate Pulse
quorums until it is and then sleeps on the round. This can cause the
rounds to overflow at round > 255, if the Service Node is never selected
to participate and cause them to reject any Pulse Block even if some
prior quorum sent it validly.

- Moving the non-participant check down to after the round starts also
puts all the participation checks (is validator, is producer, is
neither) into one spot for improved clarity.
2020-09-18 13:47:16 -03:00
Doyle
6cf53600e1 Pulse: Add work around for core_tests and fix cast 2020-09-18 13:43:51 -03:00
Doyle
86aff9765e Pulse: Move block verification outside of validate_miner_tx 2020-09-18 13:43:51 -03:00
Doyle
1557bcac0f Pulse: Avoid static_cast, truncate after range check, whitespace revert 2020-08-19 15:52:10 +10:00
Doyle
78c4bf9c3e Pulse: Clear round state when returning to preparing_for_round 2020-08-19 15:34:59 +10:00
Doyle
1301467826 Pulse: Set last_state before the loop ends
Otherwise the state machine loop only runs once, then on loop end it's
assigned the same value as context.state and terminates.

Setting it first allows the loop to detect when state has changed and
continue running.
2020-08-19 15:34:59 +10:00
Doyle
ad147acc14 Pulse: Handle round > 255, add debug logs
- Log the generated pulse quorum
- Log the round when a msg signature fails
- Handle round > 255 and revert to allowing PoW blocks
2020-08-19 15:26:46 +10:00
Doyle
cdf3a08738 Pulse: Use blake2b_hash instead of cn_fast_hash 2020-08-18 11:59:54 +10:00
Doyle
2ed787b436 Pulse: Avoid monero crypto, use sodium's blake2b 2020-08-18 11:59:54 +10:00
Doyle
e8513b1915 Pulse: Use std::sample instead of shuffle + random pick 2020-08-18 11:59:54 +10:00
Doyle
1e8d0a4fef Pulse: Use fallthrough C++17 attribute 2020-08-18 11:59:54 +10:00
Doyle
a10a2dd97a Pulse: Actually use quorum_array<T> alias 2020-08-18 11:59:54 +10:00
Doyle
9213df406c Pulse: fix off by 2 quorum gen bug, recategories log msgs 2020-08-18 11:59:54 +10:00
Doyle
d232e2c2b4 Pulse: Mask values in log in release, wipe memory 2020-08-18 11:59:54 +10:00
Doyle
d0e3b6816d Pulse: Revise some comments, add some docs to struct members 2020-08-18 11:59:54 +10:00
Doyle
abbcb57f4d Pulse: handle_message implicitly relays for us already
- Relays for us if the message has never been seen before. So our
message we construct which we haven't recorded yet will get relayed
automatically.
2020-08-18 11:59:54 +10:00
Doyle
9fee5af8c2 Pulse: Switch back to standard min validator counts
- Fix bug expecting min validators == min signatures assumption
causing blocks to be included with invalid unreceived signatures.
2020-08-18 11:59:54 +10:00
Doyle
de27ffaf51 Pulse: Add the correct signed block to the blockchain
- Not the std::move'd one.
2020-08-18 11:59:54 +10:00
Doyle
61f84ecfdc Pulse: Reject bad bitset block templates on msg receipt 2020-08-18 11:59:54 +10:00
Doyle
3d7232d67e Pulse: Make 16bit bitset with helper function 2020-08-18 11:59:54 +10:00
Doyle
f7933e648b Pulse: DRY send/wait stages; combine where we can 2020-08-18 11:59:54 +10:00
Doyle
9a0538bd88 Pulse: Handle block generation failure 2020-08-18 11:59:54 +10:00