Skip to content

Commit

Permalink
Merge #939: More IS refactoring
Browse files Browse the repository at this point in the history
149f27a More IS refactoring
  • Loading branch information
UdjinM6 authored and schinzelh committed Aug 12, 2016
1 parent ee266f2 commit e20e1dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
30 changes: 15 additions & 15 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight)
LogPrintf("DoConsensusVote -- Failed to sign consensus vote\n");
return;
}
if(!vote.SignatureValid()) {
if(!vote.CheckSignature()) {
LogPrintf("DoConsensusVote -- Signature invalid\n");
return;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ bool ProcessConsensusVote(CNode* pnode, CConsensusVote& vote)
return false;
}

if(!vote.SignatureValid()) {
if(!vote.CheckSignature()) {
LogPrintf("ProcessConsensusVote -- Signature invalid\n");
// don't ban, it could just be a non-synced masternode
mnodeman.AskForMN(pnode, vote.vinMasternode);
Expand Down Expand Up @@ -546,21 +546,21 @@ uint256 CConsensusVote::GetHash() const
}


bool CConsensusVote::SignatureValid()
bool CConsensusVote::CheckSignature()
{
std::string errorMessage;
std::string strError;
std::string strMessage = txHash.ToString().c_str() + boost::lexical_cast<std::string>(nBlockHeight);
//LogPrintf("verify strMessage %s \n", strMessage);

CMasternode* pmn = mnodeman.Find(vinMasternode);

if(pmn == NULL) {
LogPrintf("CConsensusVote::SignatureValid -- Unknown Masternode: txin=%s\n", vinMasternode.ToString());
LogPrintf("CConsensusVote::CheckSignature -- Unknown Masternode: txin=%s\n", vinMasternode.ToString());
return false;
}

if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, errorMessage)) {
LogPrintf("CConsensusVote::SignatureValid -- VerifyMessage() failed\n");
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchMasterNodeSignature, strMessage, strError)) {
LogPrintf("CConsensusVote::CheckSignature -- VerifyMessage() failed\n");
return false;
}

Expand All @@ -569,16 +569,16 @@ bool CConsensusVote::SignatureValid()

bool CConsensusVote::Sign()
{
std::string errorMessage;
std::string strError;

std::string strMessage = txHash.ToString().c_str() + boost::lexical_cast<std::string>(nBlockHeight);

if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, activeMasternode.keyMasternode)) {
if(!darkSendSigner.SignMessage(strMessage, strError, vchMasterNodeSignature, activeMasternode.keyMasternode)) {
LogPrintf("CConsensusVote::Sign -- SignMessage() failed");
return false;
}

if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchMasterNodeSignature, strMessage, errorMessage)) {
if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchMasterNodeSignature, strMessage, strError)) {
LogPrintf("CConsensusVote::Sign -- VerifyMessage() failed");
return false;
}
Expand All @@ -587,25 +587,25 @@ bool CConsensusVote::Sign()
}


bool CTransactionLock::VotesValid()
bool CTransactionLock::IsAllVotesValid()
{

BOOST_FOREACH(CConsensusVote vote, vecConsensusVotes)
{
int n = mnodeman.GetMasternodeRank(vote.vinMasternode, vote.nBlockHeight, MIN_INSTANTSEND_PROTO_VERSION);

if(n == -1) {
LogPrintf("CTransactionLock::VotesValid -- Unknown Masternode, txin=%s\n", vote.vinMasternode.ToString());
LogPrintf("CTransactionLock::IsAllVotesValid -- Unknown Masternode, txin=%s\n", vote.vinMasternode.ToString());
return false;
}

if(n > INSTANTSEND_SIGNATURES_TOTAL) {
LogPrintf("CTransactionLock::VotesValid -- Masternode not in the top %s\n", INSTANTSEND_SIGNATURES_TOTAL);
LogPrintf("CTransactionLock::IsAllVotesValid -- Masternode not in the top %s\n", INSTANTSEND_SIGNATURES_TOTAL);
return false;
}

if(!vote.SignatureValid()) {
LogPrintf("CTransactionLock::VotesValid -- Signature not valid\n");
if(!vote.CheckSignature()) {
LogPrintf("CTransactionLock::IsAllVotesValid -- Signature not valid\n");
return false;
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/instantx.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class CConsensusVote
int nBlockHeight;
std::vector<unsigned char> vchMasterNodeSignature;

uint256 GetHash() const;

bool SignatureValid();
bool Sign();

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
Expand All @@ -100,6 +95,11 @@ class CConsensusVote
READWRITE(vchMasterNodeSignature);
READWRITE(nBlockHeight);
}

uint256 GetHash() const;

bool Sign();
bool CheckSignature();
};

class CTransactionLock
Expand All @@ -111,14 +111,11 @@ class CTransactionLock
int nLockExpirationBlock;
int nTimeout;

bool VotesValid();
int CountVotes();
void AddVote(CConsensusVote& vote);
uint256 GetHash() const { return txHash; }

uint256 GetHash()
{
return txHash;
}
bool IsAllVotesValid();
void AddVote(CConsensusVote& vote);
int CountVotes();
};


Expand Down

0 comments on commit e20e1dc

Please sign in to comment.