Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contract logging #198

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -256,7 +256,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 @@ -294,11 +294,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 @@ -316,7 +319,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