veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration Namespace Reference

Defines logging helpers. More...

Namespaces

namespace  json
 Package that contains adaptors to simplify serialization of entities to JSON.
 

Classes

class  Address
 Represents address on VBK chain. More...
 
class  AltBlock
 Represents a view on Altchain block - i.e. More...
 
struct  AltBlockTree
 Represents simplified view on Altchain's block tree, maintains VBK tree and BTC tree. More...
 
struct  AltChainParams
 Base class for all Altchain-related configs. More...
 
struct  AltChainParamsRegTest
 
struct  AltCommandGroupStore
 A wrapper for the payload store that constructs command objects. More...
 
class  ArithUint256
 256-bit unsigned big integer. More...
 
class  ATV
 Atlchain endorsement. More...
 
struct  AuthenticatedContextInfoContainer
 Contains ContextInfoContainer and merkle path which authenticates hash of ContextInfoContainer to a block header. More...
 
struct  BaseBlockTree
 Base block tree that stores all blocks, maintains tree tips, maintains active chain. More...
 
struct  Blob
 Contiguous byte array of fixed size. More...
 
struct  BlockBatch
 An interface which represents single write batch of a group of blocks. More...
 
struct  BlockIndex
 A node in a block tree. More...
 
struct  BlockIterator
 An abstraction over on-disk storage block iterator. More...
 
struct  BlockReader
 An abstraction over on-disk storage iterator. More...
 
struct  BlockTree
 BlockTree is a tree of blocks with single "bootstrap" block as root. More...
 
struct  BtcBlock
 Bitcoin block. More...
 
struct  BtcChainParams
 base class for BTC params More...
 
struct  BtcChainParamsMain
 mainnet network params in Bitcoin chain. More...
 
struct  BtcChainParamsRegTest
 regtest network params in Bitcoin chain. More...
 
struct  BtcChainParamsTest
 testnet3 network params in Bitcoin chain. More...
 
struct  BtcTx
 Bitcoin transaction representation. More...
 
struct  CacheEntry
 
struct  Chain
 Fully in-memory chain representation. More...
 
struct  ChainSlice
 Non-owning partial chain view similar to std::span. More...
 
struct  CheckPublicationData
 A command which performs stateful check of PublicationData stored in ATV. More...
 
struct  Coin
 represents VBK atomic units More...
 
struct  Config
 A container for Bitcoin and Veriblock configuration data. More...
 
struct  ContextInfoContainer
 Container of context info for endorsed block. More...
 
struct  DefaultPopRewardsCalculator
 
struct  Endorsement
 
struct  EthashCache
 
struct  EthashCacheI
 
struct  FinalizedPayloadsIndex
 Stores a mapping "payload id -> containing block" hash of payloads that are stored in finalized blocks. More...
 
struct  Finalizer
 Finalizer holds a function that is executed on Finalizer destruction. More...
 
struct  IsPopPayload
 type trait which returns true on types that are "POP Payloads" More...
 
struct  KeystoneContainer
 A container for two previous keystones of endorsed block. More...
 
struct  Logger
 An interface for logger. More...
 
struct  MemPool
 Data structure, that stores in memory all valid payloads (ATV, VTB, VbkBlock) submitted by other peers through p2p or by users through rpc. More...
 
struct  MempoolResult
 An entity which is returned from MemPool on call to submitAll. More...
 
struct  MerklePath
 Path in Merkle tree which proves that subject is inside this tree. More...
 
struct  NetworkBytePair
 Stores pair of TxType and VBK network byte. More...
 
struct  Output
 Single spending output. More...
 
struct  PayloadsIndex
 Payloads index that stores mapping "payload id -> set of containing blocks" from all NON-FINALIZED blocks. More...
 
struct  PayloadsStorage
 Accessor for ATV/VTB/VbkBlock bodies given hash. More...
 
struct  PopContext
 Main entrypoint into the veriblock-pop library. More...
 
struct  PopData
 Represents ALT block body of POP-related info. More...
 
struct  PopPayouts
 A container for Pop payouts information. More...
 
struct  PopPayoutsParams
 Defines config for POP payouts. More...
 
struct  PopRewardsCalculator
 
struct  PopRewardsCurveParams
 A container for curve params. More...
 
struct  PopRewardsParams
 A container for PoP rewards params. More...
 
struct  ProgpowHeaderCache
 
struct  ProgpowHeaderCacheI
 
struct  PublicationData
 Publication data about ALT block inside VBK blockchain. More...
 
struct  ReadStream
 Binary reading stream, that is useful during binary deserialization. More...
 
class  reverse_range
 translates a pair of forward iterators to a range whose regular iteration order is "backward" More...
 
struct  Slice
 Non-owning contiguous array. More...
 
struct  StateCorruptedException
 Is thrown only when this library detects POP-related state corruption, and can't recover. More...
 
struct  StorageIOException
 exception which is thrown on any IO errors. More...
 
struct  StoredBlockIndex
 
class  ValidationState
 Class that is used for storing validation state. More...
 
struct  VbkBlock
 Veriblock block. More...
 
class  VbkBlockTree
 Veriblock block tree. More...
 
struct  VbkChainParams
 VeriBlock chain parameters. More...
 
struct  VbkChainParamsMain
 MainNet VBK parameters. More...
 
struct  VbkChainParamsRegTest
 RegTest VBK config. More...
 
struct  VbkChainParamsTest
 TestNet VBK config. More...
 
struct  VbkCommandGroupStore
 A wrapper for the payload store that constructs command objects. More...
 
struct  VbkMerklePath
 Path in Merkle tree, which proves that subject exists in the tree. More...
 
struct  VbkNetworkType
 works as optional<uint8_t> More...
 
struct  VbkPopTx
 Veriblock POP transaction, which endorses VBK block in BTC blockchain. More...
 
struct  VbkTx
 Veriblock transaction, which endorses ALT block in VBK blockchain. More...
 
struct  vblake_ctx
 vBlake hash state context. More...
 
struct  VTB
 Veriblock to Bitcoin publication, committed to Veriblock blockchain in containingBlock. More...
 
class  WriteStream
 Binary writer that is useful for binary serialization. More...
 

Typedefs

using BtcBlockTree = BlockTree< BtcBlock, BtcChainParams >
 Bitcoin tree. More...
 
using uint128 = Blob< VBK_MERKLE_ROOT_HASH_SIZE >
 Fixed-size array. More...
 
using uint256 = Blob< SHA256_HASH_SIZE >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
using uint72 = Blob< VBK_PREVIOUS_KEYSTONE_HASH_SIZE >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
using uint96 = Blob< VBK_PREVIOUS_BLOCK_HASH_SIZE >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
using uint192 = Blob< VBK_BLOCK_HASH_SIZE >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Enumerations

enum  BlockStateStatus : uint32_t {
  BLOCK_VALID_TREE = 1 , BLOCK_CONNECTED = 2 , BLOCK_CAN_BE_APPLIED_MAYBE_WITH_OTHER_CHAIN = 3 , BLOCK_CAN_BE_APPLIED = 4 ,
  BLOCK_VALID_MASK
}
 Flags that describe block status. More...
 
enum  BlockValidityStatus : uint32_t {
  BLOCK_VALID_UNKNOWN = 0 , BLOCK_BOOTSTRAP = 1 << 4 , BLOCK_FAILED_BLOCK = 1 << 5 , BLOCK_FAILED_POP = 1 << 6 ,
  BLOCK_FAILED_CHILD = 1 << 7 , BLOCK_FAILED_MASK , BLOCK_HAS_PAYLOADS = 1 << 8 , BLOCK_ACTIVE = 1 << 9 ,
  BLOCK_DELETED = 1 << 10
}
 Flags that describe block status. More...
 
enum class  PopFrOutcome {
  UNKNOWN , CANDIDATE_IS_TIP , CANDIDATE_INVALID_CHAIN , CANDIDATE_INVALID_PAYLOADS ,
  CANDIDATE_PART_OF_ACTIVE_CHAIN , CANDIDATE_IS_TIP_SUCCESSOR , TIP_IS_FINAL , BOTH_DONT_CROSS_KEYSTONE_BOUNDARY ,
  CANDIDATE_INVALID_INDEPENDENTLY , HIGHER_POP_SCORE
}
 
enum class  TxType { VBK_TX = 0x01 , VBK_POP_TX = 0x02 }
 Veriblock transaction type. More...
 
enum class  AddressType { STANDARD = 1 , MULTISIG = 3 }
 VBK Address type (modelled after transaction type). More...
 
enum class  LogLevel {
  debug , info , warn , error ,
  critical , off
}
 Log level. More...
 

Functions

template<typename T , typename Container >
const T min_or_default (Container &c, const T default_)
 returns min value in a container (vector, array...), or "default" value if container is empty More...
 
template<typename BlockTreeT >
std::vector< typename BlockTreeT::block_t > getContext (const BlockTreeT &tree, typename BlockTreeT::hash_t tip, size_t size=std::numeric_limits< size_t >::max())
 Build a context (blocks necessary to connect) in a tree from tip backwards size elements. More...
 
template<typename BlockTree >
std::vector< std::vector< uint8_t > > getLastKnownBlocks (const BlockTree &tree, size_t size)
 helper to get last N known block hashes More...
 
template<typename Block , typename ChainParams >
bool addBlocks (BlockTree< Block, ChainParams > &tree, const std::vector< std::vector< uint8_t > > &blocks, ValidationState &state)
 helper to accept multiple blocks More...
 
bool GeneratePublicationData (const std::vector< uint8_t > &endorsedBlockHeader, const std::vector< uint8_t > &txMerkleRoot, const PopData &popData, const std::vector< uint8_t > &payoutInfo, const AltBlockTree &tree, PublicationData &out)
 Creates a PublicationData - an entity, which stores information about Altchain block endorsement. More...
 
PublicationData GeneratePublicationData (const std::vector< uint8_t > &endorsedBlockHeader, const BlockIndex< AltBlock > &endorsedBlock, const std::vector< uint8_t > &txMerkleRoot, const PopData &popData, const std::vector< uint8_t > &payoutInfo, const AltChainParams &params)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
PublicationData GeneratePublicationData (const std::vector< uint8_t > &endorsedBlockHeader, const BlockIndex< AltBlock > &endorsedBlock, const std::vector< uint8_t > &txMerkleRoot, uint32_t version, const std::vector< ATV::id_t > &atv_ids, const std::vector< VTB::id_t > &vtb_ids, const std::vector< VbkBlock::id_t > &vbk_ids, const std::vector< uint8_t > &payoutInfo, const AltChainParams &params)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint256 CalculateTopLevelMerkleRoot (const std::vector< uint8_t > &txMerkleRoot, const uint256 &popDataMerkleRoot, const ContextInfoContainer &ctx)
 calculates top level merkle root that cryptographically authenticates block content (transactions, PopData, context info) to a block
 
uint256 CalculateTopLevelMerkleRoot (const AuthenticatedContextInfoContainer &ctx)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint256 CalculateTopLevelMerkleRoot (const std::vector< uint8_t > &txMerkleRoot, const PopData &popData, const BlockIndex< AltBlock > *prevBlock, const AltChainParams &params)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
int getMaxAtvsInVbkBlock (uint64_t altchainId)
 The second to the last byte is used to determine the max number of occurrences The first 7 bits determine the base (1 is added to the first 7 bits interpreted as a number), and the last bit determines the exponent (0 = exponent of 1, 1 = exponent of 2) For example: 00000000 has a base of 1 (0+1) and an exponent of 1 for a maximum of 1 publication 00000110 has a base of 4 (3+1) and an exponent of 1 for a maximum of 4 publications 00000101 has a base of 3 (2+1) and an exponent of 2 for a maximum of 9 publications.
 
void PrintTo (const ArithUint256 &uint, ::std::ostream *os)
 custom gtest printer, which prints Blob of any size as hexstring @ private More...
 
std::string EncodeBase58 (const unsigned char *pbegin, const unsigned char *pend)
 Encodes input bytes to Base58.
 
template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
std::string EncodeBase58 (const T &container)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DecodeBase58 (const std::string &str, std::vector< unsigned char > &out, ValidationState &state)
 Decodes base58 into bytes.
 
std::string EncodeBase59 (const unsigned char *pbegin, const unsigned char *pend)
 Encode input bytes to base59.
 
std::string EncodeBase59 (const uint8_t *buf, size_t size)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
std::string EncodeBase59 (const T &container)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DecodeBase59 (const std::string &input, std::vector< uint8_t > &out, ValidationState &state)
 Decode base59 string into bytes.
 
template<typename Value , size_t N>
Value ToJSON (const Blob< N > &blob)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, AltBlockAddon &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const PopPayoutsParams &p)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename JsonValue >
JsonValue ToJSON (const AltChainParams &p, bool reverseAltHashes=true)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename Block >
const BlockIndex< Block > * getForkBlock (const BlockIndex< Block > &a, const BlockIndex< Block > &b)
 getForkBlock assumes that: the block tree is not malformed the fork block(worst case: genesis/bootstrap block) is in memory the complexity is O(n) More...
 
template<typename Block >
bool isBlockOutdated (const BlockIndex< Block > &finalBlock, const BlockIndex< Block > &candidate)
 a candidate is considered outdated if it is behind finalBlock, or on same height and not equal to finalBlock, or its fork block is outdated More...
 
constexpr bool isValidInvalidationReason (const BlockValidityStatus &reason)
 Check if the reason value can be used as the reason for invalidateSubtree and revalidateSubtree. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, BtcBlockAddon &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename C >
C::index_t * findFork (const C &chain, const typename C::index_t *pindex)
 Find fork between chain and pindex. More...
 
std::string popFrOutcomeToString (PopFrOutcome value, const ValidationState &state)
 
template<typename T >
bool DeserializeFromVbkEncoding (ReadStream &stream, PopState< T > &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename JsonValue >
JsonValue ToJSON (const BlockIndex< VbkBlock > &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename JsonValue >
JsonValue ToJSON (const BlockIndex< BtcBlock > &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename Block >
void forEachNodePostorder (BlockIndex< Block > &index, const std::function< void(BlockIndex< Block > &)> &visit, const std::function< bool(BlockIndex< Block > &)> &shouldVisit)
 Postorder tree traversal algorithm. More...
 
template<typename Block >
void forEachNodePreorder (BlockIndex< Block > &index, const std::function< bool(BlockIndex< Block > &)> &visit)
 iterate across all subtrees starting (and including) given 'index' More...
 
template<typename Block >
void forEachNextNodePreorder (BlockIndex< Block > &index, const std::function< bool(BlockIndex< Block > &)> &shouldContinue)
 iterate across all subtrees starting (and excluding) given 'index' More...
 
template<typename Block >
std::vector< BlockIndex< Block > * > findValidTips (BlockIndex< Block > &index)
 Find all tips after given block, including given block. More...
 
template<typename Block >
std::vector< BlockIndex< Block > * > findValidTips (const std::unordered_set< BlockIndex< Block > * > &tips, BlockIndex< Block > &index)
 Find all tips after given block, including given block. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VbkBlockAddon &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
VbkBlock GetRegTestVbkBlock ()
 Getter for regtest_progpow VBK network genesis block.
 
BtcBlock GetRegTestBtcBlock ()
 Getter for regtest BTC network genesis block.
 
void setEthashCache (std::unique_ptr< EthashCacheI > cache)
 
void setProgpowHeaderCache (std::unique_ptr< ProgpowHeaderCacheI > cache)
 
uint192 progPowHash (Slice< const uint8_t > header)
 Calculate vPROGPOW hash of given VbkBlock header (65 bytes) More...
 
uint192 progPowHash (Slice< const uint8_t > header, progpow::ethash_cache *light)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, CacheEntry &out, ValidationState &state)
 
uint32_t kiss99 (kiss99_t &st)
 Calculate KISS99. More...
 
void vblake_init (vblake_ctx *ctx)
 Initialize the hashing context. More...
 
int vblake_update (vblake_ctx *ctx, const void *in, size_t inlen)
 Add "inlen" bytes from "in" into the hash. More...
 
void vblake_final (vblake_ctx *ctx, void *out)
 Generate the message digest. More...
 
int vblake (void *out, const void *in, size_t inlen)
 Convenience function for all-in-one computation. More...
 
template<typename Value >
Value ToJSON (const Address &addr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, Address &out, ValidationState &state)
 Read data from the stream and convert it to VBK address. More...
 
template<typename JsonValue >
JsonValue ToJSON (const AltBlock &alt, bool reverseHashes=true)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, AltBlock &out, ValidationState &state, const AltBlock::hash_t &=AltBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, AltBlock &out, ValidationState &state, const AltBlock::hash_t &=AltBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const ATV &atv)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, ATV &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const BtcBlock &b)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, BtcBlock &out, ValidationState &state, const BtcBlock::hash_t &precalculatedHash=BtcBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, BtcBlock &out, ValidationState &state, const BtcBlock::hash_t &precalculatedHash=BtcBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, BtcTx &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, Coin &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, ContextInfoContainer &ctx, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, AuthenticatedContextInfoContainer &ctx, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const ContextInfoContainer &a)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename JsonValue >
JsonValue ToJSON (const AuthenticatedContextInfoContainer &a)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename Value , class A , class B , class C >
Value ToJSON (const Endorsement< A, B, C > &e)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, KeystoneContainer &container, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const KeystoneContainer &c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename JsonValue >
JsonValue ToJSON (const MerklePath &m)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, const uint256 &subject, MerklePath &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, const uint256 &subject, MerklePath &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint32_t estimateNumberOfPopTxs (const std::vector< VbkMerklePath > &paths)
 
bool isPopSubTreeFull (const std::vector< VbkMerklePath > &paths)
 
template<typename JsonValue >
JsonValue ToJSON (const Output &o)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, Output &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const PopData &p, bool verbose=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, PopData &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const PublicationData &p)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, PublicationData &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const VbkMerklePath &mp)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VbkMerklePath &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const VbkBlock &b)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, VbkBlock &out, ValidationState &state, const VbkBlock::hash_t &hash=VbkBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VbkBlock &out, ValidationState &state, const VbkBlock::hash_t &hash=VbkBlock::hash_t{})
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const VbkPopTx &tx)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, Slice< const uint8_t > signature, Slice< const uint8_t > publicKey, VbkPopTx &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VbkPopTx &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const VbkTx &tx)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromRaw (ReadStream &stream, Slice< const uint8_t > signature, Slice< const uint8_t > publicKey, VbkTx &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VbkTx &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename JsonValue >
JsonValue ToJSON (const VTB &v)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool DeserializeFromVbkEncoding (ReadStream &stream, VTB &out, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint256 sha256 (Slice< const uint8_t > data)
 Calculates SHA256 of the input data. More...
 
uint256 sha256 (Slice< const uint8_t > a, Slice< const uint8_t > b)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint256 sha256twice (Slice< const uint8_t > data)
 Calculates SHA256 of the input data twice. More...
 
uint256 sha256twice (Slice< const uint8_t > a, Slice< const uint8_t > b)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint192 vblake (Slice< const uint8_t > data)
 Calculates VBlake of the input data. More...
 
template<typename Value , typename T >
Value ToJSON (const T &)
 Encode given entity into JSON. More...
 
bool isKeystone (int32_t blockNumber, uint32_t keystoneInterval)
 Calculates if block with height = blockNumber is keystone. More...
 
LoggerGetLogger ()
 getter for global logger instance More...
 
void SetLogger (std::unique_ptr< Logger > lgr, LogLevel log_lvl=LogLevel::info)
 setter for global logger instance
 
template<typename L >
void SetLogger (LogLevel log_lvl=LogLevel::info)
 setter for global logger instance More...
 
std::string LevelToString (LogLevel l)
 convert loglevel to string
 
LogLevel StringToLevel (const std::string &)
 convert string to loglevel More...
 
template<typename S , typename... Args>
std::string format (const S &format_str, Args &&... args)
 
template<typename JsonValue >
JsonValue ToJSON (const MempoolResult &r)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename T >
reverse_range< T > reverse_iterate (T &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool checkRange (uint64_t num, uint64_t min, uint64_t max, ValidationState &state)
 Checks if expression 'min' <= 'num' <= 'max' is true. More...
 
std::vector< uint8_t > trimmedArray (int64_t input)
 Converts the input to the byte array and trims it's size to the lowest possible value. More...
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
std::vector< uint8_t > fixedArray (T input)
 Converts the input to the byte array. More...
 
bool readVarLenValue (ReadStream &stream, Slice< const uint8_t > &out, ValidationState &state, uint64_t minLen, uint64_t maxLen)
 Read variable length value, which consists of [N=(4 bytes = size of slice) | N bytes slice] Size of slice should be within range [minLen; maxLen]. More...
 
bool readSingleByteLenValue (ReadStream &stream, Slice< const uint8_t > &out, ValidationState &state, uint64_t minLen, uint64_t maxLen)
 Read variable length value, which consists of [N=(1 byte = size of slice) | N bytes slice] Size of slice should be within range [minLen; maxLen]. More...
 
template<typename Container , typename = typename std::enable_if< sizeof(typename Container::value_type) == 1>::type>
bool readSingleByteLenValue (ReadStream &stream, Container &out, ValidationState &state, uint64_t minLen, uint64_t maxLen)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
bool readSingleBEValue (ReadStream &stream, T &out, ValidationState &state)
 Read single Big-Endian value from a stream. More...
 
void writeSingleByteLenValue (WriteStream &stream, Slice< const uint8_t > value)
 Write single byte length value, which consists of N bytes vector Appends 1 byte data length to the stream. More...
 
void writeSingleBEValue (WriteStream &stream, int64_t value)
 Write single Big-Endian value to the stream. More...
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void writeSingleFixedBEValue (WriteStream &stream, T value)
 Write single Big-Endian value to the stream. More...
 
void writeVarLenValue (WriteStream &stream, Slice< const uint8_t > value)
 Write variable length value, which consists of N bytes vector Appends up to 8 bytes data length to the stream and 1 byte data length size. More...
 
NetworkBytePair readNetworkByte (ReadStream &stream, TxType type)
 Read optional network byte from the stream. More...
 
bool readNetworkByte (ReadStream &stream, TxType type, NetworkBytePair &out, ValidationState &state)
 Read optional network byte from the stream. More...
 
void writeNetworkByte (WriteStream &stream, NetworkBytePair networkOrType)
 Write optional network byte to the stream. More...
 
template<typename Container >
bool readSetOf (ReadStream &stream, Container &out, ValidationState &state, size_t min, size_t max, std::function< bool(ReadStream &, typename Container::value_type &, ValidationState &)> readFunc)
 Reads set of entities of. More...
 
template<typename Container >
bool readSetOf (ReadStream &stream, Container &out, ValidationState &state, std::function< bool(Container &, ReadStream &, typename Container::value_type &, ValidationState &)> readFunc)
 Reads container of entities. More...
 
template<typename T >
bool readArrayOf (ReadStream &stream, std::vector< T > &out, ValidationState &state, size_t min, size_t max, std::function< bool(ReadStream &, T &, ValidationState &)> readFunc)
 Reads array of entities of type T. More...
 
template<typename T >
bool readArrayOf (ReadStream &stream, std::vector< T > &out, ValidationState &state, std::function< bool(ReadStream &, T &, ValidationState &)> readFunc)
 Reads array of entities of type T. More...
 
template<typename T >
size_t estimateArraySizeOf (const std::vector< T > &t, std::function< size_t(const T &t)> f)
 Estimate size of array in bytes. More...
 
template<typename T >
bool DeserializeFromVbkEncoding (Slice< const uint8_t > data, T &out, ValidationState &state)
 Deserialize from VBK encoding. More...
 
template<typename T >
bool DeserializeFromRaw (Slice< const uint8_t > data, T &out, ValidationState &state)
 Deserialize from RAW encoding. More...
 
template<typename T >
bool DeserializeFromHex (const std::string &hex, T &out, ValidationState &state)
 Deserialize from HEX VBK encoding. More...
 
template<typename T >
bool DeserializeFromRawHex (const std::string &hex, T &out, ValidationState &state)
 Deserialize from HEX RAW encoding. More...
 
template<typename T >
std::vector< uint8_t > SerializeToVbkEncoding (const T &obj)
 Serialize to VBK encoding. More...
 
template<typename T >
std::vector< uint8_t > SerializeToRaw (const T &obj)
 Serialize to RAW encoding. More...
 
template<typename T >
std::string SerializeToHex (const T &obj)
 Serialize to HEX VBK encoding. More...
 
template<typename T >
std::string SerializeToRawHex (const T &obj)
 Serialize to HEX RAW encoding. More...
 
template<typename T >
AssertDeserializeFromRaw (std::vector< uint8_t > raw)
 Deserialize from RAW encoding. More...
 
template<typename T >
AssertDeserializeFromVbkEncoding (Slice< const uint8_t > raw)
 Deserialize from VBK encoding. More...
 
template<typename T >
AssertDeserializeFromHex (std::string hex)
 Deserialize from HEX VBK encoding. More...
 
template<typename T >
AssertDeserializeFromRawHex (std::string hex)
 Deserialize from HEX RAW encoding. More...
 
template<typename MerklePathType , typename HashType1 , typename HashType2 >
bool checkMerklePath (const MerklePathType &merklePath, const HashType1 &transactionHash, const HashType2 &merkleRoot, ValidationState &state)
 Verify merkle path. More...
 
bool checkSignature (const VbkTx &tx, ValidationState &state)
 Verify signature of a transaction.
 
bool checkSignature (const VbkPopTx &tx, ValidationState &state)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool checkBtcBlocks (const std::vector< BtcBlock > &btcBlocks, ValidationState &state, const BtcChainParams &param)
 Stateless validation for a chain of Blocks.
 
bool checkVbkBlocks (const std::vector< VbkBlock > &vbkBlocks, ValidationState &state, const VbkChainParams &param)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool checkBitcoinTransactionForPoPData (const VbkPopTx &tx, ValidationState &state)
 Search BtcTx for POP data.
 
bool checkProofOfWork (const BtcBlock &block, const BtcChainParams &param)
 Stateless validation for a Block.
 
bool checkProofOfWork (const VbkBlock &block, const VbkChainParams &param)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool checkVbkPopTx (const VbkPopTx &tx, ValidationState &state, const BtcChainParams &param, const VbkChainParams &vbk)
 Stateless validation for VbkPopTx.
 
bool checkVbkTx (const VbkTx &tx, const AltChainParams &params, const VbkChainParams &vbkparams, ValidationState &state)
 Stateless validation for VbkTx.
 
bool checkPublicationData (const PublicationData &pub, const AltChainParams &params, ValidationState &state)
 Stateless validation for PublicationData.
 
bool checkBlock (const BtcBlock &block, ValidationState &state, const BtcChainParams &params)
 Stateless validation for a single block.
 
bool checkVbkBlockPlausibility (const VbkBlock &block, ValidationState &state, const VbkChainParams &params)
 Optimization: VBK block is not plausible if its combination of height+time do not correspond to potential VBK network.
 
bool checkBlock (const VbkBlock &block, ValidationState &state, const VbkChainParams &params)
 Stateless validation for VbkBlock.
 
bool checkATV (const ATV &atv, ValidationState &state, const AltChainParams &alt, const VbkChainParams &vbkp)
 Stateless validation for ATV.
 
bool checkVTB (const VTB &vtb, ValidationState &state, const BtcChainParams &btc, const VbkChainParams &vbk)
 Stateless validation for VTB.
 
bool checkPopData (PopValidator &validator, const PopData &popData, ValidationState &state)
 Stateless validation for PopData and all internal PoP payloads.
 
bool DeserializeFromVbkEncoding (ReadStream &stream, StoredAltBlockAddon &out, ValidationState &state)
 
template<typename Block >
bool DeserializeFromVbkEncoding (ReadStream &stream, StoredBlockIndex< Block > &out, ValidationState &state, typename Block::hash_t precalculatedHash=typename Block::hash_t())
 
bool DeserializeFromVbkEncoding (ReadStream &stream, StoredBtcBlockAddon &out, ValidationState &state)
 
bool DeserializeFromVbkEncoding (ReadStream &stream, StoredVbkBlockAddon &out, ValidationState &state)
 
template<typename BlockTreeT >
bool loadTree (BlockTreeT &tree, const typename BlockTreeT::hash_t &tiphash, std::vector< typename BlockTreeT::stored_index_t > &blocks, bool fast_load, ValidationState &state)
 efficiently loads blocks into tree (they must be sorted by height) and does validation of these blocks. More...
 
void saveTrees (const AltBlockTree &tree, BlockBatch &batch)
 Save all (BTC/VBK/ALT) trees on disk in a single Batch.
 
bool loadTrees (AltBlockTree &tree, bool fast_load, ValidationState &state)
 Load all (ALT/VBK/BTC) trees from disk into memory.
 
std::vector< uint8_t > ParseHex (const char *psz)
 Parse bytes from hex.
 
std::vector< uint8_t > ParseHex (const std::string &hex)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
constexpr bool IsSpace (char c) noexcept
 Tests if the given character is a whitespace character. More...
 
template<typename T >
std::string HexStr (const T itbegin, const T itend)
 Convert bytes to hex. More...
 
template<typename T >
std::string HexStr (const T &vch, bool reverseHex=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void setMockTime (uint32_t mocktime)
 Set mock time for usage in unit tests. More...
 
uint32_t getMockTime ()
 Get current mock time.
 
uint32_t currentTimestamp4 ()
 Get current time as 4 bytes. If mock time is set, returns mock time.
 
template<typename JsonValue >
JsonValue ToJSON (const ValidationState &s, bool *acceptedToMempool=nullptr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Variables

constexpr const auto ADDRESS_POP_DATA_SIZE_PROGPOW = 15
 VTB contains BtcTx, which contains POP-miner's address and endorsed VBK header. More...
 
constexpr const auto SHA256_HASH_SIZE = 32
 sha256 hash size More...
 
constexpr const auto BTC_TX_MAX_RAW_SIZE = 4 * 1000 * 1000
 maximum possible BTC TX serialized size. More...
 
constexpr const uint32_t BTC_HEADER_SIZE = 80
 Bitcoin header size. More...
 
constexpr const auto MAX_BTC_BLOCKS_IN_VBKPOPTX = 65535
 maximum total BTC blocks in VTB blockOfProofContext More...
 
constexpr const auto BTC_BLOCK_HASH_SIZE = 32
 size of BTC block hash More...
 
constexpr const auto VBK_BLOCK_HASH_SIZE = 24
 size of VBK block hash More...
 
constexpr const auto VBK_MERKLE_ROOT_HASH_SIZE = 16
 size of VBK merkle root More...
 
constexpr const auto VBK_PREVIOUS_BLOCK_HASH_SIZE = 12
 size of VBK previous block hash size More...
 
constexpr const auto VBK_PREVIOUS_KEYSTONE_HASH_SIZE = 9
 size of VBK previous keystone hash size More...
 
constexpr const auto MAX_PAYOUT_INFO_SIZE = 10000
 max payout info size. More...
 
constexpr const auto MAX_HEADER_SIZE_PUBLICATION_DATA = 1024
 maximum header size in PublicationData More...
 
constexpr const auto MAX_CONTEXT_SIZE_PUBLICATION_DATA = 10000
 maximum context size in PublicationData More...
 
constexpr const auto MAX_PUBLICATIONDATA_SIZE
 absolute maximum size for PublicationData More...
 
constexpr const auto MAX_POPDATA_SIZE = 5500000
 maximum size of single PopData in a single ALT block, in bytes. More...
 
constexpr const auto MAX_POPDATA_VBK = 50000
 absolute maximum number of VBK blocks per ALT block More...
 
constexpr const auto MAX_POPDATA_VTB = 50000
 absolute maximum number of VTB blocks per ALT block More...
 
constexpr const auto MAX_POPDATA_ATV = 50000
 absolute maximum number of ATV blocks per ALT block More...
 
constexpr const auto MAX_PAYOUT = 50000
 absolute maximum number of pauouts per ALT block More...
 
constexpr const auto MIN_ALT_HASH_SIZE = 0
 minimum allowed size of altchain hash More...
 
constexpr const auto MAX_ALT_HASH_SIZE = 1024
 absolute maximum allowed size for altchain hash More...
 
constexpr const auto MAX_BTCADDON_REFS = 65536
 absolute maximum of 'refs' for BTC addon More...
 
constexpr const auto MAX_VBKPOPTX_PER_VBK_BLOCK = 1024
 absolute maximum number of PopTxes (VTBs) per VBK block More...
 
constexpr const auto VTB_ID_SIZE = 32
 size of VTB id More...
 
constexpr const auto ATV_ID_SIZE = 32
 size of ATV id More...
 
constexpr const auto VBK_ID_SIZE = 12
 size of VbkBlock id More...
 
constexpr const auto VBK_PUBLICATIONDATA_SIZE = 80
 65 VBK header + 15 POP bytes of Address More...
 
constexpr const uint32_t VBK_HEADER_SIZE_VBLAKE = 64
 pre-progpow VBK header size More...
 
constexpr const uint32_t VBK_HEADER_SIZE_PROGPOW = 65
 post-progpow VBK header size More...
 
constexpr const auto MAX_LAYER_COUNT_MERKLE = 40
 max total layers in merkle paths More...
 
constexpr const auto MAX_OUTPUTS_COUNT = 255
 NodeCore is using byte value when serializing outputs so we limit to 255. More...
 
constexpr const auto MAX_SIGNATURE_SIZE = 72
 ASN.1/DER ECDSA encoding max value. More...
 
constexpr const auto MAX_PUBLIC_KEY_SIZE = 88
 X509 encoding. Max value is based on experimental data. More...
 
constexpr const auto VBK_ADDRESS_SIZE = 30
 VBK address size in bytes. More...
 
constexpr const auto VBK_MAX_CALCULATED_EPOCHS_SIZE = 4096U
 maximum number of Ethash cache sizes stored in this library. More...
 
constexpr const auto VBK_ETHASH_EPOCH_LENGTH = 8000U
 size of 1 ethash epoch in progpow More...
 
constexpr const auto VBK_ETHASH_EPOCH_OFFSET = 323U
 we start at this epoch More...
 
static const int32_t ALT_MAX_REORG_BLOCKS_MIN_VALUE = 10000
 minimum number of blocks in ALT tree More...
 
static const int32_t VBK_MAX_REORG_BLOCKS_MIN_VALUE = 20000
 minimum number of blocks in VBK tree More...
 
static const int32_t BTC_MAX_REORG_BLOCKS_MIN_VALUE = 10000
 minimum number of blocks in BTC tree More...
 
template<>
 __pad0__
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<>
 __pad1__
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<>
 __pad2__
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Detailed Description

a facade for Signals

Contains veriblock-specific serialization and deserialziation primitives.

By default, logger is disabled (no-op logger is used). Users can derive from Logger class, and specify their logger instance.

Used log levels:

  • DEBUG - most noisy and verbose, debug level
  • INFO - default recommended level for logs
  • WARN - warning level
  • ERROR - validation error happened
  • CRITICAL - assert messages are logged here
  • OFF - disable logs

Class Documentation

◆ altintegration::MempoolResult

struct altintegration::MempoolResult

Definition at line 19 of file mempool_result.hpp.

+ Collaboration diagram for altintegration::MempoolResult:
Class Members
vector< pair< id_t, ValidationState > > atvs
vector< pair< id_t, ValidationState > > context
vector< pair< id_t, ValidationState > > vtbs

◆ altintegration::NetworkBytePair

struct altintegration::NetworkBytePair

Definition at line 53 of file network_byte_pair.hpp.

+ Collaboration diagram for altintegration::NetworkBytePair:
Class Members
VbkNetworkType networkType < works as std::optional. if hasNetworkByte is true, networkByte is set
uint8_t typeId

◆ altintegration::vblake_ctx

struct altintegration::vblake_ctx

Definition at line 18 of file vblake.hpp.

+ Collaboration diagram for altintegration::vblake_ctx:
Class Members
uint8_t b[64] input buffer
uint64_t h[8] chained state

Typedef Documentation

◆ BtcBlockTree

Definition at line 39 of file vbk_block_tree.hpp.

◆ uint128

Definition at line 22 of file uint.hpp.

◆ uint192

Definition at line 30 of file uint.hpp.

◆ uint256

Definition at line 24 of file uint.hpp.

◆ uint72

Definition at line 26 of file uint.hpp.

◆ uint96

Definition at line 28 of file uint.hpp.

Enumeration Type Documentation

◆ AddressType

enum class altintegration::AddressType
strong

Definition at line 18 of file address.hpp.

18 {
19 STANDARD = 1,
20 MULTISIG = 3,
21};

◆ BlockStateStatus

Enumerator
BLOCK_VALID_TREE 

acceptBlockHeader succeded.

All ancestors are at least at this state and statelessly valid.

BLOCK_CONNECTED 

the block is connected via connectBlock, which means that this block and all its ancestors are at least BLOCK_CONNECTED and have BLOCK_HAS_PAYLOADS set.

BLOCK_CAN_BE_APPLIED_MAYBE_WITH_OTHER_CHAIN 

the block has been successfully applied, but may not be fully valid, because it may connect to the "other" chain when two chains are applied together during POP FR.

All the ancestors are at least BLOCK_CAN_BE_APPLIED_MAYBE_WITH_OTHER_CHAIN.

BLOCK_CAN_BE_APPLIED 

the chain with the block at its tip is fully valid, so if we do SetState on this block, it is guaranteed to succeed.

All the ancestors are at least BLOCK_CAN_BE_APPLIED.

BLOCK_VALID_MASK 

all stateful validity levels

Definition at line 14 of file block_status.hpp.

14 : uint32_t {
31
36
37};
@ BLOCK_VALID_MASK
all stateful validity levels
@ BLOCK_VALID_TREE
acceptBlockHeader succeded.
@ BLOCK_CONNECTED
the block is connected via connectBlock, which means that this block and all its ancestors are at lea...
@ BLOCK_CAN_BE_APPLIED_MAYBE_WITH_OTHER_CHAIN
the block has been successfully applied, but may not be fully valid, because it may connect to the "o...
@ BLOCK_CAN_BE_APPLIED
the chain with the block at its tip is fully valid, so if we do SetState on this block,...

◆ BlockValidityStatus

Enumerator
BLOCK_VALID_UNKNOWN 

default state for validity - validity state is unknown

BLOCK_BOOTSTRAP 

this is a bootstrap block

BLOCK_FAILED_BLOCK 

block is statelessly valid, but the altchain marked it as failed

BLOCK_FAILED_POP 

block failed state{less,ful} validation due to its payloads

BLOCK_FAILED_CHILD 

block is state{lessly,fully} valid and the altchain did not report it as invalid, but some of the ancestor blocks are invalid

BLOCK_FAILED_MASK 

all invalidity flags

BLOCK_HAS_PAYLOADS 

acceptBlockHeader has been executed on this block;

BLOCK_ACTIVE 

the block is currently applied via SetState.

BLOCK_DELETED 

the block is temporarily deleted

Definition at line 40 of file block_status.hpp.

40 : uint32_t {
43
44 // all values from (0, 15] are reserved for BlockStateStatus
45
47 BLOCK_BOOTSTRAP = 1 << 4,
49 BLOCK_FAILED_BLOCK = 1 << 5,
51 BLOCK_FAILED_POP = 1 << 6,
54 BLOCK_FAILED_CHILD = 1 << 7,
59 BLOCK_HAS_PAYLOADS = 1 << 8,
61 BLOCK_ACTIVE = 1 << 9,
63 BLOCK_DELETED = 1 << 10
64
65};
@ BLOCK_FAILED_BLOCK
block is statelessly valid, but the altchain marked it as failed
@ BLOCK_VALID_UNKNOWN
default state for validity - validity state is unknown
@ BLOCK_FAILED_CHILD
block is state{lessly,fully} valid and the altchain did not report it as invalid, but some of the anc...
@ BLOCK_HAS_PAYLOADS
acceptBlockHeader has been executed on this block;
@ BLOCK_DELETED
the block is temporarily deleted
@ BLOCK_ACTIVE
the block is currently applied via SetState.
@ BLOCK_FAILED_MASK
all invalidity flags
@ BLOCK_FAILED_POP
block failed state{less,ful} validation due to its payloads
@ BLOCK_BOOTSTRAP
this is a bootstrap block

◆ LogLevel

enum class altintegration::LogLevel
strong

Definition at line 31 of file logger.hpp.

31{ debug, info, warn, error, critical, off };

◆ PopFrOutcome

enum class altintegration::PopFrOutcome
strong

Definition at line 457 of file fork_resolution.hpp.

457 {
458 UNKNOWN,
459 CANDIDATE_IS_TIP,
460 CANDIDATE_INVALID_CHAIN,
461 CANDIDATE_INVALID_PAYLOADS,
462 CANDIDATE_PART_OF_ACTIVE_CHAIN,
463 CANDIDATE_IS_TIP_SUCCESSOR,
464 TIP_IS_FINAL,
465 BOTH_DONT_CROSS_KEYSTONE_BOUNDARY,
466 CANDIDATE_INVALID_INDEPENDENTLY,
467 HIGHER_POP_SCORE,
468};

◆ TxType

enum class altintegration::TxType
strong
Enumerator
VBK_TX 

regular transaction

VBK_POP_TX 

pop transaction

Definition at line 26 of file consts.hpp.

26 {
28 VBK_TX = 0x01,
30 VBK_POP_TX = 0x02,
31};
@ VBK_POP_TX
pop transaction
@ VBK_TX
regular transaction

Function Documentation

◆ addBlocks()

template<typename Block , typename ChainParams >
bool altintegration::addBlocks ( BlockTree< Block, ChainParams > &  tree,
const std::vector< std::vector< uint8_t > > &  blocks,
ValidationState state 
)

Definition at line 77 of file alt-util.hpp.

79 {
80 for (const auto& b : blocks) {
81 Block block = Block::fromRaw(b);
82 if (!tree.acceptBlockHeader(block, state)) {
83 return false;
84 }
85 }
86
87 return true;
88}

◆ AssertDeserializeFromHex()

template<typename T >
T altintegration::AssertDeserializeFromHex ( std::string  hex)
Note
will fail on assert if can't be deserialized.

Definition at line 491 of file serde.hpp.

491 {
492 T t;
493 ValidationState state;
494 bool result = DeserializeFromHex(hex, t, state);
495 VBK_ASSERT_MSG(result, "Can't deserialize: %s", state.toString());
496 return t;
497}
Class that is used for storing validation state.
bool DeserializeFromHex(const std::string &hex, T &out, ValidationState &state)
Deserialize from HEX VBK encoding.
Definition: serde.hpp:420

◆ AssertDeserializeFromRaw()

template<typename T >
T altintegration::AssertDeserializeFromRaw ( std::vector< uint8_t >  raw)
Note
will fail on assert if can't be deserialized.

Definition at line 469 of file serde.hpp.

469 {
470 T t;
471 ValidationState state;
472 bool result = DeserializeFromRaw(raw, t, state);
473 VBK_ASSERT_MSG(result, "Can't deserialize: %s", state.toString());
474 return t;
475}
bool DeserializeFromRaw(ReadStream &stream, AltBlock &out, ValidationState &state, const AltBlock::hash_t &=AltBlock::hash_t{})
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ AssertDeserializeFromRawHex()

template<typename T >
T altintegration::AssertDeserializeFromRawHex ( std::string  hex)
Note
will fail on assert if can't be deserialized.

Definition at line 502 of file serde.hpp.

502 {
503 T t;
504 ValidationState state;
505 bool result = DeserializeFromRawHex(hex, t, state);
506 VBK_ASSERT_MSG(result, "Can`t deserialize: %s", state.toString());
507 return t;
508}
bool DeserializeFromRawHex(const std::string &hex, T &out, ValidationState &state)
Deserialize from HEX RAW encoding.
Definition: serde.hpp:430

◆ AssertDeserializeFromVbkEncoding()

template<typename T >
T altintegration::AssertDeserializeFromVbkEncoding ( Slice< const uint8_t >  raw)
Note
will fail on assert if can't be deserialized.

Definition at line 480 of file serde.hpp.

480 {
481 T t;
482 ValidationState state;
483 bool result = DeserializeFromVbkEncoding(raw, t, state);
484 VBK_ASSERT_MSG(result, "Can't deserialize: %s", state.toString());
485 return t;
486}
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ checkMerklePath()

template<typename MerklePathType , typename HashType1 , typename HashType2 >
bool altintegration::checkMerklePath ( const MerklePathType &  merklePath,
const HashType1 &  transactionHash,
const HashType2 &  merkleRoot,
ValidationState state 
)

Definition at line 31 of file stateless_validation.hpp.

34 {
35 if (merklePath.subject != transactionHash) {
36 return state.Invalid("invalid-merklepath",
37 "Transaction hash cannot be proven by merkle path");
38 }
39
40 auto root = merklePath.calculateMerkleRoot();
41 if (root != merkleRoot) {
42 return state.Invalid("invalid-merklepath",
43 "Wrong merkle root. Expected: " + merkleRoot.toHex() +
44 ", got: " + root.toHex());
45 }
46
47 return true;
48}

◆ checkRange()

bool altintegration::checkRange ( uint64_t  num,
uint64_t  min,
uint64_t  max,
ValidationState state 
)

If false, returns invalid state with error description.

Parameters
numnumber to check
minmin value
maxmax value
statewill return error description here
Returns
true if check is OK, false otherwise

◆ DeserializeFromHex()

template<typename T >
bool altintegration::DeserializeFromHex ( const std::string &  hex,
T &  out,
ValidationState state 
)

Definition at line 420 of file serde.hpp.

422 {
423 auto data = ParseHex(hex);
424 ReadStream stream(data);
425 return DeserializeFromVbkEncoding(stream, out, state);
426}
std::vector< uint8_t > ParseHex(const char *psz)
Parse bytes from hex.
Binary reading stream, that is useful during binary deserialization.
Definition: read_stream.hpp:22

◆ DeserializeFromRaw()

template<typename T >
bool altintegration::DeserializeFromRaw ( Slice< const uint8_t >  data,
T &  out,
ValidationState state 
)

Definition at line 411 of file serde.hpp.

413 {
414 ReadStream stream(data);
415 return DeserializeFromRaw(stream, out, state);
416}

◆ DeserializeFromRawHex()

template<typename T >
bool altintegration::DeserializeFromRawHex ( const std::string &  hex,
T &  out,
ValidationState state 
)

Definition at line 430 of file serde.hpp.

432 {
433 auto data = ParseHex(hex);
434 ReadStream stream(data);
435 return DeserializeFromRaw(stream, out, state);
436}

◆ DeserializeFromVbkEncoding() [1/4]

bool altintegration::DeserializeFromVbkEncoding ( ReadStream stream,
Address out,
ValidationState state 
)
Parameters
streamdata stream to read from
[out]outoutput address
[out]state
Returns
Address containing VBK address

◆ DeserializeFromVbkEncoding() [2/4]

template<typename T >
bool altintegration::DeserializeFromVbkEncoding ( ReadStream stream,
PopState< T > &  out,
ValidationState state 
)

Definition at line 104 of file pop_state.hpp.

106 {
107 std::vector<T> endorsements;
108 auto max = std::max(MAX_POPDATA_ATV, MAX_POPDATA_VTB);
109 if (!readArrayOf<T>(
110 stream,
111 endorsements,
112 state,
113 0,
114 max,
115 [](ReadStream& stream, T& t, ValidationState& state) -> bool {
116 return DeserializeFromVbkEncoding(stream, t, state);
117 })) {
118 return state.Invalid("popstate-bad-endorsement");
119 }
120
121 for (const auto& endorsement : endorsements) {
122 auto it = out._containingEndorsements.emplace(
123 endorsement.getId(), std::make_shared<T>(endorsement));
124 // newly created endorsement must not be null
125 VBK_ASSERT(it->second);
126 }
127 // do not restore 'endorsedBy' here, it will be done later during tree
128 // loading
129 return true;
130}
constexpr const auto MAX_POPDATA_ATV
absolute maximum number of ATV blocks per ALT block
Definition: consts.hpp:82
constexpr const auto MAX_POPDATA_VTB
absolute maximum number of VTB blocks per ALT block
Definition: consts.hpp:80

◆ DeserializeFromVbkEncoding() [3/4]

template<typename Block >
bool altintegration::DeserializeFromVbkEncoding ( ReadStream stream,
StoredBlockIndex< Block > &  out,
ValidationState state,
typename Block::hash_t  precalculatedHash = typename Block::hash_t() 
)

Definition at line 66 of file stored_block_index.hpp.

70 {
71 const auto& name = Block::name();
72 using height_t = typename Block::height_t;
73 if (!stream.readBE<height_t>(out.height, state)) {
74 return state.Invalid(name + "-stored-block-index-height");
75 }
76 Block block{};
77 if (!DeserializeFromRaw(stream, block, state, precalculatedHash)) {
78 return state.Invalid(name + "-stored-block-index-header");
79 }
80 out.header = std::make_shared<Block>(block);
81 if (!stream.readBE<uint32_t>(out.status, state)) {
82 return state.Invalid(name + "-stored-block-index-status");
83 }
84
85 if (!DeserializeFromVbkEncoding(stream, out.addon, state)) {
86 return state.Invalid(name + "-stored-block-index-addon");
87 }
88 return true;
89}
uint32_t status
contains status flags
std::shared_ptr< block_t > header
block header
height_t height
height of the entry in the chain

◆ DeserializeFromVbkEncoding() [4/4]

template<typename T >
bool altintegration::DeserializeFromVbkEncoding ( Slice< const uint8_t >  data,
T &  out,
ValidationState state 
)

Definition at line 402 of file serde.hpp.

404 {
405 ReadStream stream(data);
406 return DeserializeFromVbkEncoding(stream, out, state);
407}

◆ EncodeBase58()

template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
std::string altintegration::EncodeBase58 ( const T &  container)

Definition at line 23 of file base58.hpp.

23 {
24 const uint8_t *ptr = container.data();
25 return EncodeBase58(ptr, ptr + container.size());
26}
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
Encodes input bytes to Base58.

◆ EncodeBase59()

template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
std::string altintegration::EncodeBase59 ( const T &  container)

Definition at line 26 of file base59.hpp.

26 {
27 const uint8_t *ptr = container.data();
28 return EncodeBase59(ptr, ptr + container.size());
29}
std::string EncodeBase59(const unsigned char *pbegin, const unsigned char *pend)
Encode input bytes to base59.

◆ estimateArraySizeOf()

template<typename T >
size_t altintegration::estimateArraySizeOf ( const std::vector< T > &  t,
std::function< size_t(const T &t)>  f 
)

Definition at line 395 of file serde.hpp.

396 {
397 return estimateContainerSize<std::vector<T>>(t, f);
398}

◆ estimateNumberOfPopTxs()

uint32_t altintegration::estimateNumberOfPopTxs ( const std::vector< VbkMerklePath > &  paths)
inline

Definition at line 237 of file merkle_tree.hpp.

238 {
239 // validate that we have a continugous indexes set
240 std::set<int32_t> indexes;
241 int32_t maxIndex = -1;
242 for (const auto& path : paths) {
243 if (path.treeIndex == (int32_t)VbkMerkleTree::TreeIndex::POP &&
244 maxIndex < path.index) {
245 maxIndex = path.index;
246 }
247 }
248
249 // find the latest index and determine amount of the leaves
250 uint32_t aproximate_leaves_number = 0;
251 for (const auto& path : paths) {
252 if (path.treeIndex == (int32_t)VbkMerkleTree::TreeIndex::POP &&
253 maxIndex == path.index) {
254 if (path.layers.empty()) {
255 aproximate_leaves_number = 1;
256 break;
257 }
258 auto vec = path.equalLayerIndexes();
259 if (vec.empty()) {
260 aproximate_leaves_number = (1 << (path.layers.size() - 2));
261 break;
262 } else if (vec.front() == 0) {
263 aproximate_leaves_number = path.index + 1;
264 break;
265 } else {
266 aproximate_leaves_number = (1 << (path.layers.size() - 2));
267 for (const auto& i : vec) {
268 aproximate_leaves_number -= (1 << i);
269 }
270 break;
271 }
272 }
273 }
274
275 return aproximate_leaves_number;
276}

◆ findFork()

template<typename C >
C::index_t * altintegration::findFork ( const C &  chain,
const typename C::index_t *  pindex 
)
Returns
nullptr if fork can not be found

Definition at line 144 of file chain.hpp.

145 {
146 if (pindex == nullptr || chain.tip() == nullptr) {
147 return nullptr;
148 }
149
150 auto lastHeight = chain.chainHeight();
151 if (pindex->getHeight() > lastHeight) {
152 pindex = pindex->getAncestor(lastHeight);
153 }
154 while (pindex != nullptr && !chain.contains(pindex)) {
155 pindex = pindex->getPrev();
156 }
157 return const_cast<typename C::index_t*>(pindex);
158}

◆ findValidTips() [1/2]

template<typename Block >
std::vector< BlockIndex< Block > * > altintegration::findValidTips ( BlockIndex< Block > &  index)
Template Parameters
Block

Definition at line 79 of file tree_algo.hpp.

79 {
80 using index_t = BlockIndex<Block>;
81 std::vector<index_t*> ret{};
82 forEachNodePreorder<Block>(index, [&ret](index_t& next) -> bool {
83 if (!next.isValid()) {
84 // this is invalid subtree
85 return false;
86 }
87
88 // this is valid subtree
89 if (next.isValidTip()) {
90 ret.push_back(&next);
91 // do not continue, as there are no valid next blocks
92 return false;
93 }
94
95 return true;
96 });
97
98 return ret;
99}
A node in a block tree.
Definition: block_index.hpp:31

◆ findValidTips() [2/2]

template<typename Block >
std::vector< BlockIndex< Block > * > altintegration::findValidTips ( const std::unordered_set< BlockIndex< Block > * > &  tips,
BlockIndex< Block > &  index 
)
Template Parameters
Block

Definition at line 106 of file tree_algo.hpp.

108 {
109 using index_t = BlockIndex<Block>;
110 std::vector<index_t*> ret{};
111 for (auto* tip : tips) {
112 auto* ancestor = tip->getAncestor(index.getHeight());
113 if (ancestor == &index) {
114 ret.push_back(tip);
115 }
116 }
117
118 return ret;
119}
const BlockIndex * getAncestor(height_t _height) const

◆ fixedArray()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
std::vector< uint8_t > altintegration::fixedArray ( input)
Parameters
inputvalue to convert
Returns
converted byte array

Definition at line 58 of file serde.hpp.

58 {
59 WriteStream inputStream;
60 inputStream.writeBE(input);
61 return inputStream.data();
62}
Binary writer that is useful for binary serialization.

◆ forEachNextNodePreorder()

template<typename Block >
void altintegration::forEachNextNodePreorder ( BlockIndex< Block > &  index,
const std::function< bool(BlockIndex< Block > &)> &  shouldContinue 
)

Definition at line 63 of file tree_algo.hpp.

65 {
66 for (auto* pnext : index.pnext) {
67 VBK_ASSERT(pnext != nullptr);
68 if (shouldContinue(*pnext)) {
69 forEachNextNodePreorder(*pnext, shouldContinue);
70 }
71 }
72}
void forEachNextNodePreorder(BlockIndex< Block > &index, const std::function< bool(BlockIndex< Block > &)> &shouldContinue)
iterate across all subtrees starting (and excluding) given 'index'
Definition: tree_algo.hpp:63
std::set< BlockIndex * > pnext
(memory only) a set of pointers for forward iteration
Definition: block_index.hpp:42

◆ forEachNodePostorder()

template<typename Block >
void altintegration::forEachNodePostorder ( BlockIndex< Block > &  index,
const std::function< void(BlockIndex< Block > &)> &  visit,
const std::function< bool(BlockIndex< Block > &)> &  shouldVisit 
)

Definition at line 19 of file tree_algo.hpp.

22 {
23 using index_t = BlockIndex<Block>;
24 std::unordered_set<index_t*> set;
25 std::stack<index_t*> stack;
26 stack.push(&index);
27 while (!stack.empty()) {
28 auto* item = stack.top();
29 if (set.count(item) > 0) {
30 visit(*item);
31 stack.pop();
32 } else {
33 for (auto* next : item->pnext) {
34 if (shouldVisit(*next)) {
35 stack.push(next);
36 }
37 }
38 set.insert(item);
39 }
40 }
41}

◆ forEachNodePreorder()

template<typename Block >
void altintegration::forEachNodePreorder ( BlockIndex< Block > &  index,
const std::function< bool(BlockIndex< Block > &)> &  visit 
)

Definition at line 45 of file tree_algo.hpp.

46 {
47 if (!visit(index)) {
48 // we should not continue traversal of this subtree
49 return;
50 }
51
52 // because pnext can be modified while iterating, we make a copy and iterate
53 // over a copy
54 auto copy = index.pnext;
55 for (auto* pnext : copy) {
56 VBK_ASSERT(pnext != nullptr);
57 forEachNodePreorder(*pnext, visit);
58 }
59}

◆ format()

template<typename S , typename... Args>
std::string altintegration::format ( const S &  format_str,
Args &&...  args 
)
inline

Definition at line 128 of file logger.hpp.

128 {
129 try {
130 return fmt::format(format_str, (Args &&) args...);
131 } catch (const fmt::format_error&) {
132 VBK_LOG_WARN("invalid string formatting, str: %s", format_str);
133 }
134 return "";
135}

◆ GeneratePublicationData()

bool altintegration::GeneratePublicationData ( const std::vector< uint8_t > &  endorsedBlockHeader,
const std::vector< uint8_t > &  txMerkleRoot,
const PopData popData,
const std::vector< uint8_t > &  payoutInfo,
const AltBlockTree tree,
PublicationData out 
)
Parameters
[in]endorsedBlockHeaderendorsed block header
[in]txMerkleRootoriginal merkle root from altchain
[in]popDataPopData from endorsed block
[in]payoutInfopayout info bytes.
[in]treeAltBlockTree instance
[out]outoutput instance
Returns
true if endorsed block found, false otherwise.

◆ getContext()

template<typename BlockTreeT >
std::vector< typename BlockTreeT::block_t > altintegration::getContext ( const BlockTreeT &  tree,
typename BlockTreeT::hash_t  tip,
size_t  size = std::numeric_limits<size_t>::max() 
)

Definition at line 43 of file alt-util.hpp.

46 {
47 std::vector<typename BlockTreeT::block_t> ret;
48 auto* cursor = tree.getBlockIndex(tip);
49 size_t i = 0;
50 while (cursor != nullptr && i++ < size) {
51 ret.push_back(cursor->getHeader());
52 cursor = cursor->pprev;
53 }
54 return ret;
55}

◆ getForkBlock()

template<typename Block >
const BlockIndex< Block > * altintegration::getForkBlock ( const BlockIndex< Block > &  a,
const BlockIndex< Block > &  b 
)

Definition at line 428 of file block_index.hpp.

429 {
430 const auto initialHeight = std::min(a.getHeight(), b.getHeight());
431
432 for (auto cursorA = a.getAncestor(initialHeight),
433 cursorB = b.getAncestor(initialHeight);
434 cursorA != nullptr && cursorB != nullptr;
435 cursorA = cursorA->getPrev(), cursorB = cursorB->getPrev()) {
436 if (cursorA == cursorB) {
437 return cursorA;
438 }
439 }
440
441 // chain `b` is not connected to `a`
442 return nullptr;
443}

◆ getLastKnownBlocks()

template<typename BlockTree >
std::vector< std::vector< uint8_t > > altintegration::getLastKnownBlocks ( const BlockTree tree,
size_t  size 
)

Definition at line 59 of file alt-util.hpp.

60 {
61 std::vector<std::vector<uint8_t>> ret;
62 ret.reserve(size);
63
64 auto* tip = tree.getBestChain().tip();
65 for (size_t i = 0; i < size && tip != nullptr; i++) {
66 ret.push_back(tip->getHash().asVector());
67 tip = tip->pprev;
68 }
69
70 // reverse them since we add them in reverse order (tip -> genesis)
71 std::reverse(ret.begin(), ret.end());
72 return ret;
73}
const Chain< index_t > & getBestChain() const
Getter for currently Active Chain.

◆ GetLogger()

Logger & altintegration::GetLogger ( )
Warning
DO NOT USE LOGGER IN DESTRUCTORS.

◆ HexStr() [1/2]

template<typename T >
std::string altintegration::HexStr ( const T &  vch,
bool  reverseHex = false 
)
inline

Definition at line 60 of file strutil.hpp.

60 {
61 if (reverseHex) {
62 return HexStr(vch.rbegin(), vch.rend());
63 } else {
64 return HexStr(vch.begin(), vch.end());
65 }
66}
std::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
Definition: strutil.hpp:44

◆ HexStr() [2/2]

template<typename T >
std::string altintegration::HexStr ( const T  itbegin,
const T  itend 
)

Definition at line 44 of file strutil.hpp.

44 {
45 std::string rv;
46 // clang-format off
47 static const char hexmap[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
48 // clang-format on
49 rv.reserve(std::distance(itbegin, itend) * 2u);
50 for (T it = itbegin; it < itend; ++it) {
51 auto val = (uint8_t)(*it);
52 rv.push_back(hexmap[val >> 4u]);
53 rv.push_back(hexmap[val & 15u]);
54 }
55 return rv;
56}

◆ isBlockOutdated()

template<typename Block >
bool altintegration::isBlockOutdated ( const BlockIndex< Block > &  finalBlock,
const BlockIndex< Block > &  candidate 
)

Definition at line 448 of file block_index.hpp.

449 {
450 // finalBlock is ancestor of candidate
451 if (candidate.getAncestor(finalBlock.getHeight()) == &finalBlock) {
452 return false;
453 }
454
455 // all candidates behind final block are outdated
456 if (candidate.getHeight() < finalBlock.getHeight()) {
457 return true;
458 }
459
460 // all parallel blocks (on same height as final, but not final) are outdated
461 if (candidate.getHeight() == finalBlock.getHeight() &&
462 &finalBlock != &candidate) {
463 return true;
464 }
465
466 // candidate is ancestor of finalBlock and within window
467 if (finalBlock.getAncestor(candidate.getHeight()) == &candidate) {
468 return false;
469 }
470
471 // candidate is on a fork
472 auto* fork = getForkBlock(finalBlock, candidate);
473
474 // candidate does not connect to finalBlock
475 if (fork == nullptr) {
476 return true;
477 }
478
479 // if fork block is outdated, then candidate is also outdated
480 return isBlockOutdated(finalBlock, *fork);
481}
bool isBlockOutdated(const BlockIndex< Block > &finalBlock, const BlockIndex< Block > &candidate)
a candidate is considered outdated if it is behind finalBlock, or on same height and not equal to fin...
const BlockIndex< Block > * getForkBlock(const BlockIndex< Block > &a, const BlockIndex< Block > &b)
getForkBlock assumes that: the block tree is not malformed the fork block(worst case: genesis/bootstr...

◆ isKeystone()

bool altintegration::isKeystone ( int32_t  blockNumber,
uint32_t  keystoneInterval 
)
Parameters
blockNumberblopck height
keystoneIntervalkeystone interval
Returns
true if block is keystone

◆ isPopSubTreeFull()

bool altintegration::isPopSubTreeFull ( const std::vector< VbkMerklePath > &  paths)
inline

Definition at line 278 of file merkle_tree.hpp.

278 {
279 return (uint32_t)paths.size() == estimateNumberOfPopTxs(paths);
280}

◆ IsSpace()

constexpr bool altintegration::IsSpace ( char  c)
inlineconstexprnoexcept

The whitespace characters are: space, form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').

This function is locale independent. Under the C locale this function gives the same result as std::isspace.

Parameters
[in]ccharacter to test
Returns
true if the argument is a whitespace character; otherwise false

Definition at line 37 of file strutil.hpp.

37 {
38 return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' ||
39 c == '\v';
40}

◆ isValidInvalidationReason()

constexpr bool altintegration::isValidInvalidationReason ( const BlockValidityStatus reason)
constexpr

Definition at line 71 of file block_status.hpp.

71 {
72 return reason == BLOCK_FAILED_BLOCK || reason == BLOCK_FAILED_POP;
73}

◆ kiss99()

uint32_t altintegration::kiss99 ( kiss99_t &  st)

◆ loadTree()

template<typename BlockTreeT >
bool altintegration::loadTree ( BlockTreeT &  tree,
const typename BlockTreeT::hash_t &  tiphash,
std::vector< typename BlockTreeT::stored_index_t > &  blocks,
bool  fast_load,
ValidationState state 
)

Sets tip after loading.

Invariant
NOT atomic

Definition at line 23 of file util.hpp.

27 {
28 using stored_index_t = typename BlockTreeT::stored_index_t;
29
30 if (blocks.size() == 0) return true;
31
32 VBK_LOG_INFO("Loading %d %s blocks with tip %s",
33 blocks.size(),
34 BlockTreeT::block_t::name(),
35 HexStr(tiphash));
36 VBK_ASSERT(tree.isBootstrapped() && "tree must be bootstrapped");
37
38 // first, sort them by height
39 std::sort(blocks.begin(),
40 blocks.end(),
41 [](const stored_index_t& a, const stored_index_t& b) {
42 return a.height < b.height;
43 });
44
45 for (const auto& block : blocks) {
46 // load blocks one by one
47 if (!tree.loadBlockForward(block, fast_load, state)) {
48 return state.Invalid("load-tree");
49 }
50 }
51
52 if (!tree.loadTip(tiphash, state)) {
53 return state.Invalid("load-tree");
54 }
55
56 auto* t = tree.getBestChain().tip();
57 VBK_ASSERT(t != nullptr);
58
59 return true;
60}

◆ min_or_default()

template<typename T , typename Container >
const T altintegration::min_or_default ( Container &  c,
const T  default_ 
)

Definition at line 152 of file algorithm.hpp.

152 {
153 const auto it = std::min_element(c.begin(), c.end());
154 return it == c.end() ? default_ : *it;
155}

◆ PrintTo()

void altintegration::PrintTo ( const ArithUint256 uint,
::std::ostream *  os 
)
inline

Definition at line 297 of file arith_uint256.hpp.

297 {
298 *os << uint.toHex();
299}

◆ progPowHash()

uint192 altintegration::progPowHash ( Slice< const uint8_t >  header)
Parameters
header65-bytes header
Returns
24-byte hash

◆ readArrayOf() [1/2]

template<typename T >
bool altintegration::readArrayOf ( ReadStream stream,
std::vector< T > &  out,
ValidationState state,
size_t  min,
size_t  max,
std::function< bool(ReadStream &, T &, ValidationState &)>  readFunc 
)
Template Parameters
Ttype of entity to read
Parameters
streamread data from this stream
outout output array of T
statewill return error description here
minmin size of array
maxmax size of array
readFuncfunction that is called to read single value of type T
Returns
true if read is OK, false otherwise

Definition at line 319 of file serde.hpp.

325 {
326 int32_t count = 0;
327 if (!readSingleBEValue<int32_t>(stream, count, state)) {
328 return state.Invalid("readarray-bad-count");
329 }
330 if (!checkRange(count, min, max, state)) {
331 return state.Invalid("readarray-bad-range");
332 }
333
334 out.reserve(count);
335
336 for (size_t i = 0; i < (size_t)count; i++) {
337 T item;
338 if (!readFunc(stream, item, state)) {
339 return state.Invalid("readarray-bad-item", i);
340 }
341 out.push_back(item);
342 }
343
344 return true;
345}

◆ readArrayOf() [2/2]

template<typename T >
bool altintegration::readArrayOf ( ReadStream stream,
std::vector< T > &  out,
ValidationState state,
std::function< bool(ReadStream &, T &, ValidationState &)>  readFunc 
)
Template Parameters
Ttype of entity to read
Parameters
[in]streamread data from this stream
[out]outoutput array of T
[in]readFuncfunction that is called to read single value of type T
[out]statevalidation state.
Exceptions
std::out_of_rangeif stream is out of data
Returns
vector of read elements of type T

Definition at line 358 of file serde.hpp.

362 {
363 int32_t max = std::numeric_limits<int32_t>::max();
364 return readArrayOf<T>(stream, out, state, 0, max, readFunc);
365}

◆ readNetworkByte() [1/2]

NetworkBytePair altintegration::readNetworkByte ( ReadStream stream,
TxType  type 
)
Parameters
streamread data from this stream
typeuse this value to detect if we are reading network byte or type byte
Exceptions
std::out_of_rangeif stream is out of data
Returns
NetworkBytePair structure

◆ readNetworkByte() [2/2]

bool altintegration::readNetworkByte ( ReadStream stream,
TxType  type,
NetworkBytePair out,
ValidationState state 
)
Parameters
streamread data from this stream
typeuse this value to detect if we are reading network byte or type byte
outNetworkBytePair structure
statewill return error description here
Returns
true if read is OK, false otherwise

◆ readSetOf() [1/2]

template<typename Container >
bool altintegration::readSetOf ( ReadStream stream,
Container &  out,
ValidationState state,
size_t  min,
size_t  max,
std::function< bool(ReadStream &, typename Container::value_type &, ValidationState &)>  readFunc 
)
Template Parameters
Ttype of entity to read
Parameters
streamread data from this stream
outoutput set
statewill return error description here
minmin size of array
maxmax size of array
readFuncfunction that is called to read single value
Returns
true if read is OK, false otherwise

Definition at line 256 of file serde.hpp.

263 {
264 int32_t count = 0;
265 if (!readSingleBEValue<int32_t>(stream, count, state)) {
266 return state.Invalid("readarray-bad-count");
267 }
268 if (!checkRange(count, min, max, state)) {
269 return state.Invalid("readarray-bad-range");
270 }
271
272 for (size_t i = 0; i < (size_t)count; i++) {
273 typename Container::value_type item;
274 if (!readFunc(stream, item, state)) {
275 return state.Invalid("readarray-bad-item", i);
276 }
277 if (out.insert(item).second == false) {
278 return state.Invalid("readarray-duplicate-item", i);
279 }
280 }
281
282 return true;
283}

◆ readSetOf() [2/2]

template<typename Container >
bool altintegration::readSetOf ( ReadStream stream,
Container &  out,
ValidationState state,
std::function< bool(Container &, ReadStream &, typename Container::value_type &, ValidationState &)>  readFunc 
)
Template Parameters
Ttype of entity to read
Parameters
[in]streamread data from this stream
[out]outoutput container
[in]readFuncfunction that is called to read single value
[out]statevalidation state
Exceptions
std::out_of_rangeif stream is out of data
Returns
vector of read elements

Definition at line 296 of file serde.hpp.

302 {
303 int32_t max = std::numeric_limits<int32_t>::max();
304 return readContainer(stream, out, state, 0, max, readFunc);
305}

◆ readSingleBEValue()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
bool altintegration::readSingleBEValue ( ReadStream stream,
T &  out,
ValidationState state 
)

This function interprets sizeof(T) bytes as Big-Endian number and returns it.

Template Parameters
Tnumber type - uint64_t, etc.
Parameters
streamread data from this stream
outread number
statewill return error description here
Returns
true if read is OK, false otherwise

Definition at line 130 of file serde.hpp.

130 {
132 if (!readSingleByteLenValue(stream, data, state, 0, sizeof(T))) {
133 return state.Invalid("readsinglebe-bad-data");
134 }
135 ReadStream dataStream(data);
136 return dataStream.readBE<T>(out, state, data.size());
137}
bool readSingleByteLenValue(ReadStream &stream, Slice< const uint8_t > &out, ValidationState &state, uint64_t minLen, uint64_t maxLen)
Read variable length value, which consists of [N=(1 byte = size of slice) | N bytes slice] Size of sl...
Non-owning contiguous array.
Definition: slice.hpp:22

◆ readSingleByteLenValue() [1/2]

template<typename Container , typename = typename std::enable_if< sizeof(typename Container::value_type) == 1>::type>
bool altintegration::readSingleByteLenValue ( ReadStream stream,
Container &  out,
ValidationState state,
uint64_t  minLen,
uint64_t  maxLen 
)

Definition at line 102 of file serde.hpp.

106 {
107 uint8_t length = 0;
108 if (!stream.readBE<uint8_t>(length, state)) {
109 return state.Invalid("readsingle-bad-length");
110 }
111 if (!checkRange(length, minLen, maxLen, state)) {
112 return state.Invalid("readsingle-bad-range");
113 }
114 out.resize(length);
115 return stream.read(length, out.data(), state);
116}
bool read(size_t size, uint8_t *out, ValidationState &state)
Read type T of 'size' bytes.

◆ readSingleByteLenValue() [2/2]

bool altintegration::readSingleByteLenValue ( ReadStream stream,
Slice< const uint8_t > &  out,
ValidationState state,
uint64_t  minLen,
uint64_t  maxLen 
)
Parameters
streamread data from this stream
outslice with data
statewill return error description here
minLenminimum possible value of slice size
maxLenmaximum possible value of slice size
Returns
true if read is OK, false otherwise

◆ readVarLenValue()

bool altintegration::readVarLenValue ( ReadStream stream,
Slice< const uint8_t > &  out,
ValidationState state,
uint64_t  minLen,
uint64_t  maxLen 
)
Parameters
streamread data from this stream
outslice with data
statewill return error description here
minLenminimum possible value of slice size
maxLenmaximum possible value of slice size
Returns
true if read is OK, false otherwise

◆ reverse_iterate()

template<typename T >
reverse_range< T > altintegration::reverse_iterate ( T &  x)

Definition at line 29 of file reversed_range.hpp.

29 {
30 return reverse_range<T>(x);
31}
translates a pair of forward iterators to a range whose regular iteration order is "backward"

◆ SerializeToHex()

template<typename T >
std::string altintegration::SerializeToHex ( const T &  obj)

Definition at line 456 of file serde.hpp.

456 {
457 return HexStr(SerializeToVbkEncoding<T>(obj));
458}

◆ SerializeToRaw()

template<typename T >
std::vector< uint8_t > altintegration::SerializeToRaw ( const T &  obj)

Definition at line 448 of file serde.hpp.

448 {
449 WriteStream w;
450 obj.toRaw(w);
451 return w.data();
452}

◆ SerializeToRawHex()

template<typename T >
std::string altintegration::SerializeToRawHex ( const T &  obj)

Definition at line 462 of file serde.hpp.

462 {
463 return HexStr(SerializeToRaw<T>(obj));
464}

◆ SerializeToVbkEncoding()

template<typename T >
std::vector< uint8_t > altintegration::SerializeToVbkEncoding ( const T &  obj)

Definition at line 440 of file serde.hpp.

440 {
441 WriteStream w;
442 obj.toVbkEncoding(w);
443 return w.data();
444}

◆ SetLogger()

template<typename L >
void altintegration::SetLogger ( LogLevel  log_lvl = LogLevel::info)

Definition at line 64 of file logger.hpp.

64 {
65 SetLogger(std::unique_ptr<L>(new L()), log_lvl);
66}
void SetLogger(std::unique_ptr< Logger > lgr, LogLevel log_lvl=LogLevel::info)
setter for global logger instance

◆ setMockTime()

void altintegration::setMockTime ( uint32_t  mocktime)

0 disables mock time.

Parameters
mocktime

◆ sha256()

uint256 altintegration::sha256 ( Slice< const uint8_t >  data)
Parameters
dataread data from this array
Returns
vector with SHA256 hash of the input data

◆ sha256twice()

uint256 altintegration::sha256twice ( Slice< const uint8_t >  data)
Parameters
dataread data from this array
Returns
vector with SHA256 hash of the input data

◆ StringToLevel()

LogLevel altintegration::StringToLevel ( const std::string &  )
Exceptions
std::invalid_argument

◆ ToJSON() [1/25]

template<typename Value >
Value altintegration::ToJSON ( const Address addr)
inline

Definition at line 100 of file address.hpp.

100 {
101 return ToJSON<Value>(addr.toString());
102}
std::string toString() const noexcept
Convert VBK address to text representation.

◆ ToJSON() [2/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const AltBlock alt,
bool  reverseHashes = true 
)

Definition at line 90 of file altblock.hpp.

90 {
91 JsonValue object = json::makeEmptyObject<JsonValue>();
92 json::putStringKV(object, "hash", HexStr(alt.getHash(), reverseHashes));
93 json::putStringKV(
94 object, "previousBlock", HexStr(alt.previousBlock, reverseHashes));
95 json::putIntKV(object, "timestamp", alt.getBlockTime());
96 json::putIntKV(object, "height", alt.height);
97 return object;
98}
const hash_t & getHash() const

◆ ToJSON() [3/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const AltChainParams p,
bool  reverseAltHashes = true 
)

Definition at line 312 of file alt_chain_params.hpp.

312 {
313 auto obj = json::makeEmptyObject<JsonValue>();
314 json::putIntKV(obj, "networkId", p.getIdentifier());
315 json::putArrayKV(
316 obj, "forkResolutionLookupTable", p.getForkResolutionLookUpTable());
317 json::putIntKV(obj, "maxVbkBlocksInAltBlock", p.getMaxVbkBlocksInAltBlock());
318 json::putIntKV(obj, "maxVTBsInAltBlock", p.getMaxVTBsInAltBlock());
319 json::putIntKV(obj, "maxATVsInAltBlock", p.getMaxATVsInAltBlock());
320 json::putIntKV(obj, "maxReorgBlocks", p.getMaxReorgBlocks());
321 json::putIntKV(obj,
322 "endorsementSettlementInterval",
324 json::putIntKV(obj, "finalityDelay", p.getFinalityDelay());
325 json::putIntKV(obj, "keystoneInterval", p.getKeystoneInterval());
326 json::putIntKV(
327 obj, "maxAltchainFutureBlockTime", p.maxAltchainFutureBlockTime());
328 json::putKV(obj, "payoutParams", ToJSON<JsonValue>(p.getPayoutParams()));
329 json::putKV(obj,
330 "bootstrapBlock",
331 ToJSON<JsonValue>(p.getBootstrapBlock(), reverseAltHashes));
332 return obj;
333}
const std::vector< uint32_t > & getForkResolutionLookUpTable() const noexcept
pop score lookup table for fork resolution
uint32_t getKeystoneInterval() const noexcept
number of blocks in single keystone interval.
uint32_t maxAltchainFutureBlockTime() const noexcept
Maximum future block time for altchain blocks.
size_t getMaxVTBsInAltBlock() const noexcept
total maximum number of VTBs per 1 ALT block
size_t getMaxATVsInAltBlock() const noexcept
total maximum number of ATVs per 1 ALT block
virtual AltBlock getBootstrapBlock() const noexcept=0
"genesis" block for POP mining.
const PopPayoutsParams & getPayoutParams() const noexcept
getter for reward parameters
uint32_t getFinalityDelay() const noexcept
number of blocks in VBK used for finalization
virtual int64_t getIdentifier() const noexcept=0
unique POP ID for the chain; identifies altchain in VBK
size_t getMaxVbkBlocksInAltBlock() const noexcept
total maximum number of VBK blocks per 1 ALT block
int32_t getMaxReorgBlocks() const noexcept
Max number of blocks that can be reorganized in altchain.
uint32_t getEndorsementSettlementInterval() const noexcept
Validity window for ATVs.

◆ ToJSON() [4/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const ATV atv)

Definition at line 103 of file atv.hpp.

103 {
104 JsonValue obj = json::makeEmptyObject<JsonValue>();
105 json::putIntKV(obj, "version", atv.version);
106 json::putKV(obj, "transaction", ToJSON<JsonValue>(atv.transaction));
107 json::putKV(obj, "merklePath", ToJSON<JsonValue>(atv.merklePath));
108 json::putKV(obj, "blockOfProof", ToJSON<JsonValue>(atv.blockOfProof));
109
110 // return this entity in VBK-serialized form for easy consumption.
111 // DO NOT REMOVE these fields - otherwise Stratum compat will break.
112 json::putStringKV(obj, "id", atv.getId().toHex());
113 json::putStringKV(obj, "serialized", SerializeToHex(atv));
114 return obj;
115}
std::string SerializeToHex(const T &obj)
Serialize to HEX VBK encoding.
Definition: serde.hpp:456
uint32_t version
ATV serialization version.
Definition: atv.hpp:40
id_t getId() const
Calculate a ATV id that is the sha256 hash of the ATV rawBytes.
VbkTx transaction
endorsing transaction.
Definition: atv.hpp:43
VbkMerklePath merklePath
merkle path that proves that endorsing transaction is in blockOfProof.
Definition: atv.hpp:46
VbkBlock blockOfProof
VBK block which contains endorsing transaction.
Definition: atv.hpp:49

◆ ToJSON() [5/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const AuthenticatedContextInfoContainer a)

Definition at line 117 of file context_info_container.hpp.

117 {
118 auto o = json::makeEmptyObject<JsonValue>();
119
120 WriteStream w;
121 a.toVbkEncoding(w);
122
123 json::putStringKV(o, "serialized", HexStr(w.data()));
124 json::putStringKV(o, "stateRoot", HexStr(a.stateRoot));
125 json::putKV(o, "context", ToJSON<JsonValue>(a.ctx));
126 return o;
127}

◆ ToJSON() [6/25]

template<typename Value , size_t N>
Value altintegration::ToJSON ( const Blob< N > &  blob)
inline

Definition at line 249 of file blob.hpp.

249 {
250 return ToJSON<Value>(blob.toHex());
251}

◆ ToJSON() [7/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const BlockIndex< BtcBlock > &  i)

Definition at line 272 of file vbk_block_tree.hpp.

272 {
273 auto obj = json::makeEmptyObject<JsonValue>();
274 json::putStringKV(obj, "chainWork", i.chainWork.toHex());
275 json::putIntKV(obj, "height", i.getHeight());
276 json::putKV(obj, "header", ToJSON<JsonValue>(i.getHeader()));
277 json::putIntKV(obj, "status", i.getStatus());
278 json::putArrayKV(obj, "vbkrefs", i.getRefs());
279
280 auto bopEndorsements = json::makeEmptyArray<JsonValue>();
281 for (const auto* e : i.getBlockOfProofEndorsement()) {
282 if (e == nullptr) {
283 continue;
284 }
285 json::arrayPushBack(bopEndorsements, ToJSON<JsonValue>(e->getId()));
286 }
287 json::putKV(obj, "blockOfProofEndorsements", bopEndorsements);
288
289 return obj;
290}

◆ ToJSON() [8/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const BlockIndex< VbkBlock > &  i)

Definition at line 234 of file vbk_block_tree.hpp.

234 {
235 auto obj = json::makeEmptyObject<JsonValue>();
236 json::putStringKV(obj, "chainWork", i.chainWork.toHex());
237
238 std::vector<uint256> endorsements;
239 for (const auto& e : i.getContainingEndorsements()) {
240 endorsements.push_back(e.first);
241 }
242 json::putArrayKV(obj, "containingEndorsements", endorsements);
243
244 std::vector<uint256> endorsedBy;
245 for (const auto* e : i.getEndorsedBy()) {
246 endorsedBy.push_back(e->id);
247 }
248 json::putArrayKV(obj, "endorsedBy", endorsedBy);
249 json::putIntKV(obj, "height", i.getHeight());
250 json::putKV(obj, "header", ToJSON<JsonValue>(i.getHeader()));
251 json::putIntKV(obj, "status", i.getStatus());
252 json::putIntKV(obj, "altrefs", i.refCount());
253
254 auto stored = json::makeEmptyObject<JsonValue>();
255 json::putArrayKV(stored, "vtbids", i.getPayloadIds<VTB>());
256 json::putKV(obj, "stored", stored);
257
258 auto bopEndorsements = json::makeEmptyArray<JsonValue>();
259 for (const auto* e : i.getBlockOfProofEndorsement()) {
260 if (e == nullptr) {
261 continue;
262 }
263 json::arrayPushBack(bopEndorsements, ToJSON<JsonValue>(e->getId()));
264 }
265 json::putKV(obj, "blockOfProofEndorsements", bopEndorsements);
266
267 return obj;
268}

◆ ToJSON() [9/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const BtcBlock b)

Definition at line 141 of file btcblock.hpp.

141 {
142 JsonValue object = json::makeEmptyObject<JsonValue>();
143 json::putStringKV(object, "hash", HexStr(b.getHash()));
144 json::putIntKV(object, "version", b.getVersion());
145 json::putStringKV(object, "previousBlock", HexStr(b.getPreviousBlock()));
146 json::putStringKV(object, "merkleRoot", HexStr(b.getMerkleRoot()));
147 json::putIntKV(object, "timestamp", b.getTimestamp());
148 json::putIntKV(object, "bits", b.getDifficulty());
149 json::putIntKV(object, "nonce", b.getNonce());
150 return object;
151}
const hash_t & getHash() const
Calculate the hash of the btc block.

◆ ToJSON() [10/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const ContextInfoContainer a)

Definition at line 105 of file context_info_container.hpp.

105 {
106 auto o = json::makeEmptyObject<JsonValue>();
107 json::putIntKV(o, "height", a.height);
108 json::putStringKV(
109 o, "firstPreviousKeystone", HexStr(a.keystones.firstPreviousKeystone));
110 json::putStringKV(
111 o, "secondPreviousKeystone", HexStr(a.keystones.secondPreviousKeystone));
112 return o;
113}
KeystoneContainer keystones
endorsed block previous keystones

◆ ToJSON() [11/25]

template<typename Value , class A , class B , class C >
Value altintegration::ToJSON ( const Endorsement< A, B, C > &  e)

Definition at line 115 of file endorsement.hpp.

115 {
116 auto obj = json::makeEmptyObject<Value>();
117 json::putStringKV(obj, "id", HexStr(e.id));
118 json::putStringKV(obj, "endorsedHash", HexStr(e.endorsedHash));
119 json::putStringKV(obj, "containingHash", e.containingHash);
120 json::putStringKV(obj, "blockOfProof", e.blockOfProof);
121 return obj;
122}

◆ ToJSON() [12/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const KeystoneContainer c)

Definition at line 56 of file keystone_container.hpp.

56 {
57 auto obj = json::makeEmptyObject<JsonValue>();
58 json::putStringKV(
59 obj, "firstPreviousKeystone", HexStr(c.firstPreviousKeystone));
60 json::putStringKV(
61 obj, "secondPreviousKeystone", HexStr(c.secondPreviousKeystone));
62 return obj;
63}

◆ ToJSON() [13/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const MempoolResult r)

Definition at line 51 of file mempool_result.hpp.

51 {
52 auto obj = json::makeEmptyObject<JsonValue>();
53 detail::putArrayOfPairs(obj, "vbkblocks", r.context);
54 detail::putArrayOfPairs(obj, "vtbs", r.vtbs);
55 detail::putArrayOfPairs(obj, "atvs", r.atvs);
56 return obj;
57}

◆ ToJSON() [14/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const MerklePath m)

Definition at line 59 of file merkle_path.hpp.

59 {
60 JsonValue obj = json::makeEmptyObject<JsonValue>();
61 json::putIntKV(obj, "index", m.index);
62 json::putStringKV(obj, "subject", HexStr(m.subject));
63 json::putArrayKV(obj, "layers", m.layers);
64 return obj;
65}

◆ ToJSON() [15/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const Output o)

Definition at line 56 of file output.hpp.

56 {
57 JsonValue obj = json::makeEmptyObject<JsonValue>();
58 json::putStringKV(obj, "address", o.address.toString());
59 json::putIntKV(obj, "coin", o.coin.units);
60 return obj;
61}

◆ ToJSON() [16/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const PopData p,
bool  verbose = false 
)

Definition at line 112 of file popdata.hpp.

112 {
113 JsonValue obj = json::makeEmptyObject<JsonValue>();
114 json::putIntKV(obj, "version", p.version);
115 if (verbose) {
116 detail::putArrayKV(obj, "vbkblocks", p.context);
117 detail::putArrayKV(obj, "vtbs", p.vtbs);
118 detail::putArrayKV(obj, "atvs", p.atvs);
119 } else {
120 detail::putArrayOfIds(obj, "vbkblocks", p.context);
121 detail::putArrayOfIds(obj, "vtbs", p.vtbs);
122 detail::putArrayOfIds(obj, "atvs", p.atvs);
123 }
124
125 return obj;
126}

◆ ToJSON() [17/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const PopPayoutsParams p)

Definition at line 110 of file alt_chain_params.hpp.

110 {
111 auto obj = json::makeEmptyObject<JsonValue>();
112 json::putArrayKV(obj, "lookupTable", p.relativeScoreLookupTable());
113 json::putArrayKV(obj, "roundRatios", p.roundRatios());
114 json::putIntKV(
115 obj, "difficultyAveragingInterval", p.difficultyAveragingInterval());
116 json::putDoubleKV(
117 obj, "maxScoreThresholdKeystone", p.maxScoreThresholdKeystone());
118 json::putDoubleKV(
119 obj, "maxScoreThresholdNormal", p.maxScoreThresholdNormal());
120 json::putBoolKV(obj, "useFlatScoreRound", p.useFlatScoreRound());
121 json::putIntKV(obj, "flatScoreRound", p.flatScoreRound());
122 json::putIntKV(obj, "payoutRounds", p.payoutRounds());
123 json::putIntKV(obj, "keystoneRound", p.keystoneRound());
124 json::putDoubleKV(obj, "slopeKeystone", p.slopeKeystone());
125 json::putDoubleKV(obj, "slopeNormal", p.slopeNormal());
126 json::putDoubleKV(obj, "startOfSlope", p.startOfSlope());
127 json::putIntKV(obj, "popPayoutDelay", p.getPopPayoutDelay());
128 return obj;
129}
double maxScoreThresholdKeystone() const noexcept
limit block with keystones score to this value
uint32_t payoutRounds() const noexcept
total number of payout rounds.
bool useFlatScoreRound() const noexcept
should we use flat rewards at all
int32_t getPopPayoutDelay() const noexcept
number of blocks in ALT between endorsed block and payout block
uint32_t flatScoreRound() const noexcept
we use this round number to pay flat reward (does not depend on pop difficulty)
double slopeKeystone() const noexcept
slope for keystone rounds
const std::vector< double > & roundRatios() const noexcept
we have these payout modifiers for different rounds.
const std::vector< double > & relativeScoreLookupTable() const noexcept
reward score table we score each VeriBlock and lower the reward for late blocks
double startOfSlope() const noexcept
we start decreasing rewards after this score
uint32_t difficultyAveragingInterval() const noexcept
collect this amount of blocks BEFORE the block to calculate pop difficulty
uint32_t keystoneRound() const noexcept
among all rounds, this number represents round for keystone blocks.
double slopeNormal() const noexcept
we decrease reward coefficient for this value for each additional score point above startOfDecreasing...
double maxScoreThresholdNormal() const noexcept
limit block score to this value

◆ ToJSON() [18/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const PublicationData p)

Definition at line 54 of file publication_data.hpp.

54 {
55 JsonValue obj = json::makeEmptyObject<JsonValue>();
56 json::putIntKV(obj, "identifier", p.identifier);
57 json::putStringKV(obj, "header", HexStr(p.header));
58 json::putStringKV(obj, "payoutInfo", HexStr(p.payoutInfo));
59 json::putStringKV(obj, "contextInfo", HexStr(p.contextInfo));
60 return obj;
61}
std::vector< uint8_t > payoutInfo
bitcoin script or POP payout address
int64_t identifier
altchain network POP ID
std::vector< uint8_t > contextInfo
serialized AuthenticatedContextInfoContainer
std::vector< uint8_t > header
altchain block header

◆ ToJSON() [19/25]

template<typename Value , typename T >
Value altintegration::ToJSON ( const T &  )
Template Parameters
ValueJSON Value type, which represents a "union" of JSON types.
TEntity type to encode.
Returns
JSON Value.

Definition at line 20 of file json.hpp.

20 {
21 static_assert(sizeof(T) == 0, "Undefined function for this type");
22}

◆ ToJSON() [20/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const ValidationState s,
bool *  acceptedToMempool = nullptr 
)

Definition at line 82 of file validation_state.hpp.

82 {
83 auto obj = json::makeEmptyObject<JsonValue>();
84
85 if (acceptedToMempool != nullptr) {
86 json::putBoolKV(obj, "accepted", *acceptedToMempool);
87 }
88
89 if (s.IsValid()) {
90 json::putStringKV(obj, "state", "valid");
91 return obj;
92 } else if (s.IsInvalid()) {
93 json::putStringKV(obj, "state", "invalid");
94 }
95
96 json::putStringKV(obj, "code", s.GetPath());
97 json::putStringKV(obj, "message", s.GetDebugMessage());
98
99 return obj;
100}

◆ ToJSON() [21/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const VbkBlock b)

Definition at line 170 of file vbkblock.hpp.

170 {
171 JsonValue obj = json::makeEmptyObject<JsonValue>();
172 json::putStringKV(obj, "hash", HexStr(b.getHash()));
173 json::putIntKV(obj, "height", b.getHeight());
174 json::putIntKV(obj, "version", b.getVersion());
175 json::putStringKV(obj, "previousBlock", HexStr(b.getPreviousBlock()));
176 json::putStringKV(obj, "previousKeystone", HexStr(b.getPreviousKeystone()));
177 json::putStringKV(
178 obj, "secondPreviousKeystone", HexStr(b.getSecondPreviousKeystone()));
179 json::putStringKV(obj, "merkleRoot", HexStr(b.getMerkleRoot()));
180 json::putIntKV(obj, "timestamp", b.getTimestamp());
181 json::putIntKV(obj, "difficulty", b.getDifficulty());
182 json::putIntKV(obj, "nonce", b.getNonce());
183
184 // return this entity in VBK-serialized form for easy consumption.
185 // DO NOT REMOVE these fields - otherwise Stratum compat will break.
186 json::putStringKV(obj, "id", HexStr(b.getId()));
187 json::putStringKV(obj, "serialized", SerializeToHex(b));
188 return obj;
189}
const hash_t & getHash() const
Get current block hash.

◆ ToJSON() [22/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const VbkMerklePath mp)

Definition at line 62 of file vbk_merkle_path.hpp.

62 {
63 JsonValue obj = json::makeEmptyObject<JsonValue>();
64 json::putIntKV(obj, "treeIndex", mp.treeIndex);
65 json::putIntKV(obj, "index", mp.index);
66 json::putStringKV(obj, "subject", mp.subject.toHex());
67 json::putArrayKV(obj, "layers", mp.layers);
68 return obj;
69}
int32_t treeIndex
an indentifier of which transactions tree (pop=0, normal=1)
std::vector< uint256 > layers
the layers in the merkle path
int32_t index
the index of the bottom data TxID in the block it came from
uint256 subject
TxID that this merkle path authenticates.

◆ ToJSON() [23/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const VbkPopTx tx)

Definition at line 90 of file vbkpoptx.hpp.

90 {
91 JsonValue obj = json::makeEmptyObject<JsonValue>();
92 tx.networkOrType.networkType.template putJson<JsonValue>(obj);
93 json::putStringKV(obj, "hash", tx.getHash().toHex());
94 json::putIntKV(obj, "type", tx.networkOrType.typeId);
95 json::putStringKV(obj, "address", tx.address.toString());
96 json::putKV(obj, "publishedBlock", ToJSON<JsonValue>(tx.publishedBlock));
97 json::putStringKV(
98 obj, "bitcoinTransaction", SerializeToRawHex(tx.bitcoinTransaction));
99 json::putKV(obj, "merklePath", ToJSON<JsonValue>(tx.merklePath));
100 json::putKV(obj, "blockOfProof", ToJSON<JsonValue>(tx.blockOfProof));
101 json::putArrayKV(obj, "blockOfProofContext", tx.blockOfProofContext);
102 json::putStringKV(obj, "signature", HexStr(tx.signature));
103 json::putStringKV(obj, "publicKey", HexStr(tx.publicKey));
104 return obj;
105}
std::string SerializeToRawHex(const T &obj)
Serialize to HEX RAW encoding.
Definition: serde.hpp:462
VbkNetworkType networkType
< works as std::optional. if hasNetworkByte is true, networkByte is set
hash_t getHash() const
Calculate the hash of the vbk pop transaction.

◆ ToJSON() [24/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const VbkTx tx)

Definition at line 95 of file vbktx.hpp.

95 {
96 JsonValue obj = json::makeEmptyObject<JsonValue>();
97 tx.networkOrType.networkType.template putJson<JsonValue>(obj);
98 json::putStringKV(obj, "hash", tx.getHash().toHex());
99 json::putIntKV(obj, "type", tx.networkOrType.typeId);
100 json::putStringKV(obj, "sourceAddress", tx.sourceAddress.toString());
101 json::putIntKV(obj, "sourceAmount", tx.sourceAmount.units);
102 json::putArrayKV(obj, "outputs", tx.outputs);
103 json::putIntKV(obj, "signatureIndex", tx.signatureIndex);
104 json::putKV(obj, "publicationData", ToJSON<JsonValue>(tx.publicationData));
105 json::putStringKV(obj, "signature", HexStr(tx.signature));
106 json::putStringKV(obj, "publicKey", HexStr(tx.publicKey));
107 return obj;
108}
uint256 getHash() const
Calculate the hash of the VBK transaction.

◆ ToJSON() [25/25]

template<typename JsonValue >
JsonValue altintegration::ToJSON ( const VTB v)

Definition at line 96 of file vtb.hpp.

96 {
97 JsonValue obj = json::makeEmptyObject<JsonValue>();
98 json::putIntKV(obj, "version", v.version);
99 json::putKV(obj, "transaction", ToJSON<JsonValue>(v.transaction));
100 json::putKV(obj, "merklePath", ToJSON<JsonValue>(v.merklePath));
101 json::putKV(obj, "containingBlock", ToJSON<JsonValue>(v.containingBlock));
102
103 // return this entity in VBK-serialized form for easy consumption.
104 // DO NOT REMOVE these fields - otherwise Stratum compat will break.
105 json::putStringKV(obj, "id", v.getId().toHex());
106 json::putStringKV(obj, "serialized", SerializeToHex(v));
107 return obj;
108}
id_t getId() const
Calculate a VTB id that is the sha256 hash of the VTB rawBytes.

◆ trimmedArray()

std::vector< uint8_t > altintegration::trimmedArray ( int64_t  input)
Parameters
inputvalue to convert
Returns
converted and trimmed byte array

◆ vblake() [1/2]

uint192 altintegration::vblake ( Slice< const uint8_t >  data)
Parameters
dataread data from this array
Returns
vector with VBlake hash of the input data

◆ vblake() [2/2]

int altintegration::vblake ( void *  out,
const void *  in,
size_t  inlen 
)
Parameters
[out]outoutput hash - 24 bytes
[in]ininput data
[in]inlenlength of input data, not more than 64 bytes
Returns
0 if succeeded, -1 if inlen is more than 64 bytes

◆ vblake_final()

void altintegration::vblake_final ( vblake_ctx ctx,
void *  out 
)
Parameters
ctxinitialized context.
outresulting hash is written here. Should be 24 bytes.

◆ vblake_init()

void altintegration::vblake_init ( vblake_ctx ctx)
Parameters
ctxcontext to initialize.

◆ vblake_update()

int altintegration::vblake_update ( vblake_ctx ctx,
const void *  in,
size_t  inlen 
)
Parameters
ctxinitialized context.
ininput buffer.
inlensize of input buffer. At most 64 bytes.
Returns
0 if succeeded, -1 if input buffer is more than 64 bytes.

◆ writeNetworkByte()

void altintegration::writeNetworkByte ( WriteStream stream,
NetworkBytePair  networkOrType 
)
Parameters
streamwrite data to this stream
networkOrTypewrite network byte if available, write type byte after

◆ writeSingleBEValue()

void altintegration::writeSingleBEValue ( WriteStream stream,
int64_t  value 
)

This function converts number to the bytes array in Big-Endian order, trims it and writes to the stream

Parameters
streamwrite data to this stream
valuevalue to be written
Exceptions
std::out_of_rangeif stream is out of data

◆ writeSingleByteLenValue()

void altintegration::writeSingleByteLenValue ( WriteStream stream,
Slice< const uint8_t >  value 
)
Parameters
streamwrite data to this stream
valuedata that should be written
Exceptions
std::out_of_rangeif value size is too high

◆ writeSingleFixedBEValue()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void altintegration::writeSingleFixedBEValue ( WriteStream stream,
value 
)

This function converts number to the bytes array in Big-Endian order and writes to the stream

Parameters
streamwrite data to this stream
valuevalue to be written
Exceptions
std::out_of_rangeif stream is out of data

Definition at line 169 of file serde.hpp.

169 {
170 WriteStream dataStream;
171 dataStream.writeBE<T>(value);
172 writeSingleByteLenValue(stream, dataStream.data());
173}
void writeSingleByteLenValue(WriteStream &stream, Slice< const uint8_t > value)
Write single byte length value, which consists of N bytes vector Appends 1 byte data length to the st...

◆ writeVarLenValue()

void altintegration::writeVarLenValue ( WriteStream stream,
Slice< const uint8_t >  value 
)
Parameters
streamwrite data to this stream
valuedata that should be written

Variable Documentation

◆ __pad0__

template<>
altintegration::__pad0__

Definition at line 452 of file mempool.hpp.

◆ __pad1__

template<>
altintegration::__pad1__

Definition at line 452 of file mempool.hpp.

◆ __pad2__

template<>
altintegration::__pad2__

Definition at line 452 of file mempool.hpp.

◆ ADDRESS_POP_DATA_SIZE_PROGPOW

constexpr const auto altintegration::ADDRESS_POP_DATA_SIZE_PROGPOW = 15
constexpr

Total size of this container is 80 bytes. 65 of which are VbkBlock (post-progpow), and 15 are address.

Definition at line 36 of file consts.hpp.

◆ ALT_MAX_REORG_BLOCKS_MIN_VALUE

const int32_t altintegration::ALT_MAX_REORG_BLOCKS_MIN_VALUE = 10000
static

Definition at line 128 of file consts.hpp.

◆ ATV_ID_SIZE

constexpr const auto altintegration::ATV_ID_SIZE = 32
constexpr

Definition at line 96 of file consts.hpp.

◆ BTC_BLOCK_HASH_SIZE

constexpr const auto altintegration::BTC_BLOCK_HASH_SIZE = 32
constexpr

Definition at line 53 of file consts.hpp.

◆ BTC_HEADER_SIZE

constexpr const uint32_t altintegration::BTC_HEADER_SIZE = 80
constexpr

Definition at line 45 of file consts.hpp.

◆ BTC_MAX_REORG_BLOCKS_MIN_VALUE

const int32_t altintegration::BTC_MAX_REORG_BLOCKS_MIN_VALUE = 10000
static

Definition at line 132 of file consts.hpp.

◆ BTC_TX_MAX_RAW_SIZE

constexpr const auto altintegration::BTC_TX_MAX_RAW_SIZE = 4 * 1000 * 1000
constexpr

Definition at line 42 of file consts.hpp.

◆ MAX_ALT_HASH_SIZE

constexpr const auto altintegration::MAX_ALT_HASH_SIZE = 1024
constexpr

Definition at line 88 of file consts.hpp.

◆ MAX_BTC_BLOCKS_IN_VBKPOPTX

constexpr const auto altintegration::MAX_BTC_BLOCKS_IN_VBKPOPTX = 65535
constexpr

Definition at line 51 of file consts.hpp.

◆ MAX_BTCADDON_REFS

constexpr const auto altintegration::MAX_BTCADDON_REFS = 65536
constexpr

Definition at line 90 of file consts.hpp.

◆ MAX_CONTEXT_SIZE_PUBLICATION_DATA

constexpr const auto altintegration::MAX_CONTEXT_SIZE_PUBLICATION_DATA = 10000
constexpr

Definition at line 69 of file consts.hpp.

◆ MAX_HEADER_SIZE_PUBLICATION_DATA

constexpr const auto altintegration::MAX_HEADER_SIZE_PUBLICATION_DATA = 1024
constexpr

Definition at line 67 of file consts.hpp.

◆ MAX_LAYER_COUNT_MERKLE

constexpr const auto altintegration::MAX_LAYER_COUNT_MERKLE = 40
constexpr

Definition at line 106 of file consts.hpp.

◆ MAX_OUTPUTS_COUNT

constexpr const auto altintegration::MAX_OUTPUTS_COUNT = 255
constexpr

Definition at line 108 of file consts.hpp.

◆ MAX_PAYOUT

constexpr const auto altintegration::MAX_PAYOUT = 50000
constexpr

Definition at line 84 of file consts.hpp.

◆ MAX_PAYOUT_INFO_SIZE

constexpr const auto altintegration::MAX_PAYOUT_INFO_SIZE = 10000
constexpr
See also
https://bitcoin.stackexchange.com/a/35881/85437

Definition at line 65 of file consts.hpp.

◆ MAX_POPDATA_ATV

constexpr const auto altintegration::MAX_POPDATA_ATV = 50000
constexpr

Definition at line 82 of file consts.hpp.

◆ MAX_POPDATA_SIZE

constexpr const auto altintegration::MAX_POPDATA_SIZE = 5500000
constexpr

VTB can have a size up to 5.3 MB, so this number must be at least 5.3MB

Definition at line 76 of file consts.hpp.

◆ MAX_POPDATA_VBK

constexpr const auto altintegration::MAX_POPDATA_VBK = 50000
constexpr

Definition at line 78 of file consts.hpp.

◆ MAX_POPDATA_VTB

constexpr const auto altintegration::MAX_POPDATA_VTB = 50000
constexpr

Definition at line 80 of file consts.hpp.

◆ MAX_PUBLIC_KEY_SIZE

constexpr const auto altintegration::MAX_PUBLIC_KEY_SIZE = 88
constexpr

Definition at line 112 of file consts.hpp.

◆ MAX_PUBLICATIONDATA_SIZE

constexpr const auto altintegration::MAX_PUBLICATIONDATA_SIZE
constexpr
Initial value:
=
1 + sizeof(int64_t) + 1 + MAX_HEADER_SIZE_PUBLICATION_DATA + 1 +
constexpr const auto MAX_CONTEXT_SIZE_PUBLICATION_DATA
maximum context size in PublicationData
Definition: consts.hpp:69
constexpr const auto MAX_HEADER_SIZE_PUBLICATION_DATA
maximum header size in PublicationData
Definition: consts.hpp:67
constexpr const auto MAX_PAYOUT_INFO_SIZE
max payout info size.
Definition: consts.hpp:65

Definition at line 71 of file consts.hpp.

◆ MAX_SIGNATURE_SIZE

constexpr const auto altintegration::MAX_SIGNATURE_SIZE = 72
constexpr

Definition at line 110 of file consts.hpp.

◆ MAX_VBKPOPTX_PER_VBK_BLOCK

constexpr const auto altintegration::MAX_VBKPOPTX_PER_VBK_BLOCK = 1024
constexpr

Definition at line 92 of file consts.hpp.

◆ MIN_ALT_HASH_SIZE

constexpr const auto altintegration::MIN_ALT_HASH_SIZE = 0
constexpr

Definition at line 86 of file consts.hpp.

◆ SHA256_HASH_SIZE

constexpr const auto altintegration::SHA256_HASH_SIZE = 32
constexpr

Definition at line 39 of file consts.hpp.

◆ VBK_ADDRESS_SIZE

constexpr const auto altintegration::VBK_ADDRESS_SIZE = 30
constexpr

Definition at line 114 of file consts.hpp.

◆ VBK_BLOCK_HASH_SIZE

constexpr const auto altintegration::VBK_BLOCK_HASH_SIZE = 24
constexpr

Definition at line 55 of file consts.hpp.

◆ VBK_ETHASH_EPOCH_LENGTH

constexpr const auto altintegration::VBK_ETHASH_EPOCH_LENGTH = 8000U
constexpr

Definition at line 119 of file consts.hpp.

◆ VBK_ETHASH_EPOCH_OFFSET

constexpr const auto altintegration::VBK_ETHASH_EPOCH_OFFSET = 323U
constexpr

Definition at line 121 of file consts.hpp.

◆ VBK_HEADER_SIZE_PROGPOW

constexpr const uint32_t altintegration::VBK_HEADER_SIZE_PROGPOW = 65
constexpr

Definition at line 104 of file consts.hpp.

◆ VBK_HEADER_SIZE_VBLAKE

constexpr const uint32_t altintegration::VBK_HEADER_SIZE_VBLAKE = 64
constexpr

Definition at line 102 of file consts.hpp.

◆ VBK_ID_SIZE

constexpr const auto altintegration::VBK_ID_SIZE = 12
constexpr

Definition at line 98 of file consts.hpp.

◆ VBK_MAX_CALCULATED_EPOCHS_SIZE

constexpr const auto altintegration::VBK_MAX_CALCULATED_EPOCHS_SIZE = 4096U
constexpr

Definition at line 117 of file consts.hpp.

◆ VBK_MAX_REORG_BLOCKS_MIN_VALUE

const int32_t altintegration::VBK_MAX_REORG_BLOCKS_MIN_VALUE = 20000
static

Definition at line 130 of file consts.hpp.

◆ VBK_MERKLE_ROOT_HASH_SIZE

constexpr const auto altintegration::VBK_MERKLE_ROOT_HASH_SIZE = 16
constexpr

Definition at line 57 of file consts.hpp.

◆ VBK_PREVIOUS_BLOCK_HASH_SIZE

constexpr const auto altintegration::VBK_PREVIOUS_BLOCK_HASH_SIZE = 12
constexpr

Definition at line 59 of file consts.hpp.

◆ VBK_PREVIOUS_KEYSTONE_HASH_SIZE

constexpr const auto altintegration::VBK_PREVIOUS_KEYSTONE_HASH_SIZE = 9
constexpr

Definition at line 61 of file consts.hpp.

◆ VBK_PUBLICATIONDATA_SIZE

constexpr const auto altintegration::VBK_PUBLICATIONDATA_SIZE = 80
constexpr

Definition at line 100 of file consts.hpp.

◆ VTB_ID_SIZE

constexpr const auto altintegration::VTB_ID_SIZE = 32
constexpr

Definition at line 94 of file consts.hpp.