Skip to content

Commit

Permalink
Merge pull request GlobalBoost#7 from ssdpool/master
Browse files Browse the repository at this point in the history
fix automatic checkpoints and algo optimizations
  • Loading branch information
GlobalBoost committed Apr 13, 2015
2 parents 749de71 + c8b9386 commit e9ad512
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 67 deletions.
10 changes: 5 additions & 5 deletions GlobalBoost-Y.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
EMPLATE = app
TARGET = globalboost-qt
TARGET = GlobalBoost-Y-qt
macx:TARGET = "GlobalBoost-Y"
VERSION = 0.9.0.3
VERSION = 0.9.0.4
INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor
QT += core gui network printsupport script widgets
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_SPIRIT_THREADSAFE BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN __NO_SYSTEM_INCLUDES
Expand Down Expand Up @@ -58,9 +58,9 @@ UI_DIR = build
# use: qmake "RELEASE=1"
contains(RELEASE, 1) {
# Mac: compile for maximum compatibility (10.5, 32-bit)
macx:QMAKE_CXXFLAGS += -mmacosx-version-min=10.5 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
macx:QMAKE_CFLAGS += -mmacosx-version-min=10.5 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
macx:QMAKE_OBJECTIVE_CFLAGS += -mmacosx-version-min=10.5 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
macx:QMAKE_CXXFLAGS += -mmacosx-version-min=10.6 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk
macx:QMAKE_CFLAGS += -mmacosx-version-min=10.6 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk
macx:QMAKE_OBJECTIVE_CFLAGS += -mmacosx-version-min=10.6 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk

!win32:!macx {
# Linux: static link and extra security (see: https://wiki.debian.org/Hardening)
Expand Down
2 changes: 1 addition & 1 deletion src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class CBase58Data
};

/** base58-encoded GlobalBoost-Y Addresses.
* Public-key-hash-addresses have version 0 (or 111 testnet).
* Public-key-hash-addresses have version 77 (or 111 testnet).
* The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.
* Script-hash-addresses have version 5 (or 196 testnet).
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void RPCTypeCheck(const Object& o,
int64 AmountFromValue(const Value& value)
{
double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > 84000000.0)
if (dAmount <= 0.0 || dAmount > 24000000.0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
int64 nAmount = roundint64(dAmount * COIN);
if (!MoneyRange(nAmount))
Expand Down
12 changes: 7 additions & 5 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ namespace Checkpoints
boost::assign::map_list_of
( 0, uint256("0x2e28050194ad73f2405394d2f081361a23c2df8904ec7f026a018bbe148d5adf"))
( 2672, uint256("0xe31f98339ec0c628bcc5bd20aef177bdef83deb7a606528c8977ad3a1f511906"))
( 29000, uint256("0x63a67152f31a4596fc6ca5073ffe4cf68264922e740285f0ae7b3bb8cbc66b39"))

;
static const CCheckpointData data = {
&mapCheckpoints,
1411808495, // * UNIX timestamp of last checkpoint block
10059, // * total number of transactions between genesis and last checkpoint
1428497654, // * UNIX timestamp of last checkpoint block
108399, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
12000.0 // * estimated number of transactions per day after checkpoint
};
Expand All @@ -59,14 +60,12 @@ namespace Checkpoints
};

const CCheckpointData &Checkpoints() {
if (fTestNet)
return dataTestnet;
else
return data;
}

bool CheckBlock(int nHeight, const uint256& hash)
{
if (fTestNet) return true; // Testnet has no checkpoints
if (!GetBoolArg("-checkpoints", true))
return true;

Expand Down Expand Up @@ -110,6 +109,7 @@ namespace Checkpoints

int GetTotalBlocksEstimate()
{
if (fTestNet) return 0; // Testnet has no checkpoints
if (!GetBoolArg("-checkpoints", true))
return 0;

Expand All @@ -120,6 +120,7 @@ namespace Checkpoints

CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
{
if (fTestNet) return NULL; // Testnet has no checkpoints
if (!GetBoolArg("-checkpoints", true))
return NULL;

Expand All @@ -134,6 +135,7 @@ namespace Checkpoints
}
return NULL;
}

uint256 GetLatestHardenedCheckpoint()
{
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
Expand Down
6 changes: 3 additions & 3 deletions src/checkpointsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ using namespace std;


// ppcoin: sync-checkpoint master key
const std::string CSyncCheckpoint::strMainPubKey = "04c91144cc667fefb3364f5c276e5aa5f8ae169eef186d81bce49f09335fe6614a6a748699d5b0ce2d7b868029313a4c56e8183e9ef2074d3e745977b48966d538";
const std::string CSyncCheckpoint::strTestPubKey = "04ec068f9cee3d5c02eb648f2264dd5cf69e17dd1024e7b54e3a477b3f9e76c5712a5a56131de55ad96f798158c9135b6777be5128163560273d55518a42bda3ba";
const std::string CSyncCheckpoint::strMainPubKey = "046c2a735d6d61e9bc2ccca972c2676070108b2aa5b55272ac9c56c1d74796392555ece455fd201dae6bf5834d18eb00de268b0aefbf573247dfdba9481828ecba";
const std::string CSyncCheckpoint::strTestPubKey = "048211e9d56bc6b434e9446e65f2ee1488434ea1ede9eae6fdfad371db95e42dd179ddacddbc48f1691a609b7788fb19cb7cf00f957c3145b3a394e8e8e86bffa2";
std::string CSyncCheckpoint::strMasterPrivKey = "";


Expand Down Expand Up @@ -367,7 +367,7 @@ bool IsMatureSyncCheckpoint()
// sync-checkpoint should always be accepted block
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
return (nBestHeight >= pindexSync->nHeight + COINBASE_MATURITY);
return (nBestHeight >= pindexSync->nHeight + nBaseMaturity);
}

// Is the sync-checkpoint too old?
Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// These need to be macros, as version.cpp's and globalboost-y-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 1
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 1
#define CLIENT_VERSION_BUILD 0

// Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
5 changes: 3 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ std::string HelpMessage()
" -externalip=<ip> " + _("Specify your own public address") + "\n" +
" -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4, IPv6 or Tor)") + "\n" +
" -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n" +
" -checkpointenforce " + _("Only accept block chain matching checkpoints issued by the Auto-Checkpoint systems Master Node (default: 1)") + "\n" +
" -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n" +
" -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" +
" -bind=<addr> " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n" +
Expand Down Expand Up @@ -351,7 +352,7 @@ std::string HelpMessage()
#endif
" -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n" +
" -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n" +
" -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 8223 or testnet: 18223)") + "\n" +
" -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 8225 or testnet: 18225)") + "\n" +
" -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
#ifndef QT_GUI
" -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n" +
Expand Down Expand Up @@ -504,7 +505,7 @@ bool AppInit2(boost::thread_group& threadGroup)

// ********************************************************* Step 2: parameter interactions

fTestNet = GetBoolArg("-testnet");
fTestNet = GetBoolArg("-testnet", false);
fBloomFilters = GetBoolArg("-bloomfilters", true);
if (fBloomFilters)
nLocalServices |= NODE_BLOOM;
Expand Down
44 changes: 39 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "txdb.h"
#include "net.h"
#include "init.h"
#include "util.h"
#include "ui_interface.h"
#include "checkqueue.h"
#include <boost/algorithm/string/replace.hpp>
Expand All @@ -35,6 +36,8 @@ CCriticalSection cs_main;
CTxMemPool mempool;
unsigned int nTransactionsUpdated = 0;

int nBaseMaturity = BASE_MATURITY;

map<uint256, CBlockIndex*> mapBlockIndex;
uint256 hashGenesisBlock("0x2e28050194ad73f2405394d2f081361a23c2df8904ec7f026a018bbe148d5adf");
static CBigNum bnProofOfWorkLimit(~uint256(0) >> 10); // Globalboost: starting difficulty is 1 / 2^12
Expand Down Expand Up @@ -944,7 +947,7 @@ int CMerkleTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
return max(0, (COINBASE_MATURITY+20) - GetDepthInMainChain());
return max(0, (nBaseMaturity+20) - GetDepthInMainChain());
}


Expand Down Expand Up @@ -1524,7 +1527,7 @@ bool CTransaction::CheckInputs(CValidationState &state, CCoinsViewCache &inputs,

// If prev is coinbase, check that it's matured
if (coins.IsCoinBase()) {
if (nSpendHeight - coins.nHeight < COINBASE_MATURITY)
if (nSpendHeight - coins.nHeight < nBaseMaturity)
return state.Invalid(error("CheckInputs() : tried to spend coinbase at depth %d", nSpendHeight - coins.nHeight));
}

Expand Down Expand Up @@ -2026,6 +2029,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
else
strCheckpointWarning = "";
}

std::string strCmd = GetArg("-blocknotify", "");

if (!fIsInitialDownload && !strCmd.empty())
Expand Down Expand Up @@ -2352,6 +2356,7 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp)
if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
pnode->PushInventory(CInv(MSG_BLOCK, hash));
}

// ppcoin: check pending sync-checkpoint
AcceptPendingSyncCheckpoint();

Expand Down Expand Up @@ -2403,9 +2408,10 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
return state.DoS(100, error("ProcessBlock() : block with too little proof-of-work"));
}
}

// ppcoin: ask for pending sync-checkpoint if any
if (!IsInitialBlockDownload())
AskForPendingSyncCheckpoint(pfrom);
AskForPendingSyncCheckpoint(pfrom);

// If we don't already have its previous block, shunt it off to holding area until we get it
if (pblock->hashPrevBlock != 0 && !mapBlockIndex.count(pblock->hashPrevBlock))
Expand Down Expand Up @@ -2459,6 +2465,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
return true;
}


CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)
{
header = block.GetBlockHeader();
Expand Down Expand Up @@ -2717,6 +2724,12 @@ bool static LoadBlockIndexDB()
if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile))
printf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString().c_str());

// ppcoin: load hashSyncCheckpoint
if (!pblocktree->ReadSyncCheckpoint(hashSyncCheckpoint))
printf("LoadBlockIndexDB(): synchronized checkpoint not read\n");
else
printf("LoadBlockIndexDB(): synchronized checkpoint %s\n", hashSyncCheckpoint.ToString().c_str());

// Load nBestInvalidWork, OK if it doesn't exist
CBigNum bnBestInvalidWork;
pblocktree->ReadBestInvalidWork(bnBestInvalidWork);
Expand Down Expand Up @@ -2922,6 +2935,7 @@ bool InitBlockIndex() {
return error("LoadBlockIndex() : writing genesis block to disk failed");
if (!block.AddToBlockIndex(state, blockPos))
return error("LoadBlockIndex() : genesis block not accepted");

// ppcoin: initialize synchronized checkpoint
if (!WriteSyncCheckpoint(hashGenesisBlock))
return error("LoadBlockIndex() : failed to init sync checkpoint");
Expand All @@ -2930,6 +2944,10 @@ bool InitBlockIndex() {
}
}

// ppcoin: if checkpoint master key changed must reset sync-checkpoint
if (!CheckCheckpointPubKey())
return error("LoadBlockIndex() : failed to reset checkpoint master pubkey");

return true;
}

Expand Down Expand Up @@ -3451,15 +3469,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
checkpointMessage.RelayTo(pfrom);
}


pfrom->fSuccessfullyConnected = true;

printf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer.c_str(), pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());

cPeerBlockCounts.input(pfrom->nStartingHeight);

// ppcoin: ask for pending sync-checkpoint if any
if (!IsInitialBlockDownload())
AskForPendingSyncCheckpoint(pfrom);

}


Expand Down Expand Up @@ -3878,6 +3897,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->addr.ToString().c_str());
}

else if (strCommand == "checkpoint") // ppcoin synchronized checkpoint
{
CSyncCheckpoint checkpoint;
vRecv >> checkpoint;

if (checkpoint.ProcessSyncCheckpoint(pfrom))
{
// Relay
pfrom->hashCheckpointKnown = checkpoint.hashCheckpoint;
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
checkpoint.RelayTo(pnode);
}
}

else if (strCommand == "filterload")
{
CBloomFilter filter;
Expand Down Expand Up @@ -4747,7 +4781,7 @@ void static GlobalboostMiner(CWallet *pwallet)

while (true)
{
yescrypt_hash_sp(BEGIN(pblock->nVersion), BEGIN(thash));
yescrypt_hash(BEGIN(pblock->nVersion), BEGIN(thash));

if (thash <= hashTarget)
{
Expand Down
9 changes: 9 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class CAddress;
class CInv;
class CNode;

/* Maturity threshold for PoW base transactions, in blocks (confirmations) */
extern int nBaseMaturity;
static const int BASE_MATURITY = 120;
static const int BASE_MATURITY_TESTNET = 120;
/* Offset for the above to allow safe network propagation, in blocks (confirmations) */
static const int BASE_MATURITY_OFFSET = 1;
/* Maturity threshold for regular transactions, in blocks (confirmations) */
static const int TX_MATURITY = 6;

struct CBlockIndexWorkComparator;

/** The maximum allowed size for a serialized block, in bytes (network rule) */
Expand Down
1 change: 0 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-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.
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//

static const int PROTOCOL_VERSION = 70002;
static const int PROTOCOL_VERSION = 70003;

// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand All @@ -38,8 +38,8 @@ static const int MIN_PEER_PROTO_VERSION = 70002;
static const int CADDR_TIME_VERSION = 31402;

// only request blocks from nodes outside this range of versions
static const int NOBLKS_VERSION_START = 32000;
static const int NOBLKS_VERSION_END = 32400;
static const int NOBLKS_VERSION_START = 0;
static const int NOBLKS_VERSION_END = 70001;

// BIP 0031, pong message, is enabled for all versions AFTER this one
static const int BIP0031_VERSION = 60000;
Expand Down
Loading

0 comments on commit e9ad512

Please sign in to comment.