Permalink
Browse files

Added Pulse

Bumped Version
Bumped Release
  • Loading branch information...
f0o committed Jul 13, 2014
1 parent ad52e97 commit c72f37ff5f109e7aa2b9d3c03f6045a5bbf69ed6
Showing with 217 additions and 25 deletions.
  1. +6 −2 bitcoin-qt.pro
  2. +2 −0 src/bitcoinrpc.cpp
  3. +2 −2 src/clientversion.h
  4. +8 −15 src/main.cpp
  5. +3 −1 src/makefile.linux-mingw
  6. +3 −1 src/makefile.mingw
  7. +3 −1 src/makefile.osx
  8. +3 −1 src/makefile.unix
  9. +90 −0 src/pulse.cpp
  10. +37 −0 src/pulse.h
  11. +43 −0 src/rpcpulse.cpp
  12. +15 −0 src/rpcpulse.h
  13. +2 −2 src/version.h
@@ -219,7 +219,9 @@ HEADERS += src/qt/bitcoingui.h \
src/threadsafety.h \
src/limitedmap.h \
src/qt/macnotificationhandler.h \
src/qt/splashscreen.h
src/qt/splashscreen.h \
src/pulse.h \
src/rpcpulse.h
SOURCES += src/qt/bitcoin.cpp \
src/qt/bitcoingui.cpp \
@@ -290,7 +292,9 @@ SOURCES += src/qt/bitcoin.cpp \
src/noui.cpp \
src/leveldb.cpp \
src/txdb.cpp \
src/qt/splashscreen.cpp
src/qt/splashscreen.cpp \
src/pulse.cpp \
src/rpcpulse.cpp
RESOURCES += src/qt/bitcoin.qrc
@@ -10,6 +10,7 @@
#include "base58.h"
#include "bitcoinrpc.h"
#include "db.h"
#include "rpcpulse.h"
#include <boost/asio.hpp>
#include <boost/asio/ip/v6_only.hpp>
@@ -213,6 +214,7 @@ static const CRPCCommand vRPCCommands[] =
{ "gethashespersec", &gethashespersec, true, false, false },
{ "getinfo", &getinfo, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false },
{ "getpulseinfo", &getpulseinfo, true, false, false },
{ "getnewaddress", &getnewaddress, true, false, true },
{ "getaccountaddress", &getaccountaddress, true, false, true },
{ "setaccount", &setaccount, true, false, true },
@@ -8,8 +8,8 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 8
#define CLIENT_VERSION_REVISION 8
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_REVISION 9
#define CLIENT_VERSION_BUILD 0
// Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
@@ -16,6 +16,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include "pulse.cpp"
using namespace std;
using namespace boost;
@@ -2422,21 +2423,14 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp) {
pindexPrev = (*mi).second;
nHeight = pindexPrev->nHeight+1;
//Following is from DarkCoin, Check their github - evan@darkcoin.io
#ifdef _WIN32
// Check proof of work Taken from
if(nHeight >= 200000){
unsigned int nBitsNext = GetNextWorkRequired(pindexPrev, this);
double n1 = ConvertBitsToDouble(nBits);
double n2 = ConvertBitsToDouble(nBitsNext);
if (abs(n1-n2) > n1*0.2)
return state.DoS(100, error("AcceptBlock() : incorrect proof of work (DGW pre-fork)"));
} else {
if (nBits != GetNextWorkRequired(pindexPrev, this))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"));
//Pulse
if( Pulse(nHeight) ) {
if( ! Pulse(pindexPrev, this) ) {
return state.Invalid(error("AcceptBlock() : Blocked by Pulse"));
}
}
#else
// Check proof of work
//Following is from DarkCoin, Check their github - evan@darkcoin.io
if(nHeight >= 200000){
unsigned int nBitsNext = GetNextWorkRequired(pindexPrev, this);
double n1 = ConvertBitsToDouble(nBits);
@@ -2447,7 +2441,6 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp) {
if (nBits != GetNextWorkRequired(pindexPrev, this))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"));
}
#endif
// Check timestamp against prev
if (GetBlockTime() <= pindexPrev->GetMedianTimePast())
@@ -88,7 +88,9 @@ OBJS= \
obj/hash.o \
obj/bloom.o \
obj/leveldb.o \
obj/txdb.o
obj/txdb.o \
obj/pulse.o \
obj/rpcpulse.o
ifdef USE_SSE2
DEFS += -DUSE_SSE2
@@ -100,7 +100,9 @@ OBJS= \
obj/bloom.o \
obj/noui.o \
obj/leveldb.o \
obj/txdb.o
obj/txdb.o \
obj/pulse.o \
obj/rpcpulse.o
ifdef USE_SSE2
DEFS += -DUSE_SSE2
@@ -106,7 +106,9 @@ OBJS= \
obj/bloom.o \
obj/noui.o \
obj/leveldb.o \
obj/txdb.o
obj/txdb.o \
obj/pulse.o \
obj/rpcpulse.o
ifdef USE_SSE2
DEFS += -DUSE_SSE2
@@ -142,7 +142,9 @@ OBJS= \
obj/bloom.o \
obj/noui.o \
obj/leveldb.o \
obj/txdb.o
obj/txdb.o \
obj/pulse.o \
obj/rpcpulse.o
ifdef USE_SSE2
@@ -0,0 +1,90 @@
// Copyright (c) 2014-.... f0o / The Cryptocoin Revival Foundation
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "pulse.h"
/* Pulse(int64 value, int64 fee, int nHeight, unsigned int nBits) : int64 >= 0
Returns value of proposed Block using algoritmic aproaches */
static int64 Pulse(int64 value, int64 fee, int nHeight, unsigned int nBits) {
return value - GetBlockValue(nHeight, fee, nBits);
}
/* Pulse(int nHeight) ? true : false
Returns true if nHeight is higher or equal to PULSE_HEIGHT */
static bool Pulse(int nHeight) {
printf("Checking for Pulse on %u: ",nHeight);
if( PulseI(nHeight) >= 0 ) {
printf("True\n");
return true;
}
printf("False\n");
return false;
}
/* Pulse(CBlockIndex* prevBlock, CBlock* block) ? true : false
Goes close to the top of CBlock::AcceptBlock
Returns true if proposed Block matches constrains */
static bool Pulse(CBlockIndex* prevBlock, CBlock* block) {
CBlockHeader blockHead = block->GetBlockHeader();
CBlockIndex blockIndex = CBlockIndex(blockHead);
CCoinsViewCache view(*pcoinsTip, true);
int nHeight = prevBlock->nHeight+1;
int rate = block->GetBlockTime() - prevBlock->GetBlockTime();
int score = 0;
int i = PulseI(nHeight);
if( PULSE_RATE[i] > 0 && rate > PULSE_RATE[i] ) {
return true;
} else if( PULSE_MIN_RATE[i] > 0 && rate < PULSE_MIN_RATE[i] ) {
return false;
} else {
if( PULSE_MIN_TX[i] > 0 && block->vtx.size() > PULSE_MIN_TX[i] ) {
score++;
}
if( PULSE_MIN_VALUE[i] > 0 || PULSE_MIN_FEE[i] > 0 ) {
int64 value = 0;
int64 fee = 0;
BOOST_FOREACH(const CTransaction& tx, block->vtx) {
if( PULSE_MIN_FEE[i] > 0 && value > 0 ) {
BOOST_FOREACH(const CTxIn txin, tx.vin)
if( !view.HaveCoins(txin.prevout.hash) ) {
return false;
}
fee += tx.GetValueIn(view) - tx.GetValueOut();
}
value += tx.GetValueOut();
}
value = Pulse(value, fee, nHeight, blockIndex.nBits);
if( PULSE_FACTOR[i] == true ) {
int64 bvalue = GetBlockValue(nHeight, 0, blockIndex.nBits);
if( PULSE_MIN_VALUE[i] > 0 && value >= (PULSE_MIN_VALUE[i] * bvalue) ) {
score++;
}
if( PULSE_MIN_FEE[i] > 0 && fee >= (PULSE_MIN_FEE[i] * bvalue) ) {
score++;
}
} else {
if( PULSE_MIN_VALUE[i] > 0 && value >= (PULSE_MIN_VALUE[i] * COIN) ) {
score++;
}
if( PULSE_MIN_FEE[i] > 0 && fee >= (PULSE_MIN_FEE[i] * COIN) ) {
score++;
}
}
}
}
if( PULSE_EXPLICIT[i] ) {
score++;
if( PULSE_MIN_TX[i] > 0 )
score--;
if( PULSE_MIN_VALUE[i] > 0 )
score--;
if( PULSE_MIN_FEE[i] > 0 )
score--;
}
if( score > 0 )
return true;
else
return false;
}
@@ -0,0 +1,37 @@
// Copyright (c) 2014-.... f0o / The Cryptocoin Revival Foundation
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PULSE_H
#define PULSE_H 1
class CBlock;
class CBlockIndex;
class CCoinsView;
class CCoinsViewCache;
static int64 GetBlockValue(int nHeight, int64 nFees, unsigned int nBits);
extern CCoinsViewCache *pcoinsTip;
static const int PULSE_HEIGHT[] = { 265000 }; /** Height to start Pulse */
static const int PULSE_RATE[] = { 120 }; /** Rate to Pulse in seconds */
static const int PULSE_MIN_RATE[] = { 30 }; /** Rate to Pulse in seconds */
static const unsigned int PULSE_MIN_TX[] = { 0 }; /** Minimum amount (not value of!) of TX in a block to bypass Pulse-Rate */
static const int PULSE_MIN_VALUE[] = { 50000 }; /** Minimum value of the TX in a block to bypass Pulse-Rate (without COIN base) */
static const int PULSE_MIN_FEE[] = { 25 }; /** Minimum value of accumulated fees of the TX in a block to bypass Pulse-Rate (without COIN base) */
static const bool PULSE_FACTOR[] = { false }; /** Treat Switches as factors of BlockReward */
static const bool PULSE_EXPLICIT[] = { false }; /** Require all switches to trigger a block */
static bool Pulse(int nHeight);
static bool Pulse(CBlockIndex* prevBlock, CBlock* block);
/* PulseI(int nHeight) ? i : -1
Returns i or -1 if not found */
static int PulseI(int nHeight) {
int i = -1;
BOOST_FOREACH(int h, PULSE_HEIGHT)
if( nHeight >= h )
i++;
return i;
}
#endif
@@ -0,0 +1,43 @@
// Copyright (c) 2014-.... f0o / The Cryptocoin Revival Foundation
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "rpcpulse.h"
#include <boost/assign/list_of.hpp>
using namespace std;
using namespace boost;
using namespace boost::assign;
using namespace json_spirit;
/* Patches
- bitcoinrpc.cpp:
#include "rpcpulse.h"
CRPCCommand:
{ "getpulseinfo", &getpulseinfo, true, false },
*/
/* getpulseinfo(const Array& params, bool fHelp) : Object
Expose Pulse-Settings via RPC */
json_spirit::Value getpulseinfo(const Array& params, bool fHelp) {
if (fHelp || params.size() != 0)
throw std::runtime_error("getpulseinfo\nReturns an object containing various pulse info.");
int i = PulseI(nBestHeight);
json_spirit::Object obj;
obj.push_back(json_spirit::Pair("height", (int)PULSE_HEIGHT[i]));
obj.push_back(json_spirit::Pair("rate", (int)PULSE_RATE[i]));
if( PULSE_MIN_RATE[i] > 0 )
obj.push_back(json_spirit::Pair("min-rate", (int)PULSE_MIN_RATE[i]));
if( PULSE_MIN_TX[i] > 0 )
obj.push_back(json_spirit::Pair("min-tx", (int)PULSE_MIN_TX[i]));
if( PULSE_MIN_VALUE[i] > 0 )
obj.push_back(json_spirit::Pair("min-value", (int)PULSE_MIN_VALUE[i]));
if( PULSE_MIN_FEE[i] > 0 )
obj.push_back(json_spirit::Pair("min-fee", (int)PULSE_MIN_FEE[i]));
if( PULSE_MIN_TX[i] > 0 )
obj.push_back(json_spirit::Pair("min-tx", (int)PULSE_MIN_TX[i]));
obj.push_back(json_spirit::Pair("factor", PULSE_FACTOR[i]));
obj.push_back(json_spirit::Pair("explicit", PULSE_EXPLICIT[i]));
return obj;
}
@@ -0,0 +1,15 @@
// Copyright (c) 2014-.... f0o / The Cryptocoin Revival Foundation
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef RPCPULSE_H
#define RPCPULSE_H 1
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
#include "pulse.h"
extern json_spirit::Value getpulseinfo(const json_spirit::Array& params, bool fHelp);
#endif
@@ -25,13 +25,13 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//
static const int PROTOCOL_VERSION = 70005;
static const int PROTOCOL_VERSION = 70006;
// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
// disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 70005;
static const int MIN_PEER_PROTO_VERSION = 70006;
// nTime field added to CAddress, starting with this version;
// if possible, avoid requesting addresses nodes older than this

0 comments on commit c72f37f

Please sign in to comment.