Skip to content

Commit

Permalink
Add Sidechain half of Drivechains & BMM (#2)
Browse files Browse the repository at this point in the history
* Add updated SCDB, remove subsidy, add GUI elements

* Remove old SCDB files

* Remove unused script operator

* Update sidechain database

* Update validation and miner

* Update sidechain page

* Update sidechain client

* Remove unused

* Pushing some initial work on BMM

- Removed PoW files
- Added BMM files
- Added BMM based chain activation code
- Modified block header for BMM
- h* validation

* Update sidechain client

- Added validate critical hash (h*) call

* Remove unused PoW related rpc calls

* Add BMM tab to sidechain page

* BMM update
  • Loading branch information
CryptAxe committed May 22, 2017
1 parent d978c41 commit 981b0ce
Show file tree
Hide file tree
Showing 57 changed files with 2,759 additions and 2,181 deletions.
8 changes: 6 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ BITCOIN_CORE_H = \
base58.h \
bloom.h \
blockencodings.h \
bmm.h \
chain.h \
chainparams.h \
chainparamsbase.h \
Expand Down Expand Up @@ -118,7 +119,6 @@ BITCOIN_CORE_H = \
policy/fees.h \
policy/policy.h \
policy/rbf.h \
pow.h \
protocol.h \
random.h \
reverselock.h \
Expand All @@ -137,6 +137,7 @@ BITCOIN_CORE_H = \
support/cleanse.h \
support/events.h \
support/lockedpool.h \
sidechainclient.h \
sync.h \
threadsafety.h \
threadinterrupt.h \
Expand Down Expand Up @@ -179,6 +180,7 @@ libbitcoin_server_a_SOURCES = \
addrdb.cpp \
bloom.cpp \
blockencodings.cpp \
bmm.cpp \
chain.cpp \
checkpoints.cpp \
httprpc.cpp \
Expand All @@ -192,7 +194,6 @@ libbitcoin_server_a_SOURCES = \
noui.cpp \
policy/fees.cpp \
policy/policy.cpp \
pow.cpp \
rest.cpp \
rpc/blockchain.cpp \
rpc/mining.cpp \
Expand All @@ -202,6 +203,7 @@ libbitcoin_server_a_SOURCES = \
rpc/server.cpp \
script/sigcache.cpp \
script/ismine.cpp \
sidechainclient.cpp \
timedata.cpp \
torcontrol.cpp \
txdb.cpp \
Expand Down Expand Up @@ -272,6 +274,8 @@ libbitcoin_consensus_a_SOURCES = \
prevector.h \
primitives/block.cpp \
primitives/block.h \
primitives/sidechain.cpp \
primitives/sidechain.h \
primitives/transaction.cpp \
primitives/transaction.h \
pubkey.cpp \
Expand Down
9 changes: 8 additions & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ QT_FORMS_UI = \
qt/forms/debugwindow.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
qt/forms/sidechainpage.ui \
qt/forms/signverifymessagedialog.ui \
qt/forms/transactiondescdialog.ui

Expand Down Expand Up @@ -147,6 +148,8 @@ QT_MOC_CPP = \
qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \
qt/moc_sidechainhistorytablemodel.cpp \
qt/moc_sidechainpage.cpp \
qt/moc_signverifymessagedialog.cpp \
qt/moc_splashscreen.cpp \
qt/moc_trafficgraphwidget.cpp \
Expand Down Expand Up @@ -218,6 +221,8 @@ BITCOIN_QT_H = \
qt/rpcconsole.h \
qt/sendcoinsdialog.h \
qt/sendcoinsentry.h \
qt/sidechainhistorytablemodel.h \
qt/sidechainpage.h \
qt/signverifymessagedialog.h \
qt/splashscreen.h \
qt/trafficgraphwidget.h \
Expand Down Expand Up @@ -333,6 +338,8 @@ BITCOIN_QT_WALLET_CPP = \
qt/recentrequeststablemodel.cpp \
qt/sendcoinsdialog.cpp \
qt/sendcoinsentry.cpp \
qt/sidechainhistorytablemodel.cpp \
qt/sidechainpage.cpp \
qt/signverifymessagedialog.cpp \
qt/transactiondesc.cpp \
qt/transactiondescdialog.cpp \
Expand All @@ -353,7 +360,7 @@ if ENABLE_WALLET
BITCOIN_QT_CPP += $(BITCOIN_QT_WALLET_CPP)
endif

RES_IMAGES =
RES_IMAGES =

RES_MOVIES = $(wildcard $(srcdir)/qt/res/movies/spinner-*.png)

Expand Down
34 changes: 34 additions & 0 deletions src/bmm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "bmm.h"

#include "primitives/block.h"

BMM::BMM()
{

}

bool BMM::StoreBMMBlock(const CBlock& block)
{
if (!block.vtx.size())
return false;

uint256 hashBlock = block.GetHash();

// Already have block stored
if (mapBMMBlocks.find(hashBlock) != mapBMMBlocks.end())
return false;

mapBMMBlocks[hashBlock] = block;

return true;
}

bool BMM::GetBMMBlock(const uint256& hashBlock, CBlock& block)
{
if (mapBMMBlocks.find(hashBlock) == mapBMMBlocks.end())
return false;

block = mapBMMBlocks[hashBlock];

return true;
}
23 changes: 23 additions & 0 deletions src/bmm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef BITCOIN_BMM_H
#define BITCOIN_BMM_H

#include "uint256.h"

#include <map>

class CBlock;

class BMM
{
public:
BMM();

bool StoreBMMBlock(const CBlock& block);

bool GetBMMBlock(const uint256& hashBlock, CBlock& block);

private:
std::map<uint256, CBlock> mapBMMBlocks;
};

#endif // BITCOIN_BMM_H
32 changes: 0 additions & 32 deletions src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,35 +116,3 @@ void CBlockIndex::BuildSkip()
if (pprev)
pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
}

arith_uint256 GetBlockProof(const CBlockIndex& block)
{
arith_uint256 bnTarget;
bool fNegative;
bool fOverflow;
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
if (fNegative || fOverflow || bnTarget == 0)
return 0;
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
// as it's too large for a arith_uint256. However, as 2**256 is at least as large
// as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
// or ~bnTarget / (nTarget+1) + 1.
return (~bnTarget / (bnTarget + 1)) + 1;
}

int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params)
{
arith_uint256 r;
int sign = 1;
if (to.nChainWork > from.nChainWork) {
r = to.nChainWork - from.nChainWork;
} else {
r = from.nChainWork - to.nChainWork;
sign = -1;
}
r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
if (r.bits() > 63) {
return sign * std::numeric_limits<int64_t>::max();
}
return sign * r.GetLow64();
}
45 changes: 21 additions & 24 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "arith_uint256.h"
#include "primitives/block.h"
#include "pow.h"
#include "tinyformat.h"
#include "uint256.h"

Expand Down Expand Up @@ -177,9 +176,6 @@ class CBlockIndex
//! Byte offset within rev?????.dat where this block's undo data is stored
unsigned int nUndoPos;

//! (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
arith_uint256 nChainWork;

//! Number of transactions in this block.
//! Note: in a potential headers-first mode, this number cannot be relied upon
unsigned int nTx;
Expand All @@ -196,8 +192,9 @@ class CBlockIndex
int nVersion;
uint256 hashMerkleRoot;
unsigned int nTime;
unsigned int nBits;
unsigned int nNonce;
std::string criticalProof;
CMutableTransaction txCritical;

//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
int32_t nSequenceId;
Expand All @@ -214,18 +211,19 @@ class CBlockIndex
nFile = 0;
nDataPos = 0;
nUndoPos = 0;
nChainWork = arith_uint256();
nTx = 0;
nChainTx = 0;
nStatus = 0;
nSequenceId = 0;
nTimeMax = 0;

nVersion = 0;
hashMerkleRoot = uint256();
nTime = 0;
nBits = 0;
nNonce = 0;
nVersion = 0;
hashMerkleRoot = uint256();
nTime = 0;
nNonce = 0;

criticalProof = "";
txCritical = CMutableTransaction();
}

CBlockIndex()
Expand All @@ -237,11 +235,12 @@ class CBlockIndex
{
SetNull();

nVersion = block.nVersion;
hashMerkleRoot = block.hashMerkleRoot;
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
nVersion = block.nVersion;
hashMerkleRoot = block.hashMerkleRoot;
nTime = block.nTime;
nNonce = block.nNonce;
criticalProof = block.criticalProof;
txCritical = block.txCritical;
}

CDiskBlockPos GetBlockPos() const {
Expand Down Expand Up @@ -270,8 +269,9 @@ class CBlockIndex
block.hashPrevBlock = pprev->GetBlockHash();
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
block.criticalProof = criticalProof;
block.txCritical = txCritical;
return block;
}

Expand Down Expand Up @@ -345,10 +345,6 @@ class CBlockIndex
const CBlockIndex* GetAncestor(int height) const;
};

arith_uint256 GetBlockProof(const CBlockIndex& block);
/** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */
int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params&);

/** Used to marshal pointers into hashes for db storage. */
class CDiskBlockIndex : public CBlockIndex
{
Expand Down Expand Up @@ -386,8 +382,9 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
READWRITE(criticalProof);
READWRITE(txCritical);
}

uint256 GetBlockHash() const
Expand All @@ -397,12 +394,12 @@ class CDiskBlockIndex : public CBlockIndex
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
block.criticalProof = criticalProof;
block.txCritical = txCritical;
return block.GetHash();
}


std::string ToString() const
{
std::string str = "CDiskBlockIndex(";
Expand Down

0 comments on commit 981b0ce

Please sign in to comment.