Skip to content

Commit a09ef6d

Browse files
committed
Workarounds for building with Clang on Ubuntu 22
This commit introduces workarounds for building Concord-BFT with Clang after the Ubuntu 22 upgrade. These workarounds include: - Changing usage of std::optional<::rocksdb::PinnableSlice> to std::unique_ptr<::rocksdb::PinnableSlice>, as Clang generates an error with this particular template instantiation. - Removal of the local variable totalVal from the function libutt::Factory::randomWallets, as this variable is unused and (with -Werror) Clang generates an error for that.
1 parent 61c4d39 commit a09ef6d

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

kvbc/include/categorization/blockchain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Blockchain {
8383
}
8484

8585
bool hasBlock(BlockId block_id) const {
86-
return native_client_->getSlice(detail::BLOCKS_CF, Block::generateKey(block_id)).has_value();
86+
return (bool)native_client_->getSlice(detail::BLOCKS_CF, Block::generateKey(block_id));
8787
}
8888

8989
/////////////////////// State transfer Block chain ///////////////////////
@@ -152,7 +152,7 @@ class Blockchain {
152152
}
153153

154154
bool hasBlock(BlockId block_id) const {
155-
return native_client_->getSlice(detail::ST_CHAIN_CF, Block::generateKey(block_id)).has_value();
155+
return (bool)native_client_->getSlice(detail::ST_CHAIN_CF, Block::generateKey(block_id));
156156
}
157157

158158
void updateLastId(const BlockId id) {

kvbc/src/categorization/block_merkle_category.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void BlockMerkleCategory::deleteStaleData(uint64_t tree_version, detail::LocalWr
724724

725725
// Create a batch to delete stale keys for this tree version
726726
auto ser_stale = db_->getSlice(BLOCK_MERKLE_STALE_CF, serialize(TreeVersion{tree_version}));
727-
ConcordAssert(ser_stale.has_value());
727+
ConcordAssert((bool)ser_stale);
728728
addStaleKeysToDeleteBatch(*ser_stale, tree_version, batch);
729729
putLastDeletedTreeVersion(tree_version, batch);
730730
}
@@ -747,7 +747,7 @@ MerkleBlockValue BlockMerkleCategory::computeRootHash(BlockId block_id,
747747
// Calculate a new root hash for all keys in the block
748748
auto versioned_key = serialize(VersionedKey{key, block_id});
749749
auto value = db_->getSlice(BLOCK_MERKLE_KEYS_CF, versioned_key);
750-
ConcordAssert(value.has_value());
750+
ConcordAssert((bool)value);
751751
auto val_hash = hash(*value);
752752
hasher.update(key.value.data(), key.value.size());
753753
hasher.update(val_hash.data(), val_hash.size());

kvbc/src/v4blockchain/detail/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ bool Blockchain::hasBlock(BlockId block_id) const {
265265
if ((block_id > last_reachable_block_id_) || (block_id < genesis_block_id_)) {
266266
return false;
267267
}
268-
return native_client_->getSlice(v4blockchain::detail::BLOCKS_CF, generateKey(block_id)).has_value();
268+
return (bool)native_client_->getSlice(v4blockchain::detail::BLOCKS_CF, generateKey(block_id));
269269
}
270270

271271
} // namespace concord::kvbc::v4blockchain::detail

kvbc/src/v4blockchain/detail/st_chain.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ StChain::StChain(const std::shared_ptr<concord::storage::rocksdb::NativeClient>&
3434
/////////// BLOCKS/////////////////////////
3535
bool StChain::hasBlock(BlockId block_id) const {
3636
if (last_block_id_ < block_id) return false;
37-
return native_client_
38-
->getSlice(v4blockchain::detail::ST_CHAIN_CF, v4blockchain::detail::Blockchain::generateKey(block_id))
39-
.has_value();
37+
return (bool)native_client_
38+
->getSlice(v4blockchain::detail::ST_CHAIN_CF, v4blockchain::detail::Blockchain::generateKey(block_id));
4039
}
4140

4241
void StChain::addBlock(const BlockId id, const char* block, const uint32_t blockSize) {

storage/include/rocksdb/native_client.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class NativeClient : public std::enable_shared_from_this<NativeClient> {
8585
std::optional<std::string> get(const std::string &cFamily, const KeySpan &key) const;
8686
template <typename KeySpan>
8787
std::optional<std::string> get(const std::string &cFamily, const KeySpan &key, ::rocksdb::ReadOptions ro) const;
88-
// Returns nullopt if the key is not found.
88+
// Returns null if the key is not found.
8989
template <typename KeySpan>
90-
std::optional<::rocksdb::PinnableSlice> getSlice(const std::string &cFamily, const KeySpan &key) const;
90+
std::unique_ptr<::rocksdb::PinnableSlice> getSlice(const std::string &cFamily, const KeySpan &key) const;
9191
// Deleting a key that doesn't exist is not an error.
9292
template <typename KeySpan>
9393
void del(const std::string &cFamily, const KeySpan &key);
@@ -98,9 +98,9 @@ class NativeClient : public std::enable_shared_from_this<NativeClient> {
9898
// Returns nullopt if the key is not found.
9999
template <typename KeySpan>
100100
std::optional<std::string> get(const KeySpan &key) const;
101-
// Returns nullopt if the key is not found.
101+
// Returns null if the key is not found.
102102
template <typename KeySpan>
103-
std::optional<::rocksdb::PinnableSlice> getSlice(const KeySpan &key) const;
103+
std::unique_ptr<::rocksdb::PinnableSlice> getSlice(const KeySpan &key) const;
104104
// Deleting a key that doesn't exist is not an error.
105105
template <typename KeySpan>
106106
void del(const KeySpan &key);

storage/include/rocksdb/native_client.ipp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ std::optional<std::string> NativeClient::get(const std::string &cFamily,
107107
}
108108

109109
template <typename KeySpan>
110-
std::optional<::rocksdb::PinnableSlice> NativeClient::getSlice(const std::string &cFamily, const KeySpan &key) const {
111-
auto slice = ::rocksdb::PinnableSlice{};
110+
std::unique_ptr<::rocksdb::PinnableSlice> NativeClient::getSlice(const std::string &cFamily, const KeySpan &key) const {
111+
auto slice = std::make_unique<::rocksdb::PinnableSlice>();
112112
auto s =
113-
client_->dbInstance_->Get(::rocksdb::ReadOptions{}, columnFamilyHandle(cFamily), detail::toSlice(key), &slice);
113+
client_->dbInstance_->Get(::rocksdb::ReadOptions{}, columnFamilyHandle(cFamily), detail::toSlice(key),
114+
slice.get());
114115
if (s.IsNotFound()) {
115-
return std::nullopt;
116+
return std::unique_ptr<::rocksdb::PinnableSlice>(nullptr);
116117
}
117118
detail::throwOnError("get() failed"sv, std::move(s));
118-
return std::move(slice);
119+
return slice;
119120
}
120121

121122
template <typename KeySpan>
@@ -135,7 +136,7 @@ std::optional<std::string> NativeClient::get(const KeySpan &key) const {
135136
}
136137

137138
template <typename KeySpan>
138-
std::optional<::rocksdb::PinnableSlice> NativeClient::getSlice(const KeySpan &key) const {
139+
std::unique_ptr<::rocksdb::PinnableSlice> NativeClient::getSlice(const KeySpan &key) const {
139140
return getSlice(defaultColumnFamily(), key);
140141
}
141142

utt/libutt/include/utt/Factory.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ class Factory {
7676

7777
// issue some random 'normal' coins to this user
7878
Coin prevCoin;
79-
size_t totalVal = 0;
8079
for (size_t k = 0; k < numCoins; k++) {
8180
// ...of value less than or equal to the allowed max coin value
8281
size_t val = static_cast<size_t>(rand()) % maxDenom + 1;
83-
totalVal += val;
8482

8583
// ...and everything else random
8684
Coin c = Factory::mintRandomCoin(Coin::NormalType(), val, ask);

0 commit comments

Comments
 (0)