Skip to content

Commit

Permalink
WIP - Backport bitcoin QT 0.17
Browse files Browse the repository at this point in the history
Signed-off-by: 216k155 <216k155@luxcore.io>
  • Loading branch information
216k155 authored and nguyenhoangtran11 committed Jan 1, 2019
1 parent 3dcce35 commit 4035ff1
Show file tree
Hide file tree
Showing 139 changed files with 2,720 additions and 885 deletions.
5 changes: 5 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ QT_FORMS_UI = \
qt/forms/editcontractinfodialog.ui \
qt/forms/helpmessagedialog.ui \
qt/forms/intro.ui \
qt/forms/modaloverlay.ui \
qt/forms/eula.ui \
qt/forms/masternodemanager.ui \
qt/forms/addeditluxnode.ui \
Expand Down Expand Up @@ -111,6 +112,7 @@ QT_MOC_CPP = \
qt/moc_eula.cpp \
qt/moc_macdockiconhandler.cpp \
qt/moc_macnotificationhandler.cpp \
qt/moc_modaloverlay.cpp \
qt/moc_masternodemanager.cpp \
qt/moc_addeditluxnode.cpp \
qt/moc_luxnodeconfigdialog.cpp \
Expand Down Expand Up @@ -237,6 +239,7 @@ BITCOIN_QT_H = \
qt/eula.h \
qt/macdockiconhandler.h \
qt/macnotificationhandler.h \
qt/modaloverlay.h \
qt/masternodemanager.h \
qt/addeditluxnode.h \
qt/luxnodeconfigdialog.h \
Expand Down Expand Up @@ -314,6 +317,7 @@ RES_ICONS = \
qt/res/icons/bitcoin_testnet.png \
qt/res/icons/browse.png \
qt/res/icons/chevron.png \
qt/res/icons/warning.png \
qt/res/icons/clock1.png \
qt/res/icons/clock2.png \
qt/res/icons/clock3.png \
Expand Down Expand Up @@ -384,6 +388,7 @@ BITCOIN_QT_CPP = \
qt/csvmodelwriter.cpp \
qt/guiutil.cpp \
qt/intro.cpp \
qt/modaloverlay.cpp \
qt/eula.cpp \
qt/masternodemanager.cpp \
qt/addeditluxnode.cpp \
Expand Down
4 changes: 3 additions & 1 deletion src/coincontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class CCoinControl
bool fAllowWatchOnly;
//! Minimum absolute fee (not per kilobyte)
CAmount nMinimumTotalFee;

//! Override the default confirmation target, 0 = use default
int nConfirmTarget;
CCoinControl()
{
SetNull();
Expand All @@ -40,6 +41,7 @@ class CCoinControl
nMinimumTotalFee = 0;
fSplitBlock = false;
nSplitBlock = 1;
nConfirmTarget = 0;
}

bool HasSelected() const
Expand Down
78 changes: 78 additions & 0 deletions src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "hash.h"
#include "crypto/common.h"
#include "crypto/hmac_sha512.h"
#include "crypto/scrypt.h"
#include "pubkey.h"

inline uint32_t ROTL32(uint32_t x, int8_t r)
{
Expand Down Expand Up @@ -95,6 +97,82 @@ void scrypt_hash(const char* pass, unsigned int pLen, const char* salt, unsigned
v2 = ROTL(v2, 32); \
} while (0)

CSipHasher::CSipHasher(uint64_t k0, uint64_t k1)
{
v[0] = 0x736f6d6570736575ULL ^ k0;
v[1] = 0x646f72616e646f6dULL ^ k1;
v[2] = 0x6c7967656e657261ULL ^ k0;
v[3] = 0x7465646279746573ULL ^ k1;
count = 0;
tmp = 0;
}

CSipHasher& CSipHasher::Write(uint64_t data)
{
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];

assert(count % 8 == 0);

v3 ^= data;
SIPROUND;
SIPROUND;
v0 ^= data;

v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;

count += 8;
return *this;
}

CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size)
{
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
uint64_t t = tmp;
int c = count;

while (size--) {
t |= ((uint64_t)(*(data++))) << (8 * (c % 8));
c++;
if ((c & 7) == 0) {
v3 ^= t;
SIPROUND;
SIPROUND;
v0 ^= t;
t = 0;
}
}

v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
count = c;
tmp = t;

return *this;
}

uint64_t CSipHasher::Finalize() const
{
uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];

uint64_t t = tmp | (((uint64_t)count) << 56);

v3 ^= t;
SIPROUND;
SIPROUND;
v0 ^= t;
v2 ^= 0xFF;
SIPROUND;
SIPROUND;
SIPROUND;
SIPROUND;
return v0 ^ v1 ^ v2 ^ v3;
}

uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val)
{
/* Specialized implementation for efficiency */
Expand Down
65 changes: 65 additions & 0 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "crypto/ripemd160.h"
#include "crypto/sha256.h"
#include "prevector.h"
#include "serialize.h"
#include "uint256.h"
#include "version.h"
Expand Down Expand Up @@ -221,6 +222,13 @@ inline uint160 Hash160(const std::vector<unsigned char>& vch)
return Hash160(vch.begin(), vch.end());
}

/** Compute the 160-bit hash of a vector. */
template<unsigned int N>
inline uint160 Hash160(const prevector<N, unsigned char>& vch)
{
return Hash160(vch.begin(), vch.end());
}

/** A writer stream (for serialization) that computes a 256-bit hash. */
class CHashWriter
{
Expand Down Expand Up @@ -259,6 +267,41 @@ class CHashWriter
}
};

/** Reads data from an underlying stream, while hashing the read data. */
template<typename Source>
class CHashVerifier : public CHashWriter
{
private:
Source* source;

public:
CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {}

void read(char* pch, size_t nSize)
{
source->read(pch, nSize);
this->write(pch, nSize);
}

void ignore(size_t nSize)
{
char data[1024];
while (nSize > 0) {
size_t now = std::min<size_t>(nSize, 1024);
read(data, now);
nSize -= now;
}
}

template<typename T>
CHashVerifier<Source>& operator>>(T& obj)
{
// Unserialize from this stream
::Unserialize(*this, obj);
return (*this);
}
};

/** Compute the 256-bit hash of an object's serialization. */
template <typename T>
uint256 SerializeHash(const T& obj, int nType = SER_GETHASH, int nVersion = PROTOCOL_VERSION)
Expand All @@ -272,6 +315,28 @@ unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char

void BIP32Hash(const ChainCode chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]);

/** SipHash-2-4 */
class CSipHasher
{
private:
uint64_t v[4];
uint64_t tmp;
int count;

public:
/** Construct a SipHash calculator initialized with 128-bit key (k0, k1) */
CSipHasher(uint64_t k0, uint64_t k1);
/** Hash a 64-bit integer worth of data
* It is treated as if this was the little-endian interpretation of 8 bytes.
* This function can only be used when a multiple of 8 bytes have been written so far.
*/
CSipHasher& Write(uint64_t data);
/** Hash arbitrary bytes. */
CSipHasher& Write(const unsigned char* data, size_t size);
/** Compute the 64-bit SipHash-2-4 of the data written so far. The object remains untouched. */
uint64_t Finalize() const;
};

//int HMAC_SHA512_Init(HMAC_SHA512_CTX *pctx, const void *pkey, size_t len);
//int HMAC_SHA512_Update(HMAC_SHA512_CTX *pctx, const void *pdata, size_t len);
//int HMAC_SHA512_Final(unsigned char *pmd, HMAC_SHA512_CTX *pctx);
Expand Down
9 changes: 6 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,13 @@ std::string LicenseInfo()
"\n";
}

static void BlockNotifyCallback(const uint256& hashNewTip)
static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex)
{
if (initialSync || !pBlockIndex)
return;
std::string strCmd = GetArg("-blocknotify", "");

boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
}

Expand Down Expand Up @@ -1583,8 +1585,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (!fLoaded && !fRequestShutdown) {
// first suggest a reindex
if (!fReset) {
bool fRet = uiInterface.ThreadSafeMessageBox(
bool fRet = uiInterface.ThreadSafeQuestion(
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?"),
strLoadError + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
Expand Down
45 changes: 36 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3715,6 +3715,28 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
return true;
}

static void NotifyHeaderTip() {
bool fNotify = false;
bool fInitialBlockDownload = false;
static CBlockIndex* pindexHeaderOld = NULL;
CBlockIndex* pindexHeader = NULL;
{
LOCK(cs_main);
if (!setBlockIndexCandidates.empty()) {
pindexHeader = *setBlockIndexCandidates.rbegin();
}
if (pindexHeader != pindexHeaderOld) {
fNotify = true;
fInitialBlockDownload = IsInitialBlockDownload();
pindexHeaderOld = pindexHeader;
}
}
// Send block tip changed notifications without cs_main
if (fNotify) {
uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
}
}

/**
* Make the best chain active, in multiple steps. The result is either failure
* or an activated best chain. pblock is either NULL or a pointer to a block
Expand Down Expand Up @@ -3761,21 +3783,22 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams,
// Relay inventory, but don't relay old inventory during initial block download.
int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints());
if (nLocalServices & NODE_NETWORK) {
vector<CNode*> vNodesCopy;
vector < CNode * > vNodesCopy;
{
LOCK(cs_vNodes);
vNodesCopy = vNodes;
}

for (CNode* pnode : vNodesCopy)
if (pnode && chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
for (CNode *pnode : vNodesCopy)
if (pnode && chainActive.Height() >
(pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
}
// Notify external listeners about the new tip.
uiInterface.NotifyBlockTip(hashNewTip);
}
} while (pindexMostWork != chainActive.Tip());
// Notify external listeners about the new tip.
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);

} while (pindexMostWork != chainActive.Tip());
CheckBlockIndex(chainparams.GetConsensus());

// Write changes periodically to disk, after relay.
Expand Down Expand Up @@ -5526,6 +5549,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
}

NotifyHeaderTip();
// Recursively process earlier encountered successors of this block
deque<uint256> queue;
queue.push_back(hash);
Expand All @@ -5540,8 +5564,9 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
hash = block.GetHash(usePhi2);
int nHeight = mapBlockIndex[hash] ? mapBlockIndex[hash]->nHeight : pindexPrev->nHeight;
if (ReadBlockFromDisk(block, it->second, nHeight, chainparams.GetConsensus())) {
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash(usePhi2).ToString(),
head.ToString());
LogPrintf("%s: Processing out of order child %s of %s\n", __func__,
block.GetHash(usePhi2).ToString(),
head.ToString());
CValidationState dummy;
if (ProcessNewBlock(dummy, chainparams, NULL, &block, &it->second)) {
nLoaded++;
Expand All @@ -5551,6 +5576,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
range.first++;
mapBlocksUnknownParent.erase(it);
}
NotifyHeaderTip();
}
} catch (std::exception& e) {
LogPrintf("%s : Deserialize or I/O error - %s", __func__, e.what());
Expand Down Expand Up @@ -6594,6 +6620,7 @@ static bool ProcessMessage(CNode* pfrom, const string &strCommand, CDataStream&
}

CheckBlockIndex(chainparams.GetConsensus());
NotifyHeaderTip();
}


Expand Down Expand Up @@ -7319,7 +7346,7 @@ class CMainCleanup


/////////////////////////////////////////////////////////////////////// lux
bool CheckSenderScript(const CCoinsViewCache& view, const CTransaction& tx){
bool CheckSenderScript(const CCoinsViewCache& view, const CTransaction& tx) {
CScript script = view.AccessCoins(tx.vin[0].prevout.hash)->vout[tx.vin[0].prevout.n].scriptPubKey;
if(!script.IsPayToPubkeyHash() && !script.IsPayToPubkey()){
return false;
Expand Down
7 changes: 7 additions & 0 deletions src/noui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ static bool noui_ThreadSafeMessageBox(const std::string& message, const std::str
return false;
}

static bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
{
return noui_ThreadSafeMessageBox(message, caption, style);
}


static void noui_InitMessage(const std::string& message)
{
LogPrintf("init message: %s\n", message);
Expand All @@ -50,5 +56,6 @@ void noui_connect()
{
// Connect luxd signal handlers
uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox);
uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion);
uiInterface.InitMessage.connect(noui_InitMessage);
}
Loading

0 comments on commit 4035ff1

Please sign in to comment.