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>
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, CSporkMessage > | mapSporksByHash |
std::unordered_map< SporkId, std::map< CKeyID, CSporkMessage > > | mapSporksActive |
std::set< CKeyID > | setSporkPubKeyIDs |
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).
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()
bool CSporkManager::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.
For value-based sporks such as SPORK_5_INSTANTSEND_MAX_VALUE, the spork value should not be considered a timestamp, but an integer value instead, and therefore this method doesn't make sense and should not be used.
Definition at line 211 of file spork.cpp.
References GetAdjustedTime(), and GetSporkValue().
Referenced by llmq::CDKGSessionManager::AlreadyHave(), llmq::CChainLocksHandler::CheckActiveState(), CChainState::ConnectBlock(), FillBlockPayments(), getblocktemplate(), llmq::CDKGSessionManager::GetComplaint(), llmq::CDKGSessionManager::GetContribution(), llmq::CDKGSessionManager::GetJustification(), CPrivateSend::GetMaxPoolParticipants(), CPrivateSend::GetMinPoolParticipants(), llmq::CDKGSessionManager::GetPrematureCommitment(), IsBlockPayeeValid(), IsBlockValueValid(), llmq::IsInstantSendEnabled(), llmq::CChainLocksHandler::IsTxSafeForMining(), llmq::CDKGSessionManager::ProcessMessage(), llmq::CChainLocksHandler::ProcessMessage(), llmq::CSigSharesManager::ProcessMessage(), spork(), llmq::CChainLocksHandler::TrySignChainTip(), llmq::CDKGSessionManager::UpdatedBlockTip(), and llmq::CInstantSendManager::UpdatedBlockTip().
◆ 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()
|
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()
|
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 |
◆ UpdateSpork()
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
◆ cs
|
mutableprivate |
Definition at line 159 of file spork.h.
Referenced by CheckAndRemove(), Clear(), GetSporkByHash(), GetSporkValue(), ProcessSpork(), SetPrivKey(), SetSporkAddress(), SporkValueIsActive(), ToString(), and UpdateSpork().
◆ mapSporksActive
|
private |
Definition at line 161 of file spork.h.
Referenced by CheckAndRemove(), Clear(), ProcessSpork(), SerializationOp(), SporkValueIsActive(), ToString(), and UpdateSpork().
◆ mapSporksByHash
|
private |
Definition at line 160 of file spork.h.
Referenced by CheckAndRemove(), Clear(), GetSporkByHash(), ProcessSpork(), SerializationOp(), and UpdateSpork().
◆ nMinSporkKeys
|
private |
Definition at line 164 of file spork.h.
Referenced by SetMinSporkKeys(), and SporkValueIsActive().
◆ SERIALIZATION_VERSION_STRING
|
staticprivate |
Definition at line 154 of file spork.h.
Referenced by SerializationOp().
◆ setSporkPubKeyIDs
|
private |
Definition at line 163 of file spork.h.
Referenced by CheckAndRemove(), ProcessSpork(), SetMinSporkKeys(), SetPrivKey(), SetSporkAddress(), and UpdateSpork().
◆ sporkDefsById
Definition at line 156 of file spork.h.
Referenced by CSporkManager(), GetSporkNameByID(), and GetSporkValue().
◆ sporkDefsByName
|
private |
Definition at line 157 of file spork.h.
Referenced by CSporkManager(), and GetSporkIDByName().
◆ 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: