Skip to content

Commit

Permalink
[wallet] Remove now unneeded stake P2PKH->P2PK out forced conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Apr 24, 2021
1 parent 433a14e commit a46b837
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
17 changes: 3 additions & 14 deletions src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CAmount CPivStake::GetValue() const
return outputFrom.nValue;
}

bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK)
bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal)
{
std::vector<valtype> vSolutions;
txnouttype whichType;
Expand All @@ -68,25 +68,14 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmoun
if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH && whichType != TX_COLDSTAKE)
return error("%s: type=%d (%s) not supported for scriptPubKeyKernel", __func__, whichType, GetTxnOutputType(whichType));

CScript scriptPubKey;
CKey key;
if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) {
// if P2PKH or P2CS check that we have the input private key
if (!pwallet->GetKey(CKeyID(uint160(vSolutions[0])), key))
return error("%s: Unable to get staking private key", __func__);
}

// Consensus check: P2PKH block signatures were not accepted before v5 update.
// This can be removed after v5.0 enforcement
if (whichType == TX_PUBKEYHASH && onlyP2PK) {
// convert to P2PK inputs
scriptPubKey << key.GetPubKey() << OP_CHECKSIG;
} else {
// keep the same script
scriptPubKey = scriptPubKeyKernel;
}

vout.emplace_back(0, scriptPubKey);
vout.emplace_back(0, scriptPubKeyKernel);

// Calculate if we need to split the output
if (pwallet->nStakeSplitThreshold > 0) {
Expand All @@ -98,7 +87,7 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmoun
nSplit = txSizeMax;
for (int i = nSplit; i > 1; i--) {
LogPrintf("%s: StakeSplit: nTotal = %d; adding output %d of %d\n", __func__, nTotal, (nSplit-i)+2, nSplit);
vout.emplace_back(0, scriptPubKey);
vout.emplace_back(0, scriptPubKeyKernel);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stakeinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CStakeInput
virtual bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) = 0;
virtual bool GetTxOutFrom(CTxOut& out) const = 0;
virtual CAmount GetValue() const = 0;
virtual bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) = 0;
virtual bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) = 0;
virtual bool IsZPIV() const = 0;
virtual CDataStream GetUniqueness() const = 0;
virtual bool ContextCheck(int nHeight, uint32_t nTime) = 0;
Expand All @@ -51,7 +51,7 @@ class CPivStake : public CStakeInput
CAmount GetValue() const override;
CDataStream GetUniqueness() const override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override;
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) override;
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override;
bool IsZPIV() const override { return false; }
bool ContextCheck(int nHeight, uint32_t nTime) override;
};
Expand Down
5 changes: 1 addition & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3227,9 +3227,6 @@ bool CWallet::CreateCoinStake(
pStakerStatus->SetLastTip(pindexPrev);
pStakerStatus->SetLastCoins((int) availableCoins->size());

// P2PKH block signatures were not accepted before v5 update.
bool onlyP2PK = !consensus.NetworkUpgradeActive(pindexPrev->nHeight + 1, Consensus::UPGRADE_V5_0);

// Kernel Search
CAmount nCredit;
CScript scriptPubKeyKernel;
Expand Down Expand Up @@ -3277,7 +3274,7 @@ bool CWallet::CreateCoinStake(

// Create the output transaction(s)
std::vector<CTxOut> vout;
if (!stakeInput.CreateTxOuts(this, vout, nCredit, onlyP2PK)) {
if (!stakeInput.CreateTxOuts(this, vout, nCredit)) {
LogPrintf("%s : failed to create output\n", __func__);
it++;
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/zpiv/zpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CLegacyZPivStake : public CStakeInput
CAmount GetValue() const override;
CDataStream GetUniqueness() const override;
bool CreateTxIn(CWallet* pwallet, CTxIn& txIn, uint256 hashTxOut = UINT256_ZERO) override { return false; /* creation disabled */}
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal, const bool onlyP2PK) override { return false; /* creation disabled */}
bool CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmount nTotal) override { return false; /* creation disabled */}
bool GetTxOutFrom(CTxOut& out) const override { return false; /* not available */ }
virtual bool ContextCheck(int nHeight, uint32_t nTime) override;
};
Expand Down

0 comments on commit a46b837

Please sign in to comment.