Skip to content

Commit

Permalink
Coin Control with weight and Fast Start
Browse files Browse the repository at this point in the history
  • Loading branch information
iamunick committed May 21, 2014
1 parent 1daa189 commit 8e74f93
Show file tree
Hide file tree
Showing 26 changed files with 2,539 additions and 69 deletions.
6 changes: 3 additions & 3 deletions growthcoin-qt.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEMPLATE = app
TARGET = growthcoin-qt
TARGET = GrowthCoin-Qt
VERSION = 1.2.2
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN __NO_SYSTEM_INCLUDES
Expand Down Expand Up @@ -258,7 +258,7 @@ SOURCES += src/qt/test/test_main.cpp \
HEADERS += src/qt/test/uritests.h
DEPENDPATH += src/qt/test
QT += testlib
TARGET = growthcoin-qt_test
TARGET = GrowthCoin-Qt_test
DEFINES += BITCOIN_QT_TEST
}

Expand Down Expand Up @@ -339,7 +339,7 @@ macx:OBJECTIVE_SOURCES += src/qt/macdockiconhandler.mm
macx:LIBS += -framework Foundation -framework ApplicationServices -framework AppKit
macx:DEFINES += MAC_OSX MSG_NOSIGNAL=0
macx:ICON = src/qt/res/icons/Growthcoin.icns
macx:TARGET = "growthcoin-qt"
macx:TARGET = "GrowthCoin-Qt"
macx:QMAKE_CFLAGS_THREAD += -pthread
macx:QMAKE_LFLAGS_THREAD += -pthread
macx:QMAKE_CXXFLAGS_THREAD += -pthread
Expand Down
57 changes: 57 additions & 0 deletions src/coincontrol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef COINCONTROL_H
#define COINCONTROL_H

/** Coin Control Features. */
class CCoinControl
{
public:
CTxDestination destChange;

CCoinControl()
{
SetNull();
}

void SetNull()
{
destChange = CNoDestination();
setSelected.clear();
}

bool HasSelected() const
{
return (setSelected.size() > 0);
}

bool IsSelected(const uint256& hash, unsigned int n) const
{
COutPoint outpt(hash, n);
return (setSelected.count(outpt) > 0);
}

void Select(COutPoint& output)
{
setSelected.insert(output);
}

void UnSelect(COutPoint& output)
{
setSelected.erase(output);
}

void UnSelectAll()
{
setSelected.clear();
}

void ListSelected(std::vector<COutPoint>& vOutpoints)
{
vOutpoints.assign(setSelected.begin(), setSelected.end());
}

private:
std::set<COutPoint> setSelected;

};

#endif // COINCONTROL_H
6 changes: 4 additions & 2 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,10 @@ bool CTxDB::LoadBlockIndexGuts()
CDiskBlockIndex diskindex;
ssValue >> diskindex;

uint256 blockHash = diskindex.GetBlockHash();

// Construct block index object
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
CBlockIndex* pindexNew = InsertBlockIndex(blockHash);
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
pindexNew->nFile = diskindex.nFile;
Expand All @@ -847,7 +849,7 @@ bool CTxDB::LoadBlockIndexGuts()
pindexNew->nNonce = diskindex.nNonce;

// Watch for genesis block
if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
if (pindexGenesisBlock == NULL && blockHash == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
pindexGenesisBlock = pindexNew;

if (!pindexNew->CheckIndex())
Expand Down
4 changes: 4 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ using namespace boost;
CWallet* pwalletMain;
CClientUIInterface uiInterface;

bool fUseFastIndex;

//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
Expand Down Expand Up @@ -354,6 +356,8 @@ bool AppInit2()
SoftSetBoolArg("-irc", true);
}

fUseFastIndex = GetBoolArg("-fastindex", true);

if (mapArgs.count("-bind")) {
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
Expand Down
9 changes: 9 additions & 0 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ static std::map<int, unsigned int> mapStakeModifierCheckpoints =
( 52261, 0xc343f31eu )
;

// Get time weight
int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
{
// Kernel hash weight starts from 0 at the 30-day min age
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low
return min(nIntervalEnd - nIntervalBeginning, (int64)nStakeMaxAge) - nStakeMinAge;
}

// Get the last stake modifier and its generation time from a given block
static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime)
{
Expand Down
3 changes: 3 additions & 0 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex);
// Check stake modifier hard checkpoints
bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);

// Get time weight using supplied timestamps
int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd);

#endif // PPCOIN_KERNEL_H
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,11 @@ bool CTransaction::CheckTransaction() const


int64 CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree,
enum GetMinFee_mode mode) const
enum GetMinFee_mode mode, unsigned int nBytes) const
{
// Base fee is either MIN_TX_FEE or MIN_RELAY_TX_FEE
int64 nBaseFee = (mode == GMF_RELAY) ? MIN_RELAY_TX_FEE : MIN_TX_FEE;

unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
unsigned int nNewBlockSize = nBlockSize + nBytes;
int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;

Expand Down Expand Up @@ -629,7 +628,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs,
unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);

// Don't accept it if it can't get into a block
int64 txMinFee = tx.GetMinFee(1000, false, GMF_RELAY);
int64 txMinFee = tx.GetMinFee(1000, false, GMF_RELAY, nSize);
if (nFees < txMinFee)
return error("CTxMemPool::accept() : not enough fees %s, %"PRI64d" < %"PRI64d,
hash.ToString().c_str(),
Expand Down
17 changes: 15 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern std::map<uint256, CBlock*> mapOrphanBlocks;

// Settings
extern int64 nTransactionFee;
extern bool fUseFastIndex;

// Minimum disk space required - used in CheckDiskSpace()
static const uint64 nMinDiskSpace = 52428800;
Expand Down Expand Up @@ -599,7 +600,7 @@ class CTransaction
return dPriority > COIN * 1920 / 250;
}

int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=false, enum GetMinFee_mode mode=GMF_BLOCK) const;
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=false, enum GetMinFee_mode mode=GMF_BLOCK, unsigned int nBytes=0) const;

bool ReadFromDisk(CDiskTxPos pos, FILE** pfileRet=NULL)
{
Expand Down Expand Up @@ -1360,6 +1361,10 @@ class CBlockIndex
/** Used to marshal pointers into hashes for db storage. */
class CDiskBlockIndex : public CBlockIndex
{

private:
uint256 blockHash;

public:
uint256 hashPrev;
uint256 hashNext;
Expand All @@ -1368,6 +1373,7 @@ class CDiskBlockIndex : public CBlockIndex
{
hashPrev = 0;
hashNext = 0;
blockHash = 0;
}

explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex)
Expand Down Expand Up @@ -1409,18 +1415,25 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
READWRITE(blockHash);
)

uint256 GetBlockHash() const
{
if (fUseFastIndex && (nTime < GetAdjustedTime() - 12 * nMaxClockDrift) && blockHash != 0)
return blockHash;

CBlock block;
block.nVersion = nVersion;
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
return block.GetHash();

const_cast<CDiskBlockIndex*>(this)->blockHash = block.GetHash();

return blockHash;
}


Expand Down
Loading

0 comments on commit 8e74f93

Please sign in to comment.