Browse Source

Merge pull request #4368

75c82d4 Move coins.cpp and keystore.cpp to libbitcoin_common (Wladimir J. van der Laan)
84ce18c Remove unnecessary dependencies for bitcoin-cli (Wladimir J. van der Laan)
14f888c Move network-time related functions to timedata.cpp/h (Wladimir J. van der Laan)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
343feecf56
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 66
      src/Makefile.am
  2. 4
      src/Makefile.qt.include
  3. 2
      src/Makefile.qttest.include
  4. 2
      src/Makefile.test.include
  5. 1
      src/addrman.h
  6. 1
      src/alert.cpp
  7. 9
      src/bitcoin-cli.cpp
  8. 36
      src/chainparams.cpp
  9. 19
      src/chainparams.h
  10. 93
      src/chainparamsbase.cpp
  11. 52
      src/chainparamsbase.h
  12. 4
      src/checkpoints.cpp
  13. 2
      src/qt/bitcoin.cpp
  14. 8
      src/qt/paymentserver.cpp
  15. 1
      src/qt/test/paymentservertests.cpp
  16. 1
      src/qt/transactiondesc.cpp
  17. 1
      src/qt/transactionrecord.cpp
  18. 2
      src/rpcmining.cpp
  19. 3
      src/rpcmisc.cpp
  20. 1
      src/rpcnet.cpp
  21. 2
      src/rpcserver.cpp
  22. 1
      src/rpcwallet.cpp
  23. 12
      src/test/base58_tests.cpp
  24. 1
      src/test/test_bitcoin.cpp
  25. 91
      src/timedata.cpp
  26. 17
      src/timedata.h
  27. 89
      src/util.cpp
  28. 4
      src/util.h
  29. 1
      src/wallet.cpp

66
src/Makefile.am

@ -20,10 +20,19 @@ endif
BITCOIN_CONFIG_INCLUDES=-I$(builddir)/config BITCOIN_CONFIG_INCLUDES=-I$(builddir)/config
BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)
LIBBITCOIN_SERVER=libbitcoin_server.a
LIBBITCOIN_WALLET=libbitcoin_wallet.a
LIBBITCOIN_COMMON=libbitcoin_common.a
LIBBITCOIN_CLI=libbitcoin_cli.a
LIBBITCOIN_UTIL=libbitcoin_util.a
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
LIBBITCOINQT=qt/libbitcoinqt.a
noinst_LIBRARIES = \ noinst_LIBRARIES = \
libbitcoin_server.a \ libbitcoin_server.a \
libbitcoin_common.a \ libbitcoin_common.a \
libbitcoin_cli.a \ libbitcoin_cli.a \
libbitcoin_util.a \
crypto/libbitcoin_crypto.a crypto/libbitcoin_crypto.a
if ENABLE_WALLET if ENABLE_WALLET
BITCOIN_INCLUDES += $(BDB_CPPFLAGS) BITCOIN_INCLUDES += $(BDB_CPPFLAGS)
@ -50,6 +59,7 @@ BITCOIN_CORE_H = \
base58.h \ base58.h \
bloom.h \ bloom.h \
chainparams.h \ chainparams.h \
chainparamsbase.h \
checkpoints.h \ checkpoints.h \
checkqueue.h \ checkqueue.h \
clientversion.h \ clientversion.h \
@ -80,6 +90,7 @@ BITCOIN_CORE_H = \
serialize.h \ serialize.h \
sync.h \ sync.h \
threadsafety.h \ threadsafety.h \
timedata.h \
tinyformat.h \ tinyformat.h \
txdb.h \ txdb.h \
txmempool.h \ txmempool.h \
@ -106,17 +117,16 @@ obj/build.h: FORCE
@$(MKDIR_P) $(builddir)/obj @$(MKDIR_P) $(builddir)/obj
@$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \ @$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \
$(abs_top_srcdir) $(abs_top_srcdir)
libbitcoin_common_a-version.$(OBJEXT): obj/build.h libbitcoin_util_a-version.$(OBJEXT): obj/build.h
# server: shared between bitcoind and bitcoin-qt
libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES) libbitcoin_server_a_CPPFLAGS = $(BITCOIN_INCLUDES)
libbitcoin_server_a_SOURCES = \ libbitcoin_server_a_SOURCES = \
addrman.cpp \ addrman.cpp \
alert.cpp \ alert.cpp \
bloom.cpp \ bloom.cpp \
checkpoints.cpp \ checkpoints.cpp \
coins.cpp \
init.cpp \ init.cpp \
keystore.cpp \
leveldbwrapper.cpp \ leveldbwrapper.cpp \
main.cpp \ main.cpp \
miner.cpp \ miner.cpp \
@ -129,11 +139,14 @@ libbitcoin_server_a_SOURCES = \
rpcnet.cpp \ rpcnet.cpp \
rpcrawtransaction.cpp \ rpcrawtransaction.cpp \
rpcserver.cpp \ rpcserver.cpp \
timedata.cpp \
txdb.cpp \ txdb.cpp \
txmempool.cpp \ txmempool.cpp \
$(JSON_H) \ $(JSON_H) \
$(BITCOIN_CORE_H) $(BITCOIN_CORE_H)
# wallet: shared between bitcoind and bitcoin-qt, but only linked
# when wallet enabled
libbitcoin_wallet_a_CPPFLAGS = $(BITCOIN_INCLUDES) libbitcoin_wallet_a_CPPFLAGS = $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_SOURCES = \ libbitcoin_wallet_a_SOURCES = \
db.cpp \ db.cpp \
@ -144,6 +157,7 @@ libbitcoin_wallet_a_SOURCES = \
walletdb.cpp \ walletdb.cpp \
$(BITCOIN_CORE_H) $(BITCOIN_CORE_H)
# crypto primitives library
crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES) crypto_libbitcoin_crypto_a_CPPFLAGS = $(BITCOIN_CONFIG_INCLUDES)
crypto_libbitcoin_crypto_a_SOURCES = \ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/sha1.cpp \ crypto/sha1.cpp \
@ -154,18 +168,29 @@ crypto_libbitcoin_crypto_a_SOURCES = \
crypto/sha1.h \ crypto/sha1.h \
crypto/ripemd160.h crypto/ripemd160.h
# common: shared between bitcoind, and bitcoin-qt and non-server tools
libbitcoin_common_a_CPPFLAGS = $(BITCOIN_INCLUDES) libbitcoin_common_a_CPPFLAGS = $(BITCOIN_INCLUDES)
libbitcoin_common_a_SOURCES = \ libbitcoin_common_a_SOURCES = \
base58.cpp \
allocators.cpp \ allocators.cpp \
base58.cpp \
chainparams.cpp \ chainparams.cpp \
coins.cpp \
core.cpp \ core.cpp \
hash.cpp \ hash.cpp \
key.cpp \ key.cpp \
keystore.cpp \
netbase.cpp \ netbase.cpp \
protocol.cpp \ protocol.cpp \
rpcprotocol.cpp \
script.cpp \ script.cpp \
$(BITCOIN_CORE_H)
# util: shared between all executables.
# This library *must* be included to make sure that the glibc
# backward-compatibility objects and their sanity checks are linked.
libbitcoin_util_a_CPPFLAGS = $(BITCOIN_INCLUDES)
libbitcoin_util_a_SOURCES = \
chainparamsbase.cpp \
rpcprotocol.cpp \
sync.cpp \ sync.cpp \
util.cpp \ util.cpp \
version.cpp \ version.cpp \
@ -174,22 +199,24 @@ libbitcoin_common_a_SOURCES = \
$(BITCOIN_CORE_H) $(BITCOIN_CORE_H)
if GLIBC_BACK_COMPAT if GLIBC_BACK_COMPAT
libbitcoin_common_a_SOURCES += compat/glibc_compat.cpp libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
libbitcoin_common_a_SOURCES += compat/glibcxx_compat.cpp libbitcoin_util_a_SOURCES += compat/glibcxx_compat.cpp
endif endif
# cli: shared between bitcoin-cli and bitcoin-qt
libbitcoin_cli_a_SOURCES = \ libbitcoin_cli_a_SOURCES = \
rpcclient.cpp \ rpcclient.cpp \
$(BITCOIN_CORE_H) $(BITCOIN_CORE_H)
nodist_libbitcoin_common_a_SOURCES = $(srcdir)/obj/build.h nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
# #
# bitcoind binary # # bitcoind binary #
bitcoind_LDADD = \ bitcoind_LDADD = \
libbitcoin_server.a \ $(LIBBITCOIN_SERVER) \
libbitcoin_common.a \ $(LIBBITCOIN_COMMON) \
crypto/libbitcoin_crypto.a \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(LIBLEVELDB) \ $(LIBLEVELDB) \
$(LIBMEMENV) $(LIBMEMENV)
if ENABLE_WALLET if ENABLE_WALLET
@ -207,11 +234,13 @@ bitcoind_CPPFLAGS = $(BITCOIN_INCLUDES)
# bitcoin-cli binary # # bitcoin-cli binary #
bitcoin_cli_LDADD = \ bitcoin_cli_LDADD = \
libbitcoin_cli.a \ $(LIBBITCOIN_CLI) \
libbitcoin_common.a \ $(LIBBITCOIN_COMMON) \
crypto/libbitcoin_crypto.a \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(BOOST_LIBS) $(BOOST_LIBS)
bitcoin_cli_SOURCES = bitcoin-cli.cpp bitcoin_cli_SOURCES = \
bitcoin-cli.cpp
bitcoin_cli_CPPFLAGS = $(BITCOIN_INCLUDES) bitcoin_cli_CPPFLAGS = $(BITCOIN_INCLUDES)
# #
@ -242,13 +271,6 @@ clean-local:
@test -f $(PROTOC) @test -f $(PROTOC)
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $(<D) $<) $(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $(<D) $<)
LIBBITCOIN_SERVER=libbitcoin_server.a
LIBBITCOIN_WALLET=libbitcoin_wallet.a
LIBBITCOIN_COMMON=libbitcoin_common.a
LIBBITCOIN_CLI=libbitcoin_cli.a
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
LIBBITCOINQT=qt/libbitcoinqt.a
if ENABLE_TESTS if ENABLE_TESTS
include Makefile.test.include include Makefile.test.include
endif endif

4
src/Makefile.qt.include

@ -355,7 +355,7 @@ qt_bitcoin_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER)
if ENABLE_WALLET if ENABLE_WALLET
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET) qt_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
endif endif
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
qt_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS) qt_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)
@ -364,7 +364,7 @@ QT_QM=$(QT_TS:.ts=.qm)
.SECONDARY: $(QT_QM) .SECONDARY: $(QT_QM)
qt/bitcoinstrings.cpp: $(libbitcoin_server_a_SOURCES) $(libbitcoin_common_a_SOURCES) $(libbitcoin_cli_a_SOURCES) qt/bitcoinstrings.cpp: $(libbitcoin_server_a_SOURCES) $(libbitcoin_common_a_SOURCES) $(libbitcoin_cli_a_SOURCES) $(libbitcoin_util_a_SOURCES)
@test -n $(XGETTEXT) || echo "xgettext is required for updating translations" @test -n $(XGETTEXT) || echo "xgettext is required for updating translations"
$(AM_V_GEN) cd $(top_srcdir); XGETTEXT=$(XGETTEXT) share/qt/extract_strings_qt.py $(AM_V_GEN) cd $(top_srcdir); XGETTEXT=$(XGETTEXT) share/qt/extract_strings_qt.py

2
src/Makefile.qttest.include

@ -30,7 +30,7 @@ qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER)
if ENABLE_WALLET if ENABLE_WALLET
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET) qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
endif endif
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) \ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) \
$(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
qt_test_test_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS) qt_test_test_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)

2
src/Makefile.test.include

@ -63,7 +63,7 @@ endif
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
test_test_bitcoin_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) test_test_bitcoin_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS)
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \ test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
if ENABLE_WALLET if ENABLE_WALLET
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET) test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)

1
src/addrman.h

@ -8,6 +8,7 @@
#include "netbase.h" #include "netbase.h"
#include "protocol.h" #include "protocol.h"
#include "sync.h" #include "sync.h"
#include "timedata.h"
#include "util.h" #include "util.h"
#include <map> #include <map>

1
src/alert.cpp

@ -8,6 +8,7 @@
#include "chainparams.h" #include "chainparams.h"
#include "key.h" #include "key.h"
#include "net.h" #include "net.h"
#include "timedata.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "util.h" #include "util.h"

9
src/bitcoin-cli.cpp

@ -8,7 +8,7 @@
#include "rpcclient.h" #include "rpcclient.h"
#include "rpcprotocol.h" #include "rpcprotocol.h"
#include "ui_interface.h" /* for _(...) */ #include "ui_interface.h" /* for _(...) */
#include "chainparams.h" #include "chainparamsbase.h"
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
@ -60,12 +60,11 @@ static bool AppInitRPC(int argc, char* argv[])
fprintf(stderr,"Error reading configuration file: %s\n", e.what()); fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false; return false;
} }
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) // Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) { if (!SelectBaseParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n"); fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
return false; return false;
} }
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{ {
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n"; std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
@ -104,7 +103,7 @@ Object CallRPC(const string& strMethod, const Array& params)
bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
do { do {
bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort()))); bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(BaseParams().RPCPort())));
if (fConnected) break; if (fConnected) break;
if (fWait) if (fWait)
MilliSleep(1000); MilliSleep(1000);

36
src/chainparams.cpp

@ -99,7 +99,7 @@ unsigned int pnSeed[] =
class CMainParams : public CChainParams { class CMainParams : public CChainParams {
public: public:
CMainParams() { CMainParams() {
networkID = CChainParams::MAIN; networkID = CBaseChainParams::MAIN;
strNetworkID = "main"; strNetworkID = "main";
// The message start string is designed to be unlikely to occur in normal data. // The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@ -110,7 +110,6 @@ public:
pchMessageStart[3] = 0xd9; pchMessageStart[3] = 0xd9;
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"); vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
nDefaultPort = 8333; nDefaultPort = 8333;
nRPCPort = 8332;
bnProofOfWorkLimit = ~uint256(0) >> 32; bnProofOfWorkLimit = ~uint256(0) >> 32;
nSubsidyHalvingInterval = 210000; nSubsidyHalvingInterval = 210000;
nEnforceBlockUpgradeMajority = 750; nEnforceBlockUpgradeMajority = 750;
@ -191,7 +190,7 @@ static CMainParams mainParams;
class CTestNetParams : public CMainParams { class CTestNetParams : public CMainParams {
public: public:
CTestNetParams() { CTestNetParams() {
networkID = CChainParams::TESTNET; networkID = CBaseChainParams::TESTNET;
strNetworkID = "test"; strNetworkID = "test";
// The message start string is designed to be unlikely to occur in normal data. // The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@ -202,14 +201,12 @@ public:
pchMessageStart[3] = 0x07; pchMessageStart[3] = 0x07;
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"); vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
nDefaultPort = 18333; nDefaultPort = 18333;
nRPCPort = 18332;
nEnforceBlockUpgradeMajority = 51; nEnforceBlockUpgradeMajority = 51;
nRejectBlockOutdatedMajority = 75; nRejectBlockOutdatedMajority = 75;
nToCheckBlockUpgradeMajority = 100; nToCheckBlockUpgradeMajority = 100;
nMinerThreads = 0; nMinerThreads = 0;
nTargetTimespan = 14 * 24 * 60 * 60; // two weeks nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
nTargetSpacing = 10 * 60; nTargetSpacing = 10 * 60;
strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start. // Modify the testnet genesis block so the timestamp is valid for a later start.
genesis.nTime = 1296688602; genesis.nTime = 1296688602;
@ -245,7 +242,7 @@ static CTestNetParams testNetParams;
class CRegTestParams : public CTestNetParams { class CRegTestParams : public CTestNetParams {
public: public:
CRegTestParams() { CRegTestParams() {
networkID = CChainParams::REGTEST; networkID = CBaseChainParams::REGTEST;
strNetworkID = "regtest"; strNetworkID = "regtest";
pchMessageStart[0] = 0xfa; pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf; pchMessageStart[1] = 0xbf;
@ -264,7 +261,6 @@ public:
genesis.nNonce = 2; genesis.nNonce = 2;
hashGenesisBlock = genesis.GetHash(); hashGenesisBlock = genesis.GetHash();
nDefaultPort = 18444; nDefaultPort = 18444;
strDataDir = "regtest";
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds. vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
@ -279,21 +275,23 @@ public:
}; };
static CRegTestParams regTestParams; static CRegTestParams regTestParams;
static CChainParams *pCurrentParams = &mainParams; static CChainParams *pCurrentParams = 0;
const CChainParams &Params() { const CChainParams &Params() {
assert(pCurrentParams);
return *pCurrentParams; return *pCurrentParams;
} }
void SelectParams(CChainParams::Network network) { void SelectParams(CBaseChainParams::Network network) {
SelectBaseParams(network);
switch (network) { switch (network) {
case CChainParams::MAIN: case CBaseChainParams::MAIN:
pCurrentParams = &mainParams; pCurrentParams = &mainParams;
break; break;
case CChainParams::TESTNET: case CBaseChainParams::TESTNET:
pCurrentParams = &testNetParams; pCurrentParams = &testNetParams;
break; break;
case CChainParams::REGTEST: case CBaseChainParams::REGTEST:
pCurrentParams = &regTestParams; pCurrentParams = &regTestParams;
break; break;
default: default:
@ -303,19 +301,9 @@ void SelectParams(CChainParams::Network network) {
} }
bool SelectParamsFromCommandLine() { bool SelectParamsFromCommandLine() {
bool fRegTest = GetBoolArg("-regtest", false); if (!SelectBaseParamsFromCommandLine())
bool fTestNet = GetBoolArg("-testnet", false);
if (fTestNet && fRegTest) {
return false; return false;
}
if (fRegTest) { SelectParams(BaseParams().NetworkID());
SelectParams(CChainParams::REGTEST);
} else if (fTestNet) {
SelectParams(CChainParams::TESTNET);
} else {
SelectParams(CChainParams::MAIN);
}
return true; return true;
} }

19
src/chainparams.h

@ -7,6 +7,7 @@
#define BITCOIN_CHAIN_PARAMS_H #define BITCOIN_CHAIN_PARAMS_H
#include "core.h" #include "core.h"
#include "chainparamsbase.h"
#include "protocol.h" #include "protocol.h"
#include "uint256.h" #include "uint256.h"
@ -29,14 +30,6 @@ struct CDNSSeedData {
class CChainParams class CChainParams
{ {
public: public:
enum Network {
MAIN,
TESTNET,
REGTEST,
MAX_NETWORK_TYPES
};
enum Base58Type { enum Base58Type {
PUBKEY_ADDRESS, PUBKEY_ADDRESS,
SCRIPT_ADDRESS, SCRIPT_ADDRESS,
@ -73,17 +66,15 @@ public:
int64_t TargetTimespan() const { return nTargetTimespan; } int64_t TargetTimespan() const { return nTargetTimespan; }
int64_t TargetSpacing() const { return nTargetSpacing; } int64_t TargetSpacing() const { return nTargetSpacing; }
int64_t Interval() const { return nTargetTimespan / nTargetSpacing; } int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }
const std::string& DataDir() const { return strDataDir; }
/* Make miner stop after a block is found. In RPC, don't return /* Make miner stop after a block is found. In RPC, don't return
* until nGenProcLimit blocks are generated */ * until nGenProcLimit blocks are generated */
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; } bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
Network NetworkID() const { return networkID; } CBaseChainParams::Network NetworkID() const { return networkID; }
/* Return the BIP70 network string (main, test or regtest) */ /* Return the BIP70 network string (main, test or regtest) */
std::string NetworkIDString() const { return strNetworkID; } std::string NetworkIDString() const { return strNetworkID; }
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; } const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; } const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
int RPCPort() const { return nRPCPort; }
protected: protected:
CChainParams() {} CChainParams() {}
@ -92,7 +83,6 @@ protected:
// Raw pub key bytes for the broadcast alert signing key. // Raw pub key bytes for the broadcast alert signing key.
std::vector<unsigned char> vAlertPubKey; std::vector<unsigned char> vAlertPubKey;
int nDefaultPort; int nDefaultPort;
int nRPCPort;
uint256 bnProofOfWorkLimit; uint256 bnProofOfWorkLimit;
int nSubsidyHalvingInterval; int nSubsidyHalvingInterval;
int nEnforceBlockUpgradeMajority; int nEnforceBlockUpgradeMajority;
@ -100,11 +90,10 @@ protected:
int nToCheckBlockUpgradeMajority; int nToCheckBlockUpgradeMajority;
int64_t nTargetTimespan; int64_t nTargetTimespan;
int64_t nTargetSpacing; int64_t nTargetSpacing;
std::string strDataDir;
int nMinerThreads; int nMinerThreads;
std::vector<CDNSSeedData> vSeeds; std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES]; std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
Network networkID; CBaseChainParams::Network networkID;
std::string strNetworkID; std::string strNetworkID;
CBlock genesis; CBlock genesis;
std::vector<CAddress> vFixedSeeds; std::vector<CAddress> vFixedSeeds;
@ -123,7 +112,7 @@ protected:
const CChainParams &Params(); const CChainParams &Params();
/** Sets the params returned by Params() to those for the given network. */ /** Sets the params returned by Params() to those for the given network. */
void SelectParams(CChainParams::Network network); void SelectParams(CBaseChainParams::Network network);
/** /**
* Looks for -regtest or -testnet and then calls SelectParams as appropriate. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.

93
src/chainparamsbase.cpp

@ -0,0 +1,93 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparamsbase.h"
#include "assert.h"
#include "util.h"
#include <boost/assign/list_of.hpp>
using namespace boost::assign;
//
// Main network
//
class CBaseMainParams : public CBaseChainParams {
public:
CBaseMainParams() {
networkID = CBaseChainParams::MAIN;
nRPCPort = 8332;
}
};
static CBaseMainParams mainParams;
//
// Testnet (v3)
//
class CBaseTestNetParams : public CBaseMainParams {
public:
CBaseTestNetParams() {
networkID = CBaseChainParams::TESTNET;
nRPCPort = 18332;
strDataDir = "testnet3";
}
};
static CBaseTestNetParams testNetParams;
//
// Regression test
//
class CBaseRegTestParams : public CBaseTestNetParams {
public:
CBaseRegTestParams() {
networkID = CBaseChainParams::REGTEST;
strDataDir = "regtest";
}
};
static CBaseRegTestParams regTestParams;
static CBaseChainParams *pCurrentBaseParams = 0;
const CBaseChainParams &BaseParams() {
assert(pCurrentBaseParams);
return *pCurrentBaseParams;
}
void SelectBaseParams(CBaseChainParams::Network network) {
switch (network) {
case CBaseChainParams::MAIN:
pCurrentBaseParams = &mainParams;
break;
case CBaseChainParams::TESTNET:
pCurrentBaseParams = &testNetParams;
break;
case CBaseChainParams::REGTEST:
pCurrentBaseParams = &regTestParams;
break;
default:
assert(false && "Unimplemented network");
return;
}
}
bool SelectBaseParamsFromCommandLine() {
bool fRegTest = GetBoolArg("-regtest", false);
bool fTestNet = GetBoolArg("-testnet", false);
if (fTestNet && fRegTest) {
return false;
}
if (fRegTest) {
SelectBaseParams(CBaseChainParams::REGTEST);
} else if (fTestNet) {
SelectBaseParams(CBaseChainParams::TESTNET);
} else {
SelectBaseParams(CBaseChainParams::MAIN);
}
return true;
}

52
src/chainparamsbase.h

@ -0,0 +1,52 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_CHAIN_PARAMS_BASE_H
#define BITCOIN_CHAIN_PARAMS_BASE_H
#include <vector>
#include <string>
/**
* CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind)
* of a given instance of the Bitcoin system.
*/
class CBaseChainParams
{
public:
enum Network {
MAIN,
TESTNET,
REGTEST,
MAX_NETWORK_TYPES
};
const std::string& DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }
Network NetworkID() const { return networkID; }
protected:
CBaseChainParams() {}
int nRPCPort;
std::string strDataDir;
Network networkID;
};
/**
* Return the currently selected parameters. This won't change after app startup
* outside of the unit tests.
*/
const CBaseChainParams &BaseParams();
/** Sets the params returned by Params() to those for the given network. */
void SelectBaseParams(CBaseChainParams::Network network);
/**
* Looks for -regtest or -testnet and then calls SelectParams as appropriate.
* Returns false if an invalid combination is given.
*/
bool SelectBaseParamsFromCommandLine();
#endif

4
src/checkpoints.cpp

@ -83,9 +83,9 @@ namespace Checkpoints
}; };
const CCheckpointData &Checkpoints() { const CCheckpointData &Checkpoints() {
if (Params().NetworkID() == CChainParams::TESTNET) if (Params().NetworkID() == CBaseChainParams::TESTNET)
return dataTestnet; return dataTestnet;
else if (Params().NetworkID() == CChainParams::MAIN) else if (Params().NetworkID() == CBaseChainParams::MAIN)
return data; return data;
else else
return dataRegtest; return dataRegtest;

2
src/qt/bitcoin.cpp

@ -546,7 +546,7 @@ int main(int argc, char *argv[])
if (!PaymentServer::ipcParseCommandLine(argc, argv)) if (!PaymentServer::ipcParseCommandLine(argc, argv))
exit(0); exit(0);
#endif #endif
bool isaTestNet = Params().NetworkID() != CChainParams::MAIN; bool isaTestNet = Params().NetworkID() != CBaseChainParams::MAIN;
// Allow for separate UI settings for testnets // Allow for separate UI settings for testnets
if (isaTestNet) if (isaTestNet)
QApplication::setApplicationName(QAPP_APP_NAME_TESTNET); QApplication::setApplicationName(QAPP_APP_NAME_TESTNET);

8
src/qt/paymentserver.cpp

@ -199,10 +199,10 @@ bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
{ {
CBitcoinAddress address(r.address.toStdString()); CBitcoinAddress address(r.address.toStdString());
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
if (!address.IsValid()) if (!address.IsValid())
{ {
SelectParams(CChainParams::TESTNET); SelectParams(CBaseChainParams::TESTNET);
} }
} }
} }
@ -214,9 +214,9 @@ bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
if (readPaymentRequest(arg, request)) if (readPaymentRequest(arg, request))
{ {
if (request.getDetails().network() == "main") if (request.getDetails().network() == "main")
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
else else
SelectParams(CChainParams::TESTNET); SelectParams(CBaseChainParams::TESTNET);
} }
} }
else else

1
src/qt/test/paymentservertests.cpp

@ -56,6 +56,7 @@ static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsig
void PaymentServerTests::paymentServerTests() void PaymentServerTests::paymentServerTests()
{ {
SelectParams(CBaseChainParams::MAIN);
OptionsModel optionsModel; OptionsModel optionsModel;
PaymentServer* server = new PaymentServer(NULL, false); PaymentServer* server = new PaymentServer(NULL, false);
X509_STORE* caStore = X509_STORE_new(); X509_STORE* caStore = X509_STORE_new();

1
src/qt/transactiondesc.cpp

@ -12,6 +12,7 @@
#include "main.h" #include "main.h"
#include "paymentserver.h" #include "paymentserver.h"
#include "transactionrecord.h" #include "transactionrecord.h"
#include "timedata.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "wallet.h" #include "wallet.h"

1
src/qt/transactionrecord.cpp

@ -5,6 +5,7 @@
#include "transactionrecord.h" #include "transactionrecord.h"
#include "base58.h" #include "base58.h"
#include "timedata.h"
#include "wallet.h" #include "wallet.h"
#include <stdint.h> #include <stdint.h>

2
src/rpcmining.cpp

@ -237,7 +237,7 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false))); obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("testnet", Params().NetworkID() == CChainParams::TESTNET)); obj.push_back(Pair("testnet", Params().NetworkID() == CBaseChainParams::TESTNET));
obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("chain", Params().NetworkIDString()));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
obj.push_back(Pair("generate", getgenerate(params, false))); obj.push_back(Pair("generate", getgenerate(params, false)));

3
src/rpcmisc.cpp

@ -9,6 +9,7 @@
#include "net.h" #include "net.h"
#include "netbase.h" #include "netbase.h"
#include "rpcserver.h" #include "rpcserver.h"
#include "timedata.h"
#include "util.h" #include "util.h"
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
#include "wallet.h" #include "wallet.h"
@ -73,7 +74,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", Params().NetworkID() == CChainParams::TESTNET)); obj.push_back(Pair("testnet", Params().NetworkID() == CBaseChainParams::TESTNET));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (pwalletMain) { if (pwalletMain) {
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));

1
src/rpcnet.cpp

@ -9,6 +9,7 @@
#include "netbase.h" #include "netbase.h"
#include "protocol.h" #include "protocol.h"
#include "sync.h" #include "sync.h"
#include "timedata.h"
#include "util.h" #include "util.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>

2
src/rpcserver.cpp

@ -600,7 +600,7 @@ void StartRPCThreads()
std::vector<ip::tcp::endpoint> vEndpoints; std::vector<ip::tcp::endpoint> vEndpoints;
bool bBindAny = false; bool bBindAny = false;
int defaultPort = GetArg("-rpcport", Params().RPCPort()); int defaultPort = GetArg("-rpcport", BaseParams().RPCPort());
if (!mapArgs.count("-rpcallowip")) // Default to loopback if not allowing external IPs if (!mapArgs.count("-rpcallowip")) // Default to loopback if not allowing external IPs
{ {
vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v6::loopback(), defaultPort)); vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v6::loopback(), defaultPort));

1
src/rpcwallet.cpp

@ -8,6 +8,7 @@
#include "init.h" #include "init.h"
#include "net.h" #include "net.h"
#include "netbase.h" #include "netbase.h"
#include "timedata.h"
#include "util.h" #include "util.h"
#include "wallet.h" #include "wallet.h"
#include "walletdb.h" #include "walletdb.h"

12
src/test/base58_tests.cpp

@ -142,9 +142,9 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
bool isTestnet = find_value(metadata, "isTestnet").get_bool(); bool isTestnet = find_value(metadata, "isTestnet").get_bool();
if (isTestnet) if (isTestnet)
SelectParams(CChainParams::TESTNET); SelectParams(CBaseChainParams::TESTNET);
else else
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
if(isPrivkey) if(isPrivkey)
{ {
bool isCompressed = find_value(metadata, "isCompressed").get_bool(); bool isCompressed = find_value(metadata, "isCompressed").get_bool();
@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest); BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest);
} }
} }
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
} }
// Goal: check that generated keys match test vectors // Goal: check that generated keys match test vectors
@ -198,9 +198,9 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
bool isTestnet = find_value(metadata, "isTestnet").get_bool(); bool isTestnet = find_value(metadata, "isTestnet").get_bool();
if (isTestnet) if (isTestnet)
SelectParams(CChainParams::TESTNET); SelectParams(CBaseChainParams::TESTNET);
else else
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
if(isPrivkey) if(isPrivkey)
{ {
bool isCompressed = find_value(metadata, "isCompressed").get_bool(); bool isCompressed = find_value(metadata, "isCompressed").get_bool();
@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
CTxDestination nodest = CNoDestination(); CTxDestination nodest = CNoDestination();
BOOST_CHECK(!dummyAddr.Set(nodest)); BOOST_CHECK(!dummyAddr.Set(nodest));
SelectParams(CChainParams::MAIN); SelectParams(CBaseChainParams::MAIN);
} }
// Goal: check that base58 parsing code is robust against a variety of corrupted data // Goal: check that base58 parsing code is robust against a variety of corrupted data

1
src/test/test_bitcoin.cpp

@ -31,6 +31,7 @@ struct TestingSetup {
TestingSetup() { TestingSetup() {
fPrintToDebugLog = false; // don't want to write to debug.log file fPrintToDebugLog = false; // don't want to write to debug.log file
SelectParams(CBaseChainParams::MAIN);
noui_connect(); noui_connect();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
bitdb.MakeMock(); bitdb.MakeMock();

91
src/timedata.cpp

@ -0,0 +1,91 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "timedata.h"
#include "netbase.h"
#include "sync.h"
#include "ui_interface.h"
#include "util.h"
#include <boost/foreach.hpp>
using namespace std;
static CCriticalSection cs_nTimeOffset;
static int64_t nTimeOffset = 0;
//
// "Never go to sea with two chronometers; take one or three."
// Our three time sources are:
// - System clock
// - Median of other nodes clocks
// - The user (asking the user to fix the system clock if the first two disagree)
//
//
int64_t GetTimeOffset()
{
LOCK(cs_nTimeOffset);
return nTimeOffset;
}
int64_t GetAdjustedTime()
{
return GetTime() + GetTimeOffset();
}
void AddTimeData(const CNetAddr& ip, int64_t nTime)
{
int64_t nOffsetSample = nTime - GetTime();
LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;
if (!setKnown.insert(ip).second)
return;
// Add data
static CMedianFilter<int64_t> vTimeOffsets(200,0);
vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
{
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
if (abs64(nMedian) < 70 * 60)
{
nTimeOffset = nMedian;
}
else
{
nTimeOffset = 0;
static bool fDone;
if (!fDone)
{
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
bool fMatch = false;
BOOST_FOREACH(int64_t nOffset, vSorted)
if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;
if (!fMatch)
{
fDone = true;
string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.");
strMiscWarning = strMessage;
LogPrintf("*** %s\n", strMessage);
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
}
}
}
if (fDebug) {
BOOST_FOREACH(int64_t n, vSorted)
LogPrintf("%+d ", n);
LogPrintf("| ");
}
LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
}
}

17
src/timedata.h

@ -0,0 +1,17 @@
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TIMEDATA_H
#define BITCOIN_TIMEDATA_H
#include <stdint.h>
class CNetAddr;
/* Functions to keep track of adjusted P2P time */
int64_t GetTimeOffset();
int64_t GetAdjustedTime();
void AddTimeData(const CNetAddr& ip, int64_t nTime);
#endif

89
src/util.cpp

@ -5,8 +5,7 @@
#include "util.h" #include "util.h"
#include "chainparams.h" #include "chainparamsbase.h"
#include "netbase.h"
#include "sync.h" #include "sync.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "uint256.h" #include "uint256.h"
@ -919,7 +918,7 @@ boost::filesystem::path GetDefaultDataDir()
#endif #endif
} }
static boost::filesystem::path pathCached[CChainParams::MAX_NETWORK_TYPES+1]; static boost::filesystem::path pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1];
static CCriticalSection csPathCached; static CCriticalSection csPathCached;
const boost::filesystem::path &GetDataDir(bool fNetSpecific) const boost::filesystem::path &GetDataDir(bool fNetSpecific)
@ -928,8 +927,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
LOCK(csPathCached); LOCK(csPathCached);
int nNet = CChainParams::MAX_NETWORK_TYPES; int nNet = CBaseChainParams::MAX_NETWORK_TYPES;
if (fNetSpecific) nNet = Params().NetworkID(); if (fNetSpecific) nNet = BaseParams().NetworkID();
fs::path &path = pathCached[nNet]; fs::path &path = pathCached[nNet];
@ -948,7 +947,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
path = GetDefaultDataDir(); path = GetDefaultDataDir();
} }
if (fNetSpecific) if (fNetSpecific)
path /= Params().DataDir(); path /= BaseParams().DataDir();
fs::create_directories(path); fs::create_directories(path);
@ -957,7 +956,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
void ClearDatadirCache() void ClearDatadirCache()
{ {
std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1], std::fill(&pathCached[0], &pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1],
boost::filesystem::path()); boost::filesystem::path());
} }
@ -1157,13 +1156,6 @@ void ShrinkDebugFile()
fclose(file); fclose(file);
} }
//
// "Never go to sea with two chronometers; take one or three."
// Our three time sources are:
// - System clock
// - Median of other nodes clocks
// - The user (asking the user to fix the system clock if the first two disagree)
//
static int64_t nMockTime = 0; // For unit testing static int64_t nMockTime = 0; // For unit testing
int64_t GetTime() int64_t GetTime()
@ -1178,75 +1170,6 @@ void SetMockTime(int64_t nMockTimeIn)
nMockTime = nMockTimeIn; nMockTime = nMockTimeIn;
} }
static CCriticalSection cs_nTimeOffset;
static int64_t nTimeOffset = 0;
int64_t GetTimeOffset()
{
LOCK(cs_nTimeOffset);
return nTimeOffset;
}
int64_t GetAdjustedTime()
{
return GetTime() + GetTimeOffset();
}
void AddTimeData(const CNetAddr& ip, int64_t nTime)
{
int64_t nOffsetSample = nTime - GetTime();
LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;
if (!setKnown.insert(ip).second)
return;
// Add data
static CMedianFilter<int64_t> vTimeOffsets(200,0);
vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
{
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
if (abs64(nMedian) < 70 * 60)
{
nTimeOffset = nMedian;
}
else
{
nTimeOffset = 0;
static bool fDone;
if (!fDone)
{
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
bool fMatch = false;
BOOST_FOREACH(int64_t nOffset, vSorted)
if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;
if (!fMatch)
{
fDone = true;
string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.");
strMiscWarning = strMessage;
LogPrintf("*** %s\n", strMessage);
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
}
}
}
if (fDebug) {
BOOST_FOREACH(int64_t n, vSorted)
LogPrintf("%+d ", n);
LogPrintf("| ");
}
LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
}
}
uint32_t insecure_rand_Rz = 11; uint32_t insecure_rand_Rz = 11;
uint32_t insecure_rand_Rw = 11; uint32_t insecure_rand_Rw = 11;
void seed_insecure_rand(bool fDeterministic) void seed_insecure_rand(bool fDeterministic)

4
src/util.h

@ -32,7 +32,6 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
class CNetAddr;
class uint256; class uint256;
static const int64_t COIN = 100000000; static const int64_t COIN = 100000000;
@ -191,11 +190,8 @@ uint64_t GetRand(uint64_t nMax);
uint256 GetRandHash(); uint256 GetRandHash();
int64_t GetTime(); int64_t GetTime();
void SetMockTime(int64_t nMockTimeIn); void SetMockTime(int64_t nMockTimeIn);
int64_t GetAdjustedTime();
int64_t GetTimeOffset();
std::string FormatFullVersion(); std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments); std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void AddTimeData(const CNetAddr& ip, int64_t nTime);
void runCommand(std::string strCommand); void runCommand(std::string strCommand);

1
src/wallet.cpp

@ -9,6 +9,7 @@
#include "checkpoints.h" #include "checkpoints.h"
#include "coincontrol.h" #include "coincontrol.h"
#include "net.h" #include "net.h"
#include "timedata.h"
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <openssl/rand.h> #include <openssl/rand.h>

Loading…
Cancel
Save