Commit Graph

164 Commits

Author SHA1 Message Date
gladcow
ace980834f Extend Bloom Filter support to InstantSend related messages (#2184)
* use bloom filters for IX lock votes

* code style fixes
2018-07-20 16:32:41 +03:00
Nathan Marley
42c193df08 replace map count/insert w/emplace in instantx.cpp (#2165)
* replace map count/insert w/emplace in instantx.cpp

This feels like an optimization, something about:

```
if map.count(key)
     return false
else
     insert(pair)
     return true
```

... just feels icky. Plus, `vote.GetMasternodeOutpoint()` is only called
once. The previous version might be slightly more readable, however.

* use std::pair template constructor shortcut
2018-07-12 12:08:22 +03:00
Nathan Marley
fd70a1eb92 iterator cleanup in several places (#2164)
* iterator cleanup in Dash-specific code

* const

* *Pair/pair

* it++ -> ++it
2018-07-12 12:07:51 +03:00
gladcow
2c0d4c9d77 Save/load InstantSend cache (#2051)
* CTxLockCandidate serialization

* COutPointLock serialization

* CInstantSend serialization

* Read/write instantsend.dat file

* Read\write InstantSend cache only if InstantSend is enabled
2018-07-12 12:01:48 +03:00
UdjinM6
8c2d16f5f3
Limit IS quorums by updated MNs only (#2107) 2018-06-11 13:14:24 +03:00
thephez
ef85d5144d Comment updates - InstantSend (#2062)
* [Comment] - Minor Instantx comment updates and additions

* [Comment] - Update to doxygen recognised format
 - Capitalisation changes

* [Comment] - Add some minor InstantSend comments
2018-05-13 23:58:01 +03:00
Nathan Marley
8e24b087b4 replace boost iterators in dash-specific code (#2048) 2018-04-23 13:25:04 +03:00
UdjinM6
b07503f013
Some cleanup (mostly trivial) (#2038)
* Drop CInstantSend::IsEnoughOrphanVotesForTxAndOutPoint

* small cleanup in rpc tests

* move some pieces from .h to .cpp

* fix few log outputs

* fix some comments

* some trivial fixes + readability
2018-04-20 13:53:23 +03:00
Alexander Block
c0a1099986 Fix instantsend in testnet and regtest (#2016)
#1962 changes the minimum required confirmations for InstantSend to 2 when
running in testnet. This resulted in the quorum rank calculation to pick
blocks which are higher then the current chain tip. This commit fixes this
by calculating the added height based on nInstantSendConfirmationsRequired.

This results in the value 4 for mainnet, so no incompatibility is
introduced. On testnet and regtest, this results in 0.
2018-03-29 18:08:24 +03:00
UdjinM6
c0c998da35
Fix CInstantSend::GetTxLockRequest() (#2006)
Should fail for empty lock request
2018-03-21 14:09:28 +03:00
UdjinM6
08033ffe4f
Reject Dash-specific messages from obsolete peers (#1983)
And send REJECT msg back to the peer we received the original message from.
Same logic as for MIN_PEER_PROTO_VERSION but using specific proto versions for each submodule.
2018-03-15 12:21:43 +03:00
UdjinM6
7d5223b5e4
Network-specific thresholds for required confirmations (IS) (#1962) 2018-03-10 15:35:09 +03:00
UdjinM6
ca3655f494
Fix some (potential dead)locks (#1977)
* Avoid locking cs_main in CMasternode/Ping/Broadcast

Deligate this to CMasternodeMan and use AssertLockHeld instead

* Ensure consistent locking order (cs_main, cs_wallet, mempool.cs, cs_instantsend) in CInstantSend while avoiding potential deadlocks at the same time

* Add missing locks in wallet

* Add missing locks in governance

* Fix cs_vPendingMasternodes vs cs_main potential deadlock

SendVerifyRequest no longer opens connection directly, so no cs_main is needed here
2018-03-09 17:15:48 +03:00
UdjinM6
2c04504f1c
Refactor IS votes processing (#1951)
Also make sure orphans are actually processed
2018-02-25 08:33:40 +03:00
UdjinM6
6a6e4cdc1b Remove remaining using namespace std 2018-02-21 22:32:13 +03:00
UdjinM6
99273f63aa
Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (#1937)
* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (gobject)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (gobjvote)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (mnw)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (txlvote)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (dsq)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (dstx)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (spork)

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (mnb)

* Actually care about old signature format in mnp, otherwise we can start banning peers rather quickly

* Use SPORK_6_NEW_SIGS to switch from signing string messages to hashes (mnv)

* Unify sign/verify code a bit by using GetSignatureHash() (even when it matches GetHash())

* fix docs

* address review comments

* fix log output (copy/paste error)

* Replace custom GetSignatureHash/GetHash with serialization (where applicable)

* Convert from/to old format in SerializationOp only for p2p

* fix
2018-02-16 17:54:53 +03:00
UdjinM6
a7fa07a30e
Drop BOOST_FOREACH and use references in loops (const ref where applicable, Dash code only) (#1899)
* Drop BOOST_FOREACH in Dash-specific code (only), no changes in behavior

* Use references in loops (use const references where applicable) in Dash-specific code (only)

And adjust related code to make it compilable.

* Loop through nodes via connman.ForEachNode in dsq Relay instead of creating a copy
2018-02-06 14:09:33 +03:00
UdjinM6
054abdbfa4
Merge pull request #1867 from codablock/pr_backport_bitcoin_0.14-10
Backport missing PRs from Bitcoin 0.14 - Part 10
2018-01-26 14:55:56 +03:00
UdjinM6
88646bd0d0
Rename fMasterNode to fMasternodeMode to clarify its meaning and to avoid confusion with CNode::fMasternode (#1874) 2018-01-26 04:11:01 +03:00
Wladimir J. van der Laan
52819ca9b9 Merge #9763: [Trivial] Update comments referencing main.cpp
00e623d [Trivial] Update comments referencing main.cpp (CryptAxe)
2018-01-23 09:24:29 +01:00
Wladimir J. van der Laan
3f1929fb0d Merge #9659: Net: Turn some methods and params/variables const
0729102 Net: pass interruptMsgProc as const where possible (Jorge Timón)
fc7f2ff Net: Make CNetMsgMaker more const (Jorge Timón)
d45955f Net: CConnman: Make some methods const (Jorge Timón)
2018-01-23 09:24:27 +01:00
Wladimir J. van der Laan
dcc9dffae9 Merge #9236: Fix races for strMiscWarning and fLargeWork*Found, make QT runawayException use GetWarnings
749be01 Move GetWarnings() into its own file. (Gregory Maxwell)
e3ba0ef Eliminate data races for strMiscWarning and fLargeWork*Found. (Gregory Maxwell)
c63198f Make QT runawayException call GetWarnings instead of directly access strMiscWarning. (Gregory Maxwell)
2018-01-18 07:31:22 +01:00
Wladimir J. van der Laan
525c049316 Merge #8580: Make CTransaction actually immutable
81e3228 Make CTransaction actually immutable (Pieter Wuille)
42fd8de Make DecodeHexTx return a CMutableTransaction (Pieter Wuille)
c3f5673 Make CWalletTx store a CTransactionRef instead of inheriting (Pieter Wuille)
a188353 Switch GetTransaction to returning a CTransactionRef (Pieter Wuille)
2018-01-17 17:30:38 +01:00
Alexander Block
1e62969fa6 Preparations for upcoming backport of Bitcoin #8580
Instead of deriving from CTransaction, we now have a CTransactionRef member
in CTxLockCandidate. This is needed for the next backported PR #8580,
which will make CTransaction immutable.

Also use CTransactionRef in CDarkSendEntry, CDarksendBroadcastTx and
CPrivateSendServer
2018-01-17 17:30:38 +01:00
Alexander Block
e3da73ebf8 Update Dash related code to use new SyncTransaction notifications interface 2018-01-08 18:41:06 +01:00
UdjinM6
38e505842a
Vote on IS only if it was accepted to mempool (#1826) 2018-01-06 13:06:43 +03:00
Wladimir J. van der Laan
ca699cebaa Merge #8126: std::shared_ptr based CTransaction storage in mempool
288d85d Get rid of CTxMempool::lookup() entirely (Pieter Wuille)
c2a4724 Optimization: use usec in expiration and reuse nNow (Pieter Wuille)
e9b4780 Optimization: don't check the mempool at all if no mempool req ever (Pieter Wuille)
dbfb426 Optimize the relay map to use shared_ptr's (Pieter Wuille)
8d39d7a Switch CTransaction storage in mempool to std::shared_ptr (Pieter Wuille)
1b9e6d3 Add support for unique_ptr and shared_ptr to memusage (Pieter Wuille)
2017-12-22 16:33:56 +01:00
Pieter Wuille
7b25879463 Merge #8059: Remove unneeded feerate param from RelayTransaction/AcceptToMemoryPool.
d87b198 Remove unneeded feerate param from RelayTransaction/AcceptToMemoryPool. (Gregory Maxwell)
2017-12-21 18:50:13 +01:00
Alexander Block
aa584522da Dash related changes for feefilter 2017-12-19 13:18:30 +01:00
UdjinM6
3028af19f1
post-DIP0001 cleanup (#1763)
* post-DIP0001 cleanup

also fixes tests

* bump nMinimumChainWork and defaultAssumeValid
2017-12-07 12:43:23 +03:00
UdjinM6
4802a1fb71
Allow IS for all txes, not only for txes with p2pkh and data outputs (#1760) 2017-12-07 12:43:08 +03:00
UdjinM6
c5ec2f82a8
Drop IsNormalPaymentScript, use IsPayToPublicKeyHash (#1761) 2017-12-07 04:33:51 +03:00
UdjinM6
c166ed39b0
Allow compilation with --disable-wallet (#1733)
* Allow compilation with `--disable-wallet`

* fix remaining references

* Drop wallet references/include in CActiveMasternode and fix other files affected by this change

* Wrap privatesend-client.h include with ifdef/endif and fix other files affected by this change

* Re-enable Travis build with no wallet

reverts 267e57877b
2017-12-01 21:53:34 +03:00
UdjinM6
5d58dd90c2
Make sure to clear setAskFor in Dash submodules (#1730)
* Make sure to clear setAskFor in Dash submodules

Thanks @sidhujag for finding the bug

* partially revert previous commit

* skip mnv until mn list is synced
2017-11-22 17:27:06 +03:00
UdjinM6
89f326c6da Merge branch 'master' into develop 2017-11-12 19:18:08 +03:00
UdjinM6
a9293ad039
update setAskFor on TXLOCKVOTE (#1713) 2017-11-03 14:19:13 +03:00
Alexander Block
9ad56fe18a Dash related fixes for per-utxo DB 2017-10-31 21:19:11 +01:00
UdjinM6
470e5435c0
remove InstantSend votes for failed lock attemts after some timeout (#1705) 2017-10-31 17:50:03 +03:00
Oleg Girko
753b1e486b Eliminate remaining uses of g_connman in Dash-specific code. (#1635)
This monstrous change eliminates all remaining uses of
g_connman global variable in Dash-specific code.

Unlike previous changes eliminating g_connman use
that were isolated to particular modules, this one covers
multiple modules simultaneously because they are so interdependent
that change in one module was quickly spreading to others.

This is mostly invariant change that was done by
* changing all functions using g_connman to use connman argument,
* changing all functions calling these functions to use connman argument,
* repeating previous step until there's nothing to change.

After multiple iterations, this process converged to final result,
producing code that is mostly equivalent to original one, but passing
CConnman instance through arguments instead of global variable.

The only exception to equivalence of resulting code is that I had to
create overload of CMasternodeMan::CheckAndRemove() method without arguments
that does nothing just for use in CFlatDB<CMasternodeMan>::Dump() and
CFlatDB<CMasternodeMan>::Load() methods.
Normal CMasternodeMan::CheckAndRemove() overload now has argument of
CConnman& type and is used everywhere else.

The normal overload has this code in the beginning:

    if(!masternodeSync.IsMasternodeListSynced()) return;

Masternode list is not synced yet when we load "mncache.dat" file,
and we save "mncache.dat" file on shutdown, so I presume that it's OK
to use overload that does nothing in both cases.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
2017-09-19 17:51:38 +03:00
UdjinM6
8f850c60fa Lower tx fees 10x (#1632)
* Lower tx fees 10x

* add DEFAULT_DIP0001_*FEE constants
2017-09-17 19:00:44 +03:00
Oleg Girko
4956ba7a7f Eliminate g_connman use in instantx module. (#1626)
Pass reference to CConnman instance to methods of CInstantSend
and other instantsend-related classes instead of using g_connman
global variable there.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
2017-09-15 21:05:13 +03:00
UdjinM6
d7a8489f31 Fix masternode score/rank calculations (#1620)
* fix CMasternode::CalculateScore, new mn score algo activation is triggered by DIP0001 lock-in

* unify rank calculation, base it on full mn vector rather than using active mns only

* bump CMasternodeMan::SERIALIZATION_VERSION_STRING

* unify rank calculations even further

* fix (partially revert previous one)
2017-09-14 16:58:29 +03:00
UdjinM6
84ecccefce InstandSend overhaul (#1592)
* InstandSend overhaul
- relay conflicting votes to detect attack earlier and PoSe-ban attacking masternode(s)
- cancel conflicting completed locks
- do not overwrite mempool or reprocess blocks
- 15 sec timeout/window to lock tx

* check nValueIn for SPORK_5_INSTANTSEND_MAX_VALUE (instead of nValueOut)

* relay valid vote asap

* ignore votes for spent coins, consider them invalid
2017-09-14 14:41:40 +03:00
UdjinM6
05da4557d0 Refactor masternode management (#1611)
* Store masternodes in a map instead of a vector, drop unused functions in CMasternodeMan

* CTxIn vin -> COutPoint outpoint

* do not use CMasternodeMan::Find outside of the class

* update GetMasternodeInfo

* safe version of GetNextMasternodeInQueueForPayment

* fix ProcessMasternodeConnections

* bump CMasternodeMan::SERIALIZATION_VERSION_STRING
2017-09-11 17:13:48 +03:00
UdjinM6
fe81d641da drop pCurrentBlockIndex and use cached block height instead (nCachedBlockHeight) (#1579) 2017-08-25 15:57:05 +03:00
UdjinM6
23582aea45 add/use GetUTXO[Coins/Confirmations] helpers instead of GetInputAge[IX] (#1578)
(also move IS confirmations calculation helper to CInstantSend)
2017-08-25 15:56:48 +03:00
Ilya Savinov
4a9fbca080 Fix potential deadlock in CInstantSend::UpdateLockedTransaction (#1571)
* cs_wallet -> cs_instantsend:

getinfo(...) - LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL)
  CAmount CWallet::GetBalance() const - LOCK2(cs_main, cs_wallet)
    CWalletTx::IsTrusted()
      GetDepthInMainChain()
        CInstantSend::IsLockedInstantSendTransaction(...) - LOCK(cs_instantsend)

cs_wallet -> cs_instantsend:

CWallet::ReacceptWalletTransactions() - LOCK2(cs_main, cs_wallet)
  GetDepthInMainChain()
    CInstantSend::IsLockedInstantSendTransaction(...) - LOCK(cs_instantsend)

cs_instantsend -> cs_wallet:

void CInstantSend::UpdateLockedTransaction(...) - LOCK(cs_instantsend)
  CWallet::UpdatedTransaction(...) - LOCK(cs_wallet)

* AssertLockHeld added
2017-08-11 21:51:44 +03:00
Oleg Girko
df6d458b85 Backport Bitcoin PR#9260: Mrs Peacock in The Library with The Candlestick (killed main.{h,cpp}) (#1566)
* Remove orphan state wipe from UnloadBlockIndex.

As orphan state is now "network state", like in
d6ea737be1,

UnloadBlockIndex is only used during init if we end up reindexing
to clear our block state so that we can start over. However, at
that time no connections have been brought up as CConnman hasn't
been started yet, so all of the network processing state logic is
empty when its called.

* Move network-msg-processing code out of main to its own file

* Rename the remaining main.{h,cpp} to validation.{h,cpp}
2017-08-09 03:19:06 +03:00
Oleg Girko
a9d771e497 Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp

This will eventually solve a circular dependency

* net: Create CConnman to encapsulate p2p connections

* net: Move socket binding into CConnman

* net: move OpenNetworkConnection into CConnman

* net: move ban and addrman functions into CConnman

* net: Add oneshot functions to CConnman

* net: move added node functions to CConnman

* net: Add most functions needed for vNodes to CConnman

* net: handle nodesignals in CConnman

* net: Pass CConnection to wallet rather than using the global

* net: Add rpc error for missing/disabled p2p functionality

* net: Pass CConnman around as needed

* gui: add NodeID to the peer table

* net: create generic functor accessors and move vNodes to CConnman

* net: move whitelist functions into CConnman

* net: move nLastNodeId to CConnman

* net: move nLocalHostNonce to CConnman

This behavior seems to have been quite racy and broken.

Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.

* net: move messageHandlerCondition to CConnman

* net: move send/recv statistics to CConnman

* net: move SendBufferSize/ReceiveFloodSize to CConnman

* net: move nLocalServices/nRelevantServices to CConnman

These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).

* net: move semOutbound and semMasternodeOutbound to CConnman

* net: SocketSendData returns written size

* net: move max/max-outbound to CConnman

* net: Pass best block known height into CConnman

CConnman then passes the current best height into CNode at creation time.

This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.

This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.

This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.

* net: pass CClientUIInterface into CConnman

* net: Drop StartNode/StopNode and use CConnman directly

* net: Introduce CConnection::Options to avoid passing so many params

* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options

* net: move vNodesDisconnected into CConnman

* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting

* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead

* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 12:35:19 +03:00
UdjinM6
bea548c612 adjust/fix some log and error messages (#1484)
* adjust/fix some log and error messages

* revert penalty

* more newline/c_str fixes

* lld -> llu
2017-06-06 02:47:23 +03:00