Commit Graph

226 Commits

Author SHA1 Message Date
Alexander Block
8ce8cb9ca8 Remove MarkXXX methods from CSigSharesNodeState
We're now directly calling the Merge/Set methods on the inventory objects.
2019-02-27 17:33:40 +01:00
Alexander Block
fa25728ca5 Use new sessionId based session management in CSigSharesManager
Stop relying on the information previously found in the CSigSharesInv
and CBatchedSigShares messages and instead use the information found in
the session refereced by the session id.

This also updates a few LogPrintf calls. Previously, CSigSharesInv::ToString
also included the signHash in the returned string, which is not the case
anymore, so we have to add it manually.
2019-02-27 17:33:40 +01:00
Alexander Block
34e3f8eb53 Implement session management based on session ids and announcements 2019-02-27 17:33:40 +01:00
Alexander Block
7372f6f10b Move RebuildSigShare from CBatchedSigShares to CSigSharesManager
Needed as CBatchedSigShares doesn't have the necessary info anymore
2019-02-27 17:33:40 +01:00
Alexander Block
55a6182b10 Introduce QSIGSESANN/CSigSesAnn P2P message 2019-02-27 17:33:40 +01:00
Alexander Block
80375a0b4f Change CSigSharesInv and CBatchedSigShares to be sessionId based 2019-02-27 17:33:40 +01:00
Alexander Block
9b4285b1c8 Use salted hashing for keys for unordered maps/sets in LLMQ code
We must watch out to not blindly use externally provided keys in unordered
sets/maps, as attackers might find ways to cause unbalanced hash buckets
causing performance degradation.
2019-02-27 14:41:20 +01:00
Alexander Block
c52e8402c0 Remove now obsolete TODO comment above CRecoveredSigsDb 2019-02-27 14:40:52 +01:00
Alexander Block
e83e32b956 Add in-memory cache for CRecoveredSigsDb::HasRecoveredSigForHash 2019-02-27 14:40:52 +01:00
Alexander Block
677c0040cd Add in-memory cache to CQuorumBlockProcessor::HasMinedCommitment 2019-02-27 14:40:52 +01:00
Alexander Block
f305cf77b6 Multiple fixes and optimizations for LLMQs and ChainLocks (#2724)
* Indicate success when signing was unnecessary

* Fix typo in name of LLMQ_400_60

* Move RemoveAskFor call for CLSIGs into ProcessNewChainLock

In case we got INV items for the same CLSIG that we recreated through
HandleNewRecoveredSig, (re-)requesting of the CLSIG from other peers
becomes unnecessary.

* Move Cleanup() call in CChainLocksHandler::UpdatedBlockTip up

We bail out early in a few situations from this method, so that Cleanup()
might not be called while its at the bottom.

* Bail out from CChainLocksHandler::UpdatedBlockTip if we already got the CLSIG

* Call RemoveAskFor when QFCOMMITMENT was received

Otherwise we might end up re-requesting it for a very long time when the
commitment INV was received shortly before it got mined.

* Call RemoveSigSharesForSession when a recovered sig is received

Otherwise we end up with session data in node states lingering around until
a fake "timeout" occurs (can be seen in the logs).

* Better handling of false-positive conflicts in CSigningManager

The old code was emitting a lot of messages in logs as it treated sigs
for exactly the same session as a conflict. This commit fixes this by
looking at the signHash before logging.

Also handle a corner-case where a recovered sig might be deleted between
the HasRecoveredSigForId and GetRecoveredSigById call.

* Don't run into session timeout when sig shares come in slow

Instead of just tracking when the first share was received, we now also
track when the last (non-duplicate) share was received. Sessios will now
timeout 5 minutes after the first share arrives, or 1 minute after the last
one arrived.
2019-02-27 16:10:12 +03:00
UdjinM6
252ee89c34
Implement new algo for quorum connections (#2710)
Instead of trying to manually figure out params for different quorum/ring sizes, connect to nodes at indexes (i+2^k)%n where k: 0..floor(log2(n-1))-1, n: size of the quorum/ring
2019-02-19 13:05:39 +03:00
UdjinM6
a79b928532
Merge pull request #2682 from PastaPastaPasta/backports-0.15-pr6
Backports 0.15 pr6
2019-02-19 13:04:49 +03:00
Alexander Block
104c6e7767 Cleanup successful sessions before doing timeout check (#2712)
Otherwise we get some false-positive timeout messages in logs.
2019-02-18 14:07:57 +03:00
UdjinM6
26db020d17
Separate init/destroy and start/stop steps in LLMQ flow (#2709) 2019-02-17 14:39:43 +03:00
Alexander Block
9f58690322 Avoid using ordered maps in LLMQ signing code (#2708)
* Implement and use SigShareMap instead of ordered map with helper methods

The old implementation was relying on the maps being ordered, which allowed
us to grab all sig shares for the same signHash by doing range queries on
the map. This has the disadvantage of being unnecessarily slow when the
maps get larger. Using an unordered map would be the naive solution, but
then it's not possible to query by range anymore.

The solution now is to have a specialized map "SigShareMap" which is
indexed by "SigShareKey". It's internally just an unordered map, indexed by
the sign hash and another unordered map for the value, indexed by the
quorum member index.

* Only use unordered maps/sets in CSigSharesManager

These are faster when maps/sets get larger.

* Use unorderes sets/maps in CSigningManager
2019-02-17 14:38:56 +03:00
Pasta
bb90eb4bf0 backports-0.15-pr6 code review 2019-02-16 15:09:51 -06:00
Alexander Block
7a192e2e4c Optimize sleeping behavior in CSigSharesManager::WorkThreadMain (#2707)
* Don't sleep in WorkThreadMain when CPU intensive work was done

When the current iteration resulted in CPU intensive work, it's likely that
the next iteration will result in work as well. Do not sleep in that case,
as we're otherwise wasting (unused) CPU resources.

* No matter how fast we process sig shares, always force 100ms between sending

* Apply review suggestions
2019-02-16 19:59:48 +03:00
Alexander Block
feb4e0ac74
Merge pull request #2706 from codablock/pr_llmq_optimizations3
Implement caching in CRecoveredSigsDb
2019-02-16 15:51:24 +01:00
Alexander Block
dae1542a0e
Merge pull request #2705 from codablock/pr_llmq_optimizations2
Optimize LLMQs initialization and (de)serialization of BLS signatures
2019-02-16 15:50:23 +01:00
Alexander Block
742a258987 Implement caching in CRecoveredSigsDb
To avoid repeated calls into LevelDB
2019-02-15 15:52:51 +01:00
Alexander Block
500b9c89a7 Use CBLSLazySignature in CBatchedSigShares
This removes the burden on the message handler thread when many sig batches
arrive. The expensive part of deserialization is now performed in the sig
shares worker thread.

This also removes the need for the specialized deserialization of the sig
shares which tried to avoid the malleability check, as CBLSLazySignature does
not perform malleability checks at all.
2019-02-15 15:44:19 +01:00
Alexander Block
c03480d20f Disable optimistic sending when pushing sig share related messages
And instead let the network thread do the actual sending.
2019-02-15 15:20:15 +01:00
UdjinM6
bedfc262e2 Rework handling of CSigSharesManager worker thread (#2703) 2019-02-15 15:11:50 +01:00
UdjinM6
3e4286a584 Less cs_main locks in quorums (#2702)
* Drop cs_main from CQuorumManager::UpdatedBlockTip()

* CLLMQUtils::IsQuorumActive() shouldn't require cs_main to be held

* Revert comment deletion
2019-02-15 15:11:35 +01:00
Alexander Block
67a86091aa Implement and use secure BLS batch verification (#2681)
* Implement secure verification in bls_batchverifier

* Rename CBLSInsecureBatchVerifier to CBLSBatchVerifier

* Add unit tests for simple BLS verifcation and CBLSBatchVerifier
2019-02-04 21:58:28 +03:00
Alexander Block
03fa115503 Speed up CQuorumManager::ScanQuorums (#2677)
* Store quorumHash of first mined commitment in evoDb

This allows to skip scanning for quorums below this block.

* Speed up CQuorumManager::ScanQuorums

This does 2 things:
1. Only call HasQuorum for blocks that are potentially a quorumBlockHash
   These are only blocks which are at index 0 of each DKG interval
2. Stop scanning for quorums when we get below the first block that
   contained a commitment. If no commitment was ever mined, we bail out
   immediately.

* Return result instead of {}

* Remove HasQuorum() call as GetQuorum already does this

* Remove unnecessary "if (!qc.IsNull()))"

It's already checked at the top of the loop

* When necessary, remove DB_FIRST_MINED_COMMITMENT from evoDb in UndoBlock
2019-02-02 03:08:51 +03:00
Alexander Block
088525bde3 Multiple fixes for LLMQs and BLS batch verification (#2674)
* Check aggPubKey for IsValid() instead of aggSig

aggSig is not reliable here as it might already be initialized by the
previous message.

* Significantly reduce sleep time for each DKG phase

Turns out the DKG is much faster then expected, and waiting multiple
minutes for each phase in a devnet is not much fun.

* Correctly use SIGN_HEIGHT_OFFSET when checking for out of bound height

* Introduce startBlockHeight to make things more explicit
2019-02-01 12:07:21 +03:00
Alexander Block
18950f923e Optimize DKG debug message processing for performance and lower bandwidth (#2672)
* Allow sub-batch verification in CBLSInsecureBatchVerifier

* Implement batch verification of CDKGDebugStatus messages

* Use uint8_t for statusBitset in CDKGDebugMemberStatus and CDKGDebugSessionStatus

No need to waste one byte per member and per LLMQ type.

* Reserve 4k of buffer for CSerializedNetMsg buffer

Profiling has shown that a lot of time is spent in resizing the data
vector when large messages are involved.

* Remove nHeight from CDKGDebugStatus

This field changes every block and causes all masternodes to propagate
its status for every block, even if nothing DKG related has changed.

* Leave out session statuses when we're not a member of that session

Otherwise MNs which are not members of DKG sessions will spam the network

* Remove receivedFinalCommitment from CDKGDebugSessionStatus

This is not bound to a session and thus is prone to spam the network when
final commitments are propagated in the finalization phase.

* Add "minableCommitments" to "quorum dkgstatus"

* Hold cs_main while calling GetMinableCommitment

* Abort processing of pending debug messages when spork18 gets disabled

* Don't ask for debug messages when we've already seen them

"statuses" only contains the current messages but none of the old messages,
so nodes kept re-requesting old messages.
2019-02-01 10:49:01 +03:00
Alexander Block
54f576ea7c
Fix LLMQ related test failures on Travis (#2666)
* Use fast_dip3_enforcement instead of fast_dip3_activation

DashTestFramework was refactored before ChainLocks got merged, causing tests
to fail now.

* Move updating of DKG debug status into WaitForNextPhase

Otherwise callers of the RPCs might believe that the next phase has already
started and start producing more blocks, which would then cancel the
current session if it happens faster than the phase handler thread can
progress to the next phase.
2019-01-30 14:05:22 +01:00
Alexander Block
6fe479aa12
Don't leak skShare in logs (#2662) 2019-01-30 14:05:04 +01:00
Alexander Block
f6828b19b6
Merge pull request #2643 from codablock/pr_llmq_chainlocks
Implement LLMQ based ChainLocks
2019-01-29 15:59:05 +01:00
UdjinM6
805aeaa16c Drop cs_main from UpdatedBlockTip in CDKGSessionManager/CDKGSessionHandler (#2655) 2019-01-29 15:55:18 +01:00
UdjinM6
25cb14b615 Fix confusion between dip3 activation and enforcement (#2651)
* Fix confusion between dip3 activation and enforcement

* drop DIP0003ActivationHeight for now
2019-01-29 15:54:38 +01:00
PastaPastaPasta
f123248f1c update copyright (#2648)
* update copyright

* Update copyright in configure.ac and COPYING
2019-01-29 15:53:14 +01:00
Alexander Block
3237668b1d Rename inInvalidate->inEnforceBestChainLock and make it atomic 2019-01-28 12:24:15 +01:00
Alexander Block
135829dc49 Add SPORK_19_CHAINLOCKS_ENABLED 2019-01-28 12:24:15 +01:00
Alexander Block
29532ba196 Implement and enforce ChainLocks 2019-01-28 12:24:15 +01:00
Alexander Block
04a51c9ef4 Use a block that is 8 blocks in the past for SelectQuorumForSigning
Otherwise nodes might already fail to verify sigs when just 1 block away
from the tip.
2019-01-28 12:24:15 +01:00
Alexander Block
cf33efc9e1 Move SelectQuorumForSigning into CSigningManager and make it height based 2019-01-28 12:24:15 +01:00
Alexander Block
4026ea203b Implement VerifyRecoveredSig to allow verifcation of sigs found in P2P messages 2019-01-28 12:24:15 +01:00
Alexander Block
9f211ef12d Add listener interface to listen for recovered sigs 2019-01-28 12:24:15 +01:00
Alexander Block
189cee2108 Don't pass poolSize to SelectQuorum and instead use consensus params 2019-01-28 12:24:15 +01:00
Alexander Block
13855674d7 Add missing new-line character in log output 2019-01-28 12:24:15 +01:00
UdjinM6
fda16f1fea
Fix off-by-1 in phase calculations and the rest of llmq-signing.py issues (#2641)
* Fix off-by-1 in phase calculations

* Fix wait_for_quorum_phase, should look for check_received_messages

* Fix wait_for_quorum_phase for complain phase

* Bump default timeout in wait_for_quorum_phase/wait_for_quorum_commitment to 15
2019-01-23 17:02:56 +03:00
Alexander Block
b595f9e6a1 Fix LLMQ signing integration tests (#2640)
* Fix cleanup of old recovered sigs

When iterating the db, we should also include entries that match exactly
the end time.

* Fix key not found error

* Raise AssertionError in case wait_for_quorum_phase/wait_for_quorum_commitment time out
2019-01-23 11:37:02 +03:00
UdjinM6
5977486897
Bring back ResetLocalSessionStatus call (#2639)
It was dropped accidentally on refactoring.
2019-01-23 11:34:31 +03:00
UdjinM6
d2ddc2a008
A couple of fixes/refactorings for CDKGSessionHandler (#2637)
* Fix confusion: `quorumHash` is both a class member and an argument of a function

Rename `height` too while at it

* Make sure height and hash we pass to InitNewQuorum are related

* Don't update expectedQuorumHash, make it const

This also streamlines logic a bit

* Compact phase calculation

* Decouple invCs and cs_vPendingMasternodes

Not an issue atm but we'd better avoid any potential interlocking if possible

* wrap `%` in `()`

Co-Authored-By: UdjinM6 <UdjinM6@users.noreply.github.com>
2019-01-22 16:33:42 +03:00
Alexander Block
b0ad1425e2 Review fixes (mostly if/else related but no change in logic) 2019-01-22 05:32:56 +01:00
Alexander Block
0cc1cf2798 Add receivedFinalCommitment flag to CDKGDebugSessionStatus 2019-01-21 14:42:08 +01:00
Alexander Block
c38f889e77 Implement processing, verifcation and propagation of signature shares 2019-01-21 14:42:08 +01:00
Alexander Block
43fd1b352f Implement CSigningManager to process and propagage recovered signatures 2019-01-21 14:42:08 +01:00
Alexander Block
b627528cef Use void as return type for WriteContributions 2019-01-17 15:25:43 +01:00
Alexander Block
217f3941d5 Skip starting of cache populator thread in case we don't have a valid vvec 2019-01-16 10:07:47 +01:00
Alexander Block
679a9895b6 Add comments about why it's ok to ignore some failures 2019-01-16 10:07:47 +01:00
Alexander Block
15c34ccbd8 Implement CQuorum and CQuorumManager 2019-01-15 15:47:24 +01:00
UdjinM6
8b7771a311 Add some consts 2019-01-11 13:45:32 +01:00
Alexander Block
0b1347c0d3 Pass self-created message to CDKGPendingMessages instead of processing them 2019-01-11 13:43:19 +01:00
UdjinM6
5daeedabf0 Batched logger should not break log parsing
It's expected to have timestamp to be the first thing in every row if it's not a whitespace
2019-01-11 07:07:54 +01:00
Alexander Block
5958f8b81d Remove dkgRndSleepTime from consensus params and make sleeping it non-random 2019-01-10 07:07:58 +01:00
Alexander Block
0dae46c2fb Move RandBool() into random.h/cpp 2019-01-09 12:16:12 +01:00
Alexander Block
e1901d24aa Handle review suggestions 2019-01-09 12:16:12 +01:00
Alexander Block
352edbd33e Introduce SPORK_18_QUORUM_DEBUG_ENABLED to enable/disable LLMQ debug messages 2019-01-09 12:16:12 +01:00
Alexander Block
324406bfed Implement debugging messages and RPC for LLMQ DKGs 2019-01-09 12:16:12 +01:00
Alexander Block
098b094959 Pass scheduler to InitLLMQSystem 2019-01-09 12:16:12 +01:00
Alexander Block
6836f8c38b Implement LLMQ DKG 2019-01-09 12:16:12 +01:00
Alexander Block
0df3871d14 Remove dummy DKG 2019-01-09 12:16:11 +01:00
Alexander Block
9d33d216b7 Remove temporary code which forked testnet at block 274000 2018-12-13 13:55:46 +01:00
UdjinM6
2127a426b8 Further refactoring of CQuorumBlockProcessor (#2545)
* Switch GetQuorumBlockHash from CBlockIndex* to nHeight

* `pindexPrev -> pindex` for ProcessCommitment

* Switch IsCommitmentRequired from CBlockIndex* to block height

* Switch GetMinableCommitment/Tx from CBlockIndex* to block height

* Add `AssertLockHeld(cs_main);`

Co-Authored-By: UdjinM6 <UdjinM6@users.noreply.github.com>
2018-12-13 09:04:08 +01:00
UdjinM6
15414dac29 Refactor CQuorumBlockProcessor and CDeterministicMNManager (#2536)
* Refactor CDeterministicMNManager::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly

* Refactor CQuorumBlockProcessor::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly

* Drop unused
2018-12-10 06:05:29 +01:00
Alexander Block
d9b28fe1ad
Introduce dummy (ping-like) contributions for the dummy DKG (#2542)
* Implement creation and propagation of dummy contributions

These act as a ping which is broadcast a few blocks before the dummy
commitments are created. They are meant to determine online/offline members.

* Use information about received dummy contributions to determine validMembers

* Fix PoSe tests

* Fix dummy DKG phase progress in PoSe tests and give tests more time

Mine one block at a time until we reach the mining phase.
2018-12-10 06:04:33 +01:00
Alexander Block
5a3f64310b Deserialize CFinalCommitmentTxPayload instead of CFinalCommitment in TxToJSON (#2510)
* Deserialize CFinalCommitmentTxPayload instead of CFinalCommitment in TxToJSON

* Implement ToJson for CFinalCommitmentTxPayload and use it in TxToJSON

Otherwise the nVersion and nHeight members of it are not shown.
2018-11-29 21:51:04 +03:00
Alexander Block
f96563462b
Fix check for nTemporaryTestnetForkDIP3Height (#2508)
This caused a crash when performing a full-sync.
2018-11-29 09:12:51 +01:00
Alexander Block
812834dc5f
Put height into mined commitments and use it instead of the special handling of quorumVvecHash (#2501)
* Allow to skip sig verification for CFinalCommitment::Verify

* Add CFinalCommitmentTxPayload and CheckLLMQCommitment and use it

As described in https://github.com/dashpay/dips/pull/31 (see discussion).

* Properly ban nodes for invalid commitments
2018-11-27 08:04:08 +01:00
Alexander Block
a4f5ba38b6
Implement CDummyDKG and CDummyCommitment until we have the real DKG merged (#2492)
* Add SPORK_17_QUORUM_DKG_ENABLED spork

* Implement CDummyDKG and CDummyCommitment until we have the real DKG merged

This is only used on testnet/devnet/regtest and will NEVER be used on
mainnet. It is NOT SECURE AT ALL!

See comment in quorums_dummydkg.h for more details.

* Test simple PoSe in DIP3 tests

* Generate 2 instead of 4 blocks per iteration in PoSe tests

4 was based on old chainparams where I used larger phases.

* Only sleep when necessary in PoSe tests

* Fix typo in comment

* Give PoSe tests more time and sync after fast-forward
2018-11-26 16:53:20 +01:00
Alexander Block
22b5952c5a
Implement and enforce DIP6 commitments (#2477)
* Add LLMQ parameters to consensus params

* Add DIP6 quorum commitment special TX

* Implement CQuorumBlockProcessor which validates and handles commitments

* Add quorum commitments to new blocks

* Propagate QFCOMMITMENT messages to all nodes

* Allow special transactions in blocks which have no inputs/outputs

But only for TRANSACTION_QUORUM_COMMITMENT for now.

* Add quorum commitments to self-crafted blocks in DIP3 tests

* Add simple fork logic for current testnet

This should avoid a fork on the current testnet. It only applies to the
current chain which activated DIP3 at height 264000 and block
00000048e6e71d4bd90e7c456dcb94683ae832fcad13e1760d8283f7e89f332f.

When we revert the chain to retest the DIP3 deployment, this fork logic
can be removed again.

* Use quorumVvecHash instead of quorumHash to make null commitments unique

Implementation of https://github.com/dashpay/dips/pull/31

* Re-add quorum commitments after pruning mempool selected blocks

* Refactor CQuorumBlockProcessor::ProcessBlock to have less nested if/else statements

Also add BEGIN/END markers for temporary code.

* Add comments/documentation to LLMQParams

* Move code which determines if a commitment is required into IsCommitmentRequired

This should make the code easier to read and also removes some duplication.

The also changes the error types that are possible from 3 to 2 now. Instead
of having "bad-qc-already-mined" and "bad-qc-not-mining-phase", there is
only "bad-qc-not-allowed" now.

* Use new parameter from consensus parames for the temporary fork
2018-11-23 15:42:09 +01:00