From 0bb4504566f2e0bd2026bc8ac35046b8d0000aff Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 11:07:06 -0600 Subject: [PATCH 01/27] Added code to bypass per block verification when not close to chain tip -base on code by barrysty1e --- configure.ac | 2 +- src/chainparams.cpp | 3 ++- src/main.cpp | 47 ++++++++++++++++++++++++++++++++------------- src/main.h | 5 ++++- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index a37f12e..5e7dc2f 100755 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 1) define(_CLIENT_VERSION_MINOR, 3) define(_CLIENT_VERSION_REVISION, 1) -define(_CLIENT_VERSION_BUILD, 18) +define(_CLIENT_VERSION_BUILD, 20) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2018) AC_INIT([NewYorkCoin],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/NewYorkCoin-NYC/nycoin/issues],[newyorkcoin]) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9de2556..965b556 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -158,7 +158,8 @@ class CMainParams : public CChainParams { (3000000, uint256S("0x66e6dcb49370062537c1f6abf655ffbbc53ba4851ef00081aa2e4be1e2903ba7")) (3500000, uint256S("0x3f1a97f68ce8eaf38fc0c56868b3eb98ccb67d14bff4e78afb91d82cba853ddf")) (3938415, uint256S("0xe1fa41f6fe8d2785d89b0468e13e4c450493e5356c024a098c5b727ca89138ee")) - (4500000, uint256S("0xdd86fad58b3fa5d83a15a18df1cc20cdcdb1b2cf5d2d702e0c60bbb7d4602fb1")), + (4500000, uint256S("0xdd86fad58b3fa5d83a15a18df1cc20cdcdb1b2cf5d2d702e0c60bbb7d4602fb1")) + (4821195, uint256S("0x7cf9862123405a687626b27ecaea377698d23d68458bb9b2a16e0262ec32df84"))), 1514765144, // * UNIX timestamp of last checkpoint block 5141422, // * total number of transactions between genesis and last checkpoint diff --git a/src/main.cpp b/src/main.cpp index e022347..a695cd7 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2696,6 +2696,20 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { + // Shortcut checks for almost all early blocks + if(chainActive.Height() < SKIP_VALIDATION_HEIGHT) + { + const CChainParams& chainParams = Params(); + // hit all the checkpoints but skip most of the rest + std::map::iterator cpItr = chainParams.checkpoints().MapCheckpoints.find(block.GetHeight()); + + // if the current block is not found in the checkpoints list, skip it + if(cpItr == chainParams.checkpoints().MapCheckpoints.end()) + { + return true; + } + } + // These are checks that are independent of context. // Check that the header is valid (particularly PoW). This is mostly @@ -2872,22 +2886,29 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return true; } - if (!CheckBlockHeader(block, state)) - return false; + // Since we're close to chaintip, reenable checks to ensure state is correct when sync completes + if(chainActive.Height() >= SKIP_VALIDATION_HEIGHT) + { + if (!CheckBlockHeader(block, state)) + return false; - // Get prev block index - CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus(0).hashGenesisBlock) { - BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); - if (mi == mapBlockIndex.end()) - return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); - pindexPrev = (*mi).second; - if (pindexPrev->nStatus & BLOCK_FAILED_MASK) - return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); + // Get prev block index + CBlockIndex* pindexPrev = NULL; + if (hash != chainparams.GetConsensus(0).hashGenesisBlock) { + BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); + if (mi == mapBlockIndex.end()) + return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + pindexPrev = (*mi).second; + if (pindexPrev->nStatus & BLOCK_FAILED_MASK) + return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); + } + + if (!ContextualCheckBlockHeader(block, state, pindexPrev)) + return false; } - if (!ContextualCheckBlockHeader(block, state, pindexPrev)) - return false; + + if (pindex == NULL) pindex = AddToBlockIndex(block); diff --git a/src/main.h b/src/main.h index 58484b5..04c287f 100755 --- a/src/main.h +++ b/src/main.h @@ -53,6 +53,9 @@ static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0; static const unsigned int DEFAULT_FEE = 0; + +/** Don't validate every block below this height **/ +static const int SKIP_VALIDATION_HEIGHT = 4500001; /** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 27000; /** Default for accepting alerts from the P2P network. */ @@ -76,7 +79,7 @@ static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; /** Number of blocks that can be requested at any given time from a single peer. */ -static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; +static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 128; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends From b5a0a3839c5e6c47ccec89281b8363bb200ffcac Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 12:28:19 -0600 Subject: [PATCH 02/27] changed git build target for experimental builds --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 9e25301..96053f0 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -20,7 +20,7 @@ packages: - "zip" reference_datetime: "2015-06-01 00:00:00" remotes: -- "url": "https://github.com/NewYorkCoin-NYC/nycoin.git" +- "url": "https://github.com/MrSlosh/nycoin.git" "dir": "nycoin" files: [] #x86_64-w64-mingw32 From 1bbbb0b3b77f3ff320c6949cf4c593be65c1a2d5 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 12:44:47 -0600 Subject: [PATCH 03/27] adding local build directory for gbuild --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 96053f0..099e483 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -21,7 +21,7 @@ packages: reference_datetime: "2015-06-01 00:00:00" remotes: - "url": "https://github.com/MrSlosh/nycoin.git" - "dir": "nycoin" + "dir": "nycx/nycoin" files: [] #x86_64-w64-mingw32 script: | From c0a65b08e89cbf234499c0de8aefe19b29f12518 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 12:49:03 -0600 Subject: [PATCH 04/27] sanitizing string? --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 099e483..8ecbdd7 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -21,7 +21,7 @@ packages: reference_datetime: "2015-06-01 00:00:00" remotes: - "url": "https://github.com/MrSlosh/nycoin.git" - "dir": "nycx/nycoin" + "dir": "nycx//nycoin" files: [] #x86_64-w64-mingw32 script: | From 006052b4ba03b73ba6e754b26202c5f7aaaafa98 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 12:51:17 -0600 Subject: [PATCH 05/27] trying again to sanitize string --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 8ecbdd7..666e579 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -21,7 +21,7 @@ packages: reference_datetime: "2015-06-01 00:00:00" remotes: - "url": "https://github.com/MrSlosh/nycoin.git" - "dir": "nycx//nycoin" + "dir": "nycx\/nycoin" files: [] #x86_64-w64-mingw32 script: | From cbe139cdcfbd1889c163ffe25e5f374db50de3a6 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 12:52:37 -0600 Subject: [PATCH 06/27] nope --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 666e579..96053f0 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -21,7 +21,7 @@ packages: reference_datetime: "2015-06-01 00:00:00" remotes: - "url": "https://github.com/MrSlosh/nycoin.git" - "dir": "nycx\/nycoin" + "dir": "nycoin" files: [] #x86_64-w64-mingw32 script: | From 5847fcbf8cbe06c08961437a576456328bbd5809 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:02:59 -0600 Subject: [PATCH 07/27] correcting a typo --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a695cd7..d43d719 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2701,10 +2701,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - std::map::iterator cpItr = chainParams.checkpoints().MapCheckpoints.find(block.GetHeight()); + std::map::iterator cpItr = chainParams.Checkpoints().MapCheckpoints.find(block.GetHeight()); // if the current block is not found in the checkpoints list, skip it - if(cpItr == chainParams.checkpoints().MapCheckpoints.end()) + if(cpItr == chainParams.Checkpoints().MapCheckpoints.end()) { return true; } From 649b4489d02c9cbb57dec82f8006931b27c7b7ba Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:11:04 -0600 Subject: [PATCH 08/27] typo in checkpoint access --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d43d719..39d1422 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2701,10 +2701,10 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - std::map::iterator cpItr = chainParams.Checkpoints().MapCheckpoints.find(block.GetHeight()); + std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(block.GetHeight()); // if the current block is not found in the checkpoints list, skip it - if(cpItr == chainParams.Checkpoints().MapCheckpoints.end()) + if(cpItr == chainParams.Checkpoints().mapCheckpoints.end()) { return true; } From 17134f58a72e32124e5bd9d7a1738ab0bd396e95 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:20:49 -0600 Subject: [PATCH 09/27] fixing height check for checkpoint iterator --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 39d1422..595b38a 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2701,7 +2701,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(block.GetHeight()); + std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); // if the current block is not found in the checkpoints list, skip it if(cpItr == chainParams.Checkpoints().mapCheckpoints.end()) From 356b105d588a08e1fb23258accf8344cc271daeb Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:30:24 -0600 Subject: [PATCH 10/27] fixing const errors for iterator --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 595b38a..d967f49 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2701,7 +2701,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); + const std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); // if the current block is not found in the checkpoints list, skip it if(cpItr == chainParams.Checkpoints().mapCheckpoints.end()) From 67eef966dd0ee959bc071f79e90574c8cbb1b42f Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:43:11 -0600 Subject: [PATCH 11/27] removing const variable scope --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d967f49..81b01ef 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2699,9 +2699,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo // Shortcut checks for almost all early blocks if(chainActive.Height() < SKIP_VALIDATION_HEIGHT) { - const CChainParams& chainParams = Params(); + CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - const std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); + std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); // if the current block is not found in the checkpoints list, skip it if(cpItr == chainParams.Checkpoints().mapCheckpoints.end()) From edf9d18d569b221b440b96be0ad91b93bcd3778f Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 13:51:19 -0600 Subject: [PATCH 12/27] implemented const iterator on std:;map --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 81b01ef..d756b39 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2699,9 +2699,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo // Shortcut checks for almost all early blocks if(chainActive.Height() < SKIP_VALIDATION_HEIGHT) { - CChainParams& chainParams = Params(); + const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest - std::map::iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); + std::map::const_iterator cpItr = chainParams.Checkpoints().mapCheckpoints.find(chainActive.Height()); // if the current block is not found in the checkpoints list, skip it if(cpItr == chainParams.Checkpoints().mapCheckpoints.end()) From 606f0b11c8ee30c5c3c2a838f499112488efa86c Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 14:00:53 -0600 Subject: [PATCH 13/27] removed extra paranthesis --- src/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 965b556..18aaea7 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -159,7 +159,7 @@ class CMainParams : public CChainParams { (3500000, uint256S("0x3f1a97f68ce8eaf38fc0c56868b3eb98ccb67d14bff4e78afb91d82cba853ddf")) (3938415, uint256S("0xe1fa41f6fe8d2785d89b0468e13e4c450493e5356c024a098c5b727ca89138ee")) (4500000, uint256S("0xdd86fad58b3fa5d83a15a18df1cc20cdcdb1b2cf5d2d702e0c60bbb7d4602fb1")) - (4821195, uint256S("0x7cf9862123405a687626b27ecaea377698d23d68458bb9b2a16e0262ec32df84"))), + (4821195, uint256S("0x7cf9862123405a687626b27ecaea377698d23d68458bb9b2a16e0262ec32df84")), 1514765144, // * UNIX timestamp of last checkpoint block 5141422, // * total number of transactions between genesis and last checkpoint From db57f54ca03ef0146f4095922ff20b6186d9da9b Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 18:34:41 -0600 Subject: [PATCH 14/27] bumped up max blocks in transit --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 04c287f..32f45b5 100755 --- a/src/main.h +++ b/src/main.h @@ -79,7 +79,7 @@ static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; /** Number of blocks that can be requested at any given time from a single peer. */ -static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 128; +static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 256; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends From ec6a517a2e6519d06ab664a56effb9fb3ec8096b Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Mon, 12 Nov 2018 22:05:21 -0600 Subject: [PATCH 15/27] added disconnectnode RPC call --- src/rpcnet.cpp | 19 +++++++++++++++++++ src/rpcprotocol.h | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index c817d44..cb819fc 100755 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -215,6 +215,25 @@ Value addnode(const Array& params, bool fHelp) return Value::null; } +Value disconnectnode(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "disconnectnode \"node\" \n" + "\nImmediately disconnects from the specified node.\n" + "\nArguments:\n" + "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" + "\nExamples:\n" + + HelpExampleCli("disconnectnode", "\"192.168.0.6:17020\"") + + HelpExampleRpc("disconnectnode", "\"192.168.0.6:17020\"") + ); + CNode* pNode = FindNode(params[0].get_str()); + if (pNode == NULL) + throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes"); + pNode->CloseSocketDisconnect(); + return Value::null; +} + Value getaddednodeinfo(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index 4f3f70f..f4f112c 100755 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -65,6 +65,7 @@ enum RPCErrorCode RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //! Still downloading initial blocks RPC_CLIENT_NODE_ALREADY_ADDED = -23, //! Node is already added RPC_CLIENT_NODE_NOT_ADDED = -24, //! Node has not been added before + RPC_CLIENT_NODE_NOT_CONNECTED = -29, //! Node to disconnect not found in connected nodes //! Wallet errors RPC_WALLET_ERROR = -4, //! Unspecified problem with wallet (key not found etc.) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 27ce74f..5ac9234 100755 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -284,6 +284,7 @@ static const CRPCCommand vRPCCommands[] = /* P2P networking */ { "network", "getnetworkinfo", &getnetworkinfo, true }, { "network", "addnode", &addnode, true }, + { "network", "disconnectnode", &disconnectnode, true }, { "network", "getaddednodeinfo", &getaddednodeinfo, true }, { "network", "getconnectioncount", &getconnectioncount, true }, { "network", "getnettotals", &getnettotals, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index d1051c4..ff216ea 100755 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -56,7 +56,7 @@ void StopRPCThreads(); /** Query whether RPC is running */ bool IsRPCRunning(); -/** +/** * Set the RPC warmup status. When this is done, all RPC calls will error out * immediately with RPC_IN_WARMUP. */ @@ -148,6 +148,7 @@ extern std::string HelpExampleRpc(std::string methodname, std::string args); extern void EnsureWalletIsUnlocked(); +extern json_spirit::Value disconnectnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); From d8f735105b1d44c022e3ed7a0f8fd72c19b2f3dd Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Tue, 13 Nov 2018 09:09:58 -0600 Subject: [PATCH 16/27] cherry picking Doge PR 1328 to fix possible win_env db corruption --- src/leveldb/util/env_win.cc | 264 ++++++++---------------------------- 1 file changed, 55 insertions(+), 209 deletions(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index ef2ecae..74af91f 100755 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -1,7 +1,7 @@ // This file contains source that originates from: // http://code.google.com/p/leveldbwin/source/browse/trunk/win32_impl_src/env_win32.h // http://code.google.com/p/leveldbwin/source/browse/trunk/win32_impl_src/port_win32.cc -// Those files dont' have any explict license headers but the +// Those files dont' have any explict license headers but the // project (http://code.google.com/p/leveldbwin/) lists the 'New BSD License' // as the license. #if defined(LEVELDB_PLATFORM_WINDOWS) @@ -103,39 +103,21 @@ class Win32RandomAccessFile : public RandomAccessFile DISALLOW_COPY_AND_ASSIGN(Win32RandomAccessFile); }; -class Win32MapFile : public WritableFile +class Win32WritableFile : public WritableFile { public: - Win32MapFile(const std::string& fname); + Win32WritableFile(const std::string& fname); - ~Win32MapFile(); + ~Win32WritableFile(); virtual Status Append(const Slice& data); virtual Status Close(); virtual Status Flush(); virtual Status Sync(); BOOL isEnable(); private: - std::string _filename; + std::string filename_; HANDLE _hFile; - size_t _page_size; - size_t _map_size; // How much extra memory to map at a time - char* _base; // The mapped region - HANDLE _base_handle; - char* _limit; // Limit of the mapped region - char* _dst; // Where to write next (in range [base_,limit_]) - char* _last_sync; // Where have we synced up to - uint64_t _file_offset; // Offset of base_ in file - //LARGE_INTEGER file_offset_; - // Have we done an munmap of unsynced data? - bool _pending_sync; - - // Roundup x to a multiple of y - static size_t _Roundup(size_t x, size_t y); - size_t _TruncateToPageBoundary(size_t s); - bool _UnmapCurrentRegion(); - bool _MapNewRegion(); - DISALLOW_COPY_AND_ASSIGN(Win32MapFile); - BOOL _Init(LPCWSTR Path); + }; class Win32FileLock : public FileLock @@ -155,7 +137,7 @@ class Win32FileLock : public FileLock class Win32Logger : public Logger { -public: +public: friend class Win32Env; virtual ~Win32Logger(); virtual void Logv(const char* format, va_list ap); @@ -265,19 +247,19 @@ std::wstring& ModifyPath(std::wstring& path) std::string GetLastErrSz() { LPWSTR lpMsgBuf; - FormatMessageW( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | + FormatMessageW( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, // Default language (LPWSTR) &lpMsgBuf, 0, - NULL + NULL ); std::string Err; - ToNarrowPath(lpMsgBuf, Err); + ToNarrowPath(lpMsgBuf, Err); LocalFree( lpMsgBuf ); return Err; } @@ -285,16 +267,16 @@ std::string GetLastErrSz() std::wstring GetLastErrSzW() { LPVOID lpMsgBuf; - FormatMessageW( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | + FormatMessageW( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, // Default language (LPWSTR) &lpMsgBuf, 0, - NULL + NULL ); std::wstring Err = (LPCWSTR)lpMsgBuf; LocalFree(lpMsgBuf); @@ -442,202 +424,65 @@ void Win32RandomAccessFile::_CleanUp() } } -size_t Win32MapFile::_Roundup( size_t x, size_t y ) +Win32WritableFile::Win32WritableFile(const std::string& fname) : filename_(fname) { - return ((x + y - 1) / y) * y; -} - -size_t Win32MapFile::_TruncateToPageBoundary( size_t s ) -{ - s -= (s & (_page_size - 1)); - assert((s % _page_size) == 0); - return s; + std::wstring path; + ToWidePath(fname, path); + DWORD Flag = PathFileExistsW(path.c_str()) ? OPEN_EXISTING : CREATE_ALWAYS; + _hFile = CreateFileW(path.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE, + NULL, + Flag, + FILE_ATTRIBUTE_NORMAL, + NULL); + // CreateFileW returns INVALID_HANDLE_VALUE in case of error, always check isEnable() before use } -bool Win32MapFile::_UnmapCurrentRegion() +Win32WritableFile::~Win32WriteableFile() { - bool result = true; - if (_base != NULL) { - if (_last_sync < _limit) { - // Defer syncing this data until next Sync() call, if any - _pending_sync = true; - } - if (!UnmapViewOfFile(_base) || !CloseHandle(_base_handle)) - result = false; - _file_offset += _limit - _base; - _base = NULL; - _base_handle = NULL; - _limit = NULL; - _last_sync = NULL; - _dst = NULL; - // Increase the amount we map the next time, but capped at 1MB - if (_map_size < (1<<20)) { - _map_size *= 2; - } - } - return result; + if(_hFile != INVALID_HANDLE_VALUE) + Close(); } -bool Win32MapFile::_MapNewRegion() +Status Win32WritableFile::Append(const Slice& data) { - assert(_base == NULL); - //LONG newSizeHigh = (LONG)((file_offset_ + map_size_) >> 32); - //LONG newSizeLow = (LONG)((file_offset_ + map_size_) & 0xFFFFFFFF); - DWORD off_hi = (DWORD)(_file_offset >> 32); - DWORD off_lo = (DWORD)(_file_offset & 0xFFFFFFFF); - LARGE_INTEGER newSize; - newSize.QuadPart = _file_offset + _map_size; - SetFilePointerEx(_hFile, newSize, NULL, FILE_BEGIN); - SetEndOfFile(_hFile); - - _base_handle = CreateFileMappingA( - _hFile, - NULL, - PAGE_READWRITE, - 0, - 0, - 0); - if (_base_handle != NULL) { - _base = (char*) MapViewOfFile(_base_handle, - FILE_MAP_ALL_ACCESS, - off_hi, - off_lo, - _map_size); - if (_base != NULL) { - _limit = _base + _map_size; - _dst = _base; - _last_sync = _base; - return true; - } + DWORD r = 0; + if(!WriteFile(_hFile, data.data(), data.size(), &r, NULL) || r != data.size()) + { + return Status::IOError("Win32WritableFile.Append::WriteFile:" +filename_, Win32::GetLastErrSz()); } - return false; + return Status::OK()); } -Win32MapFile::Win32MapFile( const std::string& fname) : - _filename(fname), - _hFile(NULL), - _page_size(Win32::g_PageSize), - _map_size(_Roundup(65536, Win32::g_PageSize)), - _base(NULL), - _base_handle(NULL), - _limit(NULL), - _dst(NULL), - _last_sync(NULL), - _file_offset(0), - _pending_sync(false) +Status Win32WritableFile::Close() { - std::wstring path; - ToWidePath(fname, path); - _Init(path.c_str()); - assert((Win32::g_PageSize & (Win32::g_PageSize - 1)) == 0); -} - -Status Win32MapFile::Append( const Slice& data ) -{ - const char* src = data.data(); - size_t left = data.size(); - Status s; - while (left > 0) { - assert(_base <= _dst); - assert(_dst <= _limit); - size_t avail = _limit - _dst; - if (avail == 0) { - if (!_UnmapCurrentRegion() || - !_MapNewRegion()) { - return Status::IOError("WinMmapFile.Append::UnmapCurrentRegion or MapNewRegion: ", Win32::GetLastErrSz()); - } - } - size_t n = (left <= avail) ? left : avail; - memcpy(_dst, src, n); - _dst += n; - src += n; - left -= n; - } - return s; -} - -Status Win32MapFile::Close() -{ - Status s; - size_t unused = _limit - _dst; - if (!_UnmapCurrentRegion()) { - s = Status::IOError("WinMmapFile.Close::UnmapCurrentRegion: ",Win32::GetLastErrSz()); - } else if (unused > 0) { - // Trim the extra space at the end of the file - LARGE_INTEGER newSize; - newSize.QuadPart = _file_offset - unused; - if (!SetFilePointerEx(_hFile, newSize, NULL, FILE_BEGIN)) { - s = Status::IOError("WinMmapFile.Close::SetFilePointer: ",Win32::GetLastErrSz()); - } else - SetEndOfFile(_hFile); - } - if (!CloseHandle(_hFile)) { - if (s.ok()) { - s = Status::IOError("WinMmapFile.Close::CloseHandle: ", Win32::GetLastErrSz()); - } + if(!CloseHandle(_hFile)) + { + return Status::IOError("Win32WritableFile.Close::CloseHandle:"+filename_, Win32::GetLastErrSz()); } _hFile = INVALID_HANDLE_VALUE; - _base = NULL; - _base_handle = NULL; - _limit = NULL; - - return s; + return Status::OK(); } -Status Win32MapFile::Sync() -{ - Status s; - if (_pending_sync) { - // Some unmapped data was not synced - _pending_sync = false; - if (!FlushFileBuffers(_hFile)) { - s = Status::IOError("WinMmapFile.Sync::FlushFileBuffers: ",Win32::GetLastErrSz()); - } - } - if (_dst > _last_sync) { - // Find the beginnings of the pages that contain the first and last - // bytes to be synced. - size_t p1 = _TruncateToPageBoundary(_last_sync - _base); - size_t p2 = _TruncateToPageBoundary(_dst - _base - 1); - _last_sync = _dst; - if (!FlushViewOfFile(_base + p1, p2 - p1 + _page_size)) { - s = Status::IOError("WinMmapFile.Sync::FlushViewOfFile: ",Win32::GetLastErrSz()); - } - } - return s; -} -Status Win32MapFile::Flush() +Status Win32WritableFile::Flush() { return Status::OK(); } -Win32MapFile::~Win32MapFile() +Status Win32WritableFile::Sync() { - if (_hFile != INVALID_HANDLE_VALUE) { - Win32MapFile::Close(); + if(!FlushFileBuffers(_hFile)) + { + return Status::IOEroor("Win32WritableFile.Sync::FlushFilebuffers:"+filename_, Win32::GetLastErrSz()); } + return Status::OK(); } -BOOL Win32MapFile::_Init( LPCWSTR Path ) -{ - DWORD Flag = PathFileExistsW(Path) ? OPEN_EXISTING : CREATE_ALWAYS; - _hFile = CreateFileW(Path, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE, - NULL, - Flag, - FILE_ATTRIBUTE_NORMAL, - NULL); - if(!_hFile || _hFile == INVALID_HANDLE_VALUE) - return FALSE; - else - return TRUE; -} - -BOOL Win32MapFile::isEnable() +BOOL Win32WritableFile::isEnable() { - return _hFile ? TRUE : FALSE; + return _hFile != INVALID_HANDLE_VALUE; } Win32FileLock::Win32FileLock( const std::string& fname ) : @@ -779,7 +624,7 @@ Status Win32Env::GetChildren(const std::string& dir, std::vector* r BOOL hasNext = TRUE; std::string child; while(hasNext){ - ToNarrowPath(wfd.cFileName, child); + ToNarrowPath(wfd.cFileName, child); if(child != ".." && child != ".") { result->push_back(child); } @@ -846,7 +691,7 @@ Status Win32Env::RenameFile( const std::string& src, const std::string& target ) sRet = Status::IOError(src, "Could not rename file."); else if(!::MoveFileW(wsrc_path.c_str(), wtarget_path.c_str() ) ) - sRet = Status::IOError(src, "Could not rename file."); + sRet = Status::IOError(src, "Could not rename file."); } } return sRet; @@ -981,7 +826,7 @@ Status Win32Env::NewLogger( const std::string& fname, Logger** result ) { Status sRet; std::string path = fname; - Win32MapFile* pMapFile = new Win32MapFile(ModifyPath(path)); + Win32WritableFile* pMapFile = new Win32WritableFile(ModifyPath(path)); if(!pMapFile->isEnable()){ delete pMapFile; *result = NULL; @@ -995,7 +840,8 @@ Status Win32Env::NewWritableFile( const std::string& fname, WritableFile** resul { Status sRet; std::string path = fname; - Win32MapFile* pFile = new Win32MapFile(ModifyPath(path)); + Win32WritableFile* pFile = new Win32WritableFile* pFile = new Win32MapFile(ModifyPath(path)); +(ModifyPath(path)); if(!pFile->isEnable()){ *result = NULL; sRet = Status::IOError(fname,Win32::GetLastErrSz()); From 3e340ced62f0305a84455c3bace883e66bb6718a Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Tue, 13 Nov 2018 09:29:45 -0600 Subject: [PATCH 17/27] fixing accidental copy paste --- src/leveldb/util/env_win.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index 74af91f..7c7167e 100755 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -840,8 +840,7 @@ Status Win32Env::NewWritableFile( const std::string& fname, WritableFile** resul { Status sRet; std::string path = fname; - Win32WritableFile* pFile = new Win32WritableFile* pFile = new Win32MapFile(ModifyPath(path)); -(ModifyPath(path)); + Win32WritableFile* pFile = new Win32WritableFile(ModifyPath(path)); if(!pFile->isEnable()){ *result = NULL; sRet = Status::IOError(fname,Win32::GetLastErrSz()); From ddce348e868659a0fc2d69bd2e8d863996a4191b Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Tue, 13 Nov 2018 09:54:59 -0600 Subject: [PATCH 18/27] Fixing typos in Doge pull modifications --- src/leveldb/util/env_win.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index 7c7167e..7014b64 100755 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -452,7 +452,7 @@ Status Win32WritableFile::Append(const Slice& data) { return Status::IOError("Win32WritableFile.Append::WriteFile:" +filename_, Win32::GetLastErrSz()); } - return Status::OK()); + return Status::OK(); } Status Win32WritableFile::Close() @@ -475,7 +475,7 @@ Status Win32WritableFile::Sync() { if(!FlushFileBuffers(_hFile)) { - return Status::IOEroor("Win32WritableFile.Sync::FlushFilebuffers:"+filename_, Win32::GetLastErrSz()); + return Status::IOError("Win32WritableFile.Sync::FlushFilebuffers:"+filename_, Win32::GetLastErrSz()); } return Status::OK(); } From a1d05568dd562bf11481ef4a731e8c24f69785a6 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Tue, 13 Nov 2018 10:12:44 -0600 Subject: [PATCH 19/27] more typos --- src/leveldb/util/env_win.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index 7014b64..3b76ee2 100755 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -116,7 +116,7 @@ class Win32WritableFile : public WritableFile BOOL isEnable(); private: std::string filename_; - HANDLE _hFile; + ::HANDLE _hFile; }; @@ -442,7 +442,9 @@ Win32WritableFile::Win32WritableFile(const std::string& fname) : filename_(fname Win32WritableFile::~Win32WriteableFile() { if(_hFile != INVALID_HANDLE_VALUE) + { Close(); + } } Status Win32WritableFile::Append(const Slice& data) From 42de6a933aa2ab1b9cf5b013a16fd92bbfc5d37f Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Tue, 13 Nov 2018 10:27:10 -0600 Subject: [PATCH 20/27] sneaky typo in class name --- src/leveldb/util/env_win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leveldb/util/env_win.cc b/src/leveldb/util/env_win.cc index 3b76ee2..d877d61 100755 --- a/src/leveldb/util/env_win.cc +++ b/src/leveldb/util/env_win.cc @@ -439,7 +439,7 @@ Win32WritableFile::Win32WritableFile(const std::string& fname) : filename_(fname // CreateFileW returns INVALID_HANDLE_VALUE in case of error, always check isEnable() before use } -Win32WritableFile::~Win32WriteableFile() +Win32WritableFile::~Win32WritableFile() { if(_hFile != INVALID_HANDLE_VALUE) { From 8d566536bf1a870e3f1f38a21980a6b8fd728197 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Wed, 14 Nov 2018 23:35:35 -0600 Subject: [PATCH 21/27] added additional debug statement for oversized messages --- src/net.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/net.cpp b/src/net.cpp index c9103b6..00c57d9 100755 --- a/src/net.cpp +++ b/src/net.cpp @@ -549,6 +549,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) if (msg.in_data && msg.hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) { LogPrint("net", "Oversized message from peer=%i, disconnecting\n", GetId()); + LogPrint("net", "Oversized message type=%s, size=%i\n", msg.hdr.GetCommand(), msg.hdr.nMessageSize); return false; } From b943151f9940d4f146926c93f8ec69fb630ec664 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Thu, 15 Nov 2018 07:43:23 -0600 Subject: [PATCH 22/27] increasing protocol_message_max size and bumping protocol version --- src/net.h | 4 ++-- src/version.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net.h b/src/net.h index 17502b9..a8ce1b8 100755 --- a/src/net.h +++ b/src/net.h @@ -47,8 +47,8 @@ static const int TIMEOUT_INTERVAL = 20 * 60; static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; -/** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024; +/** Maximum length of incoming protocol messages (no message over 4 MiB is currently acceptable). */ +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000; /** -listen default */ static const bool DEFAULT_LISTEN = true; /** -upnp default */ diff --git a/src/version.h b/src/version.h index 504262d..0465be4 100755 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70005; +static const int PROTOCOL_VERSION = 70012; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; From 87dd9bc34fec8cf70ef113d414e0a9864222c1e0 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Fri, 16 Nov 2018 11:23:00 -0600 Subject: [PATCH 23/27] added fast sync as a command line option instead of default behavior --- src/init.cpp | 18 +++++++++++++----- src/main.cpp | 23 ++++++++++++++++++----- src/main.h | 5 ++++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 4230303..8e48fed 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -322,6 +322,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-seednode=", _("Connect to a node to retrieve peer addresses, and disconnect")); strUsage += HelpMessageOpt("-timeout=", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT)); strUsage += HelpMessageOpt("-bloomfilters", _("Allow peers to set bloom filters (default: 1)")); + strUsage += HelpmessageOpt("-fastsync", _("Increases maximum number of blocks to download at any given time and only minimal validates blocks")); #ifdef USE_UPNP #if USE_UPNP strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening)")); @@ -332,7 +333,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-whitebind=", _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6")); strUsage += HelpMessageOpt("-whitelist=", _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") + " " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway")); - + #ifdef ENABLE_WALLET strUsage += HelpMessageGroup(_("Wallet options:")); @@ -451,7 +452,9 @@ std::string LicenseInfo() { return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" + "\n" + - FormatParagraph(strprintf(_("Copyright (C) 2013-%i The NewYorkCoin Developers"), COPYRIGHT_YEAR)) + "\n" + + FormatParagraph(strprintf(_("Copyright (C) 2013-%i The DogeCoin Developers"), COPYRIGHT_YEAR)) + "\n" + + "\n" + + FormatParagraph(strprintf(_("Copyright (C) 2017-%i The NewYorkCoin Developers"), COPYRIGHT_YEAR)) + "\n" + "\n" + FormatParagraph(_("This is experimental software.")) + "\n" + "\n" + @@ -734,6 +737,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__); } + if (GetBoolArg("-fastsync", true)) + { + LogPrintf("%s: parameter interaction: -fastsync=1 increasing max blocks in flight and minimizing block checks\n", __func__); + } + // -zapwallettx implies a rescan if (GetBoolArg("-zapwallettxes", false)) { if (SoftSetBoolArg("-rescan", true)) @@ -975,15 +983,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::string warningString; std::string errorString; - + if (!CWallet::Verify(strWalletFile, warningString, errorString)) return false; - + if (!warningString.empty()) InitWarning(warningString); if (!errorString.empty()) return InitError(warningString); - + } // (!fDisableWallet) #endif // ENABLE_WALLET // ********************************************************* Step 6: network initialization diff --git a/src/main.cpp b/src/main.cpp index d756b39..389e62a 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,6 +68,8 @@ size_t nCoinCacheUsage = 5000 * 300; uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; +int nAllowedBlocksInTransit = DEFAULT_MAX_BLOCKS_IN_TRANSIT_PER_PEER; + /** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */ CFeeRate minRelayTxFee = CFeeRate(DEFAULT_FEE); @@ -2697,7 +2699,7 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { // Shortcut checks for almost all early blocks - if(chainActive.Height() < SKIP_VALIDATION_HEIGHT) + if(chainActive.Height() < SKIP_VALIDATION_HEIGHT || GetBoolArg("-fastsync", false)) { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest @@ -2887,7 +2889,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } // Since we're close to chaintip, reenable checks to ensure state is correct when sync completes - if(chainActive.Height() >= SKIP_VALIDATION_HEIGHT) + if(chainActive.Height() >= SKIP_VALIDATION_HEIGHT || GetBoolArg("-fastsync", false)) { if (!CheckBlockHeader(block, state)) return false; @@ -4247,6 +4249,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return error("message inv size() = %u", vInv.size()); } + if(GetBoolArg("-fastsync"), true) + { + nAllowedBlocksInTransit = MAX_BLOCKS_IN_TRANSIT_PER_PEER; + LogPrint("net", "fastsync activated maximum number of blocks in transit increased"); + } + LOCK(cs_main); std::vector vToFetch; @@ -4278,7 +4286,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), inv.hash); CNodeState *nodestate = State(pfrom->GetId()); if (chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - chainparams.GetConsensus(chainActive.Height()).nPowTargetSpacing * 20 && - nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { + nodestate->nBlocksInFlight < nAllowedBlocksInTransit) { vToFetch.push_back(inv); // Mark block as in flight already, even though the actual "getdata" message only goes out // later (within the same cs_main lock, though). @@ -5163,11 +5171,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // // Message: getdata (blocks) // + if(GetBoolArg("-fastsync"), true) + { + nAllowedBlocksInTransit = MAX_BLOCKS_IN_TRANSIT_PER_PEER; + LogPrint("net", "fastsync activated maximum number of blocks in transit increased"); + } vector vGetData; - if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { + if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < nAllowedBlocksInTransit) { vector vToDownload; NodeId staller = -1; - FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller); + FindNextBlocksToDownload(pto->GetId(), nAllowedBlocksInTransit - state.nBlocksInFlight, vToDownload, staller); BOOST_FOREACH(CBlockIndex *pindex, vToDownload) { vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash())); MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex); diff --git a/src/main.h b/src/main.h index 32f45b5..3090a3f 100755 --- a/src/main.h +++ b/src/main.h @@ -78,7 +78,9 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; -/** Number of blocks that can be requested at any given time from a single peer. */ +/** Default Number of Blocks that can be requested at any given time from a single peer **/ +static const int DEFAULT_MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; +/** Maximum Number of blocks that can be requested at any given time from a single peer. */ static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 256; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; @@ -122,6 +124,7 @@ extern bool fCheckpointsEnabled; extern size_t nCoinCacheUsage; extern CFeeRate minRelayTxFee; extern bool fAlerts; +extern int nAllowedBlocksInTransit; /** Best header we've seen so far (used for getheaders queries' starting points). */ extern CBlockIndex *pindexBestHeader; From 626d8e496c0cd5a4faee20508519ea3729db8019 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Fri, 16 Nov 2018 11:38:30 -0600 Subject: [PATCH 24/27] typo in call to getboolarg for fastsync --- src/init.cpp | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8e48fed..f9795ed 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -737,7 +737,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__); } - if (GetBoolArg("-fastsync", true)) + if (GetBoolArg("-fastsync", false)) { LogPrintf("%s: parameter interaction: -fastsync=1 increasing max blocks in flight and minimizing block checks\n", __func__); } diff --git a/src/main.cpp b/src/main.cpp index 389e62a..a9cca10 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -4249,7 +4249,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return error("message inv size() = %u", vInv.size()); } - if(GetBoolArg("-fastsync"), true) + if(GetBoolArg("-fastsync", false)) { nAllowedBlocksInTransit = MAX_BLOCKS_IN_TRANSIT_PER_PEER; LogPrint("net", "fastsync activated maximum number of blocks in transit increased"); @@ -5171,7 +5171,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // // Message: getdata (blocks) // - if(GetBoolArg("-fastsync"), true) + if(GetBoolArg("-fastsync", false)) { nAllowedBlocksInTransit = MAX_BLOCKS_IN_TRANSIT_PER_PEER; LogPrint("net", "fastsync activated maximum number of blocks in transit increased"); From 8da83cb6095b8084878d9bbd75da296158c262a6 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Fri, 16 Nov 2018 11:45:57 -0600 Subject: [PATCH 25/27] typo in help message for fast sync --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index f9795ed..abab3bc 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -322,7 +322,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-seednode=", _("Connect to a node to retrieve peer addresses, and disconnect")); strUsage += HelpMessageOpt("-timeout=", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT)); strUsage += HelpMessageOpt("-bloomfilters", _("Allow peers to set bloom filters (default: 1)")); - strUsage += HelpmessageOpt("-fastsync", _("Increases maximum number of blocks to download at any given time and only minimal validates blocks")); + strUsage += HelpMessageOpt("-fastsync", _("Increases maximum number of blocks to download at any given time and only minimal validates blocks")); #ifdef USE_UPNP #if USE_UPNP strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening)")); From 035257935b8b822d7ccb0ce501a70227b37d2afa Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Fri, 16 Nov 2018 13:14:14 -0600 Subject: [PATCH 26/27] changing windows build descriptor to reflect main repo --- contrib/gitian-descriptors/gitian-win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 96053f0..9e25301 100755 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -20,7 +20,7 @@ packages: - "zip" reference_datetime: "2015-06-01 00:00:00" remotes: -- "url": "https://github.com/MrSlosh/nycoin.git" +- "url": "https://github.com/NewYorkCoin-NYC/nycoin.git" "dir": "nycoin" files: [] #x86_64-w64-mingw32 From bd6c3846376e330c5c776179497671897298a8e4 Mon Sep 17 00:00:00 2001 From: MrSlosh Date: Fri, 16 Nov 2018 16:35:45 -0600 Subject: [PATCH 27/27] Fixes suggested by LTA for PR #42 --- src/init.cpp | 2 +- src/main.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index abab3bc..566f28e 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -322,7 +322,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-seednode=", _("Connect to a node to retrieve peer addresses, and disconnect")); strUsage += HelpMessageOpt("-timeout=", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT)); strUsage += HelpMessageOpt("-bloomfilters", _("Allow peers to set bloom filters (default: 1)")); - strUsage += HelpMessageOpt("-fastsync", _("Increases maximum number of blocks to download at any given time and only minimal validates blocks")); + strUsage += HelpMessageOpt("-fastsync", _("Increases maximum number of in-flight blocks and only perform minimal block validation")); #ifdef USE_UPNP #if USE_UPNP strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening)")); diff --git a/src/main.cpp b/src/main.cpp index a9cca10..5d04cd5 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2699,7 +2699,7 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { // Shortcut checks for almost all early blocks - if(chainActive.Height() < SKIP_VALIDATION_HEIGHT || GetBoolArg("-fastsync", false)) + if(chainActive.Height() < SKIP_VALIDATION_HEIGHT && GetBoolArg("-fastsync", false)) { const CChainParams& chainParams = Params(); // hit all the checkpoints but skip most of the rest @@ -2889,7 +2889,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } // Since we're close to chaintip, reenable checks to ensure state is correct when sync completes - if(chainActive.Height() >= SKIP_VALIDATION_HEIGHT || GetBoolArg("-fastsync", false)) + // Also reenable checks if -fastsync is not set + if(chainActive.Height() >= SKIP_VALIDATION_HEIGHT || (GetBoolArg("-fastsync", false) == false)) { if (!CheckBlockHeader(block, state)) return false;