Commit Graph

102 Commits

Author SHA1 Message Date
Alexander Block
61e10f6512 Use llmqDb for CRecoveredSigsDb
Instead of creating its own CDBWrapper internally.
2019-03-08 17:34:09 +01:00
Alexander Block
b2cd1db406 Don't use CEvoDB in CDKGSessionManager and instead use llmqDb
Contributions are not part of on-chain consensus and shouldn't be stored in
CEvoDB.
2019-03-08 17:34:09 +01:00
Alexander Block
e2cad1bd69 Introduce global llmq::llmqDb instance of CDBWrapper
This DB is for LLMQ related data that is not part of on-chain consensus.
This for example included LLMQ secret key shares and recovered signatures.
2019-03-08 17:34:09 +01:00
Alexander Block
acb52f6ec1 Don't pass CEvoDB to CDKGSessionHandler and CDKGSession
Was never used.
2019-03-08 17:34:09 +01:00
Alexander Block
06fc655595 Actually remove from finalInstantSendLocks in CInstantSendManager::RemoveFinalISLock 2019-03-07 21:15:09 +01:00
Alexander Block
fae33e03ae Let ProcessPendingReconstructedRecoveredSigs return void instead of bool
Return value is unused and the method actually never returned something.
2019-03-07 21:15:09 +01:00
UdjinM6
41a71fe443 update autoix-mempool.py to test both "old" and "new" InstantSend (and fix CheckCanLock to respect mempool limits) 2019-03-07 21:15:09 +01:00
Alexander Block
2299ee2836 Rename IXLOCK to ISLOCK and InstantX to InstantSend 2019-03-07 21:15:09 +01:00
Alexander Block
f5dcb00acf Introduce spork SPORK_20_INSTANTSEND_LLMQ_BASED to switch between new/old system 2019-03-07 21:15:09 +01:00
Alexander Block
280690792a Combine loops in CChainLocksHandler::NewPoWValidBlock 2019-03-07 21:15:09 +01:00
Alexander Block
5b8344e8f8 Use scheduleFromNow instead of schedule+boost::chrono 2019-03-07 21:15:09 +01:00
Alexander Block
baf8b81c4a Fix no-wallet build 2019-03-07 21:15:09 +01:00
Alexander Block
2a7a5c6338 Only sign ChainLocks when all included TXs are "safe"
Safe means that the TX is either ixlocked or known since at least 10
minutes.

Also change miner code to only include safe TXs in block templates.
2019-03-07 21:15:09 +01:00
Alexander Block
96291e7a0f Cheaper/Faster bailout from TrySignChainTip when already signed before 2019-03-07 21:15:09 +01:00
Alexander Block
0a5e8eb862 Move ChainLock signing into TrySignChainTip and call it periodically
Later commits will introduce checks for "safe TXs" which might abort the
signing on first try, but succeed a few seconds later, so we periodically
retry to sign the tip.
2019-03-07 21:15:09 +01:00
Alexander Block
bd7edc8ae9 Track txids of new blocks and first-seen time of TXs in CChainLocksHandler 2019-03-07 21:15:09 +01:00
Alexander Block
83dbcc483f Implement CInstantSendManager and related P2P messages 2019-03-07 21:14:31 +01:00
Alexander Block
5bbc122749 Implement PushReconstructedRecoveredSig in CSigningManager
We can reconstruct recovered sigs from other P2P messages to avoid
re-validation of those. We will do this later in InstantSend code.
2019-03-07 21:14:31 +01:00
Alexander Block
2bbac8ff77 Introduce NotifyChainLock signal and invoke it when CLSIGs get processed 2019-03-07 21:14:31 +01:00
Alexander Block
8dd9349224
Don't be too harsh for invalid CLSIGs (#2742)
The local node might be the bad one actually as it might not have catched
up with the chain. In that case, LLMQs might be different for the sending
and receiving node.
2019-03-06 08:00:21 +01:00
Alexander Block
a34fb6d6f7 Fix banning when local node doesn't have the vvec (#2739)
When ProcessMessageBatchedSigShares returns false, it's interpreted as
if an invalid/malicious message was received, causing a ban. So, we should
return "!ban" instead of just "ban".
2019-03-05 14:04:04 +03:00
Alexander Block
9eb0ca7040 Ignore sig share inv messages when we don't have the quorum vvec (#2733)
* Ignore sig share inv messages when we don't have the quorum vvec

* Update src/llmq/quorums_signing_shares.cpp

Co-Authored-By: codablock <ablock84@gmail.com>
2019-03-01 18:30:11 +03:00
Alexander Block
2041186f4d
On timeout, print members proTxHashes from members which did not send a share (#2731)
* On timeout, print members proTxHashes from members which did not send a share

* Move inactive quorums check above timeout checks

This allows to reuse things in the next commit

* Avoid locking cs_main through GetQuorum by using a pre-filled map

* Use find() instead of [] to access quorums map
2019-03-01 08:21:42 +01:00
Alexander Block
ea90296b6d
Actually start the timers for sig share and recSig verification (#2730)
Was wondering why verification was always 0ms...this explains it :)
2019-03-01 08:21:28 +01:00
Alexander Block
5c84cab0f1
Send/Receive multiple messages as part of one P2P message in CSigSharesManager (#2729)
* Return bool in ProcessMessageXXX methods to indicate misbehaviour

* Send/Receive multiple messages as part of one P2P message in CSigSharesManager

Many messages, especially QSIGSHARESINV and QGETSIGSHARES, are very small
by nature (5-14 bytes for a 50 members LLMQ). The message headers are
24 bytes, meaning that we produce a lot of overhead for these small messages.
This sums up quite a bit when thousands of signing sessions are happening
in parallel.

This commit changes all related P2P messages to send a vector of messages
instead of a single message.

* Remove bogus lines

Included these by accident

* Unify handling of BanNode in ProcessMessageXXX methods

* Remove bogus check for fMasternodeMode

* Properly use == instead of misleading >= in SendMessages

* Put "didSend = true" near PushMessage
2019-03-01 08:21:09 +01:00
Alexander Block
6ac49da246 Send QSIGSESANN messages when sending first message for a session 2019-02-27 17:34:08 +01:00
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