Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic masternode functionalities #5

Merged
merged 12 commits into from
Dec 21, 2019
13 changes: 11 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ BITCOIN_CORE_H = \
dbwrapper.h \
limitedmap.h \
logging.h \
masternodes/masternodes.h \
masternodes/mn_checks.h \
masternodes/mn_txdb.h \
memusage.h \
merkleblock.h \
miner.h \
Expand All @@ -167,7 +170,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 @@ -275,6 +279,10 @@ libbitcoin_server_a_SOURCES = \
interfaces/node.cpp \
init.cpp \
dbwrapper.cpp \
masternodes/masternodes.cpp \
masternodes/mn_checks.cpp \
masternodes/mn_txdb.cpp \
masternodes/mn_rpc.cpp \
miner.cpp \
net.cpp \
net_processing.cpp \
Expand All @@ -286,7 +294,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
1 change: 1 addition & 0 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bench_bench_bitcoin_LDADD = \
$(LIBBITCOIN_MN) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
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