Commit Graph

53 Commits

Author SHA1 Message Date
Oleg Girko
8da26da713 Eliminate g_connman use in spork module. (#1613)
Pass reference to CConnman instance to methods of CSporkManager and
CSporkMessage instead of using g_connman global variable.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
2017-09-07 18:58:38 +03:00
UdjinM6
4f5455000e Use GetAdjustedTime instead of GetTime when dealing with network-wide timestamps (#1590) 2017-08-29 02: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
b621cfb5fb Backport Bitcoin PR#8708: net: have CConnman handle message sending (#1553)
* serialization: teach serializers variadics

Also add a variadic CDataStream ctor for ease-of-use.

* connman is in charge of pushing messages

The changes here are dense and subtle, but hopefully all is more explicit
than before.

- CConnman is now in charge of sending data rather than the nodes themselves.
  This is necessary because many decisions need to be made with all nodes in
  mind, and a model that requires the nodes calling up to their manager quickly
  turns to spaghetti.

- The per-node-serializer (ssSend) has been replaced with a (quasi-)const
  send-version. Since the send version for serialization can only change once
  per connection, we now explicitly tag messages with INIT_PROTO_VERSION if
  they are sent before the handshake. With this done, there's no need to lock
  for access to nSendVersion.

  Also, a new stream is used for each message, so there's no need to lock
  during the serialization process.

- This takes care of accounting for optimistic sends, so the
  nOptimisticBytesWritten hack can be removed.

- -dropmessagestest and -fuzzmessagestest have not been preserved, as I suspect
  they haven't been used in years.

* net: switch all callers to connman for pushing messages

Drop all of the old stuff.

* drop the optimistic write counter hack

This is now handled properly in realtime.

* net: remove now-unused ssSend and Fuzz

* net: construct CNodeStates in place

* net: handle version push in InitializeNode
2017-07-27 17:28:05 +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
96f0d6ec2b various trivial cleanup fixes (#1501) 2017-07-03 16:14:07 +03:00
UdjinM6
98990b683a Refactor: CDarkSendSigner (#1410)
* Refactor: CDarkSendSigner -> CMessageSigner + CMasternodeBroadcast::IsVinAssociatedWithPubkey

* move IsVinAssociatedWithPubkey to CMasternode

* static IsVinAssociatedWithPubkey -> no params IsInputAssociatedWithPubkey
2017-04-12 10:04:06 +03:00
UdjinM6
8c6f756362 put some reasonable limits on SPORK_12_RECONSIDER_BLOCKS (#1312)
* put some reasonable limits on SPORK_12_RECONSIDER_BLOCKS

* 6h -> 24h
2017-02-04 04:42:04 +04:00
UdjinM6
f81ea67a08 Remove hashes from setAskFor (#1264)
We should remove hash from setAskFor when the message corresponding to previous inv arrives, otherwise it's stays there forever and setAskFor overflows (i.e. AskFor returns immediately without processing).
2017-01-18 00:02:59 +04:00
Holger Schinzel
e1702cd4ec bump copyright notice to 2017 (#1207) 2016-12-20 17:26:45 +04:00
UdjinM6
072b0fd708 fix annoying compiler warnings (#1204) 2016-12-14 17:33:46 +04:00
Tim Flynn
3e8c0062a0 Implement SPORK_14_REQUIRE_SENTINEL (#1163) 2016-11-23 19:30:36 +04:00
Nathan Marley
1f98bdff06 fix spork setPrivKey (#1051) 2016-09-30 02:19:00 +04:00
UdjinM6
7f687fd696 spork debug log: (#1016)
- add "spork" debug category
- move "seen" and "unknown" to new "spork" debug category to reduce log spam
- new/updated/seen messages should not overlap
2016-09-15 10:50:16 +04:00
UdjinM6
0597900c16 Changes for sporks: (#981)
- rename all 3 instantsend sporks
- remove SPORK_7_MASTERNODE_SCANNING (not used anymore)
- change `_DEFAULT` for spork 2 and 3, adjust comments for for them
- fix GetSporkNameByID() (should not return smth_DEFAULT)
2016-09-01 18:55:25 +04:00
UdjinM6
0cf75d0ef7 Merge #974: Slightly refactor sporks
6648716 Slightly refactor sporks, rename spork9 to SPORK_9_SUPERBLOCKS_ENABLED, remove SPORK_11_RESET_BUDGET (not used anymore)
2016-08-29 21:16:02 +02:00
UdjinM6
67def9ef2e Merge #948 Refactor CDarkSendSigner
f0ed400 darkSendSigner.SignMessage() should not return error message

154f1b6 darkSendSigner.VerifyMessage() should return non-localized message, its callers should populate error to debug.log

b130c32 darkSendSigner.GetKeysFromSecret() should not return error message, its callers should handle it
2016-08-19 05:50:04 -06:00
Tim Flynn
de7b2b6c51 Merge #944: V0.12.1.x governance pr - part 1 - base functionality
068c178 Added DBG macro in util.h to facilitate debugging

    - This macro allows debugging statements (typically printf's or cout's) to
      be activated or deactivated with a single comment.  Uncomment the line:
      //#define ENABLE_DASH_DEBUG
      in util.h to enable debugging statements.

    - When commented any code wrapped with the DBG() macro will simply be removed
      by the preprocessor.  When not commented all such wrapped statements will
      be present.

    - For maximum effectiveness it is best that util.h be the first effective include
      in all source files.  It is also possible to enable the macro for a single file
      by temporarily adding #define ENABLE_DASH_DEBUG to the top of the file.

    - Code committed to non-development branches should always have the define
      commented.

d125d9b V0.12.1.x -- merging trigger/generic object/superblock changes for testnet phase II

    - This commit contains the core governance system changes for 0.12.1.  Any unrelated
      changes have either been removed or moved to separate commits.

120724c File mode fixes

    - Changed mode 0755->0644 on several source files.

c7f9e11 Updated todo reminders

    - Added reminder to revert temporary reduction of number of votes
      required to trigger superblock to 1 for testing

92adc98 Made CSuperblockManager::IsValidSuperblockHeight an inline function

    - This is for efficiency since this function is called often and is
      only 1 line of code.

c050ed7 Added comment explaining rationale for no LOCK(cs) in CSuperblock::IsValid

dc933fe Removed unused CSuperblockManager::IsBlockValid function

decec88 Moved calls to SuperblockManager::IsValidSuperblockHeight into IsSuperblockTriggered.

    - Since calls to the later function are always protected by the former there's
      no reason to keep these separate and this simplifies the code in
      masternode-payments.cpp.

8672885 Reestablished expected value check for non-superblocks in IsBlockValueValid

b01cbe0 Changes to IsBlockValueValid to fix rpc test failure

a937c76 Changed include order to allow per file activation of the DBG macro

d116aa5 Fixed IsValidSuperblockHeight logic

    - Note this has an effect on testing because we can now only create
      1 superblock per day.  Devs may need to temporarily change testnet params
      for easier testing.

2d0c2de Convert superblock payments to CAmount

    - We assume that payment values in JSON are in units of DASH
      for consistency with other RPC functions, such as
      createrawtransaction.

376b833 Revert temporary testing value for nAbsVoteReq

    - Also ensure that number of votes required is never smaller than 1

8c89f4b Cleaned up CSuperblock error handling

    - Exceptions are now thrown consistently rather than using a mix of
      exceptions and return code checking.  Exceptions are now caught only
      in AddNewTrigger when the CSuperblock constructor is called.  Unnecessary object
      status members have been removed.

d7c8a6b Removed utilstrencodings header

    - This appears to help with travis tests, for unknown reasons.

c4dfc7a Fixed some minor code review issues

63c3580 Reverted locking change in miner.

    - This should have been done in the original PR but was overlooked.

4ab72de Fixed variable name to match common practice and bracket formatting

886a678 Improvements to vote conversion code

    - Replaced redundantly defined function with inclusion of governance-vote.h

    - Replaced magic numbers with their corresponding constant symbols

0a37966 Reordered governance message handling
2016-08-17 09:08:25 +02:00
UdjinM6
5a8c0c9b9d Merge #928: Refactor All The Things - part1
86d8505 Refactor CActiveMasternode
+ move strMasterNodeAddr to CActiveMasternode

a005c79 Refactor InstantSend
+ new lock cs_instantsend to protect maps on CleanTransactionLocksList()
+ new DEFAULT_INSTANTSEND_DEPTH constant
+ rename MIN_INSTANTX_PROTO_VERSION to MIN_INSTANTSEND_PROTO_VERSION and bump it

d24182c Refactor Privatesend
+ decouple from util.h and version.h
+ more functions for CDarksendBroadcastTx: constructors, signing, serialization
+ move from rand() to insecure_rand() in general but to GetRand() for session id
+ fix defaults
2016-08-05 21:49:45 +02:00
UdjinM6
d514ee7f9a Merge #922: Refactor/fix spork
42bdf42 Refactor/fix spork:
- move ProcessSpork, GetSporkValue, IsSporkActive, ExecuteSpork and mapSporksActive to CSporkManager
- move Sign, CheckSignature, Relay to CSporkMessage
- move ReprocessBlocks out of sporks to main.cpp / rename DisconnectBlocksAndReprocess to DisconnectBlocks
- rename SporkKey to SporkPubKey
- bugfix: only set strMasterPrivKey if spork signature produced by that key was verified successfully
- few log format changes, cleaned up includes
2016-07-30 13:04:27 +02:00
Evan Duffield
6a68aea461 cleanup 2016-04-14 19:54:11 -07:00
UdjinM6
67cd10c87d Add some locks to protect chainActive.Tip() and mapBlockIndex
(fixing only few of them here, see next commit for further changes)
2016-03-04 12:10:37 +03:00
UdjinM6
c676748beb Replace all hardcoded network message strings with NetMsgType:: constants, log unknown commands (net debug category only) 2016-02-19 07:59:00 +03:00
UdjinM6
a5ac60b868 Merge remote-tracking branch 'bitcoin/0.12' into HEAD
+ merge fixes
+ keepass on evhttp
2016-02-06 16:48:04 +03:00
evan82
6bd1d7d16e Merge pull request #532 from UdjinM6/v0.12.0.x_fix_GetSporkValue
fix GetSporkValue
2015-08-15 13:30:21 -07:00
UdjinM6
1289327743 fix GetSporkValue 2015-08-15 16:34:38 +03:00
Evan Duffield
6040fc6f83 fix GetSporkValue return 2015-08-14 12:57:41 -07:00
Evan Duffield
cfe1bdd1e2 fix spork int error 2015-08-14 11:43:28 -07:00
Evan Duffield
bb5570015f Keep track of and reprocess rejected blocks 2015-08-04 18:05:57 -07:00
Evan Duffield
334c3ea971 Added ReprocessBlocks 2015-08-02 16:08:37 -07:00
Evan Duffield
f6721cbe17 Reconsider : typo, use i and break 2015-08-02 15:50:27 -07:00
Evan Duffield
d80feacc8e Reprocess before disconnect for rescan 2015-08-02 14:59:28 -07:00
evan82
718c7f14f9 Merge pull request #384 from UdjinM6/v0.12.0.x_debug_categories
V0.12.0.x additional debug categories
2015-08-01 15:48:03 -07:00
Evan Duffield
44c99417d2 disable block cache / fix reprocess 2015-08-01 01:51:30 -07:00
UdjinM6
dd8fa7c365 Continue work on more debug categories
- rebased to latest v12
- masternode, mnpayments, mnbudget and keepass categories
- remove c_str in logprint(f)
2015-07-31 19:01:18 +03:00
Evan Duffield
e03879b3cf Update spork name : SPORK_10_MASTERNODE_PAY_UPDATED_NODES 2015-07-27 08:28:10 -07:00
Evan Duffield
7101c951f8 Budget Improvements
- Client bump
- Improved syncing logic (sholud stop hanging issues)
- New spork for turning on super blocks
- Fixed issue with sending old/invalid finalized budgets
- Fixed issue with syncing clients and lack of confirmations with budget items (for IX)
2015-07-16 20:03:42 -07:00
Evan Duffield
e5f37b8c98 New Spork : Reconsider X Blocks
- This allows us to fix forks remotely without anyone having to reindex. It remains trustless, because all nodes will simply find the longest chain.
2015-07-16 11:06:45 -07:00
Evan Duffield
8a5ebeaa62 added spork for reseting budget 2015-07-08 10:25:47 -07:00
UdjinM6
9cfdaffee5 introduce RelayInv 2015-07-08 04:31:10 +03:00
Evan Duffield
2b75faefee Various fixes improvements
- Implemented spork for only paying new nodes after a period of time on mainnet
- protocol bump
- fixed a few issues with sporks. Spork show now shows all sporks, instead of the changed ones. IsSporkActive now supports sporks set to 0 as on.
2015-06-25 12:59:11 -07:00
Evan Duffield
e3963ea71c Spork changes / improvements
- New Command "Spork Active" : Show which sporks report as active
- Cleaned up the spork code and fixed some bugs with defaults
2015-06-25 08:17:53 -07:00
Evan Duffield
eaf7b940a6 Complete rewrite of consensus code for mn/budget payments
- Added FindProposal and FindFinalBudget to budgeting class
- Added 2 new sporks for Proposals and Budget payment enforcement. This is outside of the decentralized code so we can turn it off if there's a problem.
- Detect budget blocks and pay correct amounts in super blocks
2015-05-30 10:27:51 -07:00
UdjinM6
3cfd9538d5 Merge branch 'master' into merge_btc010 2015-04-10 19:32:57 +03:00
UdjinM6
debcbb75b1 do not search for known sporks by hash, search only by ID 2015-04-07 18:17:50 +03:00
UdjinM6
64eebc3316 0.12 dirty merge'n'fix (bitcoin 0.10) 2015-04-04 19:24:37 +03:00
Evan Duffield
e5267319ef Complete implementation of Proof-of-Service
- Ensures ports remain open and client are responsive to IX requests.
- Completely 100% decentralized. This farms out the work of checking the masternode network to the masternode network. 1% of the network is determistically selected to check another 1% of the network each block. It takes six separate checks to deactivate a node, thus making it tamper proof.
- Nodes are kept in the masternode list if they fail enough PoSe checks to deactivate. They will continue to be checked until the operator fixes them. However they will not be paid while they're failing checks.
2015-03-16 09:32:18 -07:00
Evan Duffield
848adbb2d3 Fixed compiling errors
std::stoi was introduced in C++11, should probably avoid using it
2015-02-26 07:23:06 -07:00
Evan Duffield
662d01733d added spork for resolving forks 2015-02-11 21:21:28 -07:00
Evan Duffield
c8c4cc48f2 fix propagation of spork messages 2015-02-11 13:40:54 -07:00