Skip to content

Commit

Permalink
Merge pull request #4 from DeFiCh/POS-staking
Browse files Browse the repository at this point in the history
PoS solution search
  • Loading branch information
uzyn authored Dec 21, 2019
2 parents 021bb9f + 4d7c2c7 commit a2d3b60
Show file tree
Hide file tree
Showing 67 changed files with 997 additions and 338 deletions.
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ BITCOIN_CORE_H = \
policy/policy.h \
policy/rbf.h \
policy/settings.h \
pow.h \
pos.h \
pos_kernel.h \
protocol.h \
psbt.h \
random.h \
Expand Down Expand Up @@ -286,7 +287,8 @@ libbitcoin_server_a_SOURCES = \
policy/fees.cpp \
policy/rbf.cpp \
policy/settings.cpp \
pow.cpp \
pos.cpp \
pos_kernel.cpp \
rest.cpp \
rpc/blockchain.cpp \
rpc/mining.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const CAmount COIN = 100000000;
/** No amount larger than this (in satoshi) is valid.
*
* Note that this constant is *not* the total money supply, which in Bitcoin
* currently happens to be less than 21,000,000 BTC for various reasons, but
* currently happens to be less than 21,000,000 DFI for various reasons, but
* rather a sanity check. As this sanity check is used by consensus-critical
* validation code, the exact value of the MAX_MONEY constant is consensus
* critical; in unusual circumstances like a(nother) overflow bug that allowed
Expand Down
6 changes: 3 additions & 3 deletions src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <coins.h>
#include <consensus/merkle.h>
#include <consensus/validation.h>
#include <pow.h>
#include <pos.h>
#include <txmempool.h>
#include <validation.h>

Expand All @@ -28,8 +28,8 @@ static void DuplicateInputs(benchmark::State& state)
LOCK(cs_main);
CBlockIndex* pindexPrev = ::ChainActive().Tip();
assert(pindexPrev != nullptr);
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
block.nNonce = 0;
block.nBits = pos::GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus().pos);
// block.nNonce = 0;
auto nHeight = pindexPrev->nHeight + 1;

// Make a coinbase TX
Expand Down
2 changes: 1 addition & 1 deletion src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& fr
r = from.nChainWork - to.nChainWork;
sign = -1;
}
r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
r = r * arith_uint256(params.pos.nTargetSpacing) / GetBlockProof(tip);
if (r.bits() > 63) {
return sign * std::numeric_limits<int64_t>::max();
}
Expand Down
39 changes: 32 additions & 7 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include <consensus/params.h>
#include <flatfile.h>
#include <primitives/block.h>
#include <streams.h>
#include <tinyformat.h>
#include <uint256.h>

#include <vector>
#include <boost/optional.hpp>

/**
* Maximum amount of time that a block timestamp is allowed to exceed the
Expand Down Expand Up @@ -180,7 +182,13 @@ class CBlockIndex
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;

// proof-of-stake specific fields
uint64_t height;
uint64_t mintedBlocks;
uint256 stakeModifier; // hash modifier for proof-of-stake
std::vector<unsigned char> sig;
CKeyID minter; // memory only

//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
int32_t nSequenceId;
Expand Down Expand Up @@ -208,7 +216,10 @@ class CBlockIndex
hashMerkleRoot = uint256();
nTime = 0;
nBits = 0;
nNonce = 0;
stakeModifier = uint256{};
height = 0;
mintedBlocks = 0;
sig = {};
}

CBlockIndex()
Expand All @@ -224,7 +235,10 @@ class CBlockIndex
hashMerkleRoot = block.hashMerkleRoot;
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
height = block.height;
mintedBlocks = block.mintedBlocks;
stakeModifier = block.stakeModifier;
sig = block.sig;
}

FlatFilePos GetBlockPos() const {
Expand Down Expand Up @@ -254,7 +268,10 @@ class CBlockIndex
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
block.stakeModifier = stakeModifier;
block.height = height;
block.mintedBlocks = mintedBlocks;
block.sig = sig;
return block;
}

Expand Down Expand Up @@ -300,8 +317,9 @@ class CBlockIndex

std::string ToString() const
{
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, stakeModifier=(%s), merkle=%s, hashBlock=%s)",
pprev, nHeight,
stakeModifier.ToString(),
hashMerkleRoot.ToString(),
GetBlockHash().ToString());
}
Expand Down Expand Up @@ -382,7 +400,10 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
READWRITE(stakeModifier);
READWRITE(height);
READWRITE(mintedBlocks);
READWRITE(sig);
}

uint256 GetBlockHash() const
Expand All @@ -393,7 +414,11 @@ class CDiskBlockIndex : public CBlockIndex
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
block.stakeModifier = stakeModifier;
block.height = height;
block.mintedBlocks = mintedBlocks;
block.sig = sig;

return block.GetHash();
}

Expand Down
Loading

0 comments on commit a2d3b60

Please sign in to comment.