Skip to content

Commit

Permalink
Merged in generate-pos-1 (pull request #4)
Browse files Browse the repository at this point in the history
Generate POS blocks using RPC

Approved-by: Cevap
  • Loading branch information
FornaxA authored and Cevap committed Dec 24, 2019
2 parents 02401f6 + e911df2 commit 4bdaa61
Show file tree
Hide file tree
Showing 34 changed files with 707 additions and 102 deletions.
4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ BITCOIN_CORE_H = \
pos/checks.h \
pos/kernel.h \
pos/stakeinput.h \
pos/staker.h \
pos/staking-manager.h \
pow.h \
protocol.h \
random.h \
Expand Down Expand Up @@ -410,6 +412,8 @@ libion_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libion_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libion_wallet_a_SOURCES = \
keepass.cpp \
pos/staker.cpp \
pos/staking-manager.cpp \
privatesend/privatesend-client.cpp \
privatesend/privatesend-util.cpp \
tokens/rpctokens.cpp \
Expand Down
136 changes: 98 additions & 38 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ class CMainParams : public CChainParams {
consensus.DIP0003EnforcementHeight = 99999999;
consensus.DIP0003EnforcementHash = uint256S("000000000000002d1734087b4c5afc3133e4e1c3e1a89218f62bcd9bb3d17f81");
consensus.IIP0006Height = 1510000;
consensus.POSStartHeight = 1001;
consensus.MidasStartHeight = 176500;
consensus.DGWStartHeight = 550000;
consensus.DGWStartTime = 1521851265;
consensus.ATPStartHeight = 1320000; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.powLimit = uint256S("000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 24
consensus.nPowTargetTimespan = 24 * 60 * 60; // Ion: 1 day
consensus.nPowTargetSpacing = 2.5 * 60; // Ion: 2.5 minutes
Expand All @@ -289,11 +284,20 @@ class CMainParams : public CChainParams {
consensus.nPowDGWHeight = 99999999;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
// ION
consensus.nCoinbaseMaturity = 60;
// POS
consensus.POSStartHeight = 1001;
consensus.MidasStartHeight = 176500;
consensus.DGWStartHeight = 550000;
consensus.DGWDifficultyStartHeight = 550000;
consensus.DGWStartTime = 1521851265;
consensus.posLimit = uint256S("000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 24
consensus.nPosTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
consensus.nPosTargetSpacingMidas = 64;
consensus.nPosTargetSpacing = 1 * 60; // 1 minute
consensus.nStakeMinDepth = 600;
// Zerocoin
consensus.nZerocoinRequiredStakeDepth = 200;
consensus.nZerocoinStartHeight = 550001;
consensus.nZerocoinStartTime = 1521851265; // GMT: Saturday, March 24, 2018 12:27:45 AM
Expand All @@ -311,8 +315,11 @@ class CMainParams : public CChainParams {
"31438167899885040445364023527381951378636564391212010397122822120720357";

// ATP
consensus.ATPStartHeight = 1320000; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.strTokenManagementKey = "inqaYuaES1cmRBXHodp25UceeVPbWQG5wY";
consensus.nOpGroupNewRequiredConfirmations = 1;
// POSPOW
consensus.POSPOWStartHeight = std::numeric_limits<int>::max();

consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
Expand Down Expand Up @@ -482,31 +489,45 @@ class CTestNetParams : public CChainParams {
consensus.BIP65Height = 2431; // 0000039cf01242c7f921dcb4806a5994bc003b48c1973ae0c89b67809c2bb2ab
consensus.BIP66Height = 2075; // 0000002acdd29a14583540cb72e1c5cc83783560e38fa7081495d474fe1671f7
consensus.DIP0001Height = 2;
consensus.DIP0003Height = 7000;
consensus.DIP0003EnforcementHeight = 7300;
consensus.DIP0003Height = 99999999;
consensus.DIP0003EnforcementHeight = 99999999;
consensus.DIP0003EnforcementHash = uint256S("00000055ebc0e974ba3a3fb785c5ad4365a39637d4df168169ee80d313612f8f");
consensus.IIP0006Height = 90000;
consensus.POSStartHeight = 250;
consensus.MidasStartHeight = 999999999;
consensus.DGWStartHeight = 300;
consensus.DGWStartTime = 1554332940;
consensus.ATPStartHeight = 5530; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.IIP0006Height = 99999999;
consensus.powLimit = uint256S("3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 2
consensus.nPowTargetTimespan = 24 * 60 * 60; // Ion: 1 day
consensus.nPowTargetSpacing = 2.5 * 60; // Ion: 2.5 minutes
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nPowKGWHeight = 4002; // nPowKGWHeight >= nPowDGWHeight means "no KGW"
consensus.nPowDGWHeight = 4002;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// ION
consensus.nCoinbaseMaturity = 15;
// POS
consensus.POSStartHeight = 203;
consensus.MidasStartHeight = 0;
consensus.DGWStartHeight = 300;
consensus.DGWDifficultyStartHeight = 0;
consensus.DGWStartTime = 1554332940;
consensus.posLimit = uint256S("000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 24
consensus.nPosTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
consensus.nPosTargetSpacingMidas = 64;
consensus.nPosTargetSpacing = 1 * 60; // 1 minute
consensus.nStakeMinDepth = 100;
// Zerocoin
consensus.nZerocoinRequiredStakeDepth = 200;
consensus.nZerocoinStartHeight = 300;
consensus.nZerocoinStartTime = 1501776000;
consensus.nBlockZerocoinV2 = 301;
consensus.nBlockZerocoinV2 = 1012710;
consensus.nPublicZCSpends = 5500;
consensus.nBlockStakeModifierV2 = 1214000;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.nBlockStakeModifierV2 = 5530;
consensus.nFakeSerialBlockheightEnd = -1;
consensus.nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
consensus.nRequiredAccumulation = 1;
consensus.zerocoinModulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
Expand All @@ -519,8 +540,11 @@ class CTestNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008

// ATP
consensus.ATPStartHeight = 5530; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.strTokenManagementKey = "gBi3gDLnGfw8HA2rN4HmNxHk9hMC4GLFbh";
consensus.nOpGroupNewRequiredConfirmations = 1;
// POSPOW
consensus.POSPOWStartHeight = std::numeric_limits<int>::max();

// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
Expand Down Expand Up @@ -614,7 +638,7 @@ class CTestNetParams : public CChainParams {
nPoolMaxParticipants = 5;
nFulfilledRequestExpireTime = 5*60; // fulfilled requests expire in 5 minutes

vSporkAddresses = {"gRgAY9dX7kN3tLNeVPQ8YoVGJdeNiE2Ubr"};
vSporkAddresses = {"gPp4w9xaDFjsiQ4KhTT5K9ATo8CVNhT7G2"};
nMinSporkKeys = 1;
fBIP9CheckMasternodesUpgraded = true;

Expand Down Expand Up @@ -666,12 +690,7 @@ class CDevNetParams : public CChainParams {
consensus.DIP0003Height = 2; // DIP0003 activated immediately on devnet
consensus.DIP0003EnforcementHeight = 2; // DIP0003 activated immediately on devnet
consensus.DIP0003EnforcementHash = uint256();
consensus.IIP0006Height = 10; // IIP0006 activated immediately on devnet
consensus.POSStartHeight = 250;
consensus.MidasStartHeight = 999999999;
consensus.DGWStartHeight = 10;
consensus.DGWStartTime = 1554332940;
consensus.ATPStartHeight = 10; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.IIP0006Height = 1; // IIP0006 activated immediately on devnet
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 1
consensus.nPowTargetTimespan = 24 * 60 * 60; // Ion: 1 day
consensus.nPowTargetSpacing = 2.5 * 60; // Ion: 2.5 minutes
Expand All @@ -684,6 +703,29 @@ class CDevNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// ION
consensus.nCoinbaseMaturity = 15;
// POS
consensus.POSStartHeight = 250;
consensus.MidasStartHeight = 999999999;
consensus.DGWStartHeight = 300;
consensus.DGWDifficultyStartHeight = 300;
consensus.DGWStartTime = 1554332940;
consensus.posLimit = uint256S("000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 24
consensus.nPosTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
consensus.nPosTargetSpacingMidas = 64;
consensus.nPosTargetSpacing = 1 * 60; // 1 minute
consensus.nStakeMinDepth = 100;
// Zerocoin
consensus.nZerocoinRequiredStakeDepth = 200;
consensus.nZerocoinStartHeight = 300;
consensus.nZerocoinStartTime = 1501776000;
consensus.nBlockZerocoinV2 = 1012710;
consensus.nPublicZCSpends = 5500;
consensus.nBlockStakeModifierV2 = 5530;
consensus.nFakeSerialBlockheightEnd = -1;
consensus.nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
consensus.nRequiredAccumulation = 1;
consensus.zerocoinModulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
Expand All @@ -692,8 +734,11 @@ class CDevNetParams : public CChainParams {
"31438167899885040445364023527381951378636564391212010397122822120720357";

// ATP
consensus.ATPStartHeight = 5530; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.strTokenManagementKey = "gBi3gDLnGfw8HA2rN4HmNxHk9hMC4GLFbh";
consensus.nOpGroupNewRequiredConfirmations = 1;
// POSPOW
consensus.POSPOWStartHeight = std::numeric_limits<int>::max();

// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
Expand Down Expand Up @@ -834,35 +879,50 @@ class CRegTestParams : public CChainParams {
consensus.DIP0003EnforcementHeight = 500;
consensus.DIP0003EnforcementHash = uint256();
consensus.IIP0006Height = 1;
consensus.POSStartHeight = 250;
consensus.MidasStartHeight = 999999999;
consensus.DGWStartHeight = 1;
consensus.DGWStartTime = 1554332940;
consensus.ATPStartHeight = 1; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 1
consensus.nPowTargetTimespan = 24 * 60 * 60; // Ion: 1 day
consensus.nPowTargetSpacing = 2.5 * 60; // Ion: 2.5 minutes
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nPowKGWHeight = 15200; // same as mainnet
consensus.nPowDGWHeight = 34140; // same as mainnet
consensus.nStakeMinDepth = 0;
consensus.nZerocoinRequiredStakeDepth = 200;
consensus.nZerocoinStartHeight = 300;
consensus.nZerocoinStartTime = 1501776000;
consensus.nBlockZerocoinV2 = 300;
consensus.nPublicZCSpends = 350;
consensus.nBlockStakeModifierV2 = std::numeric_limits<int>::max(); // max integer value (never switch on regtest)
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
consensus.strTokenManagementKey = "gBi3gDLnGfw8HA2rN4HmNxHk9hMC4GLFbh";
consensus.nOpGroupNewRequiredConfirmations = 1;
// ION
consensus.nCoinbaseMaturity = 100;
// POS
consensus.POSStartHeight = 250;
consensus.MidasStartHeight = 999999999;
consensus.DGWStartHeight = 300;
consensus.DGWDifficultyStartHeight = 300;
consensus.DGWStartTime = 1521414629;
consensus.posLimit = uint256S("000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 24
consensus.nPosTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
consensus.nPosTargetSpacingMidas = 64;
consensus.nPosTargetSpacing = 1 * 60; // 1 minute
consensus.nStakeMinDepth = 1;
// Zerocoin
consensus.nZerocoinRequiredStakeDepth = 200;
consensus.nZerocoinStartHeight = 350;
consensus.nZerocoinStartTime = 1521414629;
consensus.nBlockZerocoinV2 = 351;
consensus.nPublicZCSpends = 5500;
consensus.nBlockStakeModifierV2 = 400;
consensus.nFakeSerialBlockheightEnd = -1;
consensus.nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
consensus.nRequiredAccumulation = 1;
consensus.zerocoinModulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
"4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
"6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
"7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
"8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
"31438167899885040445364023527381951378636564391212010397122822120720357";
// ATP
consensus.ATPStartHeight = 300; // Start enforcing the Atomic Token Protocol (ATP) for blocks with version 11 and higher
consensus.strTokenManagementKey = "gAQQQjA4DCT2EZDVK6Jae4mFfB217V43Nt";
consensus.nOpGroupNewRequiredConfirmations = 1;
// POSPOW
consensus.POSPOWStartHeight = 350;

consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ inline unsigned int MaxBlockSigOps(bool fDIP0001Active /*= false */)
}
/** The maximum allowed size of version 3 extra payload */
static const unsigned int MAX_TX_EXTRA_PAYLOAD = 10000;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;

/** Flags for nSequence and nLockTime locks */
enum {
Expand Down
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ struct Params {
int POSStartHeight;
int MidasStartHeight;
int DGWStartHeight;
int DGWDifficultyStartHeight;
int DGWStartTime;
int ATPStartHeight;
int POSPOWStartHeight;
/**
* Minimum blocks including miner confirmation of the total of nMinerConfirmationWindow blocks in a retargeting period,
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
Expand All @@ -177,6 +179,9 @@ struct Params {
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;

/** ION specific consensus parameters */
int nCoinbaseMaturity;

/** Proof of stake parameters */
uint256 posLimit;
int64_t nPosTargetTimespanMidas;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c
assert(!coin.IsSpent());

// If prev is coinbase, check that it's matured
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < (nSpendHeight <= 100 ? (int)10 : COINBASE_MATURITY)) {
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < (nSpendHeight <= 100 ? (int)10 : Params().nCoinbaseMaturity)) {
return state.Invalid(false,
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
Expand Down
2 changes: 2 additions & 0 deletions src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "masternode/masternode-sync.h"
#include "privatesend/privatesend.h"
#ifdef ENABLE_WALLET
#include "pos/staking-manager.h"
#include "privatesend/privatesend-client.h"
#endif // ENABLE_WALLET
#include "validation.h"
Expand Down Expand Up @@ -56,6 +57,7 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con
CPrivateSend::UpdatedBlockTip(pindexNew);
#ifdef ENABLE_WALLET
privateSendClient.UpdatedBlockTip(pindexNew);
stakingManager->UpdatedBlockTip(pindexNew);
#endif // ENABLE_WALLET

if (fLiteMode)
Expand Down
8 changes: 4 additions & 4 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C

DecreasePoSePenalties(newList);

// we skip the coinbase
for (int i = 1; i < (int)block.vtx.size(); i++) {
// we skip the coinbase and coinstake
for (int i = block.IsProofOfStake() ? 2 : 1; i < (int)block.vtx.size(); i++) {
const CTransaction& tx = *block.vtx[i];

if (tx.nVersion != 3) {
Expand Down Expand Up @@ -811,8 +811,8 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
}
}

// we skip the coinbase
for (int i = 1; i < (int)block.vtx.size(); i++) {
// we skip the coinbase and coinstake
for (int i = block.IsProofOfStake() ? 2 : 1; i < (int)block.vtx.size(); i++) {
const CTransaction& tx = *block.vtx[i];

// check if any existing MN collateral is spent by this transaction
Expand Down
Loading

0 comments on commit 4bdaa61

Please sign in to comment.