6 #ifndef FABCOIN_CHAIN_H 7 #define FABCOIN_CHAIN_H 28 static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
36 static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
51 template <
typename Stream,
typename Operation>
79 void AddBlock(
unsigned int nHeightIn, uint64_t nTimeIn) {
80 if (nBlocks==0 || nHeightFirst > nHeightIn)
81 nHeightFirst = nHeightIn;
82 if (nBlocks==0 || nTimeFirst > nTimeIn)
85 if (nHeightIn > nHeightLast)
86 nHeightLast = nHeightIn;
87 if (nTimeIn > nTimeLast)
99 template <
typename Stream,
typename Operation>
123 bool IsNull()
const {
return (nFile == -1); }
127 return strprintf(
"CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos);
222 uint32_t nReserved[7];
239 phashBlock =
nullptr;
256 memset(nReserved, 0,
sizeof(nReserved));
331 return (int64_t)nTime;
336 return (int64_t)nTimeMax;
339 enum { nMedianTimeSpan=11 };
343 int64_t pmedian[nMedianTimeSpan];
344 int64_t* pbegin = &pmedian[nMedianTimeSpan];
345 int64_t* pend = &pmedian[nMedianTimeSpan];
348 for (
int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->
pprev)
351 std::sort(pbegin, pend);
352 return pbegin[(pend - pbegin)/2];
365 bool IsSupportContract()
const;
367 bool IsLegacyFormat()
const;
372 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
375 GetBlockHash().ToString());
395 nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;
428 hashPrev = (pprev ? pprev->GetBlockHash() :
uint256());
433 template <
typename Stream,
typename Operation>
435 int _nVersion = s.GetVersion();
453 for(
size_t i = 0; i < (
sizeof(nReserved) /
sizeof(nReserved[0])); i++) {
460 bool hascontract = IsSupportContract();
491 std::string str =
"CDiskBlockIndex(";
493 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
508 return vChain.size() > 0 ? vChain[0] :
nullptr;
513 return vChain.size() > 0 ? vChain[vChain.size() - 1] :
nullptr;
518 if (nHeight < 0 || nHeight >= (
int)vChain.size())
520 return vChain[nHeight];
531 return (*
this)[pindex->
nHeight] == pindex;
536 if (Contains(pindex))
537 return (*
this)[pindex->
nHeight + 1];
544 return vChain.size() - 1;
557 CBlockIndex* FindEarliestAtLeast(int64_t nTime)
const;
560 #endif // FABCOIN_CHAIN_H arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
CDiskBlockPos GetBlockPos() const
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
bool IsProofOfStake() const
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
std::vector< CBlockIndex * > vChain
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
descends from failed block
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
An in-memory indexed chain of blocks.
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists...
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
std::string ToString() const
stage after last reached validness failed
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid...
unsigned int nSize
number of used bytes of block file
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
assert(len-trim+(2 *lenIndices)<=WIDTH)
undo data available in rev*.dat
int nFile
Which # file this block is stored in (blk?????.dat)
bool IsProofOfWork() const
unsigned int nHeightLast
highest height of block in file
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block. ...
unsigned int nUndoSize
number of used bytes in the undo file
std::string ToString() const
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
int64_t GetBlockTimeMax() const
arith_uint256 GetBlockProof(const CBlockIndex &block)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends...
int Height() const
Return the maximal height in the chain.
unsigned int nTimeMax
(memory only) Maximum nTime in the chain upto and including this block.
uint64_t nTimeFirst
earliest time of block in file
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
CBlockHeader GetBlockHeader() const
void SerializationOp(Stream &s, Operation ser_action)
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
uint256 GetBlockHash() const
Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future...
CBlockIndex(const CBlockHeader &block)
friend bool operator==(const CChain &a, const CChain &b)
Compare two chains efficiently.
unsigned int nHeightFirst
lowest height of block in file
std::string ToString() const
Used to marshal pointers into hashes for db storage.
Parameters that influence chain consensus.
std::string ToString() const
256-bit unsigned big integer.
block data in blk*.data was received with a witness-enforcing client
void SerializationOp(Stream &s, Operation ser_action)
int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, const CBlockIndex &from, const CBlockIndex &tip, const Consensus::Params &)
Return the time it would take to redo the work difference between from and to, assuming the current h...
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
CBlockIndex * pnext
pointer to the index of the successor of this block
void SerializationOp(Stream &s, Operation ser_action)
CDiskBlockIndex(const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
void * memcpy(void *a, const void *b, size_t c)
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
unsigned int nBlocks
number of blocks stored in file
std::string ToString() const
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
uint64_t nTimeLast
latest time of block in file
CDiskBlockPos GetUndoPos() const
int nHeight
height of the entry in the chain. The genesis block has height 0
full block available in blk*.dat
int64_t GetBlockTime() const
int64_t GetMedianTimePast() const
unsigned int nTx
Number of transactions in this block.
std::vector< unsigned char > nSolution
uint256 h256Touint(const dev::h256 &in)
uint256 GetBlockHash() const
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex