Skip to content

Commit

Permalink
Workarounds for building with Clang on Ubuntu 22
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
upshaw-alex committed May 5, 2023
1 parent 3bcec13 commit 6cd292f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions kvbc/include/categorization/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ///////////////////////
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions kvbc/src/categorization/block_merkle_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion kvbc/src/v4blockchain/detail/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions kvbc/src/v4blockchain/detail/st_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ StChain::StChain(const std::shared_ptr<concord::storage::rocksdb::NativeClient>&
/////////// 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) {
Expand Down
8 changes: 4 additions & 4 deletions storage/include/rocksdb/native_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class NativeClient : public std::enable_shared_from_this<NativeClient> {
std::optional<std::string> get(const std::string &cFamily, const KeySpan &key) const;
template <typename KeySpan>
std::optional<std::string> 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 <typename KeySpan>
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 <typename KeySpan>
void del(const std::string &cFamily, const KeySpan &key);
Expand All @@ -98,9 +98,9 @@ class NativeClient : public std::enable_shared_from_this<NativeClient> {
// Returns nullopt if the key is not found.
template <typename KeySpan>
std::optional<std::string> get(const KeySpan &key) const;
// Returns nullopt if the key is not found.
// Returns null if the key is not found.
template <typename KeySpan>
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 <typename KeySpan>
void del(const KeySpan &key);
Expand Down
13 changes: 7 additions & 6 deletions storage/include/rocksdb/native_client.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ std::optional<std::string> NativeClient::get(const std::string &cFamily,
}

template <typename KeySpan>
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 <typename KeySpan>
Expand All @@ -135,7 +136,7 @@ std::optional<std::string> NativeClient::get(const KeySpan &key) const {
}

template <typename KeySpan>
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);
}

Expand Down
2 changes: 0 additions & 2 deletions utt/libutt/include/utt/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(rand()) % maxDenom + 1;
totalVal += val;

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

0 comments on commit 6cd292f

Please sign in to comment.