Skip to content

Commit

Permalink
Merge pull request #198 from TheLindaProjectInc/add-conftract-logging
Browse files Browse the repository at this point in the history
Add contract logging
  • Loading branch information
nibbles83 authored Jun 12, 2023
2 parents 95bca06 + cb8515d commit 4694c5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::LEVELDB, "leveldb"},
{BCLog::COINSTAKE, "coinstake"},
{BCLog::HTTPPOLL, "http-poll"},
{BCLog::DGP, "dgp"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};
Expand Down
1 change: 1 addition & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace BCLog {
LEVELDB = (1 << 20),
COINSTAKE = (1 << 21),
HTTPPOLL = (1 << 22),
DGP = (1 << 23),
ALL = ~(uint32_t)0,
};

Expand Down
22 changes: 17 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64
}
if (gArgs.GetBoolArg("-disablecontractstaking", false))
{
// Contract staking is disabled for the staker
return false;
}

Expand All @@ -467,6 +468,7 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64
if(!convert.extractionQtumTransactions(resultConverter)){
//this check already happens when accepting txs into mempool
//therefore, this can only be triggered by using raw transactions on the staker itself
LogPrintf("AttemptToAddContractToBlock(): Fail to extract contacts from tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}
std::vector<QtumTransaction> qtumTransactions = resultConverter.first;
Expand All @@ -475,15 +477,20 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64
txGas += qtumTransaction.gas();
if(txGas > txGasLimit) {
// Limit the tx gas limit by the soft limit if such a limit has been specified.
LogPrintf("AttemptToAddContractToBlock(): The gas needed is bigger than -staker-max-tx-gas-limit for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}

if(bceResult.usedGas + qtumTransaction.gas() > softBlockGasLimit){
//if this transaction's gasLimit could cause block gas limit to be exceeded, then don't add it
// If this transaction's gasLimit could cause block gas limit to be exceeded, then don't add it
// Log if the contract is the only contract tx
if(bceResult.usedGas == 0)
LogPrintf("AttemptToAddContractToBlock(): The gas needed is bigger than -staker-soft-block-gas-limit for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}
if(qtumTransaction.gasPrice() < minGasPrice){
//if this transaction's gasPrice is less than the current DGP minGasPrice don't add it
LogPrintf("AttemptToAddContractToBlock(): The gas price is less than -staker-min-tx-gas-price for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}
}
Expand All @@ -493,20 +500,25 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64
//error, don't add contract
globalState->setRoot(oldHashStateRoot);
globalState->setRootUTXO(oldHashUTXORoot);
LogPrintf("AttemptToAddContractToBlock(): Perform byte code fails for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}

ByteCodeExecResult testExecResult;
if(!exec.processingResults(testExecResult)){
globalState->setRoot(oldHashStateRoot);
globalState->setRootUTXO(oldHashUTXORoot);
LogPrintf("AttemptToAddContractToBlock(): Processing results fails for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}

if(bceResult.usedGas + testExecResult.usedGas > softBlockGasLimit){
//if this transaction could cause block gas limit to be exceeded, then don't add it
// If this transaction could cause block gas limit to be exceeded, then don't add it
globalState->setRoot(oldHashStateRoot);
globalState->setRootUTXO(oldHashUTXORoot);
// Log if the contract is the only contract tx
if(bceResult.usedGas == 0)
LogPrintf("AttemptToAddContractToBlock(): The gas used is bigger than -staker-soft-block-gas-limit for the contract tx %s\n", iter->GetTx().GetHash().ToString());
return false;
}

Expand Down Expand Up @@ -606,7 +618,7 @@ bool BlockAssembler::IsRewardToSelf(dev::Address addrWinner, CMutableTransaction
PKHash senderAddress;
txnouttype txType;
if(!ExtractDestination(coinstakeTx->vout[1].scriptPubKey, addressBit, &txType)) {
LogPrintf("IsRewardToSelf: Could not extract sender pubkey from output.\n");
LogPrint(BCLog::DGP, "IsRewardToSelf: Could not extract sender pubkey from output.\n");
return false;
}

Expand All @@ -615,7 +627,7 @@ bool BlockAssembler::IsRewardToSelf(dev::Address addrWinner, CMutableTransaction
// Get convert the govWinner hex to a PK address
std::string hexAddress = HexStr(addrWinner.asBytes());
if (hexAddress.size() != 40) {
LogPrintf("IsRewardToSelf: Invalid pubkeyhash hex size (should be 40 hex characters)\n");
LogPrint(BCLog::DGP, "IsRewardToSelf: Invalid pubkeyhash hex size (should be 40 hex characters)\n");
return false;
}
PKHash raw;
Expand All @@ -627,7 +639,7 @@ bool BlockAssembler::IsRewardToSelf(dev::Address addrWinner, CMutableTransaction
// If these match then the staker is choosing itsself as winning gov.
// In rare cases this causes bad consensus, and should just be avoided.
if (currentAddress == govWinnerStr) {
LogPrintf("IsRewardToSelf: Gov Winner : %s, Staker Address : %s, gov reward abandoned. The winner cannot be the staker.\n", govWinnerStr, currentAddress);
LogPrint(BCLog::DGP, "IsRewardToSelf: Gov Winner : %s, Staker Address : %s, gov reward abandoned. The winner cannot be the staker.\n", govWinnerStr, currentAddress);
return true;
}

Expand Down
10 changes: 7 additions & 3 deletions src/qtum/qtumDGP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ dev::Address QtumDGP::getGovernanceWinner(unsigned int blockHeight){
std::vector<uint64_t> v = getUint64VectorFromDGP(blockHeight, getGovernanceDGP(), ParseHex("e3eece26000000000000000000000000" + HexStr(value.asBytes())));
if (::ChainActive().Tip()->nHeight < v[0] + 1920) {
//Take the registration block and add 48hrs worth of blocks
LogPrintf("Governor immature - Address: %s | Registration Block: %u\n", HexStr(value.asBytes()), v[0] + 1920);
LogPrint(BCLog::DGP,"Governor immature - Address: %s | Registration Block: %u\n", HexStr(value.asBytes()), v[0] + 1920);
value = dev::Address(0x0);
}
}
Expand Down Expand Up @@ -322,11 +322,14 @@ dev::Address QtumDGP::getGovernanceWinner(unsigned int blockHeight){
dgpCollateral == govCollateral &&
height >= govBlockHeight + minMaturity &&
height <= govlastPing + pingInterval) {
LogPrintf("Governor valid - Address: %s | Registration block: %i | Last Rewarded: %i\n", HexStr(value.asBytes()), v[0], v[3]);
LogPrint(BCLog::DGP, "Governor valid - Address: %s | Registration block: %i | Last Rewarded: %i\n", HexStr(value.asBytes()), v[0], v[3]);
return value;
} else {
dev::Address oldValue = value;
LogPrint(BCLog::DGP, "Governor invalid - Address: %s | Registration block: %i | Last Rewarded: %i | Last Ping: %i | Current height: %i\n", HexStr(oldValue.asBytes()), v[0], v[3], v[1], height);
// if winner selection doesn't pass criteria checks then manually try and find an eligible one.
// Get the list of currently active governors

std::vector<dev::Address> governorAddresses = getAddressVectorFromDGP(blockHeight, getGovernanceDGP(), ParseHex("883703c2"));
for(std::vector<uint64_t>::size_type i = 0; i != governorAddresses.size(); i++) {
dev::Address value = dev::Address(governorAddresses[i]);
Expand All @@ -344,7 +347,8 @@ dev::Address QtumDGP::getGovernanceWinner(unsigned int blockHeight){
dgpCollateral == govCollateral &&
height >= govBlockHeight + minMaturity &&
height <= govlastPing + pingInterval) {
LogPrintf("Governor valid - Address: %s | Registration block: %i | Last Rewarded: %i\n", HexStr(value.asBytes()), v[0], v[3]);
LogPrint(BCLog::DGP, "Governor valid - Address: %s | Registration block: %i | Last Rewarded: %i\n", HexStr(value.asBytes()), v[0], v[3]);
LogPrint(BCLog::DGP, "Winner manual mismatch - Original Address: %s | New Address: %s | Current Height: %i\n", HexStr(oldValue.asBytes()), HexStr(value.asBytes()), height);
return value;
}
}
Expand Down

0 comments on commit 4694c5c

Please sign in to comment.