<commit_before>


#include "bignum.h"
#include "sync.h"
#include "net.h"
#include "key.h"
#include "util.h"
#include "script.h"
#include "hashblock.h"
#include "base58.h"
#include "instantx.h"
#include "masternode.h"
#include "activemasternode.h"
#include "darksend.h"

using namespace std;
using namespace boost;

std::vector<CTransactionLock> vecTxLocks;

std::map<uint256, CTransaction> mapTxLockReq;
std::map<uint256, CTransactionLock> mapTxLocks;

#define INSTANTX_SIGNATURES_REQUIRED           2

//txlock - Locks transaction
//
//step 1.) Broadcast intention to lock transaction inputs, "txlreg", CTransaction
//step 2.) Top 10 masternodes, open connect to top 1 masternode. Send "txvote", CTransaction, Signature, Approve
//step 3.) Top 1 masternode, waits for 10 messages. Upon success, sends "txlock'

void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
    if (strCommand == "txlreq")
    {
        printf("ProcessMessageInstantX::txlreq\n");
        CDataStream vMsg(vRecv);
        CTransaction tx;
        int nBlockHeight;
        vRecv >> tx >> nBlockHeight;

        CInv inv(MSG_TXLOCK_REQUEST, tx.GetHash());
        pfrom->AddInventoryKnown(inv);

        if(mapTxLockReq.count(inv.hash)){
            printf("ProcessMessageInstantX::txlreq - Already Have Transaction Lock Request: %s %s : accepted %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );
            return;
        }

        bool fMissingInputs = false;
        CValidationState state;
        if (tx.AcceptToMemoryPool(state, true, true, &fMissingInputs))
        {
            RelayTransactionLockReq(tx, inv.hash);
            DoConsensusVote(tx, true, nBlockHeight); 

            mapTxLockReq.insert(make_pair(inv.hash, tx));

            printf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : accepted %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );

            return;

        } else {


            // can we get the conflicting transaction as proof?

            RelayTransactionLockReq(tx, inv.hash);
            DoConsensusVote(tx, false, nBlockHeight); 

            printf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : rejected %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );

            //record prevout, increment the amount of times seen. Ban if over 100

            return;
        }
    } 
    else if (strCommand == "txlvote") //InstantX Lock Consensus Votes
    {
        CConsensusVote ctx;
        vRecv >> ctx;

        ProcessConsensusVote(ctx);
        
        return;
    }
    else if (strCommand == "txlock") //InstantX Lock Transaction Inputs
    {
        printf("ProcessMessageInstantX::txlock\n");

        CDataStream vMsg(vRecv);
        CTransactionLock ctxl;
        vRecv >> ctxl;

        CInv inv(MSG_TXLOCK, ctxl.GetHash());
        pfrom->AddInventoryKnown(inv);

        printf(" -- ProcessMessageInstantX::txlock %d  %s\n", mapTxLocks.count(inv.hash), inv.hash.ToString().c_str());

        if(!mapTxLocks.count(inv.hash)){
            /*if(ctxl.CountSignatures() < INSTANTX_SIGNATURES_REQUIRED){
                printf("InstantX::txlock - not enough signatures\n");
                return;
            }
            if(!ctxl.SignaturesValid()){
                printf("InstantX::txlock - got invalid TransactionLock, rejected\n");
                return;
            }
            if(!ctxl.AllInFavor()){
                printf("InstantX::txlock - not all in favor of lock, rejected\n");
                return;
            }*/

            mapTxLocks.insert(make_pair(inv.hash, ctxl));

            //broadcast the new lock
/*            LOCK(cs_vNodes);
            BOOST_FOREACH(CNode* pnode, vNodes)
            {
                if(!pnode->fRelayTxes)
                    continue;

                pnode->PushMessage("txlock", ctxl);
            }
*/            
            //pwalletMain->UpdatedConfirmations();<commit_msg>enabled locking protections<commit_after>


#include "bignum.h"
#include "sync.h"
#include "net.h"
#include "key.h"
#include "util.h"
#include "script.h"
#include "hashblock.h"
#include "base58.h"
#include "instantx.h"
#include "masternode.h"
#include "activemasternode.h"
#include "darksend.h"

using namespace std;
using namespace boost;

std::vector<CTransactionLock> vecTxLocks;

std::map<uint256, CTransaction> mapTxLockReq;
std::map<uint256, CTransactionLock> mapTxLocks;

#define INSTANTX_SIGNATURES_REQUIRED           2

//txlock - Locks transaction
//
//step 1.) Broadcast intention to lock transaction inputs, "txlreg", CTransaction
//step 2.) Top 10 masternodes, open connect to top 1 masternode. Send "txvote", CTransaction, Signature, Approve
//step 3.) Top 1 masternode, waits for 10 messages. Upon success, sends "txlock'

void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
    if (strCommand == "txlreq")
    {
        printf("ProcessMessageInstantX::txlreq\n");
        CDataStream vMsg(vRecv);
        CTransaction tx;
        int nBlockHeight;
        vRecv >> tx >> nBlockHeight;

        CInv inv(MSG_TXLOCK_REQUEST, tx.GetHash());
        pfrom->AddInventoryKnown(inv);

        if(mapTxLockReq.count(inv.hash)){
            printf("ProcessMessageInstantX::txlreq - Already Have Transaction Lock Request: %s %s : accepted %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );
            return;
        }

        bool fMissingInputs = false;
        CValidationState state;
        if (tx.AcceptToMemoryPool(state, true, true, &fMissingInputs))
        {
            RelayTransactionLockReq(tx, inv.hash);
            DoConsensusVote(tx, true, nBlockHeight); 

            mapTxLockReq.insert(make_pair(inv.hash, tx));

            printf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : accepted %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );

            return;

        } else {


            // can we get the conflicting transaction as proof?

            RelayTransactionLockReq(tx, inv.hash);
            DoConsensusVote(tx, false, nBlockHeight); 

            printf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : rejected %s\n",
                pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
                tx.GetHash().ToString().c_str()
            );

            //record prevout, increment the amount of times seen. Ban if over 100

            return;
        }
    } 
    else if (strCommand == "txlvote") //InstantX Lock Consensus Votes
    {
        CConsensusVote ctx;
        vRecv >> ctx;

        ProcessConsensusVote(ctx);
        
        return;
    }
    else if (strCommand == "txlock") //InstantX Lock Transaction Inputs
    {
        printf("ProcessMessageInstantX::txlock\n");

        CDataStream vMsg(vRecv);
        CTransactionLock ctxl;
        vRecv >> ctxl;

        CInv inv(MSG_TXLOCK, ctxl.GetHash());
        pfrom->AddInventoryKnown(inv);

        printf(" -- ProcessMessageInstantX::txlock %d  %s\n", mapTxLocks.count(inv.hash), inv.hash.ToString().c_str());

        if(!mapTxLocks.count(inv.hash)){
            if(ctxl.CountSignatures() < INSTANTX_SIGNATURES_REQUIRED){
                printf("InstantX::txlock - not enough signatures\n");
                return;
            }
            if(!ctxl.SignaturesValid()){
                printf("InstantX::txlock - got invalid TransactionLock, rejected\n");
                return;
            }
            if(!ctxl.AllInFavor()){
                printf("InstantX::txlock - not all in favor of lock, rejected\n");
                return;
            }

            mapTxLocks.insert(make_pair(inv.hash, ctxl));

            //broadcast the new lock
            LOCK(cs_vNodes);
            BOOST_FOREACH(CNode* pnode, vNodes)
            {
                if(!pnode->fRelayTxes)
                    continue;

                pnode->PushMessage("txlock", ctxl);
            }
            
            pwalletMain->UpdatedConfirmations();
{'fraction_non_alphanumeric': 0.12204910292728989, 'fraction_numerical': 0.004957507082152974, 'mean_word_length': 2.198565496413741, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1306572', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2539, 'n_words': 539}