aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h119
1 files changed, 74 insertions, 45 deletions
diff --git a/src/main.h b/src/main.h
index e346726045..fdaec3469e 100644
--- a/src/main.h
+++ b/src/main.h
@@ -22,7 +22,7 @@ class CAddress;
class CInv;
class CNode;
-class CBlockIndexWorkComparator;
+struct CBlockIndexWorkComparator;
/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 1000000;
@@ -89,6 +89,7 @@ extern std::set<CWallet*> setpwalletRegistered;
extern unsigned char pchMessageStart[4];
extern bool fImporting;
extern bool fReindex;
+extern bool fBenchmark;
extern unsigned int nCoinCacheSize;
// Settings
@@ -174,6 +175,11 @@ CBlockIndex * InsertBlockIndex(uint256 hash);
+static inline std::string BlockHashStr(const uint256& hash)
+{
+ return hash.ToString();
+}
+
bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
class CDiskBlockPos
@@ -187,6 +193,15 @@ public:
READWRITE(VARINT(nPos));
)
+ CDiskBlockPos() {
+ SetNull();
+ }
+
+ CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
+ nFile = nFileIn;
+ nPos = nPosIn;
+ }
+
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
return (a.nFile == b.nFile && a.nPos == b.nPos);
}
@@ -625,7 +640,7 @@ public:
// Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
// This does not modify the UTXO set
- bool CheckInputs(CCoinsViewCache &view, enum CheckSig_mode csmode, bool fStrictPayToScriptHash=true, bool fStrictEncodings=true) const;
+ bool CheckInputs(CCoinsViewCache &view, enum CheckSig_mode csmode, unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC) const;
// Apply the effects of this transaction on the UTXO set represented by view
bool UpdateCoins(CCoinsViewCache &view, CTxUndo &txundo, int nHeight, const uint256 &txhash) const;
@@ -733,7 +748,6 @@ public:
bool WriteToDisk(CDiskBlockPos &pos)
{
-
// Open history file to append
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
if (!fileout)
@@ -746,7 +760,7 @@ public:
// Write undo data
long fileOutPos = ftell(fileout);
if (fileOutPos < 0)
- return error("CBlock::WriteToDisk() : ftell failed");
+ return error("CBlockUndo::WriteToDisk() : ftell failed");
pos.nPos = (unsigned int)fileOutPos;
fileout << *this;
@@ -757,7 +771,6 @@ public:
return true;
}
-
};
/** pruned version of CTransaction: only retains metadata and unspent transaction outputs
@@ -1068,7 +1081,7 @@ public:
* in the block is a special one that creates a new coin owned by the creator
* of the block.
*/
-class CBlock
+class CBlockHeader
{
public:
// header
@@ -1080,17 +1093,7 @@ public:
unsigned int nBits;
unsigned int nNonce;
- // network and disk
- std::vector<CTransaction> vtx;
-
- // memory only
- mutable std::vector<uint256> vMerkleTree;
-
- // Denial-of-service detection:
- mutable int nDoS;
- bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
-
- CBlock()
+ CBlockHeader()
{
SetNull();
}
@@ -1104,25 +1107,16 @@ public:
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
-
- // ConnectBlock depends on vtx being last so it can calculate offset
- if (!(nType & (SER_GETHASH|SER_BLOCKHEADERONLY)))
- READWRITE(vtx);
- else if (fRead)
- const_cast<CBlock*>(this)->vtx.clear();
)
void SetNull()
{
- nVersion = CBlock::CURRENT_VERSION;
+ nVersion = CBlockHeader::CURRENT_VERSION;
hashPrevBlock = 0;
hashMerkleRoot = 0;
nTime = 0;
nBits = 0;
nNonce = 0;
- vtx.clear();
- vMerkleTree.clear();
- nDoS = 0;
}
bool IsNull() const
@@ -1141,7 +1135,45 @@ public:
}
void UpdateTime(const CBlockIndex* pindexPrev);
+};
+class CBlock : public CBlockHeader
+{
+public:
+ // network and disk
+ std::vector<CTransaction> vtx;
+
+ // memory only
+ mutable std::vector<uint256> vMerkleTree;
+
+ // Denial-of-service detection:
+ mutable int nDoS;
+ bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
+
+ CBlock()
+ {
+ SetNull();
+ }
+
+ CBlock(const CBlockHeader &header)
+ {
+ SetNull();
+ *((CBlockHeader*)this) = header;
+ }
+
+ IMPLEMENT_SERIALIZE
+ (
+ READWRITE(*(CBlockHeader*)this);
+ READWRITE(vtx);
+ )
+
+ void SetNull()
+ {
+ CBlockHeader::SetNull();
+ vtx.clear();
+ vMerkleTree.clear();
+ nDoS = 0;
+ }
uint256 BuildMerkleTree() const
{
@@ -1226,7 +1258,7 @@ public:
return true;
}
- bool ReadFromDisk(const CDiskBlockPos &pos, bool fReadTransactions = true)
+ bool ReadFromDisk(const CDiskBlockPos &pos)
{
SetNull();
@@ -1234,8 +1266,6 @@ public:
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (!filein)
return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
- if (!fReadTransactions)
- filein.nType |= SER_BLOCKHEADERONLY;
// Read block
try {
@@ -1257,9 +1287,9 @@ public:
void print() const
{
printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
- GetHash().ToString().substr(0,20).c_str(),
+ BlockHashStr(GetHash()).c_str(),
nVersion,
- hashPrevBlock.ToString().substr(0,20).c_str(),
+ BlockHashStr(hashPrevBlock).c_str(),
hashMerkleRoot.ToString().substr(0,10).c_str(),
nTime, nBits, nNonce,
vtx.size());
@@ -1282,7 +1312,7 @@ public:
bool ConnectBlock(CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false);
// Read a block from disk
- bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
+ bool ReadFromDisk(const CBlockIndex* pindex);
// Add this block to the block index, and if necessary, switch the active block chain to this
bool AddToBlockIndex(const CDiskBlockPos &pos);
@@ -1447,7 +1477,7 @@ public:
nNonce = 0;
}
- CBlockIndex(CBlock& block)
+ CBlockIndex(CBlockHeader& block)
{
phashBlock = NULL;
pprev = NULL;
@@ -1473,8 +1503,7 @@ public:
if (nStatus & BLOCK_HAVE_DATA) {
ret.nFile = nFile;
ret.nPos = nDataPos;
- } else
- ret.SetNull();
+ }
return ret;
}
@@ -1483,14 +1512,13 @@ public:
if (nStatus & BLOCK_HAVE_UNDO) {
ret.nFile = nFile;
ret.nPos = nUndoPos;
- } else
- ret.SetNull();
+ }
return ret;
}
- CBlock GetBlockHeader() const
+ CBlockHeader GetBlockHeader() const
{
- CBlock block;
+ CBlockHeader block;
block.nVersion = nVersion;
if (pprev)
block.hashPrevBlock = pprev->GetBlockHash();
@@ -1570,7 +1598,7 @@ public:
return strprintf("CBlockIndex(pprev=%p, pnext=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
pprev, pnext, nHeight,
hashMerkleRoot.ToString().substr(0,10).c_str(),
- GetBlockHash().ToString().substr(0,20).c_str());
+ BlockHashStr(GetBlockHash()).c_str());
}
void print() const
@@ -1634,7 +1662,7 @@ public:
uint256 GetBlockHash() const
{
- CBlock block;
+ CBlockHeader block;
block.nVersion = nVersion;
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
@@ -1651,7 +1679,7 @@ public:
str += CBlockIndex::ToString();
str += strprintf("\n hashBlock=%s, hashPrev=%s)",
GetBlockHash().ToString().c_str(),
- hashPrev.ToString().substr(0,20).c_str());
+ BlockHashStr(hashPrev).c_str());
return str;
}
@@ -1811,7 +1839,8 @@ public:
bool accept(CTransaction &tx, bool fCheckInputs, bool* pfMissingInputs);
bool addUnchecked(const uint256& hash, CTransaction &tx);
- bool remove(CTransaction &tx);
+ bool remove(const CTransaction &tx, bool fRecursive = false);
+ bool removeConflicts(const CTransaction &tx);
void clear();
void queryHashes(std::vector<uint256>& vtxid);
void pruneSpent(const uint256& hash, CCoins &coins);
@@ -1872,7 +1901,7 @@ public:
virtual bool GetStats(CCoinsStats &stats);
// As we use CCoinsViews polymorphically, have a virtual destructor
- virtual ~CCoinsView() {};
+ virtual ~CCoinsView() {}
};
/** CCoinsView backed by another CCoinsView */