2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
2015-02-09 21:54:51 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2016-07-30 13:04:27 +02:00
|
|
|
|
2015-02-09 21:54:51 +01:00
|
|
|
#ifndef SPORK_H
|
|
|
|
#define SPORK_H
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
#include "hash.h"
|
2016-07-30 13:04:27 +02:00
|
|
|
#include "net.h"
|
2016-02-02 16:28:56 +01:00
|
|
|
#include "utilstrencodings.h"
|
2018-03-02 14:15:04 +01:00
|
|
|
#include "key.h"
|
2015-04-03 00:51:08 +02:00
|
|
|
|
2016-08-29 21:16:02 +02:00
|
|
|
class CSporkMessage;
|
|
|
|
class CSporkManager;
|
|
|
|
|
2015-05-30 19:27:51 +02:00
|
|
|
/*
|
|
|
|
Don't ever reuse these IDs for other sporks
|
|
|
|
- This would result in old clients getting confused about which spork is for what
|
|
|
|
*/
|
2016-09-01 16:55:25 +02:00
|
|
|
static const int SPORK_2_INSTANTSEND_ENABLED = 10001;
|
|
|
|
static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING = 10002;
|
|
|
|
static const int SPORK_5_INSTANTSEND_MAX_VALUE = 10004;
|
2018-02-15 15:44:22 +01:00
|
|
|
static const int SPORK_6_NEW_SIGS = 10005;
|
2016-08-29 21:16:02 +02:00
|
|
|
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT = 10007;
|
|
|
|
static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008;
|
|
|
|
static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009;
|
|
|
|
static const int SPORK_12_RECONSIDER_BLOCKS = 10011;
|
2016-11-23 16:30:36 +01:00
|
|
|
static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
|
2018-02-15 13:57:18 +01:00
|
|
|
static const int SPORK_15_DETERMINISTIC_MNS_ENABLED = 10014;
|
2016-08-29 21:16:02 +02:00
|
|
|
|
2018-04-20 12:53:23 +02:00
|
|
|
static const int SPORK_START = SPORK_2_INSTANTSEND_ENABLED;
|
2018-02-15 13:57:18 +01:00
|
|
|
static const int SPORK_END = SPORK_15_DETERMINISTIC_MNS_ENABLED;
|
2018-04-20 12:53:23 +02:00
|
|
|
|
2018-04-18 13:50:26 +02:00
|
|
|
extern std::map<int, int64_t> mapSporkDefaults;
|
2015-02-09 21:54:51 +01:00
|
|
|
extern CSporkManager sporkManager;
|
|
|
|
|
|
|
|
//
|
2016-07-30 13:04:27 +02:00
|
|
|
// Spork classes
|
|
|
|
// Keep track of all of the network spork settings
|
2015-02-09 21:54:51 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
class CSporkMessage
|
|
|
|
{
|
2016-07-30 13:04:27 +02:00
|
|
|
private:
|
2015-02-09 21:54:51 +01:00
|
|
|
std::vector<unsigned char> vchSig;
|
2016-07-30 13:04:27 +02:00
|
|
|
|
|
|
|
public:
|
2015-02-09 21:54:51 +01:00
|
|
|
int nSporkID;
|
2015-02-11 15:47:21 +01:00
|
|
|
int64_t nValue;
|
2015-02-09 21:54:51 +01:00
|
|
|
int64_t nTimeSigned;
|
|
|
|
|
2016-08-29 21:16:02 +02:00
|
|
|
CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) :
|
|
|
|
nSporkID(nSporkID),
|
|
|
|
nValue(nValue),
|
|
|
|
nTimeSigned(nTimeSigned)
|
|
|
|
{}
|
2016-07-30 13:04:27 +02:00
|
|
|
|
2016-08-29 21:16:02 +02:00
|
|
|
CSporkMessage() :
|
|
|
|
nSporkID(0),
|
|
|
|
nValue(0),
|
|
|
|
nTimeSigned(0)
|
|
|
|
{}
|
2016-08-15 16:46:46 +02:00
|
|
|
|
2015-02-09 21:54:51 +01:00
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2015-02-09 21:54:51 +01:00
|
|
|
READWRITE(nSporkID);
|
2015-02-11 15:47:21 +01:00
|
|
|
READWRITE(nValue);
|
2015-02-09 21:54:51 +01:00
|
|
|
READWRITE(nTimeSigned);
|
2018-02-16 15:54:53 +01:00
|
|
|
if (!(s.GetType() & SER_GETHASH)) {
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
2015-04-03 00:51:08 +02:00
|
|
|
}
|
2016-08-29 21:16:02 +02:00
|
|
|
|
2018-02-16 15:54:53 +01:00
|
|
|
uint256 GetHash() const;
|
|
|
|
uint256 GetSignatureHash() const;
|
2016-08-29 21:16:02 +02:00
|
|
|
|
2018-08-22 16:46:27 +02:00
|
|
|
bool Sign(const CKey& key, bool fSporkSixActive);
|
|
|
|
bool CheckSignature(const CKeyID& pubKeyId, bool fSporkSixActive) const;
|
2017-09-07 17:58:38 +02:00
|
|
|
void Relay(CConnman& connman);
|
2015-02-09 21:54:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CSporkManager
|
|
|
|
{
|
|
|
|
private:
|
2018-09-26 16:15:02 +02:00
|
|
|
static const std::string SERIALIZATION_VERSION_STRING;
|
|
|
|
|
2018-08-13 22:21:21 +02:00
|
|
|
mutable CCriticalSection cs;
|
|
|
|
std::map<uint256, CSporkMessage> mapSporksByHash;
|
2016-07-30 13:04:27 +02:00
|
|
|
std::map<int, CSporkMessage> mapSporksActive;
|
2015-02-09 21:54:51 +01:00
|
|
|
|
2018-03-02 14:15:04 +01:00
|
|
|
CKeyID sporkPubKeyID;
|
|
|
|
CKey sporkPrivKey;
|
|
|
|
|
2015-02-09 21:54:51 +01:00
|
|
|
public:
|
|
|
|
|
2016-07-30 13:04:27 +02:00
|
|
|
CSporkManager() {}
|
2015-02-09 21:54:51 +01:00
|
|
|
|
2018-08-13 22:21:21 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2018-09-26 16:15:02 +02:00
|
|
|
std::string strVersion;
|
|
|
|
if(ser_action.ForRead()) {
|
|
|
|
READWRITE(strVersion);
|
|
|
|
if (strVersion != SERIALIZATION_VERSION_STRING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strVersion = SERIALIZATION_VERSION_STRING;
|
|
|
|
READWRITE(strVersion);
|
|
|
|
}
|
2018-08-13 22:21:21 +02:00
|
|
|
READWRITE(sporkPubKeyID);
|
|
|
|
READWRITE(mapSporksByHash);
|
|
|
|
READWRITE(mapSporksActive);
|
|
|
|
// we don't serialize private key to prevent its leakage
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear();
|
2018-09-26 16:15:02 +02:00
|
|
|
void CheckAndRemove();
|
2018-08-13 22:21:21 +02:00
|
|
|
|
2017-02-06 14:31:37 +01:00
|
|
|
void ProcessSpork(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
|
2016-07-30 13:04:27 +02:00
|
|
|
void ExecuteSpork(int nSporkID, int nValue);
|
2017-09-07 17:58:38 +02:00
|
|
|
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);
|
2015-02-09 21:54:51 +01:00
|
|
|
|
2016-07-30 13:04:27 +02:00
|
|
|
bool IsSporkActive(int nSporkID);
|
|
|
|
int64_t GetSporkValue(int nSporkID);
|
2018-02-12 13:49:00 +01:00
|
|
|
int GetSporkIDByName(const std::string& strName);
|
2016-07-30 13:04:27 +02:00
|
|
|
std::string GetSporkNameByID(int nSporkID);
|
|
|
|
|
2018-08-13 22:21:21 +02:00
|
|
|
bool GetSporkByHash(const uint256& hash, CSporkMessage &sporkRet);
|
|
|
|
|
2018-03-02 14:15:04 +01:00
|
|
|
bool SetSporkAddress(const std::string& strAddress);
|
2018-02-12 13:49:00 +01:00
|
|
|
bool SetPrivKey(const std::string& strPrivKey);
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
std::string ToString() const;
|
2015-02-09 21:54:51 +01:00
|
|
|
};
|
|
|
|
|
2015-04-03 00:51:08 +02:00
|
|
|
#endif
|