Skip to content

Commit

Permalink
refactor: make a few additional things use std::string_view (#5874)
Browse files Browse the repository at this point in the history
## Issue being fixed or feature implemented
Use string view where possible

## What was done?

## How Has This Been Tested?
Building

## Breaking Changes
None

## Checklist:
_Go over all the following points, and put an `x` in all the boxes that
apply._
- [ ] 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 _(for repository
code-owners and collaborators only)_

Co-authored-by: laanwj <[email protected]>
  • Loading branch information
PastaPastaPasta and laanwj authored Feb 19, 2024
1 parent 0f0c53a commit 95b15fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
33 changes: 15 additions & 18 deletions src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@
namespace llmq
{

static const std::string INPUTLOCK_REQUESTID_PREFIX = "inlock";
static const std::string ISLOCK_REQUESTID_PREFIX = "islock";
static const std::string_view INPUTLOCK_REQUESTID_PREFIX = "inlock";
static const std::string_view ISLOCK_REQUESTID_PREFIX = "islock";

static const std::string DB_ISLOCK_BY_HASH = "is_i";
static const std::string DB_HASH_BY_TXID = "is_tx";
static const std::string DB_HASH_BY_OUTPOINT = "is_in";
static const std::string DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
static const std::string DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
static const std::string DB_ARCHIVED_BY_HASH = "is_a2";
static const std::string_view DB_ISLOCK_BY_HASH = "is_i";
static const std::string_view DB_HASH_BY_TXID = "is_tx";
static const std::string_view DB_HASH_BY_OUTPOINT = "is_in";
static const std::string_view DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
static const std::string_view DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
static const std::string_view DB_ARCHIVED_BY_HASH = "is_a2";

static const std::string DB_VERSION = "is_v";

const int CInstantSendDb::CURRENT_VERSION;
const uint8_t CInstantSendLock::CURRENT_VERSION;
static const std::string_view DB_VERSION = "is_v";

std::unique_ptr<CInstantSendManager> quorumInstantSendManager;

Expand Down Expand Up @@ -73,7 +70,7 @@ void CInstantSendDb::Upgrade(const CTxMemPool& mempool)
CInstantSendLock islock;

auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());
it->Seek(firstKey);
decltype(firstKey) curKey;

Expand Down Expand Up @@ -142,9 +139,9 @@ void CInstantSendDb::RemoveInstantSendLock(CDBBatch& batch, const uint256& hash,
}
}

static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(const std::string& k, int nHeight, const uint256& islockHash)
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::string_view k, int nHeight, const uint256& islockHash)
{
return std::make_tuple(k, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
return std::make_tuple(std::string{k}, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
}

void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight)
Expand Down Expand Up @@ -302,7 +299,7 @@ size_t CInstantSendDb::GetInstantSendLockCount() const
{
LOCK(cs_db);
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());

it->Seek(firstKey);

Expand Down Expand Up @@ -382,7 +379,7 @@ std::vector<uint256> CInstantSendDb::GetInstantSendLocksByParent(const uint256&
{
AssertLockHeld(cs_db);
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_HASH_BY_OUTPOINT, COutPoint(parent, 0));
auto firstKey = std::make_tuple(std::string{DB_HASH_BY_OUTPOINT}, COutPoint(parent, 0));
it->Seek(firstKey);

std::vector<uint256> result;
Expand Down Expand Up @@ -751,7 +748,7 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco
pendingInstantSendLocks.emplace(hash, std::make_pair(-1, islock));
}

PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv)
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv)
{
if (IsInstantSendEnabled() && msg_type == NetMsgType::ISDLOCK) {
if (m_peerman == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class CInstantSendManager : public CRecoveredSigsListener

void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override LOCKS_EXCLUDED(cs_inputReqests, cs_creating);

PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv);
PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv);

void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_pendingLocks);
void TransactionRemovedFromMempool(const CTransactionRef& tx);
Expand Down

0 comments on commit 95b15fd

Please sign in to comment.