diff --git a/kvbc/include/categorization/blockchain.h b/kvbc/include/categorization/blockchain.h index c617f1dac8..6f57ccef82 100644 --- a/kvbc/include/categorization/blockchain.h +++ b/kvbc/include/categorization/blockchain.h @@ -83,7 +83,7 @@ class Blockchain { } bool hasBlock(BlockId block_id) const { - return native_client_->getSlice(detail::BLOCKS_CF, Block::generateKey(block_id)).has_value(); + return (bool)native_client_->getSlice(detail::BLOCKS_CF, Block::generateKey(block_id)); } /////////////////////// State transfer Block chain /////////////////////// @@ -152,7 +152,7 @@ class Blockchain { } bool hasBlock(BlockId block_id) const { - return native_client_->getSlice(detail::ST_CHAIN_CF, Block::generateKey(block_id)).has_value(); + return (bool)native_client_->getSlice(detail::ST_CHAIN_CF, Block::generateKey(block_id)); } void updateLastId(const BlockId id) { diff --git a/kvbc/src/categorization/block_merkle_category.cpp b/kvbc/src/categorization/block_merkle_category.cpp index abf13aa439..351b8751e4 100644 --- a/kvbc/src/categorization/block_merkle_category.cpp +++ b/kvbc/src/categorization/block_merkle_category.cpp @@ -724,7 +724,7 @@ void BlockMerkleCategory::deleteStaleData(uint64_t tree_version, detail::LocalWr // Create a batch to delete stale keys for this tree version auto ser_stale = db_->getSlice(BLOCK_MERKLE_STALE_CF, serialize(TreeVersion{tree_version})); - ConcordAssert(ser_stale.has_value()); + ConcordAssert((bool)ser_stale); addStaleKeysToDeleteBatch(*ser_stale, tree_version, batch); putLastDeletedTreeVersion(tree_version, batch); } @@ -747,7 +747,7 @@ MerkleBlockValue BlockMerkleCategory::computeRootHash(BlockId block_id, // Calculate a new root hash for all keys in the block auto versioned_key = serialize(VersionedKey{key, block_id}); auto value = db_->getSlice(BLOCK_MERKLE_KEYS_CF, versioned_key); - ConcordAssert(value.has_value()); + ConcordAssert((bool)value); auto val_hash = hash(*value); hasher.update(key.value.data(), key.value.size()); hasher.update(val_hash.data(), val_hash.size()); diff --git a/kvbc/src/v4blockchain/detail/blockchain.cpp b/kvbc/src/v4blockchain/detail/blockchain.cpp index 67d5d0d2c9..886f89fa34 100644 --- a/kvbc/src/v4blockchain/detail/blockchain.cpp +++ b/kvbc/src/v4blockchain/detail/blockchain.cpp @@ -265,7 +265,7 @@ bool Blockchain::hasBlock(BlockId block_id) const { if ((block_id > last_reachable_block_id_) || (block_id < genesis_block_id_)) { return false; } - return native_client_->getSlice(v4blockchain::detail::BLOCKS_CF, generateKey(block_id)).has_value(); + return (bool)native_client_->getSlice(v4blockchain::detail::BLOCKS_CF, generateKey(block_id)); } } // namespace concord::kvbc::v4blockchain::detail diff --git a/kvbc/src/v4blockchain/detail/st_chain.cpp b/kvbc/src/v4blockchain/detail/st_chain.cpp index c225e8bc31..cd78917451 100644 --- a/kvbc/src/v4blockchain/detail/st_chain.cpp +++ b/kvbc/src/v4blockchain/detail/st_chain.cpp @@ -34,9 +34,8 @@ StChain::StChain(const std::shared_ptr& /////////// BLOCKS///////////////////////// bool StChain::hasBlock(BlockId block_id) const { if (last_block_id_ < block_id) return false; - return native_client_ - ->getSlice(v4blockchain::detail::ST_CHAIN_CF, v4blockchain::detail::Blockchain::generateKey(block_id)) - .has_value(); + return (bool)native_client_ + ->getSlice(v4blockchain::detail::ST_CHAIN_CF, v4blockchain::detail::Blockchain::generateKey(block_id)); } void StChain::addBlock(const BlockId id, const char* block, const uint32_t blockSize) { diff --git a/storage/include/rocksdb/native_client.h b/storage/include/rocksdb/native_client.h index 5eede8cf0a..7db35e96e0 100644 --- a/storage/include/rocksdb/native_client.h +++ b/storage/include/rocksdb/native_client.h @@ -85,9 +85,9 @@ class NativeClient : public std::enable_shared_from_this { std::optional get(const std::string &cFamily, const KeySpan &key) const; template std::optional get(const std::string &cFamily, const KeySpan &key, ::rocksdb::ReadOptions ro) const; - // Returns nullopt if the key is not found. + // Returns null if the key is not found. template - std::optional<::rocksdb::PinnableSlice> getSlice(const std::string &cFamily, const KeySpan &key) const; + std::unique_ptr<::rocksdb::PinnableSlice> getSlice(const std::string &cFamily, const KeySpan &key) const; // Deleting a key that doesn't exist is not an error. template void del(const std::string &cFamily, const KeySpan &key); @@ -98,9 +98,9 @@ class NativeClient : public std::enable_shared_from_this { // Returns nullopt if the key is not found. template std::optional get(const KeySpan &key) const; - // Returns nullopt if the key is not found. + // Returns null if the key is not found. template - std::optional<::rocksdb::PinnableSlice> getSlice(const KeySpan &key) const; + std::unique_ptr<::rocksdb::PinnableSlice> getSlice(const KeySpan &key) const; // Deleting a key that doesn't exist is not an error. template void del(const KeySpan &key); diff --git a/storage/include/rocksdb/native_client.ipp b/storage/include/rocksdb/native_client.ipp index dc6cc793eb..059453e50c 100644 --- a/storage/include/rocksdb/native_client.ipp +++ b/storage/include/rocksdb/native_client.ipp @@ -107,15 +107,16 @@ std::optional NativeClient::get(const std::string &cFamily, } template -std::optional<::rocksdb::PinnableSlice> NativeClient::getSlice(const std::string &cFamily, const KeySpan &key) const { - auto slice = ::rocksdb::PinnableSlice{}; +std::unique_ptr<::rocksdb::PinnableSlice> NativeClient::getSlice(const std::string &cFamily, const KeySpan &key) const { + auto slice = std::make_unique<::rocksdb::PinnableSlice>(); auto s = - client_->dbInstance_->Get(::rocksdb::ReadOptions{}, columnFamilyHandle(cFamily), detail::toSlice(key), &slice); + client_->dbInstance_->Get(::rocksdb::ReadOptions{}, columnFamilyHandle(cFamily), detail::toSlice(key), + slice.get()); if (s.IsNotFound()) { - return std::nullopt; + return std::unique_ptr<::rocksdb::PinnableSlice>(nullptr); } detail::throwOnError("get() failed"sv, std::move(s)); - return std::move(slice); + return slice; } template @@ -135,7 +136,7 @@ std::optional NativeClient::get(const KeySpan &key) const { } template -std::optional<::rocksdb::PinnableSlice> NativeClient::getSlice(const KeySpan &key) const { +std::unique_ptr<::rocksdb::PinnableSlice> NativeClient::getSlice(const KeySpan &key) const { return getSlice(defaultColumnFamily(), key); } diff --git a/utt/libutt/include/utt/Factory.h b/utt/libutt/include/utt/Factory.h index fc70eb73e2..052459c655 100644 --- a/utt/libutt/include/utt/Factory.h +++ b/utt/libutt/include/utt/Factory.h @@ -76,11 +76,9 @@ class Factory { // issue some random 'normal' coins to this user Coin prevCoin; - size_t totalVal = 0; for (size_t k = 0; k < numCoins; k++) { // ...of value less than or equal to the allowed max coin value size_t val = static_cast(rand()) % maxDenom + 1; - totalVal += val; // ...and everything else random Coin c = Factory::mintRandomCoin(Coin::NormalType(), val, ask);