From 4f80c982ebfb0227c09e12179a1e66b82a7be68c Mon Sep 17 00:00:00 2001 From: kanon <60179867+decryp2kanon@users.noreply.github.com> Date: Fri, 30 Oct 2020 18:06:12 -0400 Subject: [PATCH] Sugarchain: Settings Part 5 - Changes: * During IBD, do not download additional block headers, against too much traffic * Skip BIP30 // See: https://github.com/litecoin-project/litecoin/blob/81c4f2d80fbd33d127ff9b31bf588e4925599d79/src/validation.cpp#L1866 * During download headers, do not CheckBlockHeader for performance reason // See https://github.com/sugarchain-project/sugarchain/pull/122 * Rename: Testnet v3 -> v5 // See https://github.com/sugarchain-project/sugarchain/commit/89cf9b52ce1f135c9659a5cc5f308e7452ac44e9 * During IBD, do not print "Potential stale tip detected..." - Disabled Tests: * feature_uacomment.py * feature_asmap.py - Fixed Tests: * MAX_MONEY --- src/chainparams.cpp | 2 +- src/chainparamsbase.cpp | 2 +- src/net_processing.cpp | 10 +++++ src/validation.cpp | 18 ++++++++ test/functional/p2p_dos_header_tree.py | 4 +- test/functional/test_framework/messages.py | 2 +- test/functional/test_framework/p2p.py | 2 +- test/functional/test_framework/util.py | 2 +- test/functional/test_runner.py | 48 +++++++++++----------- 9 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 50ae0923c8..1f248b97e4 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -172,7 +172,7 @@ class CMainParams : public CChainParams { }; /** - * Testnet (v3) + * Testnet (v5) */ class CTestNetParams : public CChainParams { public: diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 3a57fb64c8..b7a4a75a25 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -46,7 +46,7 @@ std::unique_ptr CreateBaseChainParams(const std::string& chain if (chain == CBaseChainParams::MAIN) { return MakeUnique("", 34229, 34231); } else if (chain == CBaseChainParams::TESTNET) { - return MakeUnique("testnet3", 44229, 44231); + return MakeUnique("testnet5", 44229, 44231); } else if (chain == CBaseChainParams::SIGNET) { return MakeUnique("signet", 54229, 54231); } else if (chain == CBaseChainParams::REGTEST) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 4de2151124..72cbbd4f57 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1869,7 +1869,11 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vectorm_last_block_announcement = GetTime(); } + // During IBD, no more getheaders, against too much traffic + /* if (nCount == MAX_HEADERS_RESULTS) { + */ + if (!::ChainstateActive().IsInitialBlockDownload() && nCount == MAX_HEADERS_RESULTS) { // Headers message had its maximum size; the peer may have more headers. // TODO: optimize: if pindexLast is an ancestor of ::ChainActive().Tip or pindexBestHeader, continue // from there instead. @@ -3996,7 +4000,13 @@ void PeerManager::CheckForStaleTipAndEvictPeers() // Check whether our tip is stale, and if so, allow using an extra // outbound peer if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale(m_chainparams.GetConsensus())) { + // During IBD, do not print "Potential stale tip detected..." + /* LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - g_last_tip_update); + */ + if (!::ChainstateActive().IsInitialBlockDownload()) { + LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - g_last_tip_update); + } m_connman.SetTryNewOutboundPeer(true); } else if (m_connman.GetTryNewOutboundPeer()) { m_connman.SetTryNewOutboundPeer(false); diff --git a/src/validation.cpp b/src/validation.cpp index a791391210..87337b0905 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2034,8 +2034,13 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, // Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the // two in the chain that violate it. This prevents exploiting the issue against nodes during their // initial block download. + + // Skip BIP30 + /* bool fEnforceBIP30 = !((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) || (pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"))); + */ + bool fEnforceBIP30 = true; // Once BIP34 activated it was not possible to create new duplicate coinbases and thus other than starting // with the 2 existing duplicate coinbase pairs, not possible to create overwriting txs. But by the @@ -2063,7 +2068,11 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, // future consensus change to do a new and improved version of BIP34 that // will actually prevent ever creating any duplicate coinbases in the // future. + + // Skip BIP30 + /* static constexpr int BIP34_IMPLIES_BIP30_LIMIT = 1983702; + */ // There is no potential to create a duplicate coinbase at block 209,921 // because this is still before the BIP34 height and so explicit BIP30 @@ -2101,7 +2110,12 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, // TODO: Remove BIP30 checking from block height 1,983,702 on, once we have a // consensus change that ensures coinbases at those heights can not // duplicate earlier coinbases. + + // Skip BIP30 + /* if (fEnforceBIP30 || pindex->nHeight >= BIP34_IMPLIES_BIP30_LIMIT) { + */ + if (fEnforceBIP30) { for (const auto& tx : block.vtx) { for (size_t o = 0; o < tx->vout.size(); o++) { if (view.HaveCoin(COutPoint(tx->GetHash(), o))) { @@ -3642,7 +3656,11 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS return true; } + // For performance reason, skip CheckBlockHeader, during download headers // See https://github.com/sugarchain-project/sugarchain/pull/122 + /* if (!CheckBlockHeader(block, state, chainparams.GetConsensus())) { + */ + if (!::ChainstateActive().IsInitialBlockDownload() && !CheckBlockHeader(block, state, chainparams.GetConsensus())) { LogPrint(BCLog::VALIDATION, "%s: Consensus::CheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString()); return false; } diff --git a/test/functional/p2p_dos_header_tree.py b/test/functional/p2p_dos_header_tree.py index 2349afa1ee..0b4418e2c4 100755 --- a/test/functional/p2p_dos_header_tree.py +++ b/test/functional/p2p_dos_header_tree.py @@ -20,13 +20,13 @@ class RejectLowDifficultyHeadersTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.chain = 'testnet3' # Use testnet chain because it has an early checkpoint + self.chain = 'testnet5' # Use testnet chain because it has an early checkpoint self.num_nodes = 2 def add_options(self, parser): parser.add_argument( '--datafile', - default='data/blockheader_testnet3.hex', + default='data/blockheader_testnet3.hex', # Using Bitcoin Testnet (v3), but not Sugarchain Testnet (v5) help='Test data file (default: %(default)s)', ) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index ff7f73bdf4..5028b09663 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -42,7 +42,7 @@ MAX_BLOOM_HASH_FUNCS = 50 COIN = 100000000 # 1 btc in satoshis -MAX_MONEY = 21000000 * COIN +MAX_MONEY = 1073741824 * COIN BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 686595da9f..5ee9021c88 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -111,7 +111,7 @@ MAGIC_BYTES = { "mainnet": b"\x9f\xeb\x4b\x9d", # mainnet - "testnet3": b"\xb0\x11\x90\x70", # testnet3 + "testnet5": b"\xb0\x11\x90\x70", # testnet5 "regtest": b"\xaf\xfb\x5b\xad", # regtest "signet": b"\x0a\x03\xcf\x40", # signet # Sugarchain: Settings Part 1 # See https://en.bitcoin.it/wiki/Signet } diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index b6cbd62245..433ce466d0 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -343,7 +343,7 @@ def initialize_datadir(dirname, n, chain): if not os.path.isdir(datadir): os.makedirs(datadir) # Translate chain name to config name - if chain == 'testnet3': + if chain == 'testnet5': chain_name_conf_arg = 'testnet' chain_name_conf_section = 'test' else: diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 3de4bab620..6443c17978 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -86,12 +86,12 @@ BASE_SCRIPTS = [ # Scripts that are run by default. # Longest test should go first, to favor running tests in parallel - # 'wallet_hd.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) - # 'wallet_hd.py --descriptors', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) - # 'wallet_backup.py', # TODO.ZENY.SETTINGS # BLOCK REWARD - # 'wallet_backup.py --descriptors', # TODO.ZENY.SETTINGS # BLOCK REWARD + # 'wallet_hd.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'wallet_hd.py --descriptors', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'wallet_backup.py', # Sugarchain: Settings Part 1 + # 'wallet_backup.py --descriptors', # Sugarchain: Settings Part 1 # vv Tests less than 5m vv - # 'mining_getblocktemplate_longpoll.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'mining_getblocktemplate_longpoll.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) 'feature_maxuploadtarget.py', # 'feature_block.py', # Sugarchain: Introduce YespowerSugar # 'rpc_fundrawtransaction.py', # Sugarchain: Settings Part 1 @@ -105,7 +105,7 @@ # 'wallet_labels.py --descriptors', # Sugarchain: Settings Part 1 # 'p2p_segwit.py', # Sugarchain: Introduce YespowerSugar 'p2p_timeouts.py', - # 'p2p_tx_download.py', # TODO.ZENY.SETTINGS + # 'p2p_tx_download.py', # Sugarchain: Settings Part 1 'mempool_updatefromblock.py', # 'wallet_dump.py --legacy-wallet', # Sugarchain: Settings Part 1 'wallet_listtransactions.py', @@ -115,7 +115,7 @@ # 'p2p_sendheaders.py', # Sugarchain: Introduce YespowerSugar # Won't fix due to "lint-python.sh" # 'wallet_importmulti.py --legacy-wallet', # Sugarchain: Settings Part 2 'mempool_limit.py', - # 'rpc_txoutproof.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'rpc_txoutproof.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) 'wallet_listreceivedby.py', 'wallet_listreceivedby.py --descriptors', 'wallet_abandonconflict.py', @@ -130,8 +130,8 @@ 'feature_reindex.py', 'feature_abortnode.py', # vv Tests less than 30s vv - # 'wallet_keypool_topup.py', # TODO.ZENY.SETTINGS - # 'wallet_keypool_topup.py --descriptors', # TODO.ZENY.SETTINGS + # 'wallet_keypool_topup.py', # Sugarchain: Settings Part 1 + # 'wallet_keypool_topup.py --descriptors', # Sugarchain: Settings Part 1 'feature_fee_estimation.py', # 'interface_zmq.py', # Sugarchain: Introduce YespowerSugar # 'interface_bitcoin_cli.py', # Sugarchain: Settings Part 1 @@ -143,15 +143,15 @@ # 'wallet_txn_clone.py --segwit', # Sugarchain: Settings Part 1 'rpc_getchaintips.py', 'rpc_misc.py', - # 'interface_rest.py', # TODO.ZENY.SETTINGS - # 'mempool_spend_coinbase.py', # TODO.ZENY.SETTINGS + # 'interface_rest.py', # Sugarchain: Settings Part 1 + # 'mempool_spend_coinbase.py', # Sugarchain: Settings Part 1 'wallet_avoidreuse.py', 'wallet_avoidreuse.py --descriptors', - # 'mempool_reorg.py', # TODO.ZENY.SETTINGS + # 'mempool_reorg.py', # Sugarchain: Settings Part 1 'mempool_persist.py', - # 'wallet_multiwallet.py', # TODO.ZENY.SETTINGS - # 'wallet_multiwallet.py --descriptors', # TODO.ZENY.SETTINGS - # 'wallet_multiwallet.py --usecli', # TODO.ZENY.SETTINGS + # 'wallet_multiwallet.py', # Sugarchain: Settings Part 1 + # 'wallet_multiwallet.py --descriptors', # Sugarchain: Settings Part 1 + # 'wallet_multiwallet.py --usecli', # Sugarchain: Settings Part 1 'wallet_createwallet.py', 'wallet_createwallet.py --usecli', 'wallet_createwallet.py --descriptors', @@ -160,8 +160,8 @@ 'wallet_reorgsrestore.py', 'interface_http.py', 'interface_rpc.py', - # 'rpc_psbt.py', # TODO.ZENY.SETTINGS - # 'rpc_psbt.py --descriptors', # TODO.ZENY.SETTINGS + # 'rpc_psbt.py', # Sugarchain: Settings Part 1 + # 'rpc_psbt.py --descriptors', # Sugarchain: Settings Part 1 'rpc_users.py', 'rpc_whitelist.py', 'feature_proxy.py', @@ -186,8 +186,8 @@ 'p2p_nobloomfilter_messages.py', 'p2p_filter.py', 'rpc_setban.py', - # 'p2p_blocksonly.py', # TODO.ZENY.SETTINGS - # 'mining_prioritisetransaction.py', # TODO.ZENY.SETTINGS # too slow... + # 'p2p_blocksonly.py', # Sugarchain: Settings Part 1 + # 'mining_prioritisetransaction.py', # Sugarchain: Settings Part 1 'p2p_invalid_locator.py', # 'p2p_invalid_block.py', # Sugarchain: Introduce YespowerSugar 'p2p_invalid_messages.py', @@ -201,7 +201,7 @@ # 'wallet_txn_clone.py --mineblock', # Sugarchain: Settings Part 1 'feature_notifications.py', 'rpc_getblockfilter.py', - # 'rpc_invalidateblock.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'rpc_invalidateblock.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) 'feature_rbf.py', 'mempool_packages.py', 'mempool_package_onemore.py', @@ -255,7 +255,7 @@ # 'wallet_send.py', # Sugarchain: Settings Part 1 # 'wallet_create_tx.py --descriptors', # Sugarchain: Introduce YespowerSugar # 'p2p_fingerprint.py', # Sugarchain: Introduce YespowerSugar - 'feature_uacomment.py', + # 'feature_uacomment.py', Sugarchain: Settings Part 5 'wallet_coinbase_category.py', 'wallet_coinbase_category.py --descriptors', 'feature_filelock.py', @@ -264,16 +264,16 @@ # 'p2p_unrequested_blocks.py', # Sugarchain: Introduce YespowerSugar # 'p2p_blockfilters.py', # Sugarchain: Settings Part 1 'feature_includeconf.py', - 'feature_asmap.py', + # 'feature_asmap.py', # During IBD, do not print "Potential stale tip detected..." 'mempool_unbroadcast.py', # 'mempool_compatibility.py', # Sugarchain: Branding # 'rpc_deriveaddresses.py', # Sugarchain: Settings Part 2 # 'rpc_deriveaddresses.py --usecli', # Sugarchain: Settings Part 2 'p2p_ping.py', - # 'rpc_scantxoutset.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'rpc_scantxoutset.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) 'feature_logging.py', 'p2p_node_network_limited.py', - # 'p2p_permissions.py', # TODO.ZENY.SETTINGS # ADDRESS # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) + # 'p2p_permissions.py', # Sugarchain: Settings Part 2 # ADDRESS_BCRT1_P2WSH_OP_TRUE (address.py) 'feature_blocksdir.py', 'wallet_startup.py', 'feature_config_args.py',