Skip to content

Commit

Permalink
Revert "Preparations for upcoming backport of Bitcoin bitcoin#8580"
Browse files Browse the repository at this point in the history
This reverts commit 4838d42.
  • Loading branch information
CryptoCentric committed Feb 26, 2019
1 parent e08578b commit 93ec6e1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 77 deletions.
34 changes: 17 additions & 17 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool CInstantSend::ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CCo
uint256 txHash = txLockRequest.GetHash();

// Check to see if we conflict with existing completed lock
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
std::map<COutPoint, uint256>::iterator it = mapLockedOutpoints.find(txin.prevout);
if(it != mapLockedOutpoints.end() && it->second != txLockRequest.GetHash()) {
// Conflicting with complete lock, proceed to see if we should cancel them both
Expand All @@ -103,7 +103,7 @@ bool CInstantSend::ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CCo

// Check to see if there are votes for conflicting request,
// if so - do not fail, just warn user
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
std::map<COutPoint, std::set<uint256> >::iterator it = mapVotedOutpoints.find(txin.prevout);
if(it != mapVotedOutpoints.end()) {
BOOST_FOREACH(const uint256& hash, it->second) {
Expand Down Expand Up @@ -146,7 +146,7 @@ bool CInstantSend::CreateTxLockCandidate(const CTxLockRequest& txLockRequest)

CTxLockCandidate txLockCandidate(txLockRequest);
// all inputs should already be checked by txLockRequest.IsValid() above, just use them now
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.vin) {
txLockCandidate.AddOutPointLock(txin.prevout);
}
mapTxLockCandidates.insert(std::make_pair(txHash, txLockCandidate));
Expand All @@ -160,7 +160,7 @@ bool CInstantSend::CreateTxLockCandidate(const CTxLockRequest& txLockRequest)
LogPrintf("CInstantSend::CreateTxLockCandidate -- update empty, txid=%s\n", txHash.ToString());

// all inputs should already be checked by txLockRequest.IsValid() above, just use them now
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.vin) {
itLockCandidate->second.AddOutPointLock(txin.prevout);
}
} else {
Expand Down Expand Up @@ -447,7 +447,7 @@ bool CInstantSend::IsEnoughOrphanVotesForTx(const CTxLockRequest& txLockRequest)
// There could be a situation when we already have quite a lot of votes
// but tx lock request still wasn't received. Let's scan through
// orphan votes to check if this is the case.
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
if(!IsEnoughOrphanVotesForTxAndOutPoint(txLockRequest.GetHash(), txin.prevout)) {
return false;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ void CInstantSend::TryToFinalizeLockCandidate(const CTxLockCandidate& txLockCand
#endif
LOCK(cs_instantsend);

uint256 txHash = txLockCandidate.txLockRequest.tx->GetHash();
uint256 txHash = txLockCandidate.txLockRequest.GetHash();
if(txLockCandidate.IsAllOutPointsReady() && !IsLockedInstantSendTransaction(txHash)) {
// we have enough votes now
LogPrint("instantsend", "CInstantSend::TryToFinalizeLockCandidate -- Transaction Lock is ready to complete, txid=%s\n", txHash.ToString());
Expand Down Expand Up @@ -521,7 +521,7 @@ void CInstantSend::UpdateLockedTransaction(const CTxLockCandidate& txLockCandida
}
#endif

GetMainSignals().NotifyTransactionLock(*txLockCandidate.txLockRequest.tx);
GetMainSignals().NotifyTransactionLock(txLockCandidate.txLockRequest);

LogPrint("instantsend", "CInstantSend::UpdateLockedTransaction -- done, txid=%s\n", txHash.ToString());
}
Expand Down Expand Up @@ -565,7 +565,7 @@ bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate)

LOCK(mempool.cs); // protect mempool.mapNextTx

BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
uint256 hashConflicting;
if(GetLockedOutPointTxHash(txin.prevout, hashConflicting) && txHash != hashConflicting) {
// completed lock which conflicts with another completed one?
Expand Down Expand Up @@ -616,7 +616,7 @@ bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate)
return true;
}
// Not in block yet, make sure all its inputs are still unspent
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
Coin coin;
if(!GetUTXOCoin(txin.prevout, coin)) {
// Not in UTXO anymore? A conflicting tx was mined while we were waiting for votes.
Expand Down Expand Up @@ -928,21 +928,21 @@ std::string CInstantSend::ToString()

bool CTxLockRequest::IsValid() const
{
if(tx->vout.size() < 1) return false;
if(vout.size() < 1) return false;

if(tx->vin.size() > WARN_MANY_INPUTS) {
if(vin.size() > WARN_MANY_INPUTS) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- WARNING: Too many inputs: tx=%s", ToString());
}

LOCK(cs_main);
if(!CheckFinalTx(*tx)) {
if(!CheckFinalTx(*this)) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- Transaction is not final: tx=%s", ToString());
return false;
}

CAmount nValueIn = 0;

BOOST_FOREACH(const CTxIn& txin, tx->vin) {
BOOST_FOREACH(const CTxIn& txin, vin) {

Coin coin;

Expand All @@ -969,7 +969,7 @@ bool CTxLockRequest::IsValid() const
return false;
}

CAmount nValueOut = tx->GetValueOut();
CAmount nValueOut = GetValueOut();

if(nValueIn - nValueOut < GetMinFee()) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- did not include enough fees in transaction: fees=%d, tx=%s", nValueOut - nValueIn, ToString());
Expand All @@ -982,12 +982,12 @@ bool CTxLockRequest::IsValid() const
CAmount CTxLockRequest::GetMinFee() const
{
CAmount nMinFee = MIN_FEE;
return std::max(nMinFee, CAmount(tx->vin.size() * nMinFee));
return std::max(nMinFee, CAmount(vin.size() * nMinFee));
}

int CTxLockRequest::GetMaxSignatures() const
{
return tx->vin.size() * COutPointLock::SIGNATURES_TOTAL;
return vin.size() * COutPointLock::SIGNATURES_TOTAL;
}

//
Expand Down Expand Up @@ -1205,7 +1205,7 @@ bool CTxLockCandidate::IsTimedOut() const

void CTxLockCandidate::Relay(CConnman& connman) const
{
connman.RelayTransaction(*txLockRequest.tx);
connman.RelayTransaction(txLockRequest);
std::map<COutPoint, COutPointLock>::const_iterator itOutpointLock = mapOutPointLocks.begin();
while(itOutpointLock != mapOutPointLocks.end()) {
itOutpointLock->second.Relay(connman);
Expand Down
33 changes: 3 additions & 30 deletions src/instantx.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,21 @@ class CInstantSend
std::string ToString();
};

class CTxLockRequest
class CTxLockRequest : public CTransaction
{
private:
static const CAmount MIN_FEE = 0.0001 * COIN;

public:
static const int WARN_MANY_INPUTS = 100;

CTransactionRef tx;

CTxLockRequest() : tx(MakeTransactionRef()) {}
CTxLockRequest(const CTransaction& _tx) : tx(MakeTransactionRef(_tx)) {};

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(tx);
}
CTxLockRequest() = default;
CTxLockRequest(const CTransaction& tx) : CTransaction(tx) {};

bool IsValid() const;
CAmount GetMinFee() const;
int GetMaxSignatures() const;

const uint256 &GetHash() const {
return tx->GetHash();
}

std::string ToString() const {
return tx->ToString();
}

friend bool operator==(const CTxLockRequest& a, const CTxLockRequest& b)
{
return *a.tx == *b.tx;
}

friend bool operator!=(const CTxLockRequest& a, const CTxLockRequest& b)
{
return *a.tx != *b.tx;
}

explicit operator bool() const
{
return *this != CTxLockRequest();
Expand Down
4 changes: 2 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,11 +1623,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
vRecv >> tx;
} else if(strCommand == NetMsgType::TXLOCKREQUEST) {
vRecv >> txLockRequest;
tx = *txLockRequest.tx;
tx = txLockRequest;
nInvType = MSG_TXLOCK_REQUEST;
} else if (strCommand == NetMsgType::DSTX) {
vRecv >> dstx;
tx = *dstx.tx;
tx = dstx.tx;
nInvType = MSG_DSTX;
}

Expand Down
28 changes: 14 additions & 14 deletions src/privatesend-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, std::string& strCommand, C
CDarkSendEntry entry;
vRecv >> entry;

LogPrint("privatesend", "DSVIN -- txCollateral %s", entry.txCollateral->ToString());
LogPrint("privatesend", "DSVIN -- txCollateral %s", entry.txCollateral.ToString());

if(entry.vecTxDSIn.size() > PRIVATESEND_ENTRY_MAX_SIZE) {
LogPrintf("DSVIN -- ERROR: too many inputs! %d/%d\n", entry.vecTxDSIn.size(), PRIVATESEND_ENTRY_MAX_SIZE);
Expand Down Expand Up @@ -399,13 +399,13 @@ void CPrivateSendServer::ChargeFees(CConnman& connman)
//we don't need to charge collateral for every offence.
if(GetRandInt(100) > 33) return;

std::vector<CTransactionRef> vecOffendersCollaterals;
std::vector<CTransaction> vecOffendersCollaterals;

if(nState == POOL_STATE_ACCEPTING_ENTRIES) {
BOOST_FOREACH(CTransactionRef txCollateral, vecSessionCollaterals) {
BOOST_FOREACH(const CTransaction& txCollateral, vecSessionCollaterals) {
bool fFound = false;
BOOST_FOREACH(const CDarkSendEntry& entry, vecEntries)
if(*entry.txCollateral == *txCollateral)
if(entry.txCollateral == txCollateral)
fFound = true;

// This queue entry didn't send us the promised transaction
Expand Down Expand Up @@ -442,17 +442,17 @@ void CPrivateSendServer::ChargeFees(CConnman& connman)

if(nState == POOL_STATE_ACCEPTING_ENTRIES || nState == POOL_STATE_SIGNING) {
LogPrintf("CPrivateSendServer::ChargeFees -- found uncooperative node (didn't %s transaction), charging fees: %s\n",
(nState == POOL_STATE_SIGNING) ? "sign" : "send", vecOffendersCollaterals[0]->ToString());
(nState == POOL_STATE_SIGNING) ? "sign" : "send", vecOffendersCollaterals[0].ToString());

LOCK(cs_main);

CValidationState state;
bool fMissingInputs;
if(!AcceptToMemoryPool(mempool, state, *vecOffendersCollaterals[0], false, &fMissingInputs, false, maxTxFee)) {
if(!AcceptToMemoryPool(mempool, state, vecOffendersCollaterals[0], false, &fMissingInputs, false, maxTxFee)) {
// should never really happen
LogPrintf("CPrivateSendServer::ChargeFees -- ERROR: AcceptToMemoryPool failed!\n");
} else {
connman.RelayTransaction(*vecOffendersCollaterals[0]);
connman.RelayTransaction(vecOffendersCollaterals[0]);
}
}
}
Expand All @@ -475,19 +475,19 @@ void CPrivateSendServer::ChargeRandomFees(CConnman& connman)

LOCK(cs_main);

BOOST_FOREACH(CTransactionRef txCollateral, vecSessionCollaterals) {
BOOST_FOREACH(const CTransaction& txCollateral, vecSessionCollaterals) {

if(GetRandInt(100) > 10) return;

LogPrintf("CPrivateSendServer::ChargeRandomFees -- charging random fees, txCollateral=%s", txCollateral->ToString());
LogPrintf("CPrivateSendServer::ChargeRandomFees -- charging random fees, txCollateral=%s", txCollateral.ToString());

CValidationState state;
bool fMissingInputs;
if(!AcceptToMemoryPool(mempool, state, *txCollateral, false, &fMissingInputs, false, maxTxFee)) {
if(!AcceptToMemoryPool(mempool, state, txCollateral, false, &fMissingInputs, false, maxTxFee)) {
// should never really happen
LogPrintf("CPrivateSendServer::ChargeRandomFees -- ERROR: AcceptToMemoryPool failed!\n");
} else {
connman.RelayTransaction(*txCollateral);
connman.RelayTransaction(txCollateral);
}
}
}
Expand Down Expand Up @@ -591,7 +591,7 @@ bool CPrivateSendServer::AddEntry(const CDarkSendEntry& entryNew, PoolMessage& n
}
}

if(!CPrivateSend::IsCollateralValid(*entryNew.txCollateral)) {
if(!CPrivateSend::IsCollateralValid(entryNew.txCollateral)) {
LogPrint("privatesend", "CPrivateSendServer::AddEntry -- collateral not valid!\n");
nMessageIDRet = ERR_INVALID_COLLATERAL;
return false;
Expand Down Expand Up @@ -739,7 +739,7 @@ bool CPrivateSendServer::CreateNewSession(int nDenom, CTransaction txCollateral,
vecDarksendQueue.push_back(dsq);
}

vecSessionCollaterals.push_back(MakeTransactionRef(txCollateral));
vecSessionCollaterals.push_back(txCollateral);
LogPrintf("CPrivateSendServer::CreateNewSession -- new session created, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n",
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());

Expand Down Expand Up @@ -772,7 +772,7 @@ bool CPrivateSendServer::AddUserToExistingSession(int nDenom, CTransaction txCol

nMessageIDRet = MSG_NOERR;
nTimeLastSuccessfulStep = GetTimeMillis();
vecSessionCollaterals.push_back(MakeTransactionRef(txCollateral));
vecSessionCollaterals.push_back(txCollateral);

LogPrintf("CPrivateSendServer::AddUserToExistingSession -- new user accepted, nSessionID: %d nSessionDenom: %d (%s) vecSessionCollaterals.size(): %d\n",
nSessionID, nSessionDenom, CPrivateSend::GetDenominationsToString(nSessionDenom), vecSessionCollaterals.size());
Expand Down
2 changes: 1 addition & 1 deletion src/privatesend-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CPrivateSendServer : public CPrivateSendBase
private:
// Mixing uses collateral transactions to trust parties entering the pool
// to behave honestly. If they don't it takes their money.
std::vector<CTransactionRef> vecSessionCollaterals;
std::vector<CTransaction> vecSessionCollaterals;

bool fUnitTest;

Expand Down
6 changes: 3 additions & 3 deletions src/privatesend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool CDarksendBroadcastTx::Sign()
{
if(!fMasterNode) return false;

std::string strMessage = tx->GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);

if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
Expand All @@ -93,7 +93,7 @@ bool CDarksendBroadcastTx::Sign()

bool CDarksendBroadcastTx::CheckSignature(const CPubKey& pubKeyMasternode)
{
std::string strMessage = tx->GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast<std::string>(sigTime);
std::string strError = "";

if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) {
Expand Down Expand Up @@ -383,7 +383,7 @@ std::string CPrivateSend::GetMessageByID(PoolMessage nMessageID)
void CPrivateSend::AddDSTX(const CDarksendBroadcastTx& dstx)
{
LOCK(cs_mapdstx);
mapDSTX.insert(std::make_pair(dstx.tx->GetHash(), dstx));
mapDSTX.insert(std::make_pair(dstx.tx.GetHash(), dstx));
}

CDarksendBroadcastTx CPrivateSend::GetDSTX(const uint256& hash)
Expand Down
Loading

0 comments on commit 93ec6e1

Please sign in to comment.