Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

CSporkManager is a higher-level class which manages the node's spork messages, rules for which sporks should be considered active/inactive, and processing for certain sporks (e.g. More...

#include <spork.h>

+ Collaboration diagram for CSporkManager:

Public Member Functions

 CSporkManager ()
 
template<typename Stream , typename Operation >
void SerializationOp (Stream &s, Operation ser_action)
 
void Clear ()
 Clear is used to clear all in-memory active spork messages. More...
 
void CheckAndRemove ()
 CheckAndRemove is defined to fulfill an interface as part of the on-disk cache used to cache sporks between runs. More...
 
void ProcessSpork (CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
 ProcessSpork is used to handle the 'getsporks' and 'spork' p2p messages. More...
 
bool UpdateSpork (SporkId nSporkID, int64_t nValue, CConnman &connman)
 UpdateSpork is used by the spork RPC command to set a new spork value, sign and broadcast the spork message. More...
 
bool IsSporkActive (SporkId nSporkID)
 IsSporkActive returns a bool for time-based sporks, and should be used to determine whether the spork can be considered active or not. More...
 
int64_t GetSporkValue (SporkId nSporkID)
 GetSporkValue returns the spork value given a Spork ID. More...
 
SporkId GetSporkIDByName (const std::string &strName)
 GetSporkIDByName returns the internal Spork ID given the spork name. More...
 
std::string GetSporkNameByID (SporkId nSporkID)
 GetSporkNameByID returns the spork name as a string, given a Spork ID. More...
 
bool GetSporkByHash (const uint256 &hash, CSporkMessage &sporkRet)
 GetSporkByHash returns a spork message given a hash of the spork message. More...
 
bool SetSporkAddress (const std::string &strAddress)
 SetSporkAddress is used to set a public key ID which will be used to verify spork signatures. More...
 
bool SetMinSporkKeys (int minSporkKeys)
 SetMinSporkKeys is used to set the required spork signer threshold, for a spork to be considered active. More...
 
bool SetPrivKey (const std::string &strPrivKey)
 SetPrivKey is used to set a spork key to enable setting / signing of spork values. More...
 
std::string ToString () const
 ToString returns the string representation of the SporkManager. More...
 

Public Attributes

 ADD_SERIALIZE_METHODS
 

Private Member Functions

bool SporkValueIsActive (SporkId nSporkID, int64_t &nActiveValueRet) const
 SporkValueIsActive is used to get the value agreed upon by the majority of signed spork messages for a given Spork ID. More...
 

Private Attributes

std::unordered_map< SporkId, CSporkDef * > sporkDefsById
 
std::unordered_map< std::string, CSporkDef * > sporkDefsByName
 
CCriticalSection cs
 
std::unordered_map< uint256, CSporkMessagemapSporksByHash
 
std::unordered_map< SporkId, std::map< CKeyID, CSporkMessage > > mapSporksActive
 
std::set< CKeyIDsetSporkPubKeyIDs
 
int nMinSporkKeys
 
CKey sporkPrivKey
 

Static Private Attributes

static const std::string SERIALIZATION_VERSION_STRING = "CSporkManager-Version-2"
 

Detailed Description

CSporkManager is a higher-level class which manages the node's spork messages, rules for which sporks should be considered active/inactive, and processing for certain sporks (e.g.

spork 12).

Definition at line 151 of file spork.h.

Constructor & Destructor Documentation

◆ CSporkManager()

CSporkManager::CSporkManager ( )

Definition at line 31 of file spork.cpp.

References sporkDefs, sporkDefsById, and sporkDefsByName.

Member Function Documentation

◆ CheckAndRemove()

void CSporkManager::CheckAndRemove ( )

CheckAndRemove is defined to fulfill an interface as part of the on-disk cache used to cache sporks between runs.

If sporks that are restored from cache do not have valid signatures when compared against the current spork private keys, they are removed from in-memory storage.

This method was introduced along with the spork cache.

Definition at line 69 of file spork.cpp.

References cs, LOCK, mapSporksActive, mapSporksByHash, and setSporkPubKeyIDs.

◆ Clear()

void CSporkManager::Clear ( )

Clear is used to clear all in-memory active spork messages.

Since spork public and private keys are set in init.cpp, we do not clear them here.

This method was introduced along with the spork cache.

Definition at line 60 of file spork.cpp.

References cs, LOCK, mapSporksActive, and mapSporksByHash.

◆ GetSporkByHash()

bool CSporkManager::GetSporkByHash ( const uint256 hash,
CSporkMessage sporkRet 
)

GetSporkByHash returns a spork message given a hash of the spork message.

This is used when a requesting peer sends a MSG_SPORK inventory message with the hash, to quickly lookup and return the full spork message. We maintain a hash-based index of sporks for this reason, and this function is the access point into that index.

Definition at line 255 of file spork.cpp.

References cs, LOCK, and mapSporksByHash.

Referenced by AlreadyHave(), and ProcessGetData().

◆ GetSporkIDByName()

SporkId CSporkManager::GetSporkIDByName ( const std::string &  strName)

GetSporkIDByName returns the internal Spork ID given the spork name.

Definition at line 235 of file spork.cpp.

References LogPrint, BCLog::SPORK, SPORK_INVALID, and sporkDefsByName.

Referenced by spork().

◆ GetSporkNameByID()

std::string CSporkManager::GetSporkNameByID ( SporkId  nSporkID)

GetSporkNameByID returns the spork name as a string, given a Spork ID.

Definition at line 245 of file spork.cpp.

References LogPrint, BCLog::SPORK, and sporkDefsById.

◆ GetSporkValue()

int64_t CSporkManager::GetSporkValue ( SporkId  nSporkID)

GetSporkValue returns the spork value given a Spork ID.

If no active spork message has yet been received by the node, it returns the default value.

Definition at line 217 of file spork.cpp.

References cs, LOCK, LogPrint, BCLog::SPORK, sporkDefsById, and SporkValueIsActive().

Referenced by llmq::CLLMQUtils::IsAllMembersConnectedEnabled(), IsSporkActive(), and spork().

◆ IsSporkActive()

◆ ProcessSpork()

void CSporkManager::ProcessSpork ( CNode pfrom,
const std::string &  strCommand,
CDataStream vRecv,
CConnman connman 
)

ProcessSpork is used to handle the 'getsporks' and 'spork' p2p messages.

For 'getsporks', it sends active sporks to the requesting peer. For 'spork', it validates the spork and adds it to the internal spork storage and performs any necessary processing.

Definition at line 114 of file spork.cpp.

References chainActive, cs, cs_main, EraseObjectRequest(), GetAdjustedTime(), CNode::GetId(), CNode::GetSendVersion(), NetMsgType::GETSPORKS, CChain::Height(), LOCK, LogPrint, LogPrintf, mapSporksActive, mapSporksByHash, Misbehaving(), MSG_SPORK, CConnman::PushMessage(), setSporkPubKeyIDs, NetMsgType::SPORK, BCLog::SPORK, spork(), strprintf, CChain::Tip(), and base_blob< BITS >::ToString().

Referenced by ProcessMessage().

◆ SerializationOp()

template<typename Stream , typename Operation >
void CSporkManager::SerializationOp ( Stream &  s,
Operation  ser_action 
)
inline

Definition at line 180 of file spork.h.

References mapSporksActive, mapSporksByHash, READWRITE, and SERIALIZATION_VERSION_STRING.

◆ SetMinSporkKeys()

bool CSporkManager::SetMinSporkKeys ( int  minSporkKeys)

SetMinSporkKeys is used to set the required spork signer threshold, for a spork to be considered active.

This value must be at least a majority of the total number of spork keys, and for obvious resons cannot be larger than that number.

Definition at line 281 of file spork.cpp.

References LogPrintf, nMinSporkKeys, and setSporkPubKeyIDs.

Referenced by AppInitMain().

◆ SetPrivKey()

bool CSporkManager::SetPrivKey ( const std::string &  strPrivKey)

SetPrivKey is used to set a spork key to enable setting / signing of spork values.

This will return false if the private key does not match any spork address in the set of valid spork signers (see SetSporkAddress).

Definition at line 292 of file spork.cpp.

References cs, CPubKey::GetID(), CMessageSigner::GetKeysFromSecret(), LOCK, LogPrintf, setSporkPubKeyIDs, spork(), and sporkPrivKey.

Referenced by AppInitMain().

◆ SetSporkAddress()

bool CSporkManager::SetSporkAddress ( const std::string &  strAddress)

SetSporkAddress is used to set a public key ID which will be used to verify spork signatures.

This can be called multiple times to add multiple keys to the set of valid spork signers.

Definition at line 269 of file spork.cpp.

References cs, DecodeDestination(), LOCK, LogPrintf, and setSporkPubKeyIDs.

Referenced by AppInitMain().

◆ SporkValueIsActive()

bool CSporkManager::SporkValueIsActive ( SporkId  nSporkID,
int64_t &  nActiveValueRet 
) const
private

SporkValueIsActive is used to get the value agreed upon by the majority of signed spork messages for a given Spork ID.

Definition at line 39 of file spork.cpp.

References cs, LOCK, mapSporksActive, and nMinSporkKeys.

Referenced by GetSporkValue().

◆ ToString()

std::string CSporkManager::ToString ( ) const

ToString returns the string representation of the SporkManager.

Definition at line 319 of file spork.cpp.

References cs, LOCK, mapSporksActive, and strprintf.

◆ UpdateSpork()

bool CSporkManager::UpdateSpork ( SporkId  nSporkID,
int64_t  nValue,
CConnman connman 
)

UpdateSpork is used by the spork RPC command to set a new spork value, sign and broadcast the spork message.

Definition at line 185 of file spork.cpp.

References cs, GetAdjustedTime(), LOCK, LogPrintf, mapSporksActive, mapSporksByHash, setSporkPubKeyIDs, spork(), and sporkPrivKey.

Referenced by spork().

Member Data Documentation

◆ ADD_SERIALIZE_METHODS

CSporkManager::ADD_SERIALIZE_METHODS

Definition at line 177 of file spork.h.

◆ cs

◆ mapSporksActive

std::unordered_map<SporkId, std::map<CKeyID, CSporkMessage> > CSporkManager::mapSporksActive
private

◆ mapSporksByHash

std::unordered_map<uint256, CSporkMessage> CSporkManager::mapSporksByHash
private

◆ nMinSporkKeys

int CSporkManager::nMinSporkKeys
private

Definition at line 164 of file spork.h.

Referenced by SetMinSporkKeys(), and SporkValueIsActive().

◆ SERIALIZATION_VERSION_STRING

const std::string CSporkManager::SERIALIZATION_VERSION_STRING = "CSporkManager-Version-2"
staticprivate

Definition at line 154 of file spork.h.

Referenced by SerializationOp().

◆ setSporkPubKeyIDs

std::set<CKeyID> CSporkManager::setSporkPubKeyIDs
private

◆ sporkDefsById

std::unordered_map<SporkId, CSporkDef*> CSporkManager::sporkDefsById
private

Definition at line 156 of file spork.h.

Referenced by CSporkManager(), GetSporkNameByID(), and GetSporkValue().

◆ sporkDefsByName

std::unordered_map<std::string, CSporkDef*> CSporkManager::sporkDefsByName
private

Definition at line 157 of file spork.h.

Referenced by CSporkManager(), and GetSporkIDByName().

◆ sporkPrivKey

CKey CSporkManager::sporkPrivKey
private

Definition at line 165 of file spork.h.

Referenced by SetPrivKey(), and UpdateSpork().


The documentation for this class was generated from the following files:
Released under the MIT license