Skip to content

Commit

Permalink
fix cppcoreguidelines-prefer-member-initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Jul 26, 2024
1 parent 1762826 commit 6a40207
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 74 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Checks: >
-cppcoreguidelines-missing-std-forward,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
Expand Down
11 changes: 3 additions & 8 deletions cmd/state-transition/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ StateTransition::StateTransition(const std::string& file_path) noexcept {
auto testObject = baseJson.begin();
test_name_ = testObject.key();
test_data_ = testObject.value();

terminate_on_error_ = false;
show_diagnostics_ = false;
}

StateTransition::StateTransition(const nlohmann::json& json, const bool terminate_on_error, const bool show_diagnostics) noexcept {
StateTransition::StateTransition(const nlohmann::json& json, const bool terminate_on_error, const bool show_diagnostics) noexcept
: terminate_on_error_{terminate_on_error},
show_diagnostics_{show_diagnostics} {
auto testObject = json.begin();
test_name_ = testObject.key();
std::cout << test_name_ << ":" << std::endl;

test_data_ = testObject.value();

terminate_on_error_ = terminate_on_error;
show_diagnostics_ = show_diagnostics;
}

std::string StateTransition::name() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/state-transition/state_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class StateTransition {
std::string test_name_;
unsigned total_count_{};
unsigned failed_count_{};
bool terminate_on_error_;
bool show_diagnostics_;
bool terminate_on_error_{false};
bool show_diagnostics_{false};

void print_message(const ExpectedState& expected_state, const ExpectedSubState& expected_sub_state, const std::string& message);
void print_error_message(const ExpectedState& expected_state, const ExpectedSubState& expected_sub_state, const std::string& message);
Expand Down
28 changes: 16 additions & 12 deletions cmd/test/backend_kv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class AsyncUnaryCall : public AsyncCall {
static UnaryStats stats() { return unary_stats_; }

explicit AsyncUnaryCall(grpc::CompletionQueue* queue, StubInterface* stub, CompletionFunc completion_handler = {})
: AsyncCall(queue), stub_(stub), completion_handler_(std::move(completion_handler)) {
finish_processor_ = [&](bool ok) { process_finish(ok); };
: AsyncCall(queue),
stub_(stub),
finish_processor_([&](bool ok) { process_finish(ok); }),
completion_handler_(std::move(completion_handler)) {
}

void start(const Request& request) {
Expand Down Expand Up @@ -164,10 +166,11 @@ class AsyncServerStreamingCall : public AsyncCall {
static ServerStreamingStats stats() { return server_streaming_stats_; }

explicit AsyncServerStreamingCall(grpc::CompletionQueue* queue, StubInterface* stub)
: AsyncCall(queue), stub_(stub) {
start_processor_ = [&](bool ok) { process_start(ok); };
read_processor_ = [&](bool ok) { process_read(ok); };
finish_processor_ = [&](bool ok) { process_finish(ok); };
: AsyncCall(queue),
start_processor_([&](bool ok) { process_start(ok); }),
read_processor_([&](bool ok) { process_read(ok); }),
finish_processor_([&](bool ok) { process_finish(ok); }),
stub_(stub) {
}

void start(const Request& request) {
Expand Down Expand Up @@ -290,12 +293,13 @@ class AsyncBidirectionalStreamingCall : public AsyncCall {
static BidirectionalStreamingStats stats() { return bidi_streaming_stats_; }

explicit AsyncBidirectionalStreamingCall(grpc::CompletionQueue* queue, StubInterface* stub)
: AsyncCall(queue), stub_(stub) {
start_processor_ = [&](bool ok) { process_start(ok); };
read_processor_ = [&](bool ok) { process_read(ok); };
write_processor_ = [&](bool ok) { process_write(ok); };
writes_done_processor_ = [&](bool ok) { process_writes_done(ok); };
finish_processor_ = [&](bool ok) { process_finish(ok); };
: AsyncCall(queue),
start_processor_([&](bool ok) { process_start(ok); }),
read_processor_([&](bool ok) { process_read(ok); }),
write_processor_([&](bool ok) { process_write(ok); }),
writes_done_processor_([&](bool ok) { process_writes_done(ok); }),
finish_processor_([&](bool ok) { process_finish(ok); }),
stub_(stub) {
}

void start() {
Expand Down
6 changes: 3 additions & 3 deletions silkworm/node/stagedsync/forks/fork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Fork::Fork(BlockId forking_point, db::ROTxnManaged&& main_chain_tx, NodeSettings
memory_tx_{memory_db_},
data_model_{memory_tx_},
pipeline_{&ns},
canonical_chain_(memory_tx_) {
// actual head
current_head_ = forking_point;
canonical_chain_(memory_tx_),
current_head_{forking_point} // actual head
{
// go down if needed
if (canonical_chain_.initial_head() != forking_point) {
reduce_down_to(forking_point);
Expand Down
6 changes: 3 additions & 3 deletions silkworm/node/stagedsync/stages/stage_bodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ BodiesStage::BodyDataModel::BodyDataModel(db::RWTxn& tx, BlockNum bodies_stage_h
data_model_(tx_),
chain_config_{chain_config},
rule_set_{protocol::rule_set_factory(chain_config)},
chain_state_{tx} {
initial_height_ = bodies_stage_height;
highest_height_ = bodies_stage_height;
chain_state_{tx},
initial_height_{bodies_stage_height},
highest_height_{bodies_stage_height} {
}

BlockNum BodiesStage::BodyDataModel::initial_height() const { return initial_height_; }
Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/stagedsync/stages/stage_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

namespace silkworm::stagedsync {

HeadersStage::HeaderDataModel::HeaderDataModel(db::RWTxn& tx, BlockNum headers_height) : tx_(tx), data_model_(tx) {
HeadersStage::HeaderDataModel::HeaderDataModel(db::RWTxn& tx, BlockNum headers_height)
: tx_(tx), data_model_(tx), previous_height_(headers_height) {
auto headers_hash = db::read_canonical_hash(tx, headers_height);
ensure(headers_hash.has_value(),
[&]() { return "Headers stage, inconsistent canonical table: not found hash at height " + std::to_string(headers_height); });
Expand All @@ -42,7 +43,6 @@ HeadersStage::HeaderDataModel::HeaderDataModel(db::RWTxn& tx, BlockNum headers_h

previous_hash_ = *headers_hash;
previous_td_ = *headers_head_td;
previous_height_ = headers_height;
}

BlockNum HeadersStage::HeaderDataModel::highest_height() const { return previous_height_; }
Expand Down
28 changes: 14 additions & 14 deletions silkworm/rpc/commands/ots_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,12 @@ Task<ChunkProviderResponse> ChunkProvider::get() {
co_return ChunkProviderResponse{key_value.value, true, false};
}

ChunkProvider::ChunkProvider(db::kv::api::Cursor* cursor, const evmc::address& address, bool navigate_forward, db::kv::api::KeyValue first_seek_key_value) {
cursor_ = cursor;
address_ = address;
navigate_forward_ = navigate_forward;
first_seek_key_value_ = std::move(first_seek_key_value);
ChunkProvider::ChunkProvider(db::kv::api::Cursor* cursor, const evmc::address& address,
bool navigate_forward, db::kv::api::KeyValue first_seek_key_value)
: cursor_{cursor},
address_{address},
navigate_forward_{navigate_forward},
first_seek_key_value_{std::move(first_seek_key_value)} {

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

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.cpp#L937-L940

Added lines #L937 - L940 were not covered by tests
}

Task<ChunkLocatorResponse> ChunkLocator::get(BlockNum min_block) {
Expand All @@ -955,10 +956,10 @@ Task<ChunkLocatorResponse> ChunkLocator::get(BlockNum min_block) {
}
}

ChunkLocator::ChunkLocator(db::kv::api::Cursor* cursor, const evmc::address& address, bool navigate_forward) {
cursor_ = cursor;
address_ = address;
navigate_forward_ = navigate_forward;
ChunkLocator::ChunkLocator(db::kv::api::Cursor* cursor, const evmc::address& address, bool navigate_forward)
: cursor_{cursor},
address_{address},
navigate_forward_{navigate_forward} {

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

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.cpp#L960-L962

Added lines #L960 - L962 were not covered by tests
}

Task<BlockProviderResponse> ForwardBlockProvider::get() {
Expand Down Expand Up @@ -1257,11 +1258,10 @@ Task<BlockProviderResponse> FromToBlockProvider::get() {
co_return BlockProviderResponse{block_num, has_more_from_ || has_more_to_, false};
}

FromToBlockProvider::FromToBlockProvider(bool is_backwards, BlockProvider* callFromProvider, BlockProvider* callToProvider) {
is_backwards_ = is_backwards;
callFromProvider_ = callFromProvider;
callToProvider_ = callToProvider;
initialized_ = false;
FromToBlockProvider::FromToBlockProvider(bool is_backwards, BlockProvider* callFromProvider, BlockProvider* callToProvider)
: is_backwards_{is_backwards},
callFromProvider_{callFromProvider},
callToProvider_{callToProvider} {

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

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.cpp#L1262-L1264

Added lines #L1262 - L1264 were not covered by tests
}

} // namespace silkworm::rpc::commands
21 changes: 12 additions & 9 deletions silkworm/rpc/commands/ots_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ class ForwardBlockProvider : public BlockProvider {
void advance_if_needed(BlockNum min_block);

public:
ForwardBlockProvider(db::kv::api::Cursor* cursor, const evmc::address& address, BlockNum min_block) : chunk_locator_(cursor, address, true), chunk_provider_() {
cursor_ = cursor;
address_ = address;
min_block_ = min_block;
ForwardBlockProvider(db::kv::api::Cursor* cursor, const evmc::address& address, BlockNum min_block)
: cursor_(cursor),
address_(address),
min_block_(min_block),
chunk_locator_(cursor, address, true),
chunk_provider_() {

Check warning on line 130 in silkworm/rpc/commands/ots_api.hpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.hpp#L126-L130

Added lines #L126 - L130 were not covered by tests
}

Task<BlockProviderResponse> get() override;
Expand Down Expand Up @@ -153,11 +155,12 @@ class BackwardBlockProvider : public BlockProvider {
void reverse_iterator(roaring::Roaring64Map& bitmap);

public:
BackwardBlockProvider(db::kv::api::Cursor* cursor, const evmc::address& address, BlockNum max_block) : chunk_locator_(cursor, address, false), chunk_provider_() {
cursor_ = cursor;
address_ = address;
max_block_ = max_block;

BackwardBlockProvider(db::kv::api::Cursor* cursor, const evmc::address& address, BlockNum max_block)
: cursor_(cursor),
address_(address),
max_block_(max_block),
chunk_locator_(cursor, address, false),
chunk_provider_() {

Check warning on line 163 in silkworm/rpc/commands/ots_api.hpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/commands/ots_api.hpp#L159-L163

Added lines #L159 - L163 were not covered by tests
if (max_block_ == 0) {
max_block_ = std::numeric_limits<BlockNum>::max();
}
Expand Down
18 changes: 12 additions & 6 deletions silkworm/rpc/ethdb/split_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ namespace silkworm::rpc::ethdb {

SplitCursor::SplitCursor(Cursor& inner_cursor, ByteView key, uint64_t match_bits, uint64_t part1_end,
uint64_t part2_start, uint64_t part3_start)
: inner_cursor_{inner_cursor}, key_{key}, part1_end_{part1_end}, part2_start_{part2_start}, part3_start_{part3_start} {
match_bytes_ = (match_bits + 7) / 8;

: inner_cursor_{inner_cursor},
key_{key},
part1_end_{part1_end},
part2_start_{part2_start},
part3_start_{part3_start},
match_bytes_{(match_bits + 7) / 8} {
uint8_t shift_bits = match_bits & 7;
if (shift_bits != 0) {
mask_ = static_cast<uint8_t>(0xff << (8 - shift_bits));
Expand Down Expand Up @@ -88,9 +91,12 @@ SplittedKeyValue SplitCursor::split_key_value(const KeyValue& kv) {

SplitCursorDupSort::SplitCursorDupSort(CursorDupSort& inner_cursor, ByteView key, ByteView subkey,
uint64_t match_bits, uint64_t part1_end, uint64_t value_offset)
: inner_cursor_{inner_cursor}, key_{key}, subkey_{subkey}, part1_end_{part1_end}, value_offset_{value_offset} {
match_bytes_ = (match_bits + 7) / 8;

: inner_cursor_{inner_cursor},
key_{key},
subkey_{subkey},
part1_end_{part1_end},
match_bytes_{(match_bits + 7) / 8},
value_offset_{value_offset} {
uint8_t shift_bits = match_bits & 7;
if (shift_bits != 0) {
mask_ = static_cast<uint8_t>(0xff << (8 - shift_bits));
Expand Down
20 changes: 10 additions & 10 deletions silkworm/sync/internals/chain_elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ 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_) {
blockHeight = h.number;
hash = h.hash(); // save computation
Link(BlockHeader h, bool persisted_)
: blockHeight{h.number},
hash{h.hash()}, // save computation
persisted{persisted_} {
header = std::make_shared<BlockHeader>(std::move(h));
persisted = persisted_;
}

void remove_child(const Link& child) {
Expand All @@ -71,12 +71,12 @@ struct Anchor {
BlockNum lastLinkHeight{0}; // the blockHeight of the last link of the chain bundle anchored to this
PeerId peerId;

Anchor(const BlockHeader& header, PeerId p) {
parentHash = header.parent_hash;
blockHeight = header.number;
lastLinkHeight = blockHeight;
// timestamp = 0; // ready to get extended
peerId = std::move(p);
Anchor(const BlockHeader& header, PeerId p)
: parentHash{header.parent_hash},
blockHeight{header.number},
lastLinkHeight{blockHeight},
// timestamp{0}, // ready to get extended
peerId{std::move(p)} {
}

BlockNum chainLength() const { return lastLinkHeight - blockHeight + 1; }
Expand Down
5 changes: 3 additions & 2 deletions silkworm/sync/messages/inbound_new_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
namespace silkworm {

InboundNewBlock::InboundNewBlock(ByteView data, PeerId peer_id)
: peerId_(std::move(peer_id)) {
reqId_ = Singleton<RandomNumber>::instance().generate_one(); // for trace purposes
: peerId_(std::move(peer_id)),
reqId_(Singleton<RandomNumber>::instance().generate_one()) // for trace purposes
{

Check warning on line 30 in silkworm/sync/messages/inbound_new_block.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/sync/messages/inbound_new_block.cpp#L28-L30

Added lines #L28 - L30 were not covered by tests
success_or_throw(rlp::decode(data, packet_));
SILK_TRACE << "Received message " << *this;
}
Expand Down
5 changes: 3 additions & 2 deletions silkworm/sync/messages/inbound_new_block_hashes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
namespace silkworm {

InboundNewBlockHashes::InboundNewBlockHashes(ByteView data, PeerId peer_id)
: peerId_(std::move(peer_id)) {
reqId_ = Singleton<RandomNumber>::instance().generate_one(); // for trace purposes
: peerId_(std::move(peer_id)),
reqId_(Singleton<RandomNumber>::instance().generate_one()) // for trace purposes
{

Check warning on line 36 in silkworm/sync/messages/inbound_new_block_hashes.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/sync/messages/inbound_new_block_hashes.cpp#L34-L36

Added lines #L34 - L36 were not covered by tests
success_or_throw(rlp::decode(data, packet_));
SILK_TRACE << "Received message " << *this;
}
Expand Down

0 comments on commit 6a40207

Please sign in to comment.