Skip to content

Commit

Permalink
Merge pull request #51 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Working MNPoS
  • Loading branch information
BlockMechanic authored Apr 9, 2022
2 parents 19fb642 + e6f94dd commit 3e8a6ac
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 180 deletions.
14 changes: 7 additions & 7 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ class CTestNetParams : public CChainParams {
strNetworkID = CBaseChainParams::TESTNET;
consensus.signet_blocks = false;
consensus.signet_challenge.clear();
consensus.nSubsidyHalvingInterval = 210000;
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
consensus.BIP34Height = 21111;
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
consensus.nSubsidyHalvingInterval = 130000;
consensus.BIP16Exception = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
consensus.BIP34Height = std::numeric_limits<int>::max();
consensus.BIP34Hash = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
consensus.BIP65Height = std::numeric_limits<int>::max();
consensus.BIP66Height = std::numeric_limits<int>::max();
consensus.CSVHeight = 1; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
consensus.SegwitHeight = std::numeric_limits<int>::max(); // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window
consensus.MinBIP9WarningHeight = std::numeric_limits<int>::max();
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 60; // two weeks
consensus.nPowTargetSpacing = 60;
Expand Down
2 changes: 2 additions & 0 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase || fCoinstake;
// Coinbase transactions can always be overwritten, in order to correctly
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
//LogPrintf("%s: %s\n", __func__, outc.ToString());
if(!outc.IsEmpty())
cache.AddCoin(COutPoint(txid, i), Coin(outc, nHeight, fCoinbase, fCoinstake), overwrite);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/consensus/tx_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <consensus/tx_check.h>
#include <logging.h>

#include <consensus/consensus.h>
#include <primitives/transaction.h>
Expand Down
2 changes: 1 addition & 1 deletion src/crown/legacysigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool CLegacySigner::IsVinAssociatedWithPubkey(CTxIn& vin, CPubKey& pubkey, int n
uint256 hash;
CTransactionRef txVin;
g_txindex->BlockUntilSyncedToCurrentChain();
CScript payee = GetScriptForDestination(PKHash(pubkey.GetID()));
CScript payee = GetScriptForDestination(PKHash(pubkey));

//! get tx from disk
if (!g_txindex->FindTx(vin.prevout.hash, hash, txVin)) {
Expand Down
8 changes: 4 additions & 4 deletions src/crown/nodewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,20 @@ bool NodeWallet::CreateCoinStake(const int nHeight, const uint32_t& nBits, const

//Add stake payment to coinstake tx
CAmount nBlockReward = GetBlockValue(nHeight, 0); //Do not add fees until after they are packaged into the block
CScript scriptBlockReward = GetScriptForDestination(PKHash(ppubkeyActiveNode->GetID()));
CScript scriptBlockReward = GetScriptForDestination(PKHash(*ppubkeyActiveNode));
CTxOutAsset out(Params().GetConsensus().subsidy_asset, nBlockReward, scriptBlockReward);

if(txCoinStake.nVersion >= TX_ELE_VERSION)
txCoinStake.vpout.emplace_back(out);
else
txCoinStake.vout.emplace_back(out);

nTxNewTime = kernel.GetTime();
stakePointer = pointer;

CTxIn txin;
txin.prevout.SetNull();// = pOutpoint; //HUH ??
txin.scriptSig << OP_PROOFOFSTAKE;
txCoinStake.vin.emplace_back(txin);

return true;
}

Expand Down Expand Up @@ -258,7 +258,7 @@ bool GetPointers(stakingnode* pstaker, std::vector<StakePointer>& vStakePointers
}

CScript scriptMNPubKey;
scriptMNPubKey = GetScriptForDestination(PKHash(pstaker->pubkey.GetID()));
scriptMNPubKey = GetScriptForDestination(PKHash(pstaker->pubkey));
for (auto& tx : blockLastPaid.vtx) {
auto stakeSource = COutPoint(tx->GetHash(), nPaymentSlot);
uint256 hashPointer = stakeSource.GetHash();
Expand Down
10 changes: 5 additions & 5 deletions src/masternode/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe
//no masternode detected
CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1);
if(winningNode){
payee = GetScriptForDestination(PKHash(winningNode->pubkey.GetID()));
payee = GetScriptForDestination(PKHash(winningNode->pubkey));
} else {
LogPrint(BCLog::NET, "CreateNewBlock: Failed to detect masternode to pay\n");
hasPayment = false;
}
}

CAmount blockValue = GetBlockSubsidy(pindexPrev->nHeight, Params().GetConsensus());
CAmount blockValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight+1, blockValue);

if(hasPayment){
if(txNew.nVersion >= TX_ELE_VERSION){
txNew.vpout.resize(2);
txNew.vpout[MN_PMT_SLOT].scriptPubKey = payee;
txNew.vpout[MN_PMT_SLOT].nValue = masternodePayment;
txNew.vpout[MN_PMT_SLOT].nAsset = txNew.vpout[0].nAsset;
txNew.vpout[MN_PMT_SLOT].nAsset = Params().GetConsensus().subsidy_asset;
txNew.vpout[0].nValue -= masternodePayment;
}else{
txNew.vout.resize(2);
Expand Down Expand Up @@ -326,7 +326,7 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
}

CScript mnpayee;
mnpayee = GetScriptForDestination(PKHash(mn.pubkey.GetID()));
mnpayee = GetScriptForDestination(PKHash(mn.pubkey));

CScript payee;
for(int64_t h = nHeight; h <= nHeight+8; h++){
Expand Down Expand Up @@ -586,7 +586,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)

newWinner.nBlockHeight = nBlockHeight;

CScript payee = GetScriptForDestination(PKHash(pmn->pubkey.GetID()));
CScript payee = GetScriptForDestination(PKHash(pmn->pubkey));
newWinner.AddPayee(payee);

LogPrint(BCLog::MASTERNODE, "CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d. \n", payee.ToString(), newWinner.nBlockHeight);
Expand Down
16 changes: 8 additions & 8 deletions src/masternode/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool CMasternode::IsValidNetAddr() const
int64_t CMasternode::SecondsSincePayment() const
{
CScript pubkeyScript;
pubkeyScript = GetScriptForDestination(PKHash(pubkey.GetID()));
pubkeyScript = GetScriptForDestination(PKHash(pubkey));

int64_t sec = (GetAdjustedTime() - GetLastPaid());
int64_t month = 60 * 60 * 24 * 30;
Expand All @@ -295,7 +295,7 @@ int64_t CMasternode::GetLastPaid() const
if(pindexPrev == NULL) return false;

CScript mnpayee;
mnpayee = GetScriptForDestination(PKHash(pubkey.GetID()));
mnpayee = GetScriptForDestination(PKHash(pubkey));

CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << vin;
Expand Down Expand Up @@ -347,7 +347,7 @@ bool CMasternode::GetRecentPaymentBlocks(std::vector<const CBlockIndex*>& vPayme
CBlockIndex* pindex = ::ChainActive()[nMinimumValidBlockHeight];

CScript mnpayee;
mnpayee = GetScriptForDestination(PKHash(pubkey.GetID()));
mnpayee = GetScriptForDestination(PKHash(pubkey));

bool fBlockFound = false;
while (::ChainActive().Next(pindex)) {
Expand Down Expand Up @@ -549,7 +549,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) const
}

CScript pubkeyScript;
pubkeyScript = GetScriptForDestination(PKHash(pubkey.GetID()));
pubkeyScript = GetScriptForDestination(PKHash(pubkey));

if(pubkeyScript.size() != 25) {
LogPrint(BCLog::MASTERNODE, "mnb - pubkey the wrong size\n");
Expand All @@ -558,7 +558,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) const
}

CScript pubkeyScript2;
pubkeyScript2 = GetScriptForDestination(PKHash(pubkey2.GetID()));
pubkeyScript2 = GetScriptForDestination(PKHash(pubkey2));

if(pubkeyScript2.size() != 25) {
LogPrint(BCLog::MASTERNODE, "mnb - pubkey2 the wrong size\n");
Expand Down Expand Up @@ -718,7 +718,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS) const
}
}

LogPrint(BCLog::MASTERNODE, "mnb - Got NEW Masternode entry - %s - %s - %s - %d \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
LogPrintf("%s: Got NEW Masternode entry %s %s %s %d \n", __func__, GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
CMasternode mn(*this);
mnodeman.Add(mn);

Expand Down Expand Up @@ -859,7 +859,7 @@ bool CMasternodePing::VerifySignature(const CPubKey& pubKeyMasternode, int &nDos
LogPrint(BCLog::MASTERNODE, "CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s\n", vin.ToString(), errorMessage);
return false;
}

/*
//Also check signature of previous blockhashes
if (nVersion > 1) {
uint256 hash;
Expand All @@ -870,7 +870,7 @@ bool CMasternodePing::VerifySignature(const CPubKey& pubKeyMasternode, int &nDos
return false;
}
}

*/
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/masternode/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ CMasternode *CMasternodeMan::Find(const CScript &payee)

for (auto& mn : vMasternodes)
{
payee2 = GetScriptForDestination(PKHash(mn.pubkey.GetID()));
payee2 = GetScriptForDestination(PKHash(mn.pubkey));
if(payee2 == payee)
return &mn;
}
Expand Down
Loading

0 comments on commit 3e8a6ac

Please sign in to comment.