Skip to content

Commit

Permalink
Sugarchain: Settings Part 5
Browse files Browse the repository at this point in the history
- 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 sugarchain-project/sugarchain#122
  * Rename: Testnet v3 -> v5 // See sugarchain-project/sugarchain@89cf9b5
  * During IBD, do not print "Potential stale tip detected..."
    - Disabled Tests:
      * feature_uacomment.py
      * feature_asmap.py

- Fixed Tests:
  * MAX_MONEY
  • Loading branch information
decryp2kanon committed Nov 20, 2020
1 parent 0b40a90 commit 4f80c98
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class CMainParams : public CChainParams {
};

/**
* Testnet (v3)
* Testnet (v5)
*/
class CTestNetParams : public CChainParams {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain
if (chain == CBaseChainParams::MAIN) {
return MakeUnique<CBaseChainParams>("", 34229, 34231);
} else if (chain == CBaseChainParams::TESTNET) {
return MakeUnique<CBaseChainParams>("testnet3", 44229, 44231);
return MakeUnique<CBaseChainParams>("testnet5", 44229, 44231);
} else if (chain == CBaseChainParams::SIGNET) {
return MakeUnique<CBaseChainParams>("signet", 54229, 54231);
} else if (chain == CBaseChainParams::REGTEST) {
Expand Down
10 changes: 10 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,11 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHe
nodestate->m_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.
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_dos_header_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
)

Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 24 additions & 24 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 4f80c98

Please sign in to comment.