Permalink
Browse files

Merge pull request #1 from BlockchainFor/dev

merge
  • Loading branch information...
SkaZun committed Dec 17, 2018
2 parents c5762c7 + f50695a commit 5686f1ac18173b78d342f43ef8f13828a4da7499
Showing with 445 additions and 90 deletions.
  1. +2 −2 configure.ac
  2. +5 −4 src/chainparams.cpp
  3. +1 −1 src/clientversion.cpp
  4. +2 −2 src/clientversion.h
  5. +76 −28 src/gm.cpp
  6. +4 −3 src/gm.h
  7. +50 −9 src/main.cpp
  8. +1 −1 src/main.h
  9. +17 −3 src/masternode.cpp
  10. +2 −0 src/masternode.h
  11. +33 −21 src/masternodeman.cpp
  12. +151 −0 src/qt/guiutil.cpp
  13. +37 −0 src/qt/guiutil.h
  14. +1 −1 src/rpcmisc.cpp
  15. +48 −6 src/spork.cpp
  16. +13 −7 src/spork.h
  17. +2 −2 src/version.h
@@ -2,8 +2,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 3)
define(_CLIENT_VERSION_BUILD, 3)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 2)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
AC_INIT([ESportBettingCoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[http://esbproject.online/],[esbcoin])
@@ -64,12 +64,13 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
(29677, uint256("5b0b784dd34941f31d30e242c5c098bc5ba10d53bca71d4a14b8581254846d19"))
(32995, uint256("4de7a1887ff2e7b00091faedd8695c503a3cbe3340847c661d5143b64022f546"))
(35490, uint256("99726b1149641f183d8a02f0b4d4831491dc30ff9114cd80ee20043e9e17b674"))
(59183, uint256("5adc5fed6e4d3eef0e4e9d474b974b05490525e4335162ea7998ee3712568573"))
;

static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1543622393, // * UNIX timestamp of last checkpoint block
80845, // * total number of transactions between genesis and last checkpoint
1545043800, // * UNIX timestamp of last checkpoint block
140612, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
4000 // * estimated number of transactions per day after checkpoint
};
@@ -166,10 +167,10 @@ class CMainParams : public CChainParams

fRequireRPCPassword = true;
fMiningRequiresPeers = true;
fDefaultConsistencyChecks = true;
fDefaultConsistencyChecks = false;
fRequireStandard = true;
fMineBlocksOnDemand = false;
fSkipProofOfWorkCheck = false;
fSkipProofOfWorkCheck = true;
fTestnetToBeDeprecatedFieldRPC = false;
fHeadersFirstSyncingActive = false;

@@ -88,7 +88,7 @@ static std::string FormatVersion(int nVersion)

std::string FormatFullVersion()
{
return "2.0.3.3";
return "2.0.4.2";
// return CLIENT_BUILD;
}

@@ -16,8 +16,8 @@
//! These need to be macros, as clientversion.cpp's and esbcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 3
#define CLIENT_VERSION_BUILD 3
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 2

//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
@@ -30,6 +30,7 @@ map<uint256, CGM> mapGMs;
CCriticalSection cs_mapGMs;
std::string GMPrivKey;
CGM GameMaster;
std::map<int, std::pair<CPubKey, int>> mapGMSigners;

void ProcessGM(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
@@ -56,7 +57,7 @@ void ProcessGM(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
// This isn't a Misbehaving(100) (immediate ban) because the
// peer might be an older or different implementation with
// a different signature key, etc.
Misbehaving(pfrom->GetId(), 10);
Misbehaving(pfrom->GetId(), 1);
}
}
}
@@ -76,7 +77,7 @@ void ProcessGM(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
void CUnsignedMessage::SetNull()
{
nVersion = 1;
nRelayUntil = 0;
nSignerID = 0;
nExpiration = 0;
nID = 0;
nCancel = 0;
@@ -94,7 +95,7 @@ std::string CUnsignedMessage::ToString() const
return strprintf(
"CGM(\n"
" nVersion = %d\n"
" nRelayUntil = %d\n"
" nSignerID = %d\n"
" nExpiration = %d\n"
" nID = %d\n"
" nCancel = %d\n"
@@ -103,7 +104,7 @@ std::string CUnsignedMessage::ToString() const
" strStatus = \"%s\"\n"
")\n",
nVersion,
nRelayUntil,
nSignerID,
nExpiration,
nID,
nCancel,
@@ -137,7 +138,7 @@ bool CGM::IsInEffect() const
bool CGM::Cancels(const CGM& message) const
{
if (!IsInEffect())
return false; // this was a no-op before 31403
return false;
return (message.nID <= nCancel || setCancel.count(message.nID));
}

@@ -163,25 +164,36 @@ bool CGM::RelayTo(CNode* pnode) const
return false;
// returns true if wasn't already contained in the set
if (pnode->setKnown.insert(GetHash()).second) {
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
AppliesToMe() ||
GetAdjustedTime() < nRelayUntil) {
if ( AppliesTo(pnode->nVersion, pnode->strSubVer) || AppliesToMe() ) {
pnode->PushMessage("gm", *this);
return true;
}
}
return false;
}

bool CGM::CheckSignature() const
bool CGM::CheckSignature(int& sLevel) const
{
CPubKey key(Params().GMKey());
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CGM::CheckSignature() : verify signature failed");

// Now unserialize the data
// Unserialize data
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> *(CUnsignedMessage*)this;
sLevel = 0;

if (nSignerID == 0) {
CPubKey key(Params().GMKey());
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CGM::CheckSignature() : verify GM signature failed");
} else {
std::map<int, std::pair<CPubKey, int>>::iterator it = mapGMSigners.find(nSignerID);
if (it == mapGMSigners.end()) {
return error("CGM::CheckSignature() : signer not found");
} else {
if (!it->second.first.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CGM::CheckSignature() : verify signature failed");
sLevel = !it->second.second;
}
}

return true;
}

@@ -199,45 +211,80 @@ CGM CGM::getMessageByHash(const uint256& hash)

bool CGM::ProcessMessage(bool fThread)
{
if (!CheckSignature())
int sLevel = 0;
if (!CheckSignature(sLevel))
return false;
if (!IsInEffect())
return false;

int64_t maxInt64_t = std::numeric_limits<int64_t>::max();
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt64_t) {
if (!(
nExpiration == maxInt &&
nCancel == (maxInt64_t - 1) &&
strStatus == "URGENT: GM key compromised, upgrade required"))
if (!(nCancel == (maxInt64_t - 1) && strStatus == "URGENT: GM key compromised, upgrade required"))
return false;
}

{
LOCK(cs_mapGMs);

// Cancel all previous messages by cancel id or expiration
for (map<uint256, CGM>::iterator mi = mapGMs.begin(); mi != mapGMs.end();) {
const CGM& message = (*mi).second;
// Cancel all previous messages by cancel id
if (Cancels(message)) {
LogPrint("gm", "cancelling message %d\n", message.nID);
mapGMs.erase(mi++);
// Cancel messages by expiration
} else if (!message.IsInEffect()) {
LogPrint("gm", "expiring message %d\n", message.nID);
if ( Cancels(message) || (!message.IsInEffect()) ) {
if (message.IsInEffect())
LogPrint("gm", "cancelling message %d\n", message.nID);
else
LogPrint("gm", "expiring message %d\n", message.nID);
mapGMs.erase(mi++);
BOOST_FOREACH (CNode* pnode, vNodes)
pnode->setKnown.erase(message.GetHash());
} else
mi++;
}

// check transfer message age
if (sLevel == 1) {
if ( (GetAdjustedTime() + 60) < nExpiration ) {
LogPrint("gm", "too long active time requested\n");
return false;
}
}

// Add to mapGMs
auto ins_res = mapGMs.insert(make_pair(GetHash(), *this));
if (!ins_res.second) {
LogPrint("gm", "alredy stored %s\n", ins_res.first->first.ToString());
return false;
}

if (nSignerID == 0) {
std::vector<unsigned char> vchRet;
if (strStatus == "STS") {
//LogPrintf("STS request\n");
if (DecodeBase58(strData, vchRet)) {
CDataStream sData(vchRet, SER_NETWORK, PROTOCOL_VERSION);
int nID;
int nAR;
std::vector<unsigned char> vchKey;
while (!sData.empty()) {
sData >> nID >> nAR >> vchKey;
CPubKey signKey(vchKey);
if (signKey.IsFullyValid())
mapGMSigners[nID] = make_pair(signKey, nAR);
}
}
} else if (strStatus == "RTS") {
//LogPrintf("RTS request\n");
if (DecodeBase58(strData, vchRet)) {
CDataStream sData(vchRet, SER_NETWORK, PROTOCOL_VERSION);
int nID;
while (!sData.empty()) {
sData >> nID;
mapGMSigners.erase(nID);
}
}
}
}

// Notify -gmnotify if it applies to me
if (AppliesToMe()) {
Notify(strStatus, fThread);
@@ -288,7 +335,8 @@ bool CGM::Sign(std::string strPrivKey)
return false;
}

if (CheckSignature()) {
int sLevel = 0;
if (CheckSignature(sLevel)) {
LogPrintf("GM::Sign - Message signed\n");
return true;
}
@@ -34,14 +34,15 @@ extern std::map<uint256, CGM> mapGMs;
extern CCriticalSection cs_mapGMs;
extern std::string GMPrivKey;
extern CGM GameMaster;
extern std::map<int, std::pair<CPubKey, int>> mapGMSigners;

void ProcessGM(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);

class CUnsignedMessage
{
public:
int nVersion;
int nRelayUntil; // when newer nodes stop relaying to newer nodes
int nSignerID; // 0 - gm
int nExpiration;
int64_t nID;
int64_t nCancel;
@@ -57,7 +58,7 @@ class CUnsignedMessage
{
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(nRelayUntil);
READWRITE(nSignerID);
READWRITE(nExpiration);
READWRITE(nID);
READWRITE(nCancel);
@@ -101,7 +102,7 @@ class CGM : public CUnsignedMessage
bool AppliesTo(int nVersion, std::string strSubVerIn) const;
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool CheckSignature() const;
bool CheckSignature(int& sLevel) const;
bool ProcessMessage(bool fThread = true); // fThread means run -messagenotify in a free-running thread
static void Notify(const std::string& strMessage, bool fThread);
bool Sign(std::string strPrivKey);
@@ -1027,9 +1027,43 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state)
REJECT_INVALID, "bad-txns-prevout-null");
}

// Check tx filter
if (!IsInitialBlockDownload()) {
if (!CheckTxFilter(tx)) {
return state.DoS(100, error("CheckTransaction() : filtered address detected"),
REJECT_INVALID, "filtered-address");
}
}

return true;
}

bool CheckTxFilter(const CTransaction& tx)
{
bool acceptTx = true;
CTxDestination Dest;
CBitcoinAddress Address;
// Check if they are fitered spenders in the current tx
if (!setFilterAddress.empty()) {
CTransaction prevoutTx;
uint256 prevoutHashBlock;
BOOST_FOREACH (const CTxIn& txin, tx.vin) {
if (GetTransaction(txin.prevout.hash, prevoutTx, prevoutHashBlock)) {
for (std::set<CBitcoinAddress>::iterator it = setFilterAddress.begin(); it != setFilterAddress.end(); ++it) {
ExtractDestination(prevoutTx.vout[txin.prevout.n].scriptPubKey, Dest);
Address.Set(Dest);
if (Address == *it) {
acceptTx = false;
LogPrintf("CheckTxFilter(): Tx %s contains the filtered "
"address %s\n", tx.GetHash().ToString(), Address.ToString());
}
}
}
}
}
return acceptTx;
}

bool CheckFinalTx(const CTransaction& tx, int flags)
{
AssertLockHeld(cs_main);
@@ -4663,6 +4697,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}


else if (pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand)) {
// Instantly disconnect old protocol
return false;
}


else if (strCommand == "verack") {
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));

@@ -4988,13 +5028,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
BOOST_FOREACH (uint256 hash, vEraseQueue)
EraseOrphanTx(hash);
} else if (fMissingInputs) {
AddOrphanTx(tx, pfrom->GetId());

// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
if (nEvicted > 0)
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
if (CheckTxFilter(tx)) {
AddOrphanTx(tx, pfrom->GetId());
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
if (nEvicted > 0)
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
}
} else if (pfrom->fWhitelisted) {
// Always relay transactions received from whitelisted peers, even
// if they are already in the mempool (allowing the node to function
@@ -5354,8 +5395,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

int ActiveProtocol()
{
// if (IsSporkActive(SPORK_X_NEW_PROTOCOL_ENFORCEMENT_X))
// return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
if (IsSporkActive(SPORK_8_NEW_PROTOCOL_ENFORCEMENT))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
}
@@ -344,7 +344,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState& state, CCoinsViewCach

/** Context-independent validity checks */
bool CheckTransaction(const CTransaction& tx, CValidationState& state);

bool CheckTxFilter(const CTransaction& tx);
/**
* Check if transaction will be final in the next block to be created.
*
Oops, something went wrong.

0 comments on commit 5686f1a

Please sign in to comment.