Skip to content

Commit

Permalink
Merge pull request #6 from cakedefi/feature_PoS_staker
Browse files Browse the repository at this point in the history
feature PoS staker
  • Loading branch information
uzyn authored Sep 26, 2019
2 parents 2d5f11d + 455b31f commit c1b560f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
8 changes: 1 addition & 7 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,6 @@ class CBlockIndex
//! Build the skiplist pointer for this entry.
void BuildSkip();

uint256 GetHashToSign() const
{
CDataStream ss(SER_GETHASH, 0);
ss << nVersion << pprev->GetBlockHash() << hashMerkleRoot << nTime << nBits << height << mintedBlocks << stakeModifier;
return Hash(ss.begin(), ss.end());
}

//! Efficiently find an ancestor of this block.
CBlockIndex* GetAncestor(int height);
const CBlockIndex* GetAncestor(int height) const;
Expand Down Expand Up @@ -407,6 +400,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
READWRITE(stakeModifier);
READWRITE(height);
READWRITE(mintedBlocks);
READWRITE(sig);
Expand Down
8 changes: 4 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CMainParams : public CChainParams {

consensus.pos.allowMintingWithoutPeers = false; // don't mint if no peers connected

consensus.CSVHeight = 0; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
consensus.CSVHeight = 1; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
consensus.SegwitHeight = 0; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nTargetTimespan / nTargetSpacing
Expand Down Expand Up @@ -195,7 +195,7 @@ class CTestNetParams : public CChainParams {

consensus.pos.allowMintingWithoutPeers = true;

consensus.CSVHeight = 0; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
consensus.CSVHeight = 1; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
consensus.SegwitHeight = 0; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nTargetTimespan / nTargetSpacing
Expand Down Expand Up @@ -283,9 +283,9 @@ class CRegTestParams : public CChainParams {

consensus.pos.coinstakeMaturity = 100;

consensus.pos.allowMintingWithoutPeers = false; // don't mint if no peers connected
consensus.pos.allowMintingWithoutPeers = true; // don't mint if no peers connected

consensus.CSVHeight = 0; // CSV activated on regtest (Used in rpc activation tests)
consensus.CSVHeight = 1; // CSV activated on regtest (Used in rpc activation tests)
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
Expand Down
18 changes: 11 additions & 7 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,19 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
pindexNew->height = diskindex.height;
pindexNew->mintedBlocks = diskindex.mintedBlocks;
pindexNew->sig = diskindex.sig;

CPubKey recoveredPubKey{};
if (!recoveredPubKey.RecoverCompact(diskindex.GetHashToSign(), diskindex.sig)) {
return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString());
if (pindexNew->nHeight) {
CPubKey recoveredPubKey{};
if (!recoveredPubKey.RecoverCompact(pindexNew->GetBlockHeader().GetHashToSign(), pindexNew->sig)) {
return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString());
}
pindexNew->minter = recoveredPubKey.GetID();
} else {
pindexNew->minter = CKeyID();
}
pindexNew->minter = recoveredPubKey.GetID();

if (pindexNew->nHeight > 0 && pindexNew->stakeModifier == uint256{})
return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString());

// if (pindexNew->nHeight > 0 && pindexNew->stakeModifier == uint256{}) // TODO: (SS) uncomment me
// return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString());

pcursor->Next();
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace {

CBlockIndex* LookupBlockIndex(const uint256& hash)
{
std::cout << "!!!LookupBlockIndex : " << hash.ToString() << std::endl;
AssertLockHeld(cs_main);
BlockMap::const_iterator it = g_blockman.m_block_index.find(hash);
return it == g_blockman.m_block_index.end() ? nullptr : it->second;
Expand Down Expand Up @@ -3220,7 +3221,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;

std::cout << "!!!ContextualCheckBlock : " << nHeight << std::endl;
// Start enforcing BIP113 (Median Time Past).
int nLockTimeFlags = 0;
if (nHeight >= consensusParams.CSVHeight) {
Expand Down

0 comments on commit c1b560f

Please sign in to comment.