dash/src/spork.h

148 lines
4.6 KiB
C
Raw Normal View History

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.
2015-02-09 21:54:51 +01:00
#ifndef SPORK_H
#define SPORK_H
#include "hash.h"
#include "net.h"
#include "utilstrencodings.h"
#include "key.h"
2015-04-03 00:51:08 +02:00
class CSporkMessage;
class CSporkManager;
/*
Don't ever reuse these IDs for other sporks
- This would result in old clients getting confused about which spork is for what
*/
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;
static const int SPORK_6_NEW_SIGS = 10005;
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;
static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
static const int SPORK_15_DETERMINISTIC_MNS_ENABLED = 10014;
Automatic InstantSend locks for "simple" transactions (#2140) * add locktransaction rpc call * Remove special instantsend fee for simple transactions * Function to check if trx is simple enough to be autolocked * Automatic lock for all received from peers simple trxes If we get a new transaction with CInv message and it is "simple" and is accepted in mempool, we initiate its lock. We don't lock orphan trxes that accepted in mempool after this trx because they are locked by other peers. * Automatically lock simple trxes in wallet * protocol bump for InstantSend without special fee * Add function to detect used mempool share * Mempool threshold for auto IX locks * Add SPORK_16_INSTANTSEND_AUTOLOCKS spork * Make autolocks active only when spork SPORK_16_INSTANTSEND_AUTOLOCKS is active * BIP9 autolocks activation * revert increasing min peer protocol version for mn rank * move IsTrxSimple check to CTxLockRequest class * make MAX_INPUTS_FOR_AUTO_IX private member of CTxLockRequest class * make AUTO_IX_MEMPOOL_THRESHOLD private member of CInstantSend class * remove locktransaction RPC call * tests for automatic IS locks * fix mempool threshod calculation * bump mocktime in activate_autoix_bip9 * set node times * no need to spam the node with gettransaction rpc requests that often * use `spork active` instead of leaking spork logic into tests * codestyle fixes * add test description in comments * fix typo * sync test nodes more often during BIP9 activation * Use 4th bit in BIP9 activation * Fix comments according codestyle guide * Call AcceptLockRequest and Vote at the first node creating autoix lock * fix mempool used memory calculation * rallback not necessary change in CWallet::CreateTransaction * test for stopping autolocks for full mempool * Inject "simple autolockable" txes into txlockrequest logic
2018-09-26 16:17:47 +02:00
static const int SPORK_16_INSTANTSEND_AUTOLOCKS = 10015;
static const int SPORK_START = SPORK_2_INSTANTSEND_ENABLED;
Automatic InstantSend locks for "simple" transactions (#2140) * add locktransaction rpc call * Remove special instantsend fee for simple transactions * Function to check if trx is simple enough to be autolocked * Automatic lock for all received from peers simple trxes If we get a new transaction with CInv message and it is "simple" and is accepted in mempool, we initiate its lock. We don't lock orphan trxes that accepted in mempool after this trx because they are locked by other peers. * Automatically lock simple trxes in wallet * protocol bump for InstantSend without special fee * Add function to detect used mempool share * Mempool threshold for auto IX locks * Add SPORK_16_INSTANTSEND_AUTOLOCKS spork * Make autolocks active only when spork SPORK_16_INSTANTSEND_AUTOLOCKS is active * BIP9 autolocks activation * revert increasing min peer protocol version for mn rank * move IsTrxSimple check to CTxLockRequest class * make MAX_INPUTS_FOR_AUTO_IX private member of CTxLockRequest class * make AUTO_IX_MEMPOOL_THRESHOLD private member of CInstantSend class * remove locktransaction RPC call * tests for automatic IS locks * fix mempool threshod calculation * bump mocktime in activate_autoix_bip9 * set node times * no need to spam the node with gettransaction rpc requests that often * use `spork active` instead of leaking spork logic into tests * codestyle fixes * add test description in comments * fix typo * sync test nodes more often during BIP9 activation * Use 4th bit in BIP9 activation * Fix comments according codestyle guide * Call AcceptLockRequest and Vote at the first node creating autoix lock * fix mempool used memory calculation * rallback not necessary change in CWallet::CreateTransaction * test for stopping autolocks for full mempool * Inject "simple autolockable" txes into txlockrequest logic
2018-09-26 16:17:47 +02:00
static const int SPORK_END = SPORK_16_INSTANTSEND_AUTOLOCKS;
extern std::map<int, int64_t> mapSporkDefaults;
2015-02-09 21:54:51 +01:00
extern CSporkManager sporkManager;
//
// Spork classes
// Keep track of all of the network spork settings
2015-02-09 21:54:51 +01:00
//
class CSporkMessage
{
private:
2015-02-09 21:54:51 +01:00
std::vector<unsigned char> vchSig;
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;
CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) :
nSporkID(nSporkID),
nValue(nValue),
nTimeSigned(nTimeSigned)
{}
CSporkMessage() :
nSporkID(0),
nValue(0),
nTimeSigned(0)
{}
2015-02-09 21:54:51 +01:00
2015-04-03 00:51:08 +02:00
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
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);
READWRITE(vchSig);
2015-04-03 00:51:08 +02:00
}
uint256 GetHash() const;
uint256 GetSignatureHash() const;
bool Sign(const CKey& key, bool fSporkSixActive);
bool CheckSignature(const CKeyID& pubKeyId, bool fSporkSixActive) const;
bool GetSignerKeyID(CKeyID& retKeyidSporkSigner, bool fSporkSixActive);
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;
mutable CCriticalSection cs;
std::map<uint256, CSporkMessage> mapSporksByHash;
std::map<int, std::map<CKeyID, CSporkMessage> > mapSporksActive;
2015-02-09 21:54:51 +01:00
std::set<CKeyID> setSporkPubKeyIDs;
int nMinSporkKeys;
CKey sporkPrivKey;
bool SporkValueIsActive(int nSporkID, int64_t& nActiveValueRet) const;
2015-02-09 21:54:51 +01:00
public:
CSporkManager() {}
2015-02-09 21:54:51 +01: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);
}
// we don't serialize pubkey ids because pubkeys should be
// hardcoded or be setted with cmdline or options, should
// not reuse pubkeys from previous dashd run
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();
void ProcessSpork(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
void ExecuteSpork(int nSporkID, int nValue);
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);
2015-02-09 21:54:51 +01:00
bool IsSporkActive(int nSporkID);
int64_t GetSporkValue(int nSporkID);
int GetSporkIDByName(const std::string& strName);
std::string GetSporkNameByID(int nSporkID);
bool GetSporkByHash(const uint256& hash, CSporkMessage &sporkRet);
bool SetSporkAddress(const std::string& strAddress);
bool SetMinSporkKeys(int minSporkKeys);
bool SetPrivKey(const std::string& strPrivKey);
std::string ToString() const;
2015-02-09 21:54:51 +01:00
};
2015-04-03 00:51:08 +02:00
#endif