Skip to content

Commit

Permalink
refactor: trivial fixes for dead, useless code and minor fixes for da…
Browse files Browse the repository at this point in the history
…sh specific code (#5793)

## Issue being fixed or feature implemented
Dead-code, useless conditions can be potential source of bug.

## What was done?
See each particular commit.
This particular commit "fix: check ptr in assert before usage" fixes
potential UB - `assert` is better than UB.
All other commits are not fixing any real issue, just to tidy-up code a
bit or to shut a potential warning.


## How Has This Been Tested?
Run unit/functional tests.

## Breaking Changes
N/A

## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone
  • Loading branch information
knst authored Jan 2, 2024
1 parent 74c7f20 commit 7d9c572
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/evo/cbtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CCbTx
int32_t nHeight{0};
uint256 merkleRootMNList;
uint256 merkleRootQuorums;
uint32_t bestCLHeightDiff;
uint32_t bestCLHeightDiff{0};
CBLSSignature bestCLSignature;
CAmount creditPoolBalance{0};

Expand Down
2 changes: 1 addition & 1 deletion src/evo/mnhftx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ std::optional<CMNHFManager::Signals> CMNHFManager::GetFromCache(const CBlockInde

void CMNHFManager::AddToCache(const Signals& signals, const CBlockIndex* const pindex)
{
assert(pindex != nullptr);
const uint256& blockHash = pindex->GetBlockHash();
{
LOCK(cs_cache);
mnhfCache.insert(blockHash, signals);
}
assert(pindex != nullptr);
{
LOCK(cs_cache);
if (ThresholdState::ACTIVE != v20_activation.State(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) return;
Expand Down
5 changes: 0 additions & 5 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,6 @@ void CGovernanceManager::UpdateCachesAndClean()
while (it != mapObjects.end()) {
CGovernanceObject* pObj = &((*it).second);

if (!pObj) {
++it;
continue;
}

uint256 nHash = it->first;
std::string strHash = nHash.ToString();

Expand Down
2 changes: 1 addition & 1 deletion src/llmq/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ CQuorumCPtr CSigningManager::SelectQuorumForSigning(const Consensus::LLMQParams&
//Extract last 64 bits of selectionHash
uint64_t b = selectionHash.GetUint64(3);
//Take last n bits of b
uint64_t signer = (((1 << n) - 1) & (b >> (64 - n - 1)));
uint64_t signer = (((1ull << n) - 1) & (b >> (64 - n - 1)));

if (signer > quorums.size()) {
return nullptr;
Expand Down
6 changes: 1 addition & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3291,8 +3291,7 @@ void CExplicitNetCleanup::callCleanup()
{
// Explicit call to destructor of CNetCleanup because it's not implicitly called
// when the wallet is restarted from within the wallet itself.
CNetCleanup *tmp = new CNetCleanup();
delete tmp; // Stroustrup's gonna kill me for that
CNetCleanup tmp;
}

void CConnman::Interrupt()
Expand Down Expand Up @@ -3955,7 +3954,6 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
statsClient.count("bandwidth.message." + SanitizeString(msg.command.c_str()) + ".bytesSent", nTotalSize, 1.0f);
statsClient.inc("message.sent." + SanitizeString(msg.command.c_str()), 1.0f);

size_t nBytesSent = 0;
{
LOCK(pnode->cs_vSend);
bool hasPendingData = !pnode->vSendMsg.empty();
Expand Down Expand Up @@ -3986,8 +3984,6 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
if (!hasPendingData && wakeupSelectNeeded)
WakeSelect();
}
if (nBytesSent)
RecordBytesSent(nBytesSent);
}

bool CConnman::ForNode(const CService& addr, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func)
Expand Down
7 changes: 1 addition & 6 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
unsigned int nBytesInputs = 0;
unsigned int nQuantity = 0;
bool fUnselectedSpent{false};
bool fUnselectedNonMixed{false};

std::vector<COutPoint> vCoinControl;
m_coin_control.ListSelected(vCoinControl);
Expand Down Expand Up @@ -575,7 +574,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *

// actually update labels
int nDisplayUnit = BitcoinUnits::DASH;
if (model && model->getOptionsModel())
if (model->getOptionsModel())
nDisplayUnit = model->getOptionsModel()->getDisplayUnit();

QLabel *l1 = dialog->findChild<QLabel *>("labelCoinControlQuantity");
Expand Down Expand Up @@ -639,10 +638,6 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
QMessageBox::warning(dialog, "CoinControl",
tr("Some coins were unselected because they were spent."),
QMessageBox::Ok, QMessageBox::Ok);
} else if (fUnselectedNonMixed) {
QMessageBox::warning(dialog, "CoinControl",
tr("Some coins were unselected because they do not have enough mixing rounds."),
QMessageBox::Ok, QMessageBox::Ok);
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)

updateCoinJoinProgress();

if (walletModel) {
int numISLocks = walletModel->getNumISLocks();
if(cachedNumISLocks != numISLocks) {
cachedNumISLocks = numISLocks;
ui->listTransactions->update();
}
int numISLocks = walletModel->getNumISLocks();
if(cachedNumISLocks != numISLocks) {
cachedNumISLocks = numISLocks;
ui->listTransactions->update();
}
}

Expand Down Expand Up @@ -638,7 +636,7 @@ void OverviewPage::toggleCoinJoin(){
}

// if wallet is locked, ask for a passphrase
if (walletModel && walletModel->getEncryptionStatus() == WalletModel::Locked)
if (walletModel->getEncryptionStatus() == WalletModel::Locked)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock(true));
if(!ctx.isValid())
Expand Down

0 comments on commit 7d9c572

Please sign in to comment.