Anoncoin  0.9.4
P2P Digital Currency
Classes | Functions | Variables
main.cpp File Reference
#include "main.h"
#include "addrman.h"
#include "alert.h"
#include "chainparams.h"
#include "checkpoints.h"
#include "checkqueue.h"
#include "init.h"
#include "net.h"
#include "txdb.h"
#include "txmempool.h"
#include "ui_interface.h"
#include "util.h"
#include <sstream>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include "main2.cpp"
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

struct  COrphanBlock
 
struct  COrphanTx
 
class  CMainCleanup
 

Functions

void EraseOrphansFor (NodeId peer)
 
void RegisterWallet (CWalletInterface *pwalletIn)
 Register a wallet to receive updates from core. More...
 
void UnregisterWallet (CWalletInterface *pwalletIn)
 Unregister a wallet from core. More...
 
void UnregisterAllWallets ()
 Unregister all wallets from core. More...
 
void SyncWithWallets (const uint256 &hash, const CTransaction &tx, const CBlock *pblock)
 Push an updated transaction to all registered wallets. More...
 
bool GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats)
 Get statistics from node state. More...
 
void RegisterNodeSignals (CNodeSignals &nodeSignals)
 Register with a network node to receive its signals. More...
 
void UnregisterNodeSignals (CNodeSignals &nodeSignals)
 Unregister a network node. More...
 
bool AddOrphanTx (const CTransaction &tx, NodeId peer)
 
unsigned int LimitOrphanTxSize (unsigned int nMaxOrphans)
 
bool IsStandardTx (const CTransaction &tx, string &reason)
 
bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
 
bool AreInputsStandard (const CTransaction &tx, CCoinsViewCache &mapInputs)
 Check for standard transaction types. More...
 
unsigned int GetLegacySigOpCount (const CTransaction &tx)
 Count ECDSA signature operations the old-fashioned (pre-0.6) way. More...
 
unsigned int GetP2SHSigOpCount (const CTransaction &tx, CCoinsViewCache &inputs)
 Count ECDSA signature operations in pay-to-script-hash inputs. More...
 
bool CheckTransaction (const CTransaction &tx, CValidationState &state)
 
int64_t GetMinFee (const CTransaction &tx, unsigned int nBytes, bool fAllowFree, enum GetMinFee_mode mode)
 
bool AcceptToMemoryPool (CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fRejectInsaneFee)
 (try to) add transaction to memory pool More...
 
bool GetTransaction (const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
 Retrieve a transaction (from memory pool, or from disk, if possible) More...
 
bool WriteBlockToDisk (CBlock &block, CDiskBlockPos &pos)
 Functions for disk access for blocks. More...
 
bool ReadBlockFromDisk (CBlock &block, const CDiskBlockPos &pos)
 
bool ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex)
 
bool IsInitialBlockDownload ()
 Check whether we are doing an initial block download (synchronizing from disk or network) More...
 
void CheckForkWarningConditions ()
 
void CheckForkWarningConditionsOnNewFork (CBlockIndex *pindexNewForkTip)
 
void Misbehaving (NodeId pnode, int howmuch)
 Increase a node's misbehavior score. More...
 
void UpdateTime (CBlockHeader &block, const CBlockIndex *pindexPrev)
 
void UpdateCoins (const CTransaction &tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash)
 
bool VerifySignature (const CCoins &txFrom, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
 Verify a signature. More...
 
bool CheckInputs (const CTransaction &tx, CValidationState &state, CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, std::vector< CScriptCheck > *pvChecks)
 
bool DisconnectBlock (CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, bool *pfClean)
 Functions for validating blocks and updating the block tree. More...
 
bool FindUndoPos (CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize)
 
void ThreadScriptCheck ()
 Run an instance of the script checking thread. More...
 
bool ConnectBlock (CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, bool fJustCheck)
 
bool ActivateBestChain (CValidationState &state)
 Find the best known block, and make it the tip of the block chain. More...
 
bool AddToBlockIndex (CBlock &block, CValidationState &state, const CDiskBlockPos &pos)
 
bool FindBlockPos (CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown=false)
 
bool CheckBlock (const CBlock &block, CValidationState &state, bool fCheckPOW, bool fCheckMerkleRoot)
 
bool AcceptBlock (CBlock &block, CValidationState &state, CDiskBlockPos *dbp)
 
void PushGetBlocks (CNode *pnode, CBlockIndex *pindexBegin, uint256 hashEnd)
 
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_t 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...
 

Variables

CCriticalSection cs_main
 
CTxMemPool mempool
 
map< uint256, CBlockIndex * > mapBlockIndex
 
CChain chainActive
 The currently-connected chain of blocks. More...
 
CChain chainMostWork
 The currently best known chain of headers (some of which may be invalid). More...
 
int64_t nTimeBestReceived = 0
 
int nScriptCheckThreads = 0
 
bool fImporting = false
 
bool fReindex = false
 
bool fBenchmark = false
 
bool fTxIndex = false
 
unsigned int nCoinCacheSize = 5000
 
map< uint256, COrphanBlock * > mapOrphanBlocks
 
multimap< uint256, COrphanBlock * > mapOrphanBlocksByPrev
 
map< uint256, COrphanTxmapOrphanTransactions
 
map< uint256, set< uint256 > > mapOrphanTransactionsByPrev
 
CScript COINBASE_FLAGS
 
const string strMessageMagic = "Anoncoin Signed Message:\n"
 
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...
 
bool fLargeWorkForkFound = false
 
bool fLargeWorkInvalidChainFound = false
 
CBlockIndexpindexBestForkTip = NULL
 
CBlockIndexpindexBestForkBase = NULL
 
class CMainCleanup instance_of_cmaincleanup
 

Function Documentation

bool AbortNode ( const std::string &  strMessage)

Abort with a message.

Definition at line 2687 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool AcceptBlock ( CBlock block,
CValidationState state,
CDiskBlockPos dbp 
)

Definition at line 2295 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool AcceptToMemoryPool ( CTxMemPool pool,
CValidationState state,
const CTransaction tx,
bool  fLimitFree,
bool *  pfMissingInputs,
bool  fRejectInsaneFee 
)

(try to) add transaction to memory pool

Definition at line 878 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ActivateBestChain ( CValidationState state)

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

Definition at line 2028 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool AddOrphanTx ( const CTransaction tx,
NodeId  peer 
)

Definition at line 444 of file main.cpp.

Here is the call graph for this function:

bool AddToBlockIndex ( CBlock block,
CValidationState state,
const CDiskBlockPos pos 
)

Definition at line 2076 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool AreInputsStandard ( const CTransaction tx,
CCoinsViewCache mapInputs 
)

Check for standard transaction types.

Parameters
[in]mapInputsMap of previous transactions that have outputs we're spending
Returns
True if all inputs (scriptSigs) use only standard transaction forms

Definition at line 646 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckBlock ( const CBlock block,
CValidationState state,
bool  fCheckPOW,
bool  fCheckMerkleRoot 
)

Definition at line 2229 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckDiskSpace ( uint64_t  nAdditionalBytes)

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

Definition at line 2695 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void CheckForkWarningConditions ( )

Definition at line 1266 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void CheckForkWarningConditionsOnNewFork ( CBlockIndex pindexNewForkTip)

Definition at line 1312 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckInputs ( const CTransaction tx,
CValidationState state,
CCoinsViewCache inputs,
bool  fScriptChecks,
unsigned int  flags,
std::vector< CScriptCheck > *  pvChecks 
)

Definition at line 1454 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckTransaction ( const CTransaction tx,
CValidationState state 
)

Definition at line 783 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ConnectBlock ( CBlock block,
CValidationState state,
CBlockIndex pindex,
CCoinsViewCache view,
bool  fJustCheck 
)

Definition at line 1669 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool DisconnectBlock ( CBlock block,
CValidationState state,
CBlockIndex pindex,
CCoinsViewCache coins,
bool *  pfClean = NULL 
)

Functions for validating blocks and updating the block tree.

Undo the effects of this block (with given index) on the UTXO set represented by coins. In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean will be true if no problems were found. Otherwise, the return value will be false in case of problems. Note that in any case, coins may be modified.

Definition at line 1543 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EraseOrphansFor ( NodeId  peer)

Definition at line 491 of file main.cpp.

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

Definition at line 2134 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2188 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int GetLegacySigOpCount ( const CTransaction tx)

Count ECDSA signature operations the old-fashioned (pre-0.6) way.

Returns
number of sigops this transaction's outputs will produce when spent
See also
CTransaction::FetchInputs

Definition at line 700 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t GetMinFee ( const CTransaction tx,
unsigned int  nBytes,
bool  fAllowFree,
enum GetMinFee_mode  mode 
)

Definition at line 847 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool GetNodeStateStats ( NodeId  nodeid,
CNodeStateStats stats 
)

Get statistics from node state.

Definition at line 344 of file main.cpp.

Here is the caller graph for this function:

unsigned int GetP2SHSigOpCount ( const CTransaction tx,
CCoinsViewCache mapInputs 
)

Count ECDSA signature operations in pay-to-script-hash inputs.

Parameters
[in]mapInputsMap of previous transactions that have outputs we're spending
Returns
maximum number of sigops required to validate this transaction's inputs
See also
CTransaction::FetchInputs

Definition at line 714 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 1075 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

string GetWarnings ( string  strFor)

Definition at line 3093 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool InitBlockIndex ( )

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

Definition at line 2903 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

CBlockIndex* InsertBlockIndex ( uint256  hash)

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

Definition at line 2737 of file main.cpp.

Here is the caller graph for this function:

bool IsFinalTx ( const CTransaction tx,
int  nBlockHeight,
int64_t  nBlockTime 
)

Definition at line 617 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsInitialBlockDownload ( )

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

Definition at line 1246 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsStandardTx ( const CTransaction tx,
string &  reason 
)

Definition at line 530 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int LimitOrphanTxSize ( unsigned int  nMaxOrphans)

Definition at line 508 of file main.cpp.

Here is the call graph for this function:

bool LoadBlockIndex ( )

Load the block tree and coins database from disk.

Definition at line 2894 of file main.cpp.

Here is the caller graph for this function:

bool LoadExternalBlockFile ( FILE *  fileIn,
CDiskBlockPos dbp 
)

Import blocks from an external file.

Definition at line 3007 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Misbehaving ( NodeId  nodeid,
int  howmuch 
)

Increase a node's misbehavior score.

Definition at line 1346 of file main.cpp.

Here is the call graph for this function:

FILE* OpenBlockFile ( const CDiskBlockPos pos,
bool  fReadOnly 
)

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

Definition at line 2729 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2706 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* OpenUndoFile ( const CDiskBlockPos pos,
bool  fReadOnly 
)

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

Definition at line 2733 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void PrintBlockTree ( )

Print the loaded block tree.

Definition at line 2938 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Process an incoming block.

Definition at line 2431 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ProcessMessages ( CNode pfrom)

Process protocol messages received from a given node.

Definition at line 4042 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void PushGetBlocks ( CNode pnode,
CBlockIndex pindexBegin,
uint256  hashEnd 
)

Definition at line 2419 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ReadBlockFromDisk ( CBlock block,
const CDiskBlockPos pos 
)

Definition at line 1171 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ReadBlockFromDisk ( CBlock block,
const CBlockIndex pindex 
)

Definition at line 1195 of file main.cpp.

Here is the call graph for this function:

void RegisterNodeSignals ( CNodeSignals nodeSignals)

Register with a network node to receive its signals.

Definition at line 359 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void RegisterWallet ( CWalletInterface pwalletIn)

Register a wallet to receive updates from core.

Definition at line 156 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool SendMessages ( CNode pto,
bool  fSendTrickle 
)

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

Definition at line 4163 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Push an updated transaction to all registered wallets.

Definition at line 183 of file main.cpp.

Here is the caller graph for this function:

void ThreadScriptCheck ( )

Run an instance of the script checking thread.

Definition at line 1664 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void UnloadBlockIndex ( )

Unload database information.

Definition at line 2886 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void UnregisterAllWallets ( )

Unregister all wallets from core.

Definition at line 174 of file main.cpp.

Here is the caller graph for this function:

void UnregisterNodeSignals ( CNodeSignals nodeSignals)

Unregister a network node.

Definition at line 368 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void UnregisterWallet ( CWalletInterface pwalletIn)

Unregister a wallet from core.

Definition at line 165 of file main.cpp.

Here is the call graph for this function:

void UpdateCoins ( const CTransaction tx,
CValidationState state,
CCoinsViewCache inputs,
CTxUndo txundo,
int  nHeight,
const uint256 txhash 
)

Definition at line 1423 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void UpdateTime ( CBlockHeader block,
const CBlockIndex pindexPrev 
)

Definition at line 1404 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool VerifyDB ( int  nCheckLevel,
int  nCheckDepth 
)

Verify consistency of the block and coin databases.

Definition at line 2812 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Verify a signature.

Definition at line 1449 of file main.cpp.

bool WriteBlockToDisk ( CBlock block,
CDiskBlockPos pos 
)

Functions for disk access for blocks.

Definition at line 1145 of file main.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

CChain chainActive

The currently-connected chain of blocks.

Definition at line 43 of file main.cpp.

CChain chainMostWork

The currently best known chain of headers (some of which may be invalid).

Definition at line 44 of file main.cpp.

CScript COINBASE_FLAGS

Definition at line 75 of file main.cpp.

Definition at line 38 of file main.cpp.

bool fBenchmark = false

Definition at line 49 of file main.cpp.

bool fImporting = false

Definition at line 47 of file main.cpp.

bool fLargeWorkForkFound = false

Definition at line 1262 of file main.cpp.

bool fLargeWorkInvalidChainFound = false

Definition at line 1263 of file main.cpp.

bool fReindex = false

Definition at line 48 of file main.cpp.

bool fTxIndex = false

Definition at line 50 of file main.cpp.

class CMainCleanup instance_of_cmaincleanup
map<uint256, CBlockIndex*> mapBlockIndex

Definition at line 42 of file main.cpp.

map<uint256, COrphanBlock*> mapOrphanBlocks

Definition at line 63 of file main.cpp.

multimap<uint256, COrphanBlock*> mapOrphanBlocksByPrev

Definition at line 64 of file main.cpp.

map<uint256, COrphanTx> mapOrphanTransactions

Definition at line 70 of file main.cpp.

map<uint256, set<uint256> > mapOrphanTransactionsByPrev

Definition at line 71 of file main.cpp.

CTxMemPool mempool

Definition at line 40 of file main.cpp.

unsigned int nCoinCacheSize = 5000

Definition at line 51 of file main.cpp.

int nScriptCheckThreads = 0

Definition at line 46 of file main.cpp.

int64_t nTimeBestReceived = 0

Definition at line 45 of file main.cpp.

CBlockTreeDB* pblocktree = NULL

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

Definition at line 437 of file main.cpp.

CCoinsViewCache* pcoinsTip = NULL

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

Definition at line 436 of file main.cpp.

CBlockIndex * pindexBestForkBase = NULL

Definition at line 1264 of file main.cpp.

CBlockIndex* pindexBestForkTip = NULL

Definition at line 1264 of file main.cpp.

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

Definition at line 77 of file main.cpp.