Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Classes | Typedefs | Functions | Variables
main.cpp File Reference
#include "alert.h"
#include "checkpoints.h"
#include "db.h"
#include "txdb.h"
#include "net.h"
#include "init.h"
#include "ui_interface.h"
#include "checkqueue.h"
#include "checkpointsync.h"
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

class  COrphan
 
class  TxPriorityCompare
 
class  CMainCleanup
 

Typedefs

typedef boost::tuple< double,
double, CTransaction * > 
TxPriority
 

Functions

void RegisterWallet (CWallet *pwalletIn)
 Register a wallet to receive updates from core. More...
 
void UnregisterWallet (CWallet *pwalletIn)
 Unregister a wallet from core. More...
 
void SyncWithWallets (const uint256 &hash, const CTransaction &tx, const CBlock *pblock, bool fUpdate)
 Push an updated transaction to all registered wallets. More...
 
bool AddOrphanTx (const CTransaction &tx)
 
unsigned int LimitOrphanTxSize (unsigned int nMaxOrphans)
 
bool GetTransaction (const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
 Retrieve a transaction (from memory pool, or from disk, if possible) More...
 
CBlockIndexFindBlockByHeight (int nHeight)
 Find a block by height in the currently-connected chain. More...
 
bool CheckProofOfWork (uint256 hash, unsigned int nBits)
 Check whether a block hash satisfies the proof-of-work requirement specified by nBits. More...
 
int GetNumBlocksOfPeers ()
 Get the number of active peers. More...
 
bool IsInitialBlockDownload ()
 Check whether we are doing an initial block download (synchronizing from disk or network) More...
 
bool ConnectBestBlock (CValidationState &state)
 Find the best known block, and make it the tip of the block chain. More...
 
bool VerifySignature (const CCoins &txFrom, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
 Verify a signature. More...
 
bool FindUndoPos (CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize)
 
void ThreadScriptCheck ()
 Run an instance of the script checking thread. More...
 
bool SetBestChain (CValidationState &state, CBlockIndex *pindexNew)
 Connect/disconnect blocks until pindexNew is the new tip of the active block chain. More...
 
bool FindBlockPos (CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64 nTime, bool fKnown=false)
 
bool ProcessBlock (CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp)
 Process an incoming block. More...
 
bool AbortNode (const std::string &strMessage)
 Abort with a message. More...
 
bool CheckDiskSpace (uint64 nAdditionalBytes)
 Check whether enough disk space is available for an incoming block. More...
 
FILE * OpenDiskFile (const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
 
FILE * OpenBlockFile (const CDiskBlockPos &pos, bool fReadOnly)
 Open a block file (blk?????.dat) More...
 
FILE * OpenUndoFile (const CDiskBlockPos &pos, bool fReadOnly)
 Open an undo file (rev?????.dat) More...
 
CBlockIndexInsertBlockIndex (uint256 hash)
 Create a new block index entry for a given block hash. More...
 
bool VerifyDB (int nCheckLevel, int nCheckDepth)
 Verify consistency of the block and coin databases. More...
 
void UnloadBlockIndex ()
 Unload database information. More...
 
bool LoadBlockIndex ()
 Load the block tree and coins database from disk. More...
 
bool InitBlockIndex ()
 Initialize a new block tree database + block data on disk. More...
 
void PrintBlockTree ()
 Print the loaded block tree. More...
 
bool LoadExternalBlockFile (FILE *fileIn, CDiskBlockPos *dbp)
 Import blocks from an external file. More...
 
string GetWarnings (string strFor)
 
bool ProcessMessages (CNode *pfrom)
 Process protocol messages received from a given node. More...
 
bool SendMessages (CNode *pto, bool fSendTrickle)
 Send queued protocol messages to be sent to a give node. More...
 
void SHA256Transform (void *pstate, void *pinput, const void *pinit)
 
CBlockTemplateCreateNewBlock (const CScript &scriptPubKeyIn)
 Generate a new block, without valid proof-of-work. More...
 
CBlockTemplateCreateNewBlockWithKey (CReserveKey &reservekey)
 
void IncrementExtraNonce (CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
 Modify the extranonce in a block. More...
 
void FormatHashBuffers (CBlock *pblock, char *pmidstate, char *pdata, char *phash1)
 Do mining precalculation. More...
 
bool CheckWork (CBlock *pblock, CWallet &wallet, CReserveKey &reservekey)
 Check mined block. More...
 
void GenerateBitcoins (bool fGenerate, CWallet *pwallet)
 Run the miner threads. More...
 

Variables

CCriticalSection cs_setpwalletRegistered
 
set< CWallet * > setpwalletRegistered
 
CCriticalSection cs_main
 
CTxMemPool mempool
 
unsigned int nTransactionsUpdated = 0
 
map< uint256, CBlockIndex * > mapBlockIndex
 
uint256 hashGenesisBlock ("0x12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2")
 
CBlockIndexpindexGenesisBlock = NULL
 
int nBestHeight = -1
 
uint256 nBestChainWork = 0
 
uint256 nBestInvalidWork = 0
 
uint256 hashBestChain = 0
 
CBlockIndexpindexBest = NULL
 
set< CBlockIndex
*, CBlockIndexWorkComparator
setBlockIndexValid
 
int64 nTimeBestReceived = 0
 
int nScriptCheckThreads = 0
 
bool fImporting = false
 
bool fReindex = false
 
bool fBenchmark = false
 
bool fTxIndex = false
 
unsigned int nCoinCacheSize = 5000
 
const int nForkOne = 33000
 
const int nForkTwo = 87948
 
const int nForkThree = 204639
 
CMedianFilter< int > cPeerBlockCounts (8, 0)
 
map< uint256, CBlock * > mapOrphanBlocks
 
multimap< uint256, CBlock * > mapOrphanBlocksByPrev
 
map< uint256, CTransactionmapOrphanTransactions
 
map< uint256, set< uint256 > > mapOrphanTransactionsByPrev
 
CScript COINBASE_FLAGS
 
const string strMessageMagic = "Feathercoin Signed Message:\n"
 
double dHashesPerSec = 0.0
 
int64 nHPSTimerStart = 0
 
int64 nTransactionFee = 0
 
int64 nMinimumInputValue = DUST_HARD_LIMIT
 
CCoinsViewCachepcoinsTip = NULL
 Global variable that points to the active CCoinsView (protected by cs_main) More...
 
CBlockTreeDBpblocktree = NULL
 Global variable that points to the active block tree (protected by cs_main) More...
 
int nTargetTimespan = 3.5 * 24 * 60 * 60
 
int nTargetSpacing = 2.5 * 60
 
CCriticalSection cs_LastBlockFile
 
CBlockFileInfo infoLastBlockFile
 
int nLastBlockFile = 0
 
map< uint256, CAlertmapAlerts
 
CCriticalSection cs_mapAlerts
 
unsigned char pchMessageStart [4] = { 0xfb, 0xc0, 0xb6, 0xdb }
 
uint64 nLastBlockTx = 0
 
uint64 nLastBlockSize = 0
 
class CMainCleanup instance_of_cmaincleanup
 

Typedef Documentation

typedef boost::tuple<double, double, CTransaction*> TxPriority

Definition at line 4296 of file main.cpp.

Function Documentation

bool AbortNode ( const std::string &  strMessage)

Abort with a message.

Definition at line 2583 of file main.cpp.

bool AddOrphanTx ( const CTransaction tx)

Definition at line 297 of file main.cpp.

bool CheckDiskSpace ( uint64  nAdditionalBytes)

Check whether enough disk space is available for an incoming block.

Definition at line 2591 of file main.cpp.

bool CheckProofOfWork ( uint256  hash,
unsigned int  nBits 
)

Check whether a block hash satisfies the proof-of-work requirement specified by nBits.

Definition at line 1254 of file main.cpp.

bool CheckWork ( CBlock pblock,
CWallet wallet,
CReserveKey reservekey 
)

Check mined block.

Definition at line 4632 of file main.cpp.

bool ConnectBestBlock ( CValidationState state)

Find the best known block, and make it the tip of the block chain.

Definition at line 1321 of file main.cpp.

CBlockTemplate* CreateNewBlock ( const CScript scriptPubKeyIn)

Generate a new block, without valid proof-of-work.

Definition at line 4319 of file main.cpp.

CBlockTemplate* CreateNewBlockWithKey ( CReserveKey reservekey)

Definition at line 4558 of file main.cpp.

CBlockIndex* FindBlockByHeight ( int  nHeight)

Find a block by height in the currently-connected chain.

Definition at line 1041 of file main.cpp.

bool FindBlockPos ( CValidationState state,
CDiskBlockPos pos,
unsigned int  nAddSize,
unsigned int  nHeight,
uint64  nTime,
bool  fKnown = false 
)

Definition at line 2070 of file main.cpp.

bool FindUndoPos ( CValidationState state,
int  nFile,
CDiskBlockPos pos,
unsigned int  nAddSize 
)

Definition at line 2124 of file main.cpp.

void FormatHashBuffers ( CBlock pblock,
char *  pmidstate,
char *  pdata,
char *  phash1 
)

Do mining precalculation.

Definition at line 4586 of file main.cpp.

void GenerateBitcoins ( bool  fGenerate,
CWallet pwallet 
)

Run the miner threads.

Definition at line 4800 of file main.cpp.

int GetNumBlocksOfPeers ( )

Get the number of active peers.

Definition at line 1271 of file main.cpp.

bool GetTransaction ( const uint256 hash,
CTransaction txOut,
uint256 hashBlock,
bool  fAllowSlow 
)

Retrieve a transaction (from memory pool, or from disk, if possible)

Definition at line 968 of file main.cpp.

string GetWarnings ( string  strFor)

Definition at line 3075 of file main.cpp.

void IncrementExtraNonce ( CBlock pblock,
CBlockIndex pindexPrev,
unsigned int &  nExtraNonce 
)

Modify the extranonce in a block.

Definition at line 4568 of file main.cpp.

bool InitBlockIndex ( )

Initialize a new block tree database + block data on disk.

Definition at line 2836 of file main.cpp.

CBlockIndex* InsertBlockIndex ( uint256  hash)

Create a new block index entry for a given block hash.

Definition at line 2637 of file main.cpp.

bool IsInitialBlockDownload ( )

Check whether we are doing an initial block download (synchronizing from disk or network)

Definition at line 1276 of file main.cpp.

unsigned int LimitOrphanTxSize ( unsigned int  nMaxOrphans)

Definition at line 340 of file main.cpp.

bool LoadBlockIndex ( )

Load the block tree and coins database from disk.

Definition at line 2815 of file main.cpp.

bool LoadExternalBlockFile ( FILE *  fileIn,
CDiskBlockPos dbp 
)

Import blocks from an external file.

Definition at line 2986 of file main.cpp.

FILE* OpenBlockFile ( const CDiskBlockPos pos,
bool  fReadOnly 
)

Open a block file (blk?????.dat)

Definition at line 2629 of file main.cpp.

FILE* OpenDiskFile ( const CDiskBlockPos pos,
const char *  prefix,
bool  fReadOnly 
)

Definition at line 2606 of file main.cpp.

FILE* OpenUndoFile ( const CDiskBlockPos pos,
bool  fReadOnly 
)

Open an undo file (rev?????.dat)

Definition at line 2633 of file main.cpp.

void PrintBlockTree ( )

Print the loaded block tree.

Definition at line 2916 of file main.cpp.

bool ProcessBlock ( CValidationState state,
CNode pfrom,
CBlock pblock,
CDiskBlockPos dbp 
)

Process an incoming block.

Definition at line 2339 of file main.cpp.

bool ProcessMessages ( CNode pfrom)

Process protocol messages received from a given node.

Definition at line 3921 of file main.cpp.

void RegisterWallet ( CWallet pwalletIn)

Register a wallet to receive updates from core.

Definition at line 96 of file main.cpp.

bool SendMessages ( CNode pto,
bool  fSendTrickle 
)

Send queued protocol messages to be sent to a give node.

Definition at line 4044 of file main.cpp.

bool SetBestChain ( CValidationState state,
CBlockIndex pindexNew 
)

Connect/disconnect blocks until pindexNew is the new tip of the active block chain.

Definition at line 1832 of file main.cpp.

void SHA256Transform ( void *  pstate,
void *  pinput,
const void *  pinit 
)

Definition at line 4249 of file main.cpp.

void SyncWithWallets ( const uint256 hash,
const CTransaction tx,
const CBlock pblock,
bool  fUpdate 
)

Push an updated transaction to all registered wallets.

Definition at line 129 of file main.cpp.

void ThreadScriptCheck ( )

Run an instance of the script checking thread.

Definition at line 1672 of file main.cpp.

void UnloadBlockIndex ( )

Unload database information.

Definition at line 2803 of file main.cpp.

void UnregisterWallet ( CWallet pwalletIn)

Unregister a wallet from core.

Definition at line 104 of file main.cpp.

bool VerifyDB ( int  nCheckLevel,
int  nCheckDepth 
)

Verify consistency of the block and coin databases.

Definition at line 2730 of file main.cpp.

bool VerifySignature ( const CCoins txFrom,
const CTransaction txTo,
unsigned int  nIn,
unsigned int  flags,
int  nHashType 
)

Verify a signature.

Definition at line 1470 of file main.cpp.

Variable Documentation

CScript COINBASE_FLAGS

Definition at line 76 of file main.cpp.

CMedianFilter<int> cPeerBlockCounts(8, 0)
CCriticalSection cs_LastBlockFile

Definition at line 2602 of file main.cpp.

Definition at line 32 of file main.cpp.

CCriticalSection cs_mapAlerts

Definition at line 20 of file alert.cpp.

CCriticalSection cs_setpwalletRegistered

Definition at line 29 of file main.cpp.

double dHashesPerSec = 0.0

Definition at line 80 of file main.cpp.

bool fBenchmark = false

Definition at line 51 of file main.cpp.

bool fImporting = false

Definition at line 49 of file main.cpp.

bool fReindex = false

Definition at line 50 of file main.cpp.

bool fTxIndex = false

Definition at line 52 of file main.cpp.

uint256 hashBestChain = 0

Definition at line 44 of file main.cpp.

uint256 hashGenesisBlock("0x12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2")
CBlockFileInfo infoLastBlockFile

Definition at line 2603 of file main.cpp.

class CMainCleanup instance_of_cmaincleanup
map<uint256, CAlert> mapAlerts

Definition at line 19 of file alert.cpp.

map<uint256, CBlockIndex*> mapBlockIndex

Definition at line 37 of file main.cpp.

map<uint256, CBlock*> mapOrphanBlocks

Definition at line 69 of file main.cpp.

multimap<uint256, CBlock*> mapOrphanBlocksByPrev

Definition at line 70 of file main.cpp.

map<uint256, CTransaction> mapOrphanTransactions

Definition at line 72 of file main.cpp.

map<uint256, set<uint256> > mapOrphanTransactionsByPrev

Definition at line 73 of file main.cpp.

CTxMemPool mempool

Definition at line 34 of file main.cpp.

uint256 nBestChainWork = 0

Definition at line 42 of file main.cpp.

int nBestHeight = -1

Definition at line 41 of file main.cpp.

uint256 nBestInvalidWork = 0

Definition at line 43 of file main.cpp.

unsigned int nCoinCacheSize = 5000

Definition at line 53 of file main.cpp.

const int nForkOne = 33000

Definition at line 56 of file main.cpp.

const int nForkThree = 204639

Definition at line 60 of file main.cpp.

const int nForkTwo = 87948

Definition at line 58 of file main.cpp.

int64 nHPSTimerStart = 0

Definition at line 81 of file main.cpp.

int nLastBlockFile = 0

Definition at line 2604 of file main.cpp.

uint64 nLastBlockSize = 0

Definition at line 4293 of file main.cpp.

uint64 nLastBlockTx = 0

Definition at line 4292 of file main.cpp.

int64 nMinimumInputValue = DUST_HARD_LIMIT

Definition at line 85 of file main.cpp.

int nScriptCheckThreads = 0

Definition at line 48 of file main.cpp.

int nTargetSpacing = 2.5 * 60

Definition at line 1090 of file main.cpp.

int nTargetTimespan = 3.5 * 24 * 60 * 60

Definition at line 1089 of file main.cpp.

int64 nTimeBestReceived = 0

Definition at line 47 of file main.cpp.

int64 nTransactionFee = 0

Definition at line 84 of file main.cpp.

unsigned int nTransactionsUpdated = 0

Definition at line 35 of file main.cpp.

CBlockTreeDB* pblocktree = NULL

Global variable that points to the active block tree (protected by cs_main)

Definition at line 290 of file main.cpp.

unsigned char pchMessageStart[4] = { 0xfb, 0xc0, 0xb6, 0xdb }

Definition at line 3178 of file main.cpp.

CCoinsViewCache* pcoinsTip = NULL

Global variable that points to the active CCoinsView (protected by cs_main)

Definition at line 289 of file main.cpp.

CBlockIndex* pindexBest = NULL

Definition at line 45 of file main.cpp.

CBlockIndex* pindexGenesisBlock = NULL

Definition at line 40 of file main.cpp.

set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid

Definition at line 46 of file main.cpp.

set<CWallet*> setpwalletRegistered

Definition at line 30 of file main.cpp.

const string strMessageMagic = "Feathercoin Signed Message:\n"

Definition at line 78 of file main.cpp.