PIVX Core  5.6.99
P2P Digital Currency
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CDeterministicMNList Class Reference

#include <deterministicmns.h>

Collaboration diagram for CDeterministicMNList:
[legend]

Public Types

typedef immer::map< uint256, CDeterministicMNCPtrMnMap
 
typedef immer::map< uint64_t, uint256MnInternalIdMap
 
typedef immer::map< uint256, std::pair< uint256, uint32_t > > MnUniquePropertyMap
 

Public Member Functions

 CDeterministicMNList ()
 
 CDeterministicMNList (const uint256 &_blockHash, int _height, uint32_t _totalRegisteredCount)
 
template<typename Stream >
void Serialize (Stream &s) const
 
template<typename Stream >
void Unserialize (Stream &s)
 
size_t GetAllMNsCount () const
 
size_t GetValidMNsCount () const
 
template<typename Callback >
void ForEachMN (bool onlyValid, Callback &&cb) const
 
const uint256GetBlockHash () const
 
int GetHeight () const
 
uint32_t GetTotalRegisteredCount () const
 
void SetHeight (int _height)
 
void SetBlockHash (const uint256 &_blockHash)
 
bool HasMN (const uint256 &proTxHash) const
 
bool HasMNByCollateral (const COutPoint &collateralOutpoint) const
 
bool HasValidMNByCollateral (const COutPoint &collateralOutpoint) const
 
CDeterministicMNCPtr GetMN (const uint256 &proTxHash) const
 
CDeterministicMNCPtr GetValidMN (const uint256 &proTxHash) const
 
CDeterministicMNCPtr GetMNByOperatorKey (const CBLSPublicKey &pubKey)
 
CDeterministicMNCPtr GetMNByCollateral (const COutPoint &collateralOutpoint) const
 
CDeterministicMNCPtr GetValidMNByCollateral (const COutPoint &collateralOutpoint) const
 
CDeterministicMNCPtr GetMNByService (const CService &service) const
 
CDeterministicMNCPtr GetMNByInternalId (uint64_t internalId) const
 
CDeterministicMNCPtr GetMNPayee () const
 
std::vector< CDeterministicMNCPtrGetProjectedMNPayees (unsigned int nCount) const
 Calculates the projected MN payees for the next count blocks. More...
 
std::vector< CDeterministicMNCPtrCalculateQuorum (size_t maxSize, const uint256 &modifier) const
 Calculate a quorum based on the modifier. More...
 
std::vector< std::pair< arith_uint256, CDeterministicMNCPtr > > CalculateScores (const uint256 &modifier) const
 
int CalcMaxPoSePenalty () const
 Calculates the maximum penalty which is allowed at the height of this MN list. More...
 
int CalcPenalty (int percent) const
 Returns a the given percentage from the max penalty for this MN list. More...
 
void PoSePunish (const uint256 &proTxHash, int penalty, bool debugLogs)
 Punishes a MN for misbehavior. More...
 
void PoSeDecrease (const uint256 &proTxHash)
 Decrease penalty score of MN by 1. More...
 
CDeterministicMNListDiff BuildDiff (const CDeterministicMNList &to) const
 
CDeterministicMNList ApplyDiff (const CBlockIndex *pindex, const CDeterministicMNListDiff &diff) const
 
void AddMN (const CDeterministicMNCPtr &dmn, bool fBumpTotalCount=true)
 
void UpdateMN (const CDeterministicMNCPtr &oldDmn, const CDeterministicMNStateCPtr &pdmnState)
 
void UpdateMN (const uint256 &proTxHash, const CDeterministicMNStateCPtr &pdmnState)
 
void UpdateMN (const CDeterministicMNCPtr &oldDmn, const CDeterministicMNStateDiff &stateDiff)
 
void RemoveMN (const uint256 &proTxHash)
 
template<typename T >
bool HasUniqueProperty (const T &v) const
 
template<typename T >
CDeterministicMNCPtr GetUniquePropertyMN (const T &v) const
 

Private Member Functions

template<typename T >
void AddUniqueProperty (const CDeterministicMNCPtr &dmn, const T &v)
 
template<typename T >
void DeleteUniqueProperty (const CDeterministicMNCPtr &dmn, const T &oldValue)
 
template<typename T >
void UpdateUniqueProperty (const CDeterministicMNCPtr &dmn, const T &oldValue, const T &newValue)
 

Private Attributes

uint256 blockHash
 
int nHeight {-1}
 
uint32_t nTotalRegisteredCount {0}
 
MnMap mnMap
 
MnInternalIdMap mnInternalIdMap
 
MnUniquePropertyMap mnUniquePropertyMap
 

Detailed Description

Definition at line 265 of file deterministicmns.h.

Member Typedef Documentation

◆ MnInternalIdMap

typedef immer::map<uint64_t, uint256> CDeterministicMNList::MnInternalIdMap

Definition at line 269 of file deterministicmns.h.

◆ MnMap

Definition at line 268 of file deterministicmns.h.

◆ MnUniquePropertyMap

typedef immer::map<uint256, std::pair<uint256, uint32_t> > CDeterministicMNList::MnUniquePropertyMap

Definition at line 270 of file deterministicmns.h.

Constructor & Destructor Documentation

◆ CDeterministicMNList() [1/2]

CDeterministicMNList::CDeterministicMNList ( )
inline

Definition at line 284 of file deterministicmns.h.

◆ CDeterministicMNList() [2/2]

CDeterministicMNList::CDeterministicMNList ( const uint256 _blockHash,
int  _height,
uint32_t  _totalRegisteredCount 
)
inlineexplicit

Definition at line 285 of file deterministicmns.h.

Member Function Documentation

◆ AddMN()

void CDeterministicMNList::AddMN ( const CDeterministicMNCPtr dmn,
bool  fBumpTotalCount = true 
)

Definition at line 377 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddUniqueProperty()

template<typename T >
void CDeterministicMNList::AddUniqueProperty ( const CDeterministicMNCPtr dmn,
const T v 
)
inlineprivate

Definition at line 451 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyDiff()

CDeterministicMNList CDeterministicMNList::ApplyDiff ( const CBlockIndex pindex,
const CDeterministicMNListDiff diff 
) const

Definition at line 353 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ BuildDiff()

CDeterministicMNListDiff CDeterministicMNList::BuildDiff ( const CDeterministicMNList to) const

Definition at line 322 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalcMaxPoSePenalty()

int CDeterministicMNList::CalcMaxPoSePenalty ( ) const

Calculates the maximum penalty which is allowed at the height of this MN list.

It is dynamic and might change for every block.

Returns

Definition at line 265 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalcPenalty()

int CDeterministicMNList::CalcPenalty ( int  percent) const

Returns a the given percentage from the max penalty for this MN list.

Always use this method to calculate the value later passed to PoSePunish. The percentage should be high enough to take per-block penalty decreasing for MNs into account. This means, if you want to accept 2 failures per payment cycle, you should choose a percentage that is higher then 50%, e.g. 66%.

Parameters
percent
Returns

Definition at line 273 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateQuorum()

std::vector< CDeterministicMNCPtr > CDeterministicMNList::CalculateQuorum ( size_t  maxSize,
const uint256 modifier 
) const

Calculate a quorum based on the modifier.

The resulting list is deterministically sorted by score

Parameters
maxSize
modifier
Returns

Definition at line 217 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ CalculateScores()

std::vector< std::pair< arith_uint256, CDeterministicMNCPtr > > CDeterministicMNList::CalculateScores ( const uint256 modifier) const
Todo:
When https://github.com/bitcoin/bitcoin/pull/13191 gets backported, implement something that is similar but for single-sha256

Definition at line 239 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteUniqueProperty()

template<typename T >
void CDeterministicMNList::DeleteUniqueProperty ( const CDeterministicMNCPtr dmn,
const T oldValue 
)
inlineprivate

Definition at line 466 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForEachMN()

template<typename Callback >
void CDeterministicMNList::ForEachMN ( bool  onlyValid,
Callback &&  cb 
) const
inline

Definition at line 338 of file deterministicmns.h.

Here is the caller graph for this function:

◆ GetAllMNsCount()

size_t CDeterministicMNList::GetAllMNsCount ( ) const
inline

Definition at line 321 of file deterministicmns.h.

Here is the caller graph for this function:

◆ GetBlockHash()

const uint256& CDeterministicMNList::GetBlockHash ( ) const
inline

Definition at line 348 of file deterministicmns.h.

Here is the caller graph for this function:

◆ GetHeight()

int CDeterministicMNList::GetHeight ( ) const
inline

Definition at line 349 of file deterministicmns.h.

Here is the caller graph for this function:

◆ GetMN()

CDeterministicMNCPtr CDeterministicMNList::GetMN ( const uint256 proTxHash) const

Definition at line 98 of file deterministicmns.cpp.

Here is the caller graph for this function:

◆ GetMNByCollateral()

CDeterministicMNCPtr CDeterministicMNList::GetMNByCollateral ( const COutPoint collateralOutpoint) const

Definition at line 126 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMNByInternalId()

CDeterministicMNCPtr CDeterministicMNList::GetMNByInternalId ( uint64_t  internalId) const

Definition at line 145 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMNByOperatorKey()

CDeterministicMNCPtr CDeterministicMNList::GetMNByOperatorKey ( const CBLSPublicKey pubKey)

Definition at line 116 of file deterministicmns.cpp.

◆ GetMNByService()

CDeterministicMNCPtr CDeterministicMNList::GetMNByService ( const CService service) const

Definition at line 140 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ GetMNPayee()

CDeterministicMNCPtr CDeterministicMNList::GetMNPayee ( ) const

Definition at line 180 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetProjectedMNPayees()

std::vector< CDeterministicMNCPtr > CDeterministicMNList::GetProjectedMNPayees ( unsigned int  nCount) const

Calculates the projected MN payees for the next count blocks.

The result is not guaranteed to be correct as PoSe banning might occur later

Parameters
count
Returns

Definition at line 196 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ GetTotalRegisteredCount()

uint32_t CDeterministicMNList::GetTotalRegisteredCount ( ) const
inline

Definition at line 350 of file deterministicmns.h.

◆ GetUniquePropertyMN()

template<typename T >
CDeterministicMNCPtr CDeterministicMNList::GetUniquePropertyMN ( const T v) const
inline

Definition at line 440 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValidMN()

CDeterministicMNCPtr CDeterministicMNList::GetValidMN ( const uint256 proTxHash) const

Definition at line 107 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ GetValidMNByCollateral()

CDeterministicMNCPtr CDeterministicMNList::GetValidMNByCollateral ( const COutPoint collateralOutpoint) const

Definition at line 131 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValidMNsCount()

size_t CDeterministicMNList::GetValidMNsCount ( ) const
inline

Definition at line 326 of file deterministicmns.h.

Here is the caller graph for this function:

◆ HasMN()

bool CDeterministicMNList::HasMN ( const uint256 proTxHash) const
inline

Definition at line 354 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasMNByCollateral()

bool CDeterministicMNList::HasMNByCollateral ( const COutPoint collateralOutpoint) const
inline

Definition at line 358 of file deterministicmns.h.

Here is the call graph for this function:

◆ HasUniqueProperty()

template<typename T >
bool CDeterministicMNList::HasUniqueProperty ( const T v) const
inline

Definition at line 435 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasValidMNByCollateral()

bool CDeterministicMNList::HasValidMNByCollateral ( const COutPoint collateralOutpoint) const
inline

Definition at line 362 of file deterministicmns.h.

Here is the call graph for this function:

◆ PoSeDecrease()

void CDeterministicMNList::PoSeDecrease ( const uint256 proTxHash)

Decrease penalty score of MN by 1.

Only allowed on non-banned MNs.

Parameters
proTxHash

Definition at line 309 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PoSePunish()

void CDeterministicMNList::PoSePunish ( const uint256 proTxHash,
int  penalty,
bool  debugLogs 
)

Punishes a MN for misbehavior.

If the resulting penalty score of the MN reaches the max penalty, it is banned. Penalty scores are only increased when the MN is not already banned, which means that after banning the penalty might appear lower then the current max penalty, while the MN is still banned.

Parameters
proTxHash
penalty

Definition at line 279 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveMN()

void CDeterministicMNList::RemoveMN ( const uint256 proTxHash)

Definition at line 445 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serialize()

template<typename Stream >
void CDeterministicMNList::Serialize ( Stream &  s) const
inline

Definition at line 293 of file deterministicmns.h.

Here is the call graph for this function:

◆ SetBlockHash()

void CDeterministicMNList::SetBlockHash ( const uint256 _blockHash)
inline

Definition at line 352 of file deterministicmns.h.

Here is the caller graph for this function:

◆ SetHeight()

void CDeterministicMNList::SetHeight ( int  _height)
inline

Definition at line 351 of file deterministicmns.h.

Here is the caller graph for this function:

◆ Unserialize()

template<typename Stream >
void CDeterministicMNList::Unserialize ( Stream &  s)
inline

Definition at line 306 of file deterministicmns.h.

Here is the call graph for this function:

◆ UpdateMN() [1/3]

void CDeterministicMNList::UpdateMN ( const CDeterministicMNCPtr oldDmn,
const CDeterministicMNStateCPtr pdmnState 
)

Definition at line 409 of file deterministicmns.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateMN() [2/3]

void CDeterministicMNList::UpdateMN ( const CDeterministicMNCPtr oldDmn,
const CDeterministicMNStateDiff stateDiff 
)

Definition at line 436 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ UpdateMN() [3/3]

void CDeterministicMNList::UpdateMN ( const uint256 proTxHash,
const CDeterministicMNStateCPtr pdmnState 
)

Definition at line 427 of file deterministicmns.cpp.

Here is the call graph for this function:

◆ UpdateUniqueProperty()

template<typename T >
void CDeterministicMNList::UpdateUniqueProperty ( const CDeterministicMNCPtr dmn,
const T oldValue,
const T newValue 
)
inlineprivate

Definition at line 481 of file deterministicmns.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ blockHash

uint256 CDeterministicMNList::blockHash
private

Definition at line 273 of file deterministicmns.h.

◆ mnInternalIdMap

MnInternalIdMap CDeterministicMNList::mnInternalIdMap
private

Definition at line 277 of file deterministicmns.h.

◆ mnMap

MnMap CDeterministicMNList::mnMap
private

Definition at line 276 of file deterministicmns.h.

◆ mnUniquePropertyMap

MnUniquePropertyMap CDeterministicMNList::mnUniquePropertyMap
private

Definition at line 281 of file deterministicmns.h.

◆ nHeight

int CDeterministicMNList::nHeight {-1}
private

Definition at line 274 of file deterministicmns.h.

◆ nTotalRegisteredCount

uint32_t CDeterministicMNList::nTotalRegisteredCount {0}
private

Definition at line 275 of file deterministicmns.h.


The documentation for this class was generated from the following files: