Browse Source

Litecoin: Protocol and default settings

0) Adjust BIP30 enforcement values

1) Reduce amount that peers can adjust our time to eliminate an attack vector. Thanks to
coblee for this fix.

2) Zeitgeist2 patch - thanks to Lolcust and ArtForz. This fixes an issue where a
51% attack can change difficulty at will. Go back the full period unless it's the
first retarget after genesis.

3) Avoid overflow in CalculateNextWorkRequired(). Thanks to pooler for the overflow fix.

4) Zeitgeist2 bool fshift bnNew.bits(). Thanks to romanornr for this path.

5) SegWit ContextualCheckBlockHeader adjustment and extra coverage.

6) Reject peer proto version below 70002. Thanks to wtogami for this patch.

7) Send final alert message to nodes warning about removal of the alert system. Thanks to coblee for this patch.

8) Adjust default settings for Litecoin.
0.16
Adrian Gallagher 8 years ago
parent
commit
fee6799b12
No known key found for this signature in database
GPG Key ID: FE3348877809386C
  1. 6
      contrib/debian/examples/bitcoin.conf
  2. 6
      contrib/linearize/example-linearize.cfg
  3. 2
      contrib/linearize/linearize-hashes.py
  4. 6
      contrib/qos/README.md
  5. 34
      contrib/qos/tc.sh
  6. 24
      contrib/rpm/bitcoin.spec
  7. 4
      contrib/seeds/generate-seeds.py
  8. 4
      doc/REST-interface.md
  9. 4
      doc/developer-notes.md
  10. 8
      doc/tor.md
  11. 2
      src/amount.h
  12. 2
      src/net_processing.cpp
  13. 2
      src/net_processing.h
  14. 4
      src/netaddress.cpp
  15. 25
      src/pow.cpp
  16. 2
      src/qt/intro.cpp
  17. 6
      src/rpc/net.cpp
  18. 2
      src/rpc/server.cpp
  19. 4
      src/test/compress_tests.cpp
  20. 2
      src/test/miner_tests.cpp
  21. 6
      src/test/netbase_tests.cpp
  22. 2
      src/timedata.h
  23. 11
      src/validation.cpp
  24. 2
      src/validation.h
  25. 2
      src/version.h
  26. 7
      test/functional/feature_nulldummy.py
  27. 8
      test/functional/feature_proxy.py
  28. 21
      test/functional/p2p_segwit.py

6
contrib/debian/examples/bitcoin.conf vendored

@ -44,11 +44,11 @@
# Use as many addnode= settings as you like to connect to specific peers # Use as many addnode= settings as you like to connect to specific peers
#addnode=69.164.218.197 #addnode=69.164.218.197
#addnode=10.0.0.2:8333 #addnode=10.0.0.2:9333
# Alternatively use as many connect= settings as you like to connect ONLY to specific peers # Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=69.164.218.197 #connect=69.164.218.197
#connect=10.0.0.1:8333 #connect=10.0.0.1:9333
# Listening mode, enabled by default except when 'connect' is being used # Listening mode, enabled by default except when 'connect' is being used
#listen=1 #listen=1
@ -110,7 +110,7 @@
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96 #rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96
# Listen for RPC connections on this TCP port: # Listen for RPC connections on this TCP port:
#rpcport=8332 #rpcport=9332
# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind # You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind
# running on another host using this option: # running on another host using this option:

6
contrib/linearize/example-linearize.cfg

@ -5,13 +5,13 @@ rpcpassword=somepassword
host=127.0.0.1 host=127.0.0.1
#mainnet default #mainnet default
port=8332 port=9332
#testnet default #testnet default
#port=18332 #port=19332
#regtest default #regtest default
#port=18443 #port=19443
# bootstrap.dat hashlist settings (linearize-hashes) # bootstrap.dat hashlist settings (linearize-hashes)
max_height=313000 max_height=313000

2
contrib/linearize/linearize-hashes.py

@ -125,7 +125,7 @@ if __name__ == '__main__':
if 'host' not in settings: if 'host' not in settings:
settings['host'] = '127.0.0.1' settings['host'] = '127.0.0.1'
if 'port' not in settings: if 'port' not in settings:
settings['port'] = 8332 settings['port'] = 9332
if 'min_height' not in settings: if 'min_height' not in settings:
settings['min_height'] = 0 settings['min_height'] = 0
if 'max_height' not in settings: if 'max_height' not in settings:

6
contrib/qos/README.md

@ -1,5 +1,5 @@
### QoS (Quality of service) ### ### Qos ###
This is a Linux bash script that will set up tc to limit the outgoing bandwidth for connections to the Bitcoin network. It limits outbound TCP traffic with a source or destination port of 8333, but not if the destination IP is within a LAN. This is a Linux bash script that will set up tc to limit the outgoing bandwidth for connections to the Litecoin network. It limits outbound TCP traffic with a source or destination port of 9333, but not if the destination IP is within a LAN (defined as 192.168.x.x).
This means one can have an always-on bitcoind instance running, and another local bitcoind/bitcoin-qt instance which connects to this node and receives blocks from it. This means one can have an always-on litecoind instance running, and another local litecoind/litecoin-qt instance which connects to this node and receives blocks from it.

34
contrib/qos/tc.sh

@ -1,4 +1,4 @@
# Copyright (c) 2017 The Bitcoin Core developers # Copyright (c) 2013 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -6,12 +6,10 @@
IF="eth0" IF="eth0"
#limit of the network interface in question #limit of the network interface in question
LINKCEIL="1gbit" LINKCEIL="1gbit"
#limit outbound Bitcoin protocol traffic to this rate #limit outbound Litecoin protocol traffic to this rate
LIMIT="160kbit" LIMIT="160kbit"
#defines the IPv4 address space for which you wish to disable rate limiting #defines the address space for which you wish to disable rate limiting
LOCALNET_V4="192.168.0.0/16" LOCALNET="192.168.0.0/16"
#defines the IPv6 address space for which you wish to disable rate limiting
LOCALNET_V6="fe80::/10"
#delete existing rules #delete existing rules
tc qdisc del dev ${IF} root tc qdisc del dev ${IF} root
@ -30,12 +28,6 @@ tc class add dev ${IF} parent 1:1 classid 1:11 htb rate ${LIMIT} ceil ${LIMIT} p
tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10 tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10
tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11 tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11
if [ ! -z "${LOCALNET_V6}" ] ; then
# v6 cannot have the same priority value as v4
tc filter add dev ${IF} parent 1: protocol ipv6 prio 3 handle 1 fw classid 1:10
tc filter add dev ${IF} parent 1: protocol ipv6 prio 4 handle 2 fw classid 1:11
fi
#delete any existing rules #delete any existing rules
#disable for now #disable for now
#ret=0 #ret=0
@ -44,16 +36,10 @@ fi
# ret=$? # ret=$?
#done #done
#limit outgoing traffic to and from port 8333. but not when dealing with a host on the local network #limit outgoing traffic to and from port 9333. but not when dealing with a host on the local network
# (defined by $LOCALNET_V4 and $LOCALNET_V6) # (defined by $LOCALNET)
# --set-mark marks packages matching these criteria with the number "2" (v4) # --set-mark marks packages matching these criteria with the number "2"
# --set-mark marks packages matching these criteria with the number "4" (v6) # these packages are filtered by the tc filter with "handle 2"
# these packets are filtered by the tc filter with "handle 2"
# this filter sends the packages into the 1:11 class, and this class is limited to ${LIMIT} # this filter sends the packages into the 1:11 class, and this class is limited to ${LIMIT}
iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 8333 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2 iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 9333 ! -d ${LOCALNET} -j MARK --set-mark 0x2
iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 8333 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2 iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 9333 ! -d ${LOCALNET} -j MARK --set-mark 0x2
if [ ! -z "${LOCALNET_V6}" ] ; then
ip6tables -t mangle -A OUTPUT -p tcp -m tcp --dport 8333 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
ip6tables -t mangle -A OUTPUT -p tcp -m tcp --sport 8333 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
fi

24
contrib/rpm/bitcoin.spec

@ -332,12 +332,12 @@ if [ `%{_sbindir}/sestatus |grep -c "disabled"` -eq 0 ]; then
for selinuxvariant in %{selinux_variants}; do for selinuxvariant in %{selinux_variants}; do
%{_sbindir}/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/bitcoin.pp &> /dev/null || : %{_sbindir}/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/bitcoin.pp &> /dev/null || :
done done
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 8332 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 9332
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 8333 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 9333
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 18332 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 19332
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 18333 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 19335
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 18443 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 19443
%{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 18444 %{_sbindir}/semanage port -a -t bitcoin_port_t -p tcp 19444
%{_sbindir}/fixfiles -R bitcoin-server restore &> /dev/null || : %{_sbindir}/fixfiles -R bitcoin-server restore &> /dev/null || :
%{_sbindir}/restorecon -R %{_localstatedir}/lib/bitcoin || : %{_sbindir}/restorecon -R %{_localstatedir}/lib/bitcoin || :
fi fi
@ -353,12 +353,12 @@ fi
# SELinux # SELinux
if [ $1 -eq 0 ]; then if [ $1 -eq 0 ]; then
if [ `%{_sbindir}/sestatus |grep -c "disabled"` -eq 0 ]; then if [ `%{_sbindir}/sestatus |grep -c "disabled"` -eq 0 ]; then
%{_sbindir}/semanage port -d -p tcp 8332 %{_sbindir}/semanage port -d -p tcp 9332
%{_sbindir}/semanage port -d -p tcp 8333 %{_sbindir}/semanage port -d -p tcp 9333
%{_sbindir}/semanage port -d -p tcp 18332 %{_sbindir}/semanage port -d -p tcp 19332
%{_sbindir}/semanage port -d -p tcp 18333 %{_sbindir}/semanage port -d -p tcp 19335
%{_sbindir}/semanage port -d -p tcp 18443 %{_sbindir}/semanage port -d -p tcp 19443
%{_sbindir}/semanage port -d -p tcp 18444 %{_sbindir}/semanage port -d -p tcp 19444
for selinuxvariant in %{selinux_variants}; do for selinuxvariant in %{selinux_variants}; do
%{_sbindir}/semodule -s ${selinuxvariant} -r bitcoin &> /dev/null || : %{_sbindir}/semodule -s ${selinuxvariant} -r bitcoin &> /dev/null || :
done done

4
contrib/seeds/generate-seeds.py

@ -127,10 +127,10 @@ def main():
g.write(' * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly.\n') g.write(' * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly.\n')
g.write(' */\n') g.write(' */\n')
with open(os.path.join(indir,'nodes_main.txt'),'r') as f: with open(os.path.join(indir,'nodes_main.txt'),'r') as f:
process_nodes(g, f, 'pnSeed6_main', 8333) process_nodes(g, f, 'pnSeed6_main', 9333)
g.write('\n') g.write('\n')
with open(os.path.join(indir,'nodes_test.txt'),'r') as f: with open(os.path.join(indir,'nodes_test.txt'),'r') as f:
process_nodes(g, f, 'pnSeed6_test', 18333) process_nodes(g, f, 'pnSeed6_test', 19333)
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n') g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
if __name__ == '__main__': if __name__ == '__main__':

4
doc/REST-interface.md

@ -58,7 +58,7 @@ https://github.com/bitcoin/bips/blob/master/bip-0064.mediawiki
Example: Example:
``` ```
$ curl localhost:18332/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.json 2>/dev/null | json_pp $ curl localhost:19332/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff7627ff72e5e8b0f71210f92ea7a4000c5d75-0.json 2>/dev/null | json_pp
{ {
"chainHeight" : 325347, "chainHeight" : 325347,
"chaintipHash" : "00000000fb01a7f3745a717f8caebee056c484e6e0bfe4a9591c235bb70506fb", "chaintipHash" : "00000000fb01a7f3745a717f8caebee056c484e6e0bfe4a9591c235bb70506fb",
@ -100,4 +100,4 @@ Only supports JSON as output format.
Risks Risks
------------- -------------
Running a web browser on the same node with a REST enabled bitcoind can be a risk. Accessing prepared XSS websites could read out tx/block data of your node by placing links like `<script src="http://127.0.0.1:8332/rest/tx/1234567890.json">` which might break the nodes privacy. Running a web browser on the same node with a REST enabled bitcoind can be a risk. Accessing prepared XSS websites could read out tx/block data of your node by placing links like `<script src="http://127.0.0.1:9332/rest/tx/1234567890.json">` which might break the nodes privacy.

4
doc/developer-notes.md

@ -228,7 +228,7 @@ Threads
- ThreadMapPort : Universal plug-and-play startup/shutdown - ThreadMapPort : Universal plug-and-play startup/shutdown
- ThreadSocketHandler : Sends/Receives data from peers on port 8333. - ThreadSocketHandler : Sends/Receives data from peers on port 9333.
- ThreadOpenAddedConnections : Opens network connections to added nodes. - ThreadOpenAddedConnections : Opens network connections to added nodes.
@ -240,7 +240,7 @@ Threads
- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms. - ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms.
- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them. - ThreadRPCServer : Remote procedure call handler, listens on port 9332 for connections and services them.
- BitcoinMiner : Generates bitcoins (if wallet is enabled). - BitcoinMiner : Generates bitcoins (if wallet is enabled).

8
doc/tor.md

@ -42,11 +42,11 @@ reachable from the Tor network. Add these lines to your /etc/tor/torrc (or equiv
config file): config file):
HiddenServiceDir /var/lib/tor/bitcoin-service/ HiddenServiceDir /var/lib/tor/bitcoin-service/
HiddenServicePort 8333 127.0.0.1:8333 HiddenServicePort 9333 127.0.0.1:9333
HiddenServicePort 18333 127.0.0.1:18333 HiddenServicePort 19333 127.0.0.1:19333
The directory can be different of course, but (both) port numbers should be equal to The directory can be different of course, but (both) port numbers should be equal to
your bitcoind's P2P listen port (8333 by default). your bitcoind's P2P listen port (9333 by default).
-externalip=X You can tell bitcoin about its publicly reachable address using -externalip=X You can tell bitcoin about its publicly reachable address using
this option, and this can be a .onion address. Given the above this option, and this can be a .onion address. Given the above
@ -81,7 +81,7 @@ as well, use `discover` instead:
./bitcoind ... -discover ./bitcoind ... -discover
and open port 8333 on your firewall (or use -upnp). and open port 9333 on your firewall (or use -upnp).
If you only want to use Tor to reach onion addresses, but not use it as a proxy If you only want to use Tor to reach onion addresses, but not use it as a proxy
for normal IPv4/IPv6 communication, use: for normal IPv4/IPv6 communication, use:

2
src/amount.h

@ -23,7 +23,7 @@ static const CAmount CENT = 1000000;
* critical; in unusual circumstances like a(nother) overflow bug that allowed * critical; in unusual circumstances like a(nother) overflow bug that allowed
* for the creation of coins out of thin air modification could lead to a fork. * for the creation of coins out of thin air modification could lead to a fork.
* */ * */
static const CAmount MAX_MONEY = 21000000 * COIN; static const CAmount MAX_MONEY = 84000000 * COIN;
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
#endif // BITCOIN_AMOUNT_H #endif // BITCOIN_AMOUNT_H

2
src/net_processing.cpp

@ -1704,7 +1704,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// If the peer is old enough to have the old alert system, send it the final alert. // If the peer is old enough to have the old alert system, send it the final alert.
if (pfrom->nVersion <= 70012) { if (pfrom->nVersion <= 70012) {
CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION); CDataStream finalAlert(ParseHex("5c0100000015f7675900000000ffffff7f00000000ffffff7ffeffff7f0000000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220405f7e7572b176f3316d4e12deab75ad4ff978844f7a7bcd5ed06f6aa094eb6602207880fcc07d0a78e0f46f188d115e04ed4ad48980ea3572cb0e0cb97921048095"), SER_NETWORK, PROTOCOL_VERSION);
connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert)); connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert));
} }

2
src/net_processing.h

@ -29,7 +29,7 @@ static constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4;
/** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */ /** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */
static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
/** How frequently to check for stale tips, in seconds */ /** How frequently to check for stale tips, in seconds */
static constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60; // 10 minutes static constexpr int64_t STALE_CHECK_INTERVAL = 2.5 * 60; // 2.5 minutes
/** How frequently to check for extra outbound peers and disconnect, in seconds */ /** How frequently to check for extra outbound peers and disconnect, in seconds */
static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45; static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */ /** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */

4
src/netaddress.cpp

@ -11,8 +11,8 @@
static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43}; static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
// 0xFD + sha256("bitcoin")[0:5] // 0xFD + sha256("litecoin")[0:5]
static const unsigned char g_internal_prefix[] = { 0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 }; static const unsigned char g_internal_prefix[] = { 0xFD, 0x6C, 0xE9, 0xFE, 0x45, 0x49 };
void CNetAddr::Init() void CNetAddr::Init()
{ {

25
src/pow.cpp

@ -9,6 +9,7 @@
#include <chain.h> #include <chain.h>
#include <primitives/block.h> #include <primitives/block.h>
#include <uint256.h> #include <uint256.h>
#include <util.h>
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{ {
@ -38,9 +39,17 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
} }
// Go back by what we want to be 14 days worth of blocks // Go back by what we want to be 14 days worth of blocks
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); // Litecoin: This fixes an issue where a 51% attack can change difficulty at will.
assert(nHeightFirst >= 0); // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); int blockstogoback = params.DifficultyAdjustmentInterval()-1;
if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval())
blockstogoback = params.DifficultyAdjustmentInterval();
// Go back by what we want to be 14 days worth of blocks
const CBlockIndex* pindexFirst = pindexLast;
for (int i = 0; pindexFirst && i < blockstogoback; i++)
pindexFirst = pindexFirst->pprev;
assert(pindexFirst); assert(pindexFirst);
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
@ -59,11 +68,19 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
nActualTimespan = params.nPowTargetTimespan*4; nActualTimespan = params.nPowTargetTimespan*4;
// Retarget // Retarget
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
arith_uint256 bnNew; arith_uint256 bnNew;
arith_uint256 bnOld;
bnNew.SetCompact(pindexLast->nBits); bnNew.SetCompact(pindexLast->nBits);
bnOld = bnNew;
// Litecoin: intermediate uint256 can overflow by 1 bit
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
bool fShift = bnNew.bits() > bnPowLimit.bits() - 1;
if (fShift)
bnNew >>= 1;
bnNew *= nActualTimespan; bnNew *= nActualTimespan;
bnNew /= params.nPowTargetTimespan; bnNew /= params.nPowTargetTimespan;
if (fShift)
bnNew <<= 1;
if (bnNew > bnPowLimit) if (bnNew > bnPowLimit)
bnNew = bnPowLimit; bnNew = bnPowLimit;

2
src/qt/intro.cpp

@ -22,7 +22,7 @@
static const uint64_t GB_BYTES = 1000000000LL; static const uint64_t GB_BYTES = 1000000000LL;
/* Minimum free space (in GB) needed for data directory */ /* Minimum free space (in GB) needed for data directory */
static const uint64_t BLOCK_CHAIN_SIZE = 200; static const uint64_t BLOCK_CHAIN_SIZE = 8;
/* Minimum free space (in GB) needed for data directory when pruned; Does not include prune target */ /* Minimum free space (in GB) needed for data directory when pruned; Does not include prune target */
static const uint64_t CHAIN_STATE_SIZE = 3; static const uint64_t CHAIN_STATE_SIZE = 3;
/* Total required space (in GB) depending on user choice (prune, not prune) */ /* Total required space (in GB) depending on user choice (prune, not prune) */

6
src/rpc/net.cpp

@ -207,8 +207,8 @@ UniValue addnode(const JSONRPCRequest& request)
"1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
"2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n" "2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + HelpExampleCli("addnode", "\"192.168.0.6:9333\" \"onetry\"")
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"") + HelpExampleRpc("addnode", "\"192.168.0.6:9333\", \"onetry\"")
); );
if(!g_connman) if(!g_connman)
@ -296,7 +296,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
" \"connected\" : true|false, (boolean) If connected\n" " \"connected\" : true|false, (boolean) If connected\n"
" \"addresses\" : [ (list of objects) Only when connected = true\n" " \"addresses\" : [ (list of objects) Only when connected = true\n"
" {\n" " {\n"
" \"address\" : \"192.168.0.201:8333\", (string) The bitcoin server IP and port we're connected to\n" " \"address\" : \"192.168.0.201:9333\", (string) The litecoin server IP and port we're connected to\n"
" \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n"
" }\n" " }\n"
" ]\n" " ]\n"

2
src/rpc/server.cpp

@ -519,7 +519,7 @@ std::string HelpExampleCli(const std::string& methodname, const std::string& arg
std::string HelpExampleRpc(const std::string& methodname, const std::string& args) std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
{ {
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", " return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
"\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"; "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:9332/\n";
} }
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface) void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)

4
src/test/compress_tests.cpp

@ -20,7 +20,7 @@
#define NUM_MULTIPLES_1BTC 10000 #define NUM_MULTIPLES_1BTC 10000
// amounts 50 .. 21000000 // amounts 50 .. 21000000
#define NUM_MULTIPLES_50BTC 420000 #define NUM_MULTIPLES_50BTC 1680000
BOOST_FIXTURE_TEST_SUITE(compress_tests, BasicTestingSetup) BOOST_FIXTURE_TEST_SUITE(compress_tests, BasicTestingSetup)
@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(compress_amounts)
BOOST_CHECK(TestPair( CENT, 0x7)); BOOST_CHECK(TestPair( CENT, 0x7));
BOOST_CHECK(TestPair( COIN, 0x9)); BOOST_CHECK(TestPair( COIN, 0x9));
BOOST_CHECK(TestPair( 50*COIN, 0x32)); BOOST_CHECK(TestPair( 50*COIN, 0x32));
BOOST_CHECK(TestPair(21000000*COIN, 0x1406f40)); BOOST_CHECK(TestPair(84000000*COIN, 0x501BD00));
for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++)
BOOST_CHECK(TestEncode(i)); BOOST_CHECK(TestEncode(i));

2
src/test/miner_tests.cpp

@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
} }
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey)); BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
// Extend to a 210000-long block chain. // Extend to a 210000-long block chain.
while (chainActive.Tip()->nHeight < 210000) { while (chainActive.Tip()->nHeight < 840000) {
CBlockIndex* prev = chainActive.Tip(); CBlockIndex* prev = chainActive.Tip();
CBlockIndex* next = new CBlockIndex(); CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(InsecureRand256()); next->phashBlock = new uint256(InsecureRand256());

6
src/test/netbase_tests.cpp

@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(netbase_properties)
BOOST_CHECK(ResolveIP("8.8.8.8").IsRoutable()); BOOST_CHECK(ResolveIP("8.8.8.8").IsRoutable());
BOOST_CHECK(ResolveIP("2001::1").IsRoutable()); BOOST_CHECK(ResolveIP("2001::1").IsRoutable());
BOOST_CHECK(ResolveIP("127.0.0.1").IsValid()); BOOST_CHECK(ResolveIP("127.0.0.1").IsValid());
BOOST_CHECK(CreateInternal("FD6B:88C0:8724:edb1:8e4:3588:e546:35ca").IsInternal()); BOOST_CHECK(CreateInternal("FD6C:E9FE:4549:edb1:8e4:3588:e546:35ca").IsInternal());
BOOST_CHECK(CreateInternal("bar.com").IsInternal()); BOOST_CHECK(CreateInternal("bar.com").IsInternal());
} }
@ -116,9 +116,9 @@ BOOST_AUTO_TEST_CASE(netbase_lookupnumeric)
BOOST_CHECK(TestParse(":::", "[::]:0")); BOOST_CHECK(TestParse(":::", "[::]:0"));
// verify that an internal address fails to resolve // verify that an internal address fails to resolve
BOOST_CHECK(TestParse("[fd6b:88c0:8724:1:2:3:4:5]", "[::]:0")); BOOST_CHECK(TestParse("[fd6c:e9fe:4549:1:2:3:4:5]", "[::]:0"));
// and that a one-off resolves correctly // and that a one-off resolves correctly
BOOST_CHECK(TestParse("[fd6c:88c0:8724:1:2:3:4:5]", "[fd6c:88c0:8724:1:2:3:4:5]:65535")); BOOST_CHECK(TestParse("[fd6d:e9fe:4549:1:2:3:4:5]", "[fd6d:e9fe:4549:1:2:3:4:5]:65535"));
} }
BOOST_AUTO_TEST_CASE(onioncat_test) BOOST_AUTO_TEST_CASE(onioncat_test)

2
src/timedata.h

@ -10,7 +10,7 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
static const int64_t DEFAULT_MAX_TIME_ADJUSTMENT = 70 * 60; static const int64_t DEFAULT_MAX_TIME_ADJUSTMENT = 35 * 60;
class CNetAddr; class CNetAddr;

11
src/validation.cpp

@ -1848,9 +1848,10 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
// Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the // 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 // two in the chain that violate it. This prevents exploiting the issue against nodes during their
// initial block download. // initial block download.
bool fEnforceBIP30 = (!pindex->phashBlock) || // Enforce on CreateNewBlock invocations which don't have a hash. bool fEnforceBIP30 = true;
!((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) || //(!pindex->phashBlock) || // Enforce on CreateNewBlock invocations which don't have a hash.
(pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"))); // !((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
// (pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")));
// Once BIP34 activated it was not possible to create new duplicate coinbases and thus other than starting // 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 // with the 2 existing duplicate coinbase pairs, not possible to create overwriting txs. But by the
@ -3124,6 +3125,10 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion), return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
strprintf("rejected nVersion=0x%08x block", block.nVersion)); strprintf("rejected nVersion=0x%08x block", block.nVersion));
if (block.nVersion < VERSIONBITS_TOP_BITS && IsWitnessEnabled(pindexPrev, consensusParams))
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
strprintf("rejected nVersion=0x%08x block", block.nVersion));
return true; return true;
} }

2
src/validation.h

@ -206,7 +206,7 @@ static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
/** Minimum blocks required to signal NODE_NETWORK_LIMITED */ /** Minimum blocks required to signal NODE_NETWORK_LIMITED */
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288; static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
static const signed int DEFAULT_CHECKBLOCKS = 6; static const signed int DEFAULT_CHECKBLOCKS = 6 * 4;
static const unsigned int DEFAULT_CHECKLEVEL = 3; static const unsigned int DEFAULT_CHECKLEVEL = 3;
// Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat) // Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)

2
src/version.h

@ -15,7 +15,7 @@ static const int PROTOCOL_VERSION = 70015;
static const int INIT_PROTO_VERSION = 209; static const int INIT_PROTO_VERSION = 209;
//! In this version, 'getheaders' was introduced. //! In this version, 'getheaders' was introduced.
static const int GETHEADERS_VERSION = 31800; static const int GETHEADERS_VERSION = 70002;
//! disconnect from peers older than this proto version //! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION; static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION;

7
test/functional/feature_nulldummy.py

@ -22,6 +22,7 @@ from io import BytesIO
import time import time
NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)" NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
VB_TOP_BITS = 0x20000000
def trueDummy(tx): def trueDummy(tx):
scriptSig = CScript(tx.vin[0].scriptSig) scriptSig = CScript(tx.vin[0].scriptSig)
@ -95,7 +96,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
self.log.info("Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [432]") self.log.info("Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [432]")
for i in test6txs: for i in test6txs:
self.nodes[0].sendrawtransaction(bytes_to_hex_str(i.serialize_with_witness()), True) self.nodes[0].sendrawtransaction(bytes_to_hex_str(i.serialize_with_witness()), True)
self.block_submit(self.nodes[0], test6txs, True, True) self.block_submit(self.nodes[0], test6txs, True, True, VB_TOP_BITS)
def create_transaction(self, node, txid, to_address, amount): def create_transaction(self, node, txid, to_address, amount):
@ -109,9 +110,9 @@ class NULLDUMMYTest(BitcoinTestFramework):
return tx return tx
def block_submit(self, node, txs, witness = False, accept = False): def block_submit(self, node, txs, witness = False, accept = False, version=4):
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1) block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1)
block.nVersion = 4 block.nVersion = version
for tx in txs: for tx in txs:
tx.rehash() tx.rehash()
block.vtx.append(tx) block.vtx.append(tx)

8
test/functional/feature_proxy.py

@ -120,24 +120,24 @@ class ProxyTest(BitcoinTestFramework):
if test_onion: if test_onion:
# Test: outgoing onion connection through node # Test: outgoing onion connection through node
node.addnode("bitcoinostk4e4re.onion:8333", "onetry") node.addnode("bitcoinostk4e4re.onion:9333", "onetry")
cmd = proxies[2].queue.get() cmd = proxies[2].queue.get()
assert(isinstance(cmd, Socks5Command)) assert(isinstance(cmd, Socks5Command))
assert_equal(cmd.atyp, AddressType.DOMAINNAME) assert_equal(cmd.atyp, AddressType.DOMAINNAME)
assert_equal(cmd.addr, b"bitcoinostk4e4re.onion") assert_equal(cmd.addr, b"bitcoinostk4e4re.onion")
assert_equal(cmd.port, 8333) assert_equal(cmd.port, 9333)
if not auth: if not auth:
assert_equal(cmd.username, None) assert_equal(cmd.username, None)
assert_equal(cmd.password, None) assert_equal(cmd.password, None)
rv.append(cmd) rv.append(cmd)
# Test: outgoing DNS name connection through node # Test: outgoing DNS name connection through node
node.addnode("node.noumenon:8333", "onetry") node.addnode("node.noumenon:9333", "onetry")
cmd = proxies[3].queue.get() cmd = proxies[3].queue.get()
assert(isinstance(cmd, Socks5Command)) assert(isinstance(cmd, Socks5Command))
assert_equal(cmd.atyp, AddressType.DOMAINNAME) assert_equal(cmd.atyp, AddressType.DOMAINNAME)
assert_equal(cmd.addr, b"node.noumenon") assert_equal(cmd.addr, b"node.noumenon")
assert_equal(cmd.port, 8333) assert_equal(cmd.port, 9333)
if not auth: if not auth:
assert_equal(cmd.username, None) assert_equal(cmd.username, None)
assert_equal(cmd.password, None) assert_equal(cmd.password, None)

21
test/functional/p2p_segwit.py

@ -129,7 +129,7 @@ class SegWitTest(BitcoinTestFramework):
''' Helpers ''' ''' Helpers '''
# Build a block on top of node0's tip. # Build a block on top of node0's tip.
def build_next_block(self, nVersion=4): def build_next_block(self, nVersion=VB_TOP_BITS):
tip = self.nodes[0].getbestblockhash() tip = self.nodes[0].getbestblockhash()
height = self.nodes[0].getblockcount() + 1 height = self.nodes[0].getblockcount() + 1
block_time = self.nodes[0].getblockheader(tip)["mediantime"] + 1 block_time = self.nodes[0].getblockheader(tip)["mediantime"] + 1
@ -963,12 +963,11 @@ class SegWitTest(BitcoinTestFramework):
assert(self.test_node.last_message["getdata"].inv[0].type == blocktype) assert(self.test_node.last_message["getdata"].inv[0].type == blocktype)
test_witness_block(self.nodes[0].rpc, self.test_node, block1, True) test_witness_block(self.nodes[0].rpc, self.test_node, block1, True)
block2 = self.build_next_block(nVersion=4) # Litecoin: Blocks with nVersion < VB_TOP_BITS are rejected
block2.solve()
self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True) # self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True)
assert(self.test_node.last_message["getdata"].inv[0].type == blocktype) # assert(self.test_node.last_message["getdata"].inv[0].type == blocktype)
test_witness_block(self.nodes[0].rpc, self.test_node, block2, True) # test_witness_block(self.nodes[0].rpc, self.test_node, block2, True)
block3 = self.build_next_block(nVersion=(VB_TOP_BITS | (1<<15))) block3 = self.build_next_block(nVersion=(VB_TOP_BITS | (1<<15)))
block3.solve() block3.solve()
@ -1021,7 +1020,8 @@ class SegWitTest(BitcoinTestFramework):
assert_equal(rpc_details["weight"], weight) assert_equal(rpc_details["weight"], weight)
# Upgraded node should not ask for blocks from unupgraded # Upgraded node should not ask for blocks from unupgraded
block4 = self.build_next_block(nVersion=4) # Litecoin: Blocks with nVersion < VB_TOP_BITS are rejected
block4 = self.build_next_block(nVersion=(VB_TOP_BITS | (1<<15)))
block4.solve() block4.solve()
self.old_node.getdataset = set() self.old_node.getdataset = set()
@ -1874,6 +1874,12 @@ class SegWitTest(BitcoinTestFramework):
self.utxo.pop(0) self.utxo.pop(0)
def test_reject_blocks(self):
print ("\tTesting rejection of block.nVersion < BIP9_TOP_BITS blocks")
block = self.build_next_block(nVersion=4)
block.solve()
resp = self.nodes[0].submitblock(bytes_to_hex_str(block.serialize(True)))
assert_equal(resp, 'bad-version(0x00000004)')
def run_test(self): def run_test(self):
# Setup the p2p connections and start up the network thread. # Setup the p2p connections and start up the network thread.
@ -1926,6 +1932,7 @@ class SegWitTest(BitcoinTestFramework):
sync_blocks(self.nodes) sync_blocks(self.nodes)
# Test P2SH witness handling again # Test P2SH witness handling again
self.test_reject_blocks()
self.test_p2sh_witness(segwit_activated=True) self.test_p2sh_witness(segwit_activated=True)
self.test_witness_commitments() self.test_witness_commitments()
self.test_block_malleability() self.test_block_malleability()

Loading…
Cancel
Save