Skip to content

Commit

Permalink
Merge pull request #114 from enkayz/v2.5
Browse files Browse the repository at this point in the history
sync and ui improvements
  • Loading branch information
metaspartan authored Apr 20, 2018
2 parents 8aaa961 + 25136b4 commit 9ffd1b1
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 83 deletions.
89 changes: 46 additions & 43 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "uint256.h"


static const int nCheckpointSpan = 10;
static const int nCheckpointSpan = nCoinbaseMaturity * 2; // twice of coin maturity is a long enough chain

namespace Checkpoints
{
Expand All @@ -34,24 +34,38 @@ namespace Checkpoints
( 20000, uint256("0x00000000000420ca6af3e3e90066c806ac033ed963247adf566b7397122e2c8a") )
( 30000, uint256("0x000000000282bafc3e63bb0f86134329de9ff387d04764ad6a4ca700c47fbf7e") )
( 50000, uint256("0x00000000000b5e89366f583548f77c0e88476d6ff1ddd4b391d00ec7fd1d4bb3") )
( 75009, uint256("0x00000000004b4ca508c4006f9163b479b4c6599e5949140bca835da1ff1234fd") )
( 104999, uint256("0x0000000000116592035fde4848d187a48a67a37c2a8e3e6c12150e40121054d8") )
( 144999, uint256("0x00000000008509564a6a3fb42a9f9d77a93218e1c5738758cb6753fc03dee1ae") )
( 150001, uint256("0x00000000005aaad7814e1eb4ec9c2e33846078f80b45a99e3f37cb6c3b1e07bd") )
( 175503, uint256("0x0000000000f6e716fd9c763077337499fea706bf1012c6617991c0f0699e92fc") )
( 195500, uint256("0x00000000000125265e79f31c6aa19d2f5db5391d41416d4d44aa675dd205acfa") )
( 249999, uint256("0x0000000000200eaf8ce9cc5ebb5e623fac9da021c11fc8e5f7db91a74004a53d") )
( 260001, uint256("0x0000000000ac126bfc1d9d9af9b2bb6d5063e5f2d6144e3b0fae40e04ec350c2") )
( 271836, uint256("0x00000000004397a1b2c812695093c437667665337a3c11c652b616a1ee1efe89") )
( 280140, uint256("0x000000000026b26dc0bdd088e0cf7c86e845ae2c115170460e5440e092a75017") )
( 300000, uint256("0x0000000000b52718d9b5eab10aa7757a5d6f7b17bfd85c68cbb2f83f6577a5ed") )
( 320000, uint256("0x0000000000218a6999d1c922b7d4e04f79be3e1e90ec139789851651d5d8d39e") )
( 351430, uint256("0x0000000000901ce4a4cf6849515142cb2af344730f9fe16e77f456eb2bfccdc7") )
( 380001, uint256("0x0000000000b8d93082b7bca98042839dc5c57c059eaf81fad137db137115cb22") )
( 400000, uint256("0x00000000005d6a6ad52162db36954af6651a1edb8189f850116f7f8ec85f507b") )
( 440001, uint256("0x00000000000438fd4ee164c095d16ad8f8fd5a036f6d21a2ffd5e07309fe1132") )
( 480000, uint256("0x0000000000242586fe6aac7718830ae9a397aa8960b9fabd95b924d3cdfa183c") )
( 519998, uint256("0x00000000001da6bd8bac044f8d6a17d6d2aac59c49ea61556d35abc872bfdbfb") )
( 560007, uint256("0x0000000000025219f9002ca2529d58b89890c4e5c984d39653daf01cbb2dcf4f") )
( 584682, uint256("0x000000000007e848f9cba04a7ba99c9882ed377fecd36848d4e391f90dd739d2") )
( 600000, uint256("0x000000000003de26b4aaaf400c816e2bb2b2b75c16653e5428330f98438eb7ca") )
( 608581, uint256("0x000000000005b26af64dda3e172bef208342295fabfd916165211518eb7f8ad7") )
( 625114, uint256("0x000000000024290e8a2919d4b5ecb915892648df2f362d3136391e8b9f542a9c") )
( 636115, uint256("0x000000000002e90ba8bd7737b206c75a48cafef514e640b7c03753e93fb5fffe") )
( 640042, uint256("0x000000000010014c70f1eef2e6a0599b4c05f19e3dc0510758c684eaec513a28") )
( 641361, uint256("0x000000000005e6b7e106ce402511a64b239b5668e3599fb9e71dd75c16528033") )
( 654900, uint256("0x000000000003200e2a80124060eab0f846671ec542cfa8f19f1bf4ad9501ad3e") )
( 695732, uint256("0x000000000039800dffda8f76c6fc46db0e0fc585274d34d3377058a7ae4be093") )
( 705320, uint256("0x00000000002759fa23cc4e06f8356086bb842f8083be877c246ea44ca9cb5fad") )
( 715006, uint256("0x000000000040fcb3164c963fb3031f8d73b519d3f181dde0fbd1c00280a9202f") )
( 735000, uint256("0x000000000026ee4128cd6cc718bcd6e346e83be573cbc1bd7aba846e4f843939") )
( 755516, uint256("0x00000000000a4c4951f38632c593cdd6c12fc3df3f8eb483f97cb6152589fbdb") )
;

// TestNet has no checkpoints
Expand Down Expand Up @@ -211,61 +225,50 @@ namespace Checkpoints
return false;
}

/*

// Automatically select a suitable sync-checkpoint
uint256 AutoSelectSyncCheckpoint()
const CBlockIndex* AutoSelectSyncCheckpoint()
{
const CBlockIndex *pindex = pindexBest;
// Search backward for a block within max span and maturity window
while (pindex->pprev && (pindex->GetBlockTime() + nCheckpointSpan * nTargetSpacing > pindexBest->GetBlockTime() || pindex->nHeight + nCheckpointSpan > pindexBest->nHeight))
pindex = pindex->pprev;
return pindex->GetBlockHash();
return pindex;
}
// Check against synchronized checkpoint

// Check the chain this block is going to attach to is valid past maturity
bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev)
{
if (fTestNet) return true; // Testnet has no checkpoints
int nHeight = pindexPrev->nHeight + 1;
if (IsInitialBlockDownload()) { // Do a basic check if we are catching up
const CBlockIndex* pindexSync = AutoSelectSyncCheckpoint();
if (nHeight <= pindexSync->nHeight){
return false; // lower height than auto checkpoint
}
return true;
} else { // do a more thorough check when we are already synced
LOCK(cs_hashSyncCheckpoint);
// sync-checkpoint should always be accepted block
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];

LOCK(cs_hashSyncCheckpoint);
// sync-checkpoint should always be accepted block
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
if (nHeight > pindexSync->nHeight)
{
// trace back to same height as sync-checkpoint
const CBlockIndex* pindex = pindexPrev;
while (pindex->nHeight > pindexSync->nHeight)
if (!(pindex = pindex->pprev))
return error("CheckSync: pprev null - block index structure failure");
if (pindex->nHeight < pindexSync->nHeight || pindex->GetBlockHash() != hashSyncCheckpoint)
return false; // only descendant of sync-checkpoint can pass check
}
if (nHeight == pindexSync->nHeight && hashBlock != hashSyncCheckpoint)
return false; // same height with sync-checkpoint
if (nHeight < pindexSync->nHeight && !mapBlockIndex.count(hashBlock))
return false; // lower height than sync-checkpoint
return true;
}
*/
// Automatically select a suitable sync-checkpoint
const CBlockIndex* AutoSelectSyncCheckpoint()
{
const CBlockIndex *pindex = pindexBest;
// Search backward for a block within max span and maturity window
while (pindex->pprev && pindex->nHeight + nCheckpointSpan > pindexBest->nHeight)
pindex = pindex->pprev;
return pindex;
}

bool CheckSync(int nHeight)
{
const CBlockIndex* pindexSync = AutoSelectSyncCheckpoint();
if (nHeight <= pindexSync->nHeight){
return false;
if (nHeight > pindexSync->nHeight)
{
// trace back to same height as sync-checkpoint
const CBlockIndex* pindex = pindexPrev;
while (pindex->nHeight > pindexSync->nHeight)
if (!(pindex = pindex->pprev))
return error("CheckSync: pprev null - block index structure failure");
if (pindex->nHeight < pindexSync->nHeight || pindex->GetBlockHash() != hashSyncCheckpoint)
return false; // only descendant of sync-checkpoint can pass check
}
if (nHeight == pindexSync->nHeight && hashBlock != hashSyncCheckpoint)
return false; // same height with sync-checkpoint
if (nHeight < pindexSync->nHeight && !mapBlockIndex.count(hashBlock))
return false; // lower height than sync-checkpoint
return true;
}
return true;
}

bool WantedByPendingSyncCheckpoint(uint256 hashBlock)
Expand Down
4 changes: 1 addition & 3 deletions src/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ namespace Checkpoints
CBlockIndex* GetLastSyncCheckpoint();
bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
bool AcceptPendingSyncCheckpoint();
//uint256 AutoSelectSyncCheckpoint();
//bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
const CBlockIndex* AutoSelectSyncCheckpoint();
bool CheckSync(int nHeight);
bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
bool ResetSyncCheckpoint();
void AskForPendingSyncCheckpoint(CNode* pfrom);
Expand Down
13 changes: 6 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct CMainSignals {
boost::signals2::signal<void (const uint256 &)> Inventory;
// Tells listeners to broadcast their data.
boost::signals2::signal<void (bool)> Broadcast;

} g_signals;
}

Expand Down Expand Up @@ -1445,7 +1446,6 @@ int GetNumBlocksOfPeers()

bool IsInitialBlockDownload()
{
LOCK(cs_main);
if (pindexBest == NULL || nBestHeight < Checkpoints::GetTotalBlocksEstimate())
return true;
static int64_t nLastUpdate;
Expand All @@ -1456,7 +1456,7 @@ bool IsInitialBlockDownload()
nLastUpdate = GetTime();
}
return (GetTime() - nLastUpdate < 15 &&
pindexBest->GetBlockTime() < GetTime() - 8 * 60 * 60);
pindexBest->GetBlockTime() < GetTime() - 2 * 60 * 60);
}

void static InvalidChainFound(CBlockIndex* pindexNew)
Expand All @@ -1465,7 +1465,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
{
nBestInvalidTrust = pindexNew->nChainTrust;
CTxDB().WriteBestInvalidTrust(CBigNum(nBestInvalidTrust));
uiInterface.NotifyBlocksChanged();
uiInterface.NotifyBlocksChanged(pindexBest->nHeight, GetNumBlocksOfPeers());
}

uint256 nBestInvalidBlockTrust = pindexNew->nChainTrust - pindexNew->pprev->nChainTrust;
Expand Down Expand Up @@ -2642,7 +2642,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos, const u
hashPrevBestCoinBase = vtx[0].GetHash();
}

uiInterface.NotifyBlocksChanged();
uiInterface.NotifyBlocksChanged(pindexNew->nHeight, GetNumBlocksOfPeers());
return true;
}

Expand Down Expand Up @@ -2795,8 +2795,7 @@ bool CBlock::AcceptBlock()
hashProof = GetPoWHash();
}

// bool cpSatisfies = Checkpoints::CheckSync(hash, pindexPrev);
bool cpSatisfies = Checkpoints::CheckSync(nHeight);
bool cpSatisfies = Checkpoints::CheckSync(hash, pindexPrev);

// Check that the block satisfies synchronized checkpoint
if (CheckpointsMode == Checkpoints::STRICT && !cpSatisfies)
Expand Down Expand Up @@ -4622,7 +4621,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
pto->PushMessage("getdata", vGetData);

if (fSecMsgEnabled)
SecureMsgSendData(pto, fSendTrickle); // should be in cs_main?
SecureMsgSendData(pto, fSendTrickle);
}


Expand Down
13 changes: 7 additions & 6 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1318,14 +1318,15 @@ void MapPort()
// The second name should resolve to a list of seed addresses.

static const char *strDNSSeed[][2] = {
{"seed.denariusexplorer.org", "seed.denariusexplorer.org"},
{"107.181.154.106", "107.181.154.106"},
{"chainz.cryptoid.info", "chainz.cryptoid.info"},
{"hashbag.cc", "hashbag.cc"},
{"dnsseed.hashbag.cc", "dnsseed.hashbag.cc"},
{"denarius.name", "denarius.name"},
{"seed.denarius.host", "seed.denarius.host"},
{"seed.denariusexplorer.org", "seed.denariusexplorer.org"},
{"seed.yiimp.eu", "seed.yiimp.eu"},
{"seed.denarius.host", "seed.denarius.host"}
{"chainz.cryptoid.info", "chainz.cryptoid.info"},
{"seed1.denarius.io", "seed1.denarius.io"},
{"seed2.denarius.io", "seed2.denarius.io"},
{"seed3.denarius.io", "seed3.denarius.io"},
{"seed4.denarius.io", "seed4.denarius.io"}
};

void ThreadDNSAddressSeed(void* parg)
Expand Down
59 changes: 51 additions & 8 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
rpcConsole(0),
nWeight(0),
prevBlocks(0),
spinnerFrame(0)
spinnerFrame(0),
nBlocksInLastPeriod(0),
nLastBlocks(0)
{
resize(1300, 400);
setWindowTitle(tr("Denarius") + " - " + tr("Wallet"));
Expand Down Expand Up @@ -175,7 +177,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
overviewPage = new OverviewPage();
statisticsPage = new StatisticsPage(this);
blockBrowser = new BlockBrowser(this);
marketBrowser = new MarketBrowser(this);
marketBrowser = new MarketBrowser(this);
multisigPage = new MultisigDialog(this);
proofOfImagePage = new ProofOfImage(this);
//chatWindow = new ChatWindow(this);
Expand Down Expand Up @@ -495,7 +497,7 @@ void BitcoinGUI::createMenuBar()

QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
settings->addAction(encryptWalletAction);
settings->addAction(backupWalletAction);
settings->addAction(backupWalletAction);
settings->addAction(changePassphraseAction);
settings->addAction(unlockWalletAction);
settings->addAction(lockWalletAction);
Expand Down Expand Up @@ -524,13 +526,13 @@ void BitcoinGUI::createToolBars()
mainIcon->show();

mainToolbar = addToolBar(tr("Tabs toolbar"));
mainToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mainToolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
mainToolbar->addWidget(mainIcon);
mainToolbar->addAction(overviewAction);
mainToolbar->addAction(sendCoinsAction);
mainToolbar->addAction(receiveCoinsAction);
mainToolbar->addAction(historyAction);
mainToolbar->addAction(mintingAction);
mainToolbar->addAction(mintingAction);
mainToolbar->addAction(addressBookAction);
mainToolbar->addAction(messageAction);
mainToolbar->addAction(statisticsAction);
Expand All @@ -542,6 +544,18 @@ void BitcoinGUI::createToolBars()
secondaryToolbar = addToolBar(tr("Actions toolbar"));
secondaryToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
secondaryToolbar->addAction(exportAction);
secondaryToolbar->addSeparator();
secondaryToolbar->addAction(openRPCConsoleAction);
secondaryToolbar->addAction(openGraphAction);
secondaryToolbar->addSeparator();
secondaryToolbar->addAction(lockWalletAction);
secondaryToolbar->addAction(unlockWalletAction);
secondaryToolbar->addAction(encryptWalletAction);
secondaryToolbar->addAction(changePassphraseAction);
secondaryToolbar->addSeparator();
removeToolBar(secondaryToolbar);
addToolBar(Qt::BottomToolBarArea, secondaryToolbar);
secondaryToolbar->show();

connect(mainToolbar, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(mainToolbarOrientation(Qt::Orientation)));
connect(secondaryToolbar, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(secondaryToolbarOrientation(Qt::Orientation)));
Expand Down Expand Up @@ -594,6 +608,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
setNumConnections(clientModel->getNumConnections());
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));


nClientUpdateTime = GetTime();
setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));

Expand All @@ -604,6 +620,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
addressBookPage->setOptionsModel(clientModel->getOptionsModel());
receiveCoinsPage->setOptionsModel(clientModel->getOptionsModel());
}

}

void BitcoinGUI::setWalletModel(WalletModel *walletModel)
Expand Down Expand Up @@ -754,6 +771,24 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)

QString strStatusBarWarnings = clientModel->getStatusBarWarnings();
QString tooltip;
QString nRemainingTime;

if (nLastBlocks == 0)
nLastBlocks = pindexBest->nHeight;

if (count > nLastBlocks && GetTime() - nClientUpdateTime > BPS_PERIOD) {
nBlocksInLastPeriod = count - nLastBlocks;
nLastBlocks = count;
nClientUpdateTime = GetTime();
}
if (nBlocksInLastPeriod>0)
nBlocksPerSec = nBlocksInLastPeriod / BPS_PERIOD;
else
nBlocksPerSec = 0;

if (nBlocksPerSec>0) {
nRemainingTime = QDateTime::fromTime_t((nTotalBlocks - count) / nBlocksPerSec).toUTC().toString("hh'h'mm'm'");
}

QDateTime lastBlockDate = clientModel->getLastBlockDate();
int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
Expand Down Expand Up @@ -785,12 +820,14 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
{
int nRemainingBlocks = nTotalBlocks - count;
float nPercentageDone = count / (nTotalBlocks * 0.01f);

if (strStatusBarWarnings.isEmpty())
{
progressBarLabel->setText(tr("Synchronizing with network..."));
progressBarLabel->setVisible(true);
progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
if (nBlocksPerSec>0)
progressBar->setFormat(tr("~%1 block(s) remaining (est: %2 at %3 blocks/sec)").arg(nRemainingBlocks).arg(nRemainingTime).arg(nBlocksPerSec));
else
progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
progressBar->setMaximum(nTotalBlocks);
progressBar->setValue(count);
progressBar->setVisible(true);
Expand Down Expand Up @@ -1207,20 +1244,26 @@ void BitcoinGUI::handleURI(QString strURI)
notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid Denarius address or malformed URI parameters."));
}


void BitcoinGUI::mainToolbarOrientation(Qt::Orientation orientation)
{


if(orientation == Qt::Horizontal)
{
mainIcon->setPixmap(QPixmap(":images/horizontal"));
mainIcon->setAlignment(Qt::AlignLeft);
mainIcon->show();
mainToolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
mainToolbar->setStyleSheet(HORIZONTAL_TOOLBAR_STYLESHEET);
messageAction->setIconText(tr("&Messages"));
}
else
{
mainIcon->setPixmap(QPixmap(":images/vertical"));
mainIcon->setAlignment(Qt::AlignCenter);
mainIcon->show();

mainToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mainToolbar->setStyleSheet(VERTICAL_TOOBAR_STYLESHEET);
messageAction->setIconText(tr("Encrypted &Messages"));
}
Expand Down
Loading

0 comments on commit 9ffd1b1

Please sign in to comment.