CatapultServer  v0.5.0.1 (Elephant)
BlockScorer.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/types.h"
24 #include <boost/multiprecision/cpp_int.hpp>
25 #include <functional>
26 
27 namespace catapult { namespace model { struct Block; } }
28 
29 namespace catapult { namespace chain {
30 
31  using BlockTarget = boost::multiprecision::uint256_t;
32 
34  uint64_t CalculateHit(const GenerationHash& generationHash);
35 
37  uint64_t CalculateScore(const model::Block& parentBlock, const model::Block& currentBlock);
38 
42  const utils::TimeSpan& timeSpan,
43  Difficulty difficulty,
44  Importance signerImportance,
45  const model::BlockChainConfiguration& config);
46 
50  const model::Block& parentBlock,
51  const model::Block& currentBlock,
52  Importance signerImportance,
53  const model::BlockChainConfiguration& config);
54 
56  struct BlockHitContext {
57  public:
59  BlockHitContext() : ElapsedTime(utils::TimeSpan::FromSeconds(0))
60  {}
61 
62  public:
65 
68 
71 
74 
77  };
78 
81  private:
82  using ImportanceLookupFunc = std::function<Importance (const Key&, Height)>;
83 
84  public:
87  BlockHitPredicate(const model::BlockChainConfiguration& config, const ImportanceLookupFunc& importanceLookup);
88 
89  public:
91  bool operator()(const model::Block& parentBlock, const model::Block& block, const GenerationHash& generationHash) const;
92 
94  bool operator()(const BlockHitContext& context) const;
95 
96  private:
99  };
100 }}
Block.h
catapult::chain::CalculateTarget
BlockTarget CalculateTarget(const utils::TimeSpan &timeSpan, Difficulty difficulty, Importance signerImportance, const model::BlockChainConfiguration &config)
Definition: BlockScorer.cpp:123
ImportanceHeight.h
catapult::chain::BlockHitPredicate
Predicate used to determine if a block is a hit or not.
Definition: BlockScorer.h:80
catapult::model::BlockChainConfiguration
Block chain configuration settings.
Definition: BlockChainConfiguration.h:33
catapult::chain::BlockHitPredicate::m_importanceLookup
ImportanceLookupFunc m_importanceLookup
Definition: BlockScorer.h:98
BlockChainConfiguration.h
catapult::model::BlockChainConfiguration::BlockTimeSmoothingFactor
uint32_t BlockTimeSmoothingFactor
Definition: BlockChainConfiguration.h:57
catapult::chain::BlockHitContext::Height
catapult::Height Height
Block height.
Definition: BlockScorer.h:76
catapult::chain::BlockHitPredicate::m_config
model::BlockChainConfiguration m_config
Definition: BlockScorer.h:97
catapult::utils::Log2TimesPowerOfTwo
uint64_t Log2TimesPowerOfTwo(uint64_t value, uint64_t n)
Calculates log2(value^(2^n)).
Definition: IntegerMath.cpp:48
catapult::model::BlockHeader::Difficulty
catapult::Difficulty Difficulty
Difficulty of a block.
Definition: Block.h:47
catapult::utils::TimeSpan::FromDifference
static constexpr TimeSpan FromDifference(Timestamp end, Timestamp start)
Creates a time span from the difference between start and end.
Definition: TimeSpan.h:64
NumLeadingZeros
uint32_t NumLeadingZeros
Definition: BlockScorer.cpp:33
catapult::chain::BlockHitContext::GenerationHash
catapult::GenerationHash GenerationHash
Generation hash.
Definition: BlockScorer.h:64
catapult::chain::BlockHitContext::ElapsedTime
utils::TimeSpan ElapsedTime
Time since the last block.
Definition: BlockScorer.h:67
catapult::utils::TimeSpan
Represents a time duration.
Definition: TimeSpan.h:30
IntegerMath.h
catapult::utils::BasicBaseValue::unwrap
constexpr ValueType unwrap() const
Unwraps this value and returns the underlying raw value.
Definition: BaseValue.h:53
Value
uint32_t Value
Definition: BlockScorer.cpp:32
catapult::chain::BlockHitPredicate::BlockHitPredicate
BlockHitPredicate(const model::BlockChainConfiguration &config, const ImportanceLookupFunc &importanceLookup)
Definition: BlockScorer.cpp:149
catapult::utils::BaseValue< uint64_t, Importance_tag >
catapult::chain::BlockHitContext::Difficulty
catapult::Difficulty Difficulty
Block difficulty.
Definition: BlockScorer.h:73
catapult::chain::CalculateHit
uint64_t CalculateHit(const GenerationHash &generationHash)
Calculates the hit for a generationHash.
Definition: BlockScorer.cpp:73
catapult::utils::TimeSpan::seconds
constexpr uint64_t seconds() const
Returns the number of seconds.
Definition: TimeSpan.h:86
catapult::model::BlockChainConfiguration::BlockGenerationTargetTime
utils::TimeSpan BlockGenerationTargetTime
Targeted time between blocks.
Definition: BlockChainConfiguration.h:51
catapult::chain::CalculateScore
uint64_t CalculateScore(const model::Block &parentBlock, const model::Block &currentBlock)
Calculates the score of currentBlock with parent parentBlock.
Definition: BlockScorer.cpp:99
catapult::chain::BlockHitPredicate::operator()
bool operator()(const model::Block &parentBlock, const model::Block &block, const GenerationHash &generationHash) const
Determines if the block is a hit given its parent (parentBlock) and generation hash (generationHash).
Definition: BlockScorer.cpp:154
catapult::chain::BlockTarget
boost::multiprecision::uint256_t BlockTarget
Definition: BlockScorer.h:31
BlockScorer.h
catapult::chain::BlockHitPredicate::ImportanceLookupFunc
std::function< Importance(const Key &, Height)> ImportanceLookupFunc
Definition: BlockScorer.h:82
catapult::model::AccountRestrictionType::Block
Account restriction is interpreted as blocking operation.
catapult::chain::BlockHitContext::BlockHitContext
BlockHitContext()
Creates a block hit context.
Definition: BlockScorer.h:59
catapult::model::Block
Binary layout for a block.
Definition: Block.h:69
BSWAP
#define BSWAP(VAL)
Definition: BlockScorer.cpp:52
catapult::model::BlockHeader::Timestamp
catapult::Timestamp Timestamp
Timestamp of a block.
Definition: Block.h:44
types.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::GenerationHash
utils::ByteArray< Hash256_Size, GenerationHash_tag > GenerationHash
Definition: src/catapult/types.h:53
catapult::utils::ClampedBaseValue
Base values that are constrained to a range of values.
Definition: ClampedBaseValue.h:27
catapult::utils::Log2
constexpr T Log2(T value)
Calculates log2(value).
Definition: IntegerMath.h:46
catapult::Hash256_Size
constexpr size_t Hash256_Size
Definition: src/catapult/types.h:34
catapult::utils::ByteArray
Base class for wrappers of byte array types, to provide some type-safety.
Definition: ByteArray.h:29
catapult::chain::BlockHitContext::Signer
Key Signer
Public key of the block signer.
Definition: BlockScorer.h:70
catapult::chain::BlockHitContext
Contextual information for calculating a block hit.
Definition: BlockScorer.h:56