Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: enforce parameter case #2583

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ CheckOptions:
readability-identifier-naming.GlobalConstantPrefix: k
readability-identifier-naming.LocalVariableCase: lower_case
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
readability-identifier-naming.NamespaceCase: lower_case
readability-identifier-naming.ParameterCase: lower_case
readability-identifier-naming.PrivateMemberCase: lower_case
readability-identifier-naming.PrivateMemberSuffix: _
readability-identifier-naming.ProtectedMemberCase: lower_case
Expand All @@ -108,4 +110,5 @@ CheckOptions:
readability-identifier-naming.PublicMemberSuffix: ''
readability-identifier-naming.StaticConstantCase: CamelCase
readability-identifier-naming.StaticConstantPrefix: k
readability-identifier-naming.StaticVariableCase: lower_case
readability-simplify-boolean-expr.SimplifyDeMorgan: false
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct RecSplit<LEAF_SIZE>::SequentialBuildingStrategy : public BuildingStrategy
// We use an exception for collision error condition because ETL currently does not support loading errors
// TODO(canepat) refactor ETL to support errors in LoadFunc and propagate them to caller to get rid of CollisionError
struct CollisionError : public std::runtime_error {
explicit CollisionError(uint64_t _bucket_id) : runtime_error("collision"), bucket_id(_bucket_id) {}
explicit CollisionError(uint64_t bucket_id) : runtime_error("collision"), bucket_id(bucket_id) {}
uint64_t bucket_id;
};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST_CASE("PatternCoveringSearch1") {

PatternCoveringSearch search{
patterns_tree,
[](void* patternScore) { return *reinterpret_cast<uint64_t*>(patternScore); }};
[](void* pattern_score) { return *reinterpret_cast<uint64_t*>(pattern_score); }};

{
auto& result = search.cover_word("0x6c6f6e67"_hex);
Expand Down
16 changes: 8 additions & 8 deletions silkworm/infra/common/ensure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ inline void ensure(bool condition, const char (&message)[N]) {

//! Ensure that condition is met, otherwise raise a logic error with dynamically built message
//! Usage: `ensure(condition, [&]() { return "Message: " + get_str(); });`
inline void ensure(bool condition, const std::function<std::string()>& messageBuilder) {
inline void ensure(bool condition, const std::function<std::string()>& message_builder) {
if (!condition) [[unlikely]] {
throw std::logic_error(messageBuilder());
throw std::logic_error(message_builder());
}
}

Expand All @@ -47,23 +47,23 @@ inline void ensure_invariant(bool condition, const char (&message)[N]) {
}

//! Similar to \code ensure with emphasis on invariant violation
inline void ensure_invariant(bool condition, const std::function<std::string()>& messageBuilder) {
inline void ensure_invariant(bool condition, const std::function<std::string()>& message_builder) {
if (!condition) [[unlikely]] {
throw std::logic_error("Invariant violation: " + messageBuilder());
throw std::logic_error("Invariant violation: " + message_builder());
}
}

//! Similar to \code ensure with emphasis on pre-condition violation
inline void ensure_pre_condition(bool condition, const std::function<std::string()>& messageBuilder) {
inline void ensure_pre_condition(bool condition, const std::function<std::string()>& message_builder) {
if (!condition) [[unlikely]] {
throw std::invalid_argument("Pre-condition violation: " + messageBuilder());
throw std::invalid_argument("Pre-condition violation: " + message_builder());
}
}

//! Similar to \code ensure with emphasis on post-condition violation
inline void ensure_post_condition(bool condition, const std::function<std::string()>& messageBuilder) {
inline void ensure_post_condition(bool condition, const std::function<std::string()>& message_builder) {
if (!condition) [[unlikely]] {
throw std::logic_error("Post-condition violation: " + messageBuilder());
throw std::logic_error("Post-condition violation: " + message_builder());
}
}

Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/stagedsync/forks/fork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
memory_tx_.abort();
}

void Fork::flush(db::RWTxn& main_chain_tx_) {
memory_tx_.flush(main_chain_tx_);
void Fork::flush(db::RWTxn& main_chain_tx) {
memory_tx_.flush(main_chain_tx);

Check warning on line 82 in silkworm/node/stagedsync/forks/fork.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/node/stagedsync/forks/fork.cpp#L81-L82

Added lines #L81 - L82 were not covered by tests
}

BlockId Fork::current_head() const {
Expand Down
2 changes: 1 addition & 1 deletion silkworm/node/stagedsync/forks/fork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Fork {
Fork(const Fork&) = delete;

void close();
void flush(db::RWTxn& main_chain_tx_);
void flush(db::RWTxn& main_chain_tx);

// extension & contraction
void extend_with(const std::list<std::shared_ptr<Block>>&);
Expand Down
6 changes: 3 additions & 3 deletions silkworm/rpc/commands/ots_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,10 +1374,10 @@
co_return BlockProviderResponse{block_num, has_more_from_ || has_more_to_, false};
}

FromToBlockProvider::FromToBlockProvider(bool is_backwards, BlockProvider* callFromProvider, BlockProvider* callToProvider)
FromToBlockProvider::FromToBlockProvider(bool is_backwards, BlockProvider* call_from_provider, BlockProvider* call_to_provider)
: is_backwards_{is_backwards},
call_from_provider_{callFromProvider},
call_to_provider_{callToProvider} {
call_from_provider_{call_from_provider},
call_to_provider_{call_to_provider} {

Check warning on line 1380 in silkworm/rpc/commands/ots_api.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.cpp#L1379-L1380

Added lines #L1379 - L1380 were not covered by tests
}

} // namespace silkworm::rpc::commands
2 changes: 1 addition & 1 deletion silkworm/rpc/commands/ots_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class FromToBlockProvider : public BlockProvider {
bool initialized_{false};

public:
FromToBlockProvider(bool is_backwards, BlockProvider* callFromProvider, BlockProvider* callToProvider);
FromToBlockProvider(bool is_backwards, BlockProvider* call_from_provider, BlockProvider* call_to_provider);

Task<BlockProviderResponse> get() override;
};
Expand Down
12 changes: 6 additions & 6 deletions silkworm/rpc/commands/rpc_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ using test_util::RpcApiTestBase;
#endif

// Function to recursively sort JSON arrays
void sort_array(nlohmann::json& jsonObj) { // NOLINT(*-no-recursion)
if (jsonObj.is_array()) {
void sort_array(nlohmann::json& json_obj) { // NOLINT(*-no-recursion)
if (json_obj.is_array()) {
// Sort the elements within the array
std::sort(jsonObj.begin(), jsonObj.end(), [](const nlohmann::json& a, const nlohmann::json& b) {
std::sort(json_obj.begin(), json_obj.end(), [](const nlohmann::json& a, const nlohmann::json& b) {
return a.dump() < b.dump();
});

// Recursively sort nested arrays
for (auto& item : jsonObj) {
for (auto& item : json_obj) {
sort_array(item);
}
} else if (jsonObj.is_object()) {
for (auto& item : jsonObj.items()) {
} else if (json_obj.is_object()) {
for (auto& item : json_obj.items()) {
sort_array(item.value());
}
}
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/estimate_gas_oracle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class EstimateGasOracle {
Task<intx::uint256> estimate_gas(const Call& call, const silkworm::Block& latest_block, TxnId txn_id, std::optional<BlockNum> block_num_for_gas_limit = {});

protected:
virtual ExecutionResult try_execution(EVMExecutor& executor, const silkworm::Block& _block, const silkworm::Transaction& transaction);
virtual ExecutionResult try_execution(EVMExecutor& executor, const silkworm::Block& block, const silkworm::Transaction& transaction);

private:
void throw_exception(ExecutionResult& result);
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/engine/execution_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ExecutionEngine {

virtual Task<PayloadStatus> new_payload(const NewPayloadRequest& request, Msec timeout) = 0;
virtual Task<ForkChoiceUpdatedReply> fork_choice_updated(const ForkChoiceUpdatedRequest& request, Msec timeout) = 0;
virtual Task<ExecutionPayloadAndValue> get_payload(uint64_t payloadId, Msec timeout) = 0;
virtual Task<ExecutionPayloadAndValue> get_payload(uint64_t payload_id, Msec timeout) = 0;
virtual Task<ExecutionPayloadBodies> get_payload_bodies_by_hash(const std::vector<Hash>& block_hashes, Msec timeout) = 0;
virtual Task<ExecutionPayloadBodies> get_payload_bodies_by_range(BlockNum start, uint64_t count, Msec timeout) = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions silkworm/rpc/engine/remote_execution_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
co_return fork_choice_updated_reply_from_result(fork_choice_result);
}

Task<ExecutionPayloadAndValue> RemoteExecutionEngine::get_payload(uint64_t /*payloadId*/, Msec /*timeout*/) {
// We do not support the payload building process yet, so any payloadId is unknown
Task<ExecutionPayloadAndValue> RemoteExecutionEngine::get_payload(uint64_t /*payload_id*/, Msec /*timeout*/) {

Check warning on line 91 in silkworm/rpc/engine/remote_execution_engine.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/engine/remote_execution_engine.cpp#L91

Added line #L91 was not covered by tests
// We do not support the payload building process yet, so any payload ID is unknown
throw boost::system::system_error{to_system_code(ErrorCode::kUnknownPayload)};
}

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/engine/remote_execution_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RemoteExecutionEngine final : public ExecutionEngine {

Task<PayloadStatus> new_payload(const NewPayloadRequest& request, Msec timeout) override;
Task<ForkChoiceUpdatedReply> fork_choice_updated(const ForkChoiceUpdatedRequest& request, Msec timeout) override;
Task<ExecutionPayloadAndValue> get_payload(uint64_t payloadId, Msec timeout) override;
Task<ExecutionPayloadAndValue> get_payload(uint64_t payload_id, Msec timeout) override;
Task<ExecutionPayloadBodies> get_payload_bodies_by_hash(const std::vector<Hash>& block_hashes, Msec timeout) override;
Task<ExecutionPayloadBodies> get_payload_bodies_by_range(BlockNum start, uint64_t count, Msec timeout) override;

Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/internals/chain_elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ struct Link {
bool persisted = false; // Whether this link comes from the database record
bool preverified = false; // Ancestor of pre-verified header

Link(BlockHeader h, bool persisted_)
Link(BlockHeader h, bool persist)
: block_num{h.number},
hash{h.hash()}, // save computation
persisted{persisted_} {
persisted{persist} {
header = std::make_shared<BlockHeader>(std::move(h));
}

Expand Down
14 changes: 7 additions & 7 deletions silkworm/sync/internals/header_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void HeaderChain::request_nack(const GetBlockHeadersPacket66& packet) {
SILK_TRACE_M("HeaderChain") << "restoring timestamp due to request nack;"
<< " request_id=" << packet.request_id;

anchor_queue_.update(anchor, [&](auto& anchor_) { anchor_->restore_timestamp(); });
anchor_queue_.update(anchor, [&](auto& anchor_arg) { anchor_arg->restore_timestamp(); });
}

bool HeaderChain::has_link(Hash hash) { return (links_.find(hash) != links_.end()); }
Expand Down Expand Up @@ -700,7 +700,7 @@ std::tuple<std::vector<Segment>, Penalty> HeaderList::split_into_segments() {
return {segments, Penalty::kNoPenalty};
}

HeaderChain::RequestMoreHeaders HeaderChain::process_segment(const Segment& segment, bool is_a_new_block, const PeerId& peerId) {
HeaderChain::RequestMoreHeaders HeaderChain::process_segment(const Segment& segment, bool is_a_new_block, const PeerId& peer_id) {
if (segment.empty()) return false;
auto [anchor, start] = find_anchor(segment);
auto [tip, end] = find_link(segment, start);
Expand Down Expand Up @@ -755,7 +755,7 @@ HeaderChain::RequestMoreHeaders HeaderChain::process_segment(const Segment& segm
}
} else {
op = "new anchor";
request_more = new_anchor(segment_slice, peerId);
request_more = new_anchor(segment_slice, peer_id);
}
// SILK_TRACE << "HeaderChain, segment " << op << " up=" << start_num << " (" << segment[start]->hash()
// << ") down=" << end_num << " (" << segment[end - 1]->hash() << ") (more=" << request_more << ")";
Expand Down Expand Up @@ -986,13 +986,13 @@ void HeaderChain::extend_up(const std::shared_ptr<Link>& attachment_link, Segmen
<< (segment_slice.rend() - 1)->operator*().number;
}

HeaderChain::RequestMoreHeaders HeaderChain::new_anchor(Segment::Slice segment_slice, PeerId peerId) {
HeaderChain::RequestMoreHeaders HeaderChain::new_anchor(Segment::Slice segment_slice, PeerId peer_id) {
using std::to_string;

// Add or find anchor
auto anchor_header = *segment_slice.rbegin(); // lowest header
bool check_limits = true;
auto [anchor, pre_existing] = add_anchor_if_not_present(*anchor_header, std::move(peerId), check_limits);
auto [anchor, pre_existing] = add_anchor_if_not_present(*anchor_header, std::move(peer_id), check_limits);

// Iterate over headers backwards (from parents towards children)
std::shared_ptr<Link> prev_link;
Expand All @@ -1018,7 +1018,7 @@ HeaderChain::RequestMoreHeaders HeaderChain::new_anchor(Segment::Slice segment_s
return !pre_existing;
}

std::tuple<std::shared_ptr<Anchor>, HeaderChain::Pre_Existing> HeaderChain::add_anchor_if_not_present(const BlockHeader& anchor_header, PeerId peerId, bool check_limits) {
std::tuple<std::shared_ptr<Anchor>, HeaderChain::Pre_Existing> HeaderChain::add_anchor_if_not_present(const BlockHeader& anchor_header, PeerId peer_id, bool check_limits) {
using std::to_string;

auto a = anchors_.find(anchor_header.parent_hash);
Expand All @@ -1039,7 +1039,7 @@ std::tuple<std::shared_ptr<Anchor>, HeaderChain::Pre_Existing> HeaderChain::add_
", limit: " + to_string(kAnchorLimit));
}

std::shared_ptr<Anchor> anchor = std::make_shared<Anchor>(anchor_header, std::move(peerId));
std::shared_ptr<Anchor> anchor = std::make_shared<Anchor>(anchor_header, std::move(peer_id));
if (anchor->block_num > 0) {
anchors_[anchor_header.parent_hash] = anchor;
anchor_queue_.push(anchor);
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/sync_pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
}
}

Task<rpc::ExecutionPayloadAndValue> PoSSync::get_payload(uint64_t /*payloadId*/, std::chrono::milliseconds /*timeout*/) {
Task<rpc::ExecutionPayloadAndValue> PoSSync::get_payload(uint64_t /*payload_id*/, std::chrono::milliseconds /*timeout*/) {

Check warning on line 379 in silkworm/sync/sync_pos.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/sync/sync_pos.cpp#L379

Added line #L379 was not covered by tests
// Implementation of engine_getPayloadVx method
ensure_invariant(false, "get_payload not implemented");
co_return rpc::ExecutionPayloadAndValue{};
Expand Down
2 changes: 1 addition & 1 deletion silkworm/sync/sync_pos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PoSSync : public ChainSync, public rpc::engine::ExecutionEngine {
// public interface called by the external PoS client
Task<rpc::PayloadStatus> new_payload(const rpc::NewPayloadRequest& request, std::chrono::milliseconds timeout) override;
Task<rpc::ForkChoiceUpdatedReply> fork_choice_updated(const rpc::ForkChoiceUpdatedRequest& request, std::chrono::milliseconds timeout) override;
Task<rpc::ExecutionPayloadAndValue> get_payload(uint64_t payloadId, std::chrono::milliseconds timeout) override;
Task<rpc::ExecutionPayloadAndValue> get_payload(uint64_t payload_id, std::chrono::milliseconds timeout) override;
Task<rpc::ExecutionPayloadBodies> get_payload_bodies_by_hash(const std::vector<Hash>& block_hashes, std::chrono::milliseconds timeout) override;
Task<rpc::ExecutionPayloadBodies> get_payload_bodies_by_range(BlockNum start, uint64_t count, std::chrono::milliseconds timeout) override;

Expand Down
Loading