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 local variable case #2418

Draft
wants to merge 9 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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CheckOptions:
readability-identifier-naming.FunctionCase: lower_case
readability-identifier-naming.GlobalConstantCase: CamelCase
readability-identifier-naming.GlobalConstantPrefix: k
readability-identifier-naming.LocalVariableCase: lower_case
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
readability-identifier-naming.PrivateMemberCase: lower_case
readability-identifier-naming.PrivateMemberSuffix: _
Expand Down
44 changes: 22 additions & 22 deletions cmd/dev/grpc_toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,25 +373,25 @@ int kv_seek_async(const std::string& target, const std::string& table_name, silk
context.set_deadline(std::chrono::system_clock::system_clock::now() + std::chrono::milliseconds{timeout});
const auto reader_writer = stub->PrepareAsyncTx(&context, &queue);

void* START_TAG = reinterpret_cast<void*>(0);
void* OPEN_TAG = reinterpret_cast<void*>(1);
void* SEEK_TAG = reinterpret_cast<void*>(2);
void* CLOSE_TAG = reinterpret_cast<void*>(3);
void* FINISH_TAG = reinterpret_cast<void*>(4);
void* start_tag = reinterpret_cast<void*>(0);
void* open_tag = reinterpret_cast<void*>(1);
void* seek_tag = reinterpret_cast<void*>(2);
void* close_tag = reinterpret_cast<void*>(3);
void* finish_tag = reinterpret_cast<void*>(4);

// 1) StartCall
std::cout << "KV Tx START\n";
// 1.1) StartCall + Next
reader_writer->StartCall(START_TAG);
reader_writer->StartCall(start_tag);
bool has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != START_TAG) {
if (!has_event || got_tag != start_tag) {
return -1;
}
// 1.2) Read + Next
auto tx_id_pair = remote::Pair{};
reader_writer->Read(&tx_id_pair, START_TAG);
reader_writer->Read(&tx_id_pair, start_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != START_TAG) {
if (!has_event || got_tag != start_tag) {
return -1;
}
const auto tx_id = tx_id_pair.cursor_id();
Expand All @@ -403,16 +403,16 @@ int kv_seek_async(const std::string& target, const std::string& table_name, silk
auto open_message = remote::Cursor{};
open_message.set_op(remote::Op::OPEN);
open_message.set_bucket_name(table_name);
reader_writer->Write(open_message, OPEN_TAG);
reader_writer->Write(open_message, open_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != OPEN_TAG) {
if (!has_event || got_tag != open_tag) {
return -1;
}
// 2.2) Read + Next
auto open_pair = remote::Pair{};
reader_writer->Read(&open_pair, OPEN_TAG);
reader_writer->Read(&open_pair, open_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != OPEN_TAG) {
if (!has_event || got_tag != open_tag) {
return -1;
}
auto cursor_id = open_pair.cursor_id();
Expand All @@ -425,16 +425,16 @@ int kv_seek_async(const std::string& target, const std::string& table_name, silk
seek_message.set_op(remote::Op::SEEK);
seek_message.set_cursor(cursor_id);
seek_message.set_k(key.data(), key.length());
reader_writer->Write(seek_message, SEEK_TAG);
reader_writer->Write(seek_message, seek_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != SEEK_TAG) {
if (!has_event || got_tag != seek_tag) {
return -1;
}
// 3.2) Read + Next
auto seek_pair = remote::Pair{};
reader_writer->Read(&seek_pair, SEEK_TAG);
reader_writer->Read(&seek_pair, seek_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != SEEK_TAG) {
if (!has_event || got_tag != seek_tag) {
return -1;
}
const auto& key_bytes = silkworm::string_view_to_byte_view(seek_pair.k());
Expand All @@ -447,22 +447,22 @@ int kv_seek_async(const std::string& target, const std::string& table_name, silk
auto close_message = remote::Cursor{};
close_message.set_op(remote::Op::CLOSE);
close_message.set_cursor(cursor_id);
reader_writer->Write(close_message, CLOSE_TAG);
reader_writer->Write(close_message, close_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != CLOSE_TAG) {
if (!has_event || got_tag != close_tag) {
return -1;
}
// 4.2) Read + Next
auto close_pair = remote::Pair{};
reader_writer->Read(&close_pair, CLOSE_TAG);
reader_writer->Read(&close_pair, close_tag);
has_event = queue.Next(&got_tag, &ok);
if (!has_event || got_tag != CLOSE_TAG) {
if (!has_event || got_tag != close_tag) {
return -1;
}
std::cout << "KV Tx CLOSE <- cursor: " << close_pair.cursor_id() << "\n";

// 5) Finish
reader_writer->Finish(&status, FINISH_TAG);
reader_writer->Finish(&status, finish_tag);
if (!status.ok()) {
std::cout << "KV Tx Status <- error_code: " << status.error_code() << "\n";
std::cout << "KV Tx Status <- error_message: " << status.error_message() << "\n";
Expand Down
30 changes: 15 additions & 15 deletions cmd/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,24 @@ void parse_silkworm_command_line(CLI::App& cli, int argc, char* argv[], node::Se
node_settings.chaindata_env_config.path = node_settings.data_directory->chaindata().path().string();

// Parse prune mode
db::PruneDistance olderHistory, olderReceipts, olderSenders, olderTxIndex, olderCallTraces;
if (cli["--prune.h.older"]->count()) olderHistory.emplace(cli["--prune.h.older"]->as<BlockNum>());
if (cli["--prune.r.older"]->count()) olderReceipts.emplace(cli["--prune.r.older"]->as<BlockNum>());
if (cli["--prune.s.older"]->count()) olderSenders.emplace(cli["--prune.s.older"]->as<BlockNum>());
if (cli["--prune.t.older"]->count()) olderTxIndex.emplace(cli["--prune.t.older"]->as<BlockNum>());
if (cli["--prune.c.older"]->count()) olderCallTraces.emplace(cli["--prune.c.older"]->as<BlockNum>());

db::PruneThreshold beforeHistory, beforeReceipts, beforeSenders, beforeTxIndex, beforeCallTraces;
if (cli["--prune.h.before"]->count()) beforeHistory.emplace(cli["--prune.h.before"]->as<BlockNum>());
if (cli["--prune.r.before"]->count()) beforeReceipts.emplace(cli["--prune.r.before"]->as<BlockNum>());
if (cli["--prune.s.before"]->count()) beforeSenders.emplace(cli["--prune.s.before"]->as<BlockNum>());
if (cli["--prune.t.before"]->count()) beforeTxIndex.emplace(cli["--prune.t.before"]->as<BlockNum>());
if (cli["--prune.c.before"]->count()) beforeCallTraces.emplace(cli["--prune.c.before"]->as<BlockNum>());
db::PruneDistance older_history, older_receipts, older_senders, older_tx_index, older_call_traces;
if (cli["--prune.h.older"]->count()) older_history.emplace(cli["--prune.h.older"]->as<BlockNum>());
if (cli["--prune.r.older"]->count()) older_receipts.emplace(cli["--prune.r.older"]->as<BlockNum>());
if (cli["--prune.s.older"]->count()) older_senders.emplace(cli["--prune.s.older"]->as<BlockNum>());
if (cli["--prune.t.older"]->count()) older_tx_index.emplace(cli["--prune.t.older"]->as<BlockNum>());
if (cli["--prune.c.older"]->count()) older_call_traces.emplace(cli["--prune.c.older"]->as<BlockNum>());

db::PruneThreshold before_history, before_receipts, before_senders, before_tx_index, before_call_traces;
if (cli["--prune.h.before"]->count()) before_history.emplace(cli["--prune.h.before"]->as<BlockNum>());
if (cli["--prune.r.before"]->count()) before_receipts.emplace(cli["--prune.r.before"]->as<BlockNum>());
if (cli["--prune.s.before"]->count()) before_senders.emplace(cli["--prune.s.before"]->as<BlockNum>());
if (cli["--prune.t.before"]->count()) before_tx_index.emplace(cli["--prune.t.before"]->as<BlockNum>());
if (cli["--prune.c.before"]->count()) before_call_traces.emplace(cli["--prune.c.before"]->as<BlockNum>());

node_settings.prune_mode = db::parse_prune_mode(
prune_mode,
olderHistory, olderReceipts, olderSenders, olderTxIndex, olderCallTraces,
beforeHistory, beforeReceipts, beforeSenders, beforeTxIndex, beforeCallTraces);
older_history, older_receipts, older_senders, older_tx_index, older_call_traces,
before_history, before_receipts, before_senders, before_tx_index, before_call_traces);

// snapshots::SnapshotSettings
auto& snapshot_settings = settings.snapshot_settings;
Expand Down
22 changes: 11 additions & 11 deletions cmd/state-transition/expected_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ std::vector<ExpectedSubState> ExpectedState::get_sub_states() {
unsigned i = 0;

for (auto& tx : state_data_) {
ExpectedSubState subState;
ExpectedSubState sub_state;

subState.stateHash = to_bytes32(from_hex(tx["hash"].get<std::string>()).value_or(Bytes{}));
subState.logsHash = to_bytes32(from_hex(tx["logs"].get<std::string>()).value_or(Bytes{}));
subState.dataIndex = tx["indexes"]["data"].get<uint64_t>();
subState.gasIndex = tx["indexes"]["gas"].get<uint64_t>();
subState.valueIndex = tx["indexes"]["value"].get<uint64_t>();
sub_state.stateHash = to_bytes32(from_hex(tx["hash"].get<std::string>()).value_or(Bytes{}));
sub_state.logsHash = to_bytes32(from_hex(tx["logs"].get<std::string>()).value_or(Bytes{}));
sub_state.dataIndex = tx["indexes"]["data"].get<uint64_t>();
sub_state.gasIndex = tx["indexes"]["gas"].get<uint64_t>();
sub_state.valueIndex = tx["indexes"]["value"].get<uint64_t>();
if (tx.contains("expectException")) {
subState.exceptionExpected = true;
subState.exceptionMessage = tx["expectException"];
sub_state.exceptionExpected = true;
sub_state.exceptionMessage = tx["expectException"];
} else {
subState.exceptionExpected = false;
sub_state.exceptionExpected = false;
}

subState.index = i;
sub_states.push_back(subState);
sub_state.index = i;
sub_states.push_back(sub_state);
++i;
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/state-transition/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ int main(int argc, char* argv[]) {

void execute_test(const std::string& path, bool terminate_flag, bool diagnostics_flag) {
std::ifstream input_file(path);
nlohmann::json baseJson;
input_file >> baseJson;
auto stateTransition = StateTransition(baseJson, terminate_flag, diagnostics_flag);
stateTransition.run();
nlohmann::json base_json;
input_file >> base_json;
auto state_transition = StateTransition(base_json, terminate_flag, diagnostics_flag);
state_transition.run();
}
46 changes: 23 additions & 23 deletions cmd/state-transition/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ namespace silkworm::cmd::state_transition {

StateTransition::StateTransition(const std::string& file_path) noexcept {
std::ifstream input_file(file_path);
nlohmann::json baseJson;
input_file >> baseJson;
auto testObject = baseJson.begin();
test_name_ = testObject.key();
test_data_ = testObject.value();
nlohmann::json base_json;
input_file >> base_json;
auto test_object = base_json.begin();
test_name_ = test_object.key();
test_data_ = test_object.value();
}

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();
auto test_object = json.begin();
test_name_ = test_object.key();
std::cout << test_name_ << ":" << std::endl;
test_data_ = testObject.value();
test_data_ = test_object.value();
}

std::string StateTransition::name() {
Expand All @@ -71,15 +71,15 @@ bool StateTransition::contains_env(const std::string& key) {
}

std::vector<ExpectedState> StateTransition::get_expected_states() {
std::vector<ExpectedState> expectedStates;
std::vector<ExpectedState> expected_states;

for (const auto& postState : test_data_.at("post").items()) {
nlohmann::json data = postState.value();
const std::string& key = postState.key();
expectedStates.emplace_back(data, key);
for (const auto& post_state : test_data_.at("post").items()) {
nlohmann::json data = post_state.value();
const std::string& key = post_state.key();
expected_states.emplace_back(data, key);
}

return expectedStates;
return expected_states;
}

evmc::address StateTransition::to_evmc_address(const std::string& address) {
Expand Down Expand Up @@ -281,22 +281,22 @@ void StateTransition::run() {
failed_count_ = 0;
total_count_ = 0;

for (auto& expectedState : get_expected_states()) {
for (const auto& expectedSubState : expectedState.get_sub_states()) {
for (auto& expected_state : get_expected_states()) {
for (const auto& expected_sub_state : expected_state.get_sub_states()) {
++total_count_;
auto config = expectedState.get_config();
auto ruleSet = protocol::rule_set_factory(config);
auto config = expected_state.get_config();
auto rule_set = protocol::rule_set_factory(config);
auto state = read_genesis_allocation(test_data_["pre"]);
auto block = get_block(state, config);
auto txn = get_transaction(expectedSubState);
auto txn = get_transaction(expected_sub_state);

ExecutionProcessor processor{block, *ruleSet, state, config};
ExecutionProcessor processor{block, *rule_set, state, config};
Receipt receipt;

const evmc_revision rev{config.revision(block.header.number, block.header.timestamp)};

auto pre_block_validation = ruleSet->pre_validate_block_body(block, state);
auto block_validation = ruleSet->validate_block_header(block.header, state, true);
auto pre_block_validation = rule_set->pre_validate_block_body(block, state);
auto block_validation = rule_set->validate_block_header(block.header, state, true);
auto pre_txn_validation = protocol::pre_validate_transaction(txn, rev, config.chain_id, block.header.base_fee_per_gas, block.header.blob_gas_price());
auto txn_validation = protocol::validate_transaction(txn, processor.evm().state(), processor.available_gas());

Expand All @@ -317,7 +317,7 @@ void StateTransition::run() {
// std::cout << "post: " << std::endl;
// state->print_state_root_hash();

validate_transition(receipt, expectedState, expectedSubState, state);
validate_transition(receipt, expected_state, expected_sub_state, state);
}
}

Expand Down
16 changes: 8 additions & 8 deletions silkworm/core/chain/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST_CASE("Agra revision") {
}

TEST_CASE("distinct_fork_points") {
const std::vector<BlockNum> kExpectedMainnetForkNumbers{
const std::vector<BlockNum> expected_mainnet_fork_numbers{
1'150'000,
1'920'000,
2'463'000,
Expand All @@ -120,17 +120,17 @@ TEST_CASE("distinct_fork_points") {
13'773'000,
15'050'000,
};
const std::vector<BlockTime> kExpectedMainnetForkTimes{
const std::vector<BlockTime> expected_mainnet_fork_times{
1681338455,
1710338135,
};
std::vector<uint64_t> kExpectedMainnetForkPoints{kExpectedMainnetForkNumbers};
kExpectedMainnetForkPoints.insert(kExpectedMainnetForkPoints.end(),
kExpectedMainnetForkTimes.cbegin(), kExpectedMainnetForkTimes.cend());
std::vector<uint64_t> expected_mainnet_fork_points{expected_mainnet_fork_numbers};
expected_mainnet_fork_points.insert(expected_mainnet_fork_points.end(),
expected_mainnet_fork_times.cbegin(), expected_mainnet_fork_times.cend());

CHECK(kMainnetConfig.distinct_fork_numbers() == kExpectedMainnetForkNumbers);
CHECK(kMainnetConfig.distinct_fork_times() == kExpectedMainnetForkTimes);
CHECK(kMainnetConfig.distinct_fork_points() == kExpectedMainnetForkPoints);
CHECK(kMainnetConfig.distinct_fork_numbers() == expected_mainnet_fork_numbers);
CHECK(kMainnetConfig.distinct_fork_times() == expected_mainnet_fork_times);
CHECK(kMainnetConfig.distinct_fork_points() == expected_mainnet_fork_points);
}

TEST_CASE("JSON serialization") {
Expand Down
1 change: 1 addition & 0 deletions silkworm/core/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <algorithm>
#include <cstdio>
#include <regex>
#include <string_view>

#include <silkworm/core/common/assert.hpp>

Expand Down
8 changes: 4 additions & 4 deletions silkworm/core/common/util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ TEST_CASE("human_size") {
}

TEST_CASE("intx::uint256 from scientific notation string") {
const intx::uint256 kMainnetTTD{intx::from_string<intx::uint256>("58750000000000000000000")};
static constexpr intx::uint256 kMainnetTTD{intx::from_string<intx::uint256>("58750000000000000000000")};
CHECK(from_string_sci<intx::uint256>("5.875e+22") == kMainnetTTD);
CHECK(from_string_sci<intx::uint256>("58750000000000000000000") == kMainnetTTD);

const intx::uint256 kSepoliaTTD{intx::from_string<intx::uint256>("17000000000000000")};
static constexpr intx::uint256 kSepoliaTTD{intx::from_string<intx::uint256>("17000000000000000")};
CHECK(from_string_sci<intx::uint256>("1.7e+16") == kSepoliaTTD);
CHECK(from_string_sci<intx::uint256>("17000000000000000") == kSepoliaTTD);

Expand All @@ -211,9 +211,9 @@ TEST_CASE("intx::uint256 from scientific notation string") {
CHECK(from_string_sci<intx::uint256>("18.1e+2") == intx::from_string<intx::uint256>("1810"));
CHECK(from_string_sci<intx::uint256>("18.12e+2") == intx::from_string<intx::uint256>("1812"));

const char* kMaxFixedDecimalNotation{"115792089237316195423570985008687907853269984665640564039457584007913129639935"};
static constexpr char kMaxFixedDecimalNotation[] = "115792089237316195423570985008687907853269984665640564039457584007913129639935";
CHECK(from_string_sci<intx::uint256>(kMaxFixedDecimalNotation) == std::numeric_limits<intx::uint256>::max());
const char* kMaxScientificNotation{"1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77"};
static constexpr char kMaxScientificNotation[] = "1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77";
CHECK(from_string_sci<intx::uint256>(kMaxScientificNotation) == std::numeric_limits<intx::uint256>::max());
}

Expand Down
8 changes: 4 additions & 4 deletions silkworm/core/execution/precompile_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ TEST_CASE("POINT_EVALUATION") {
"a444d6bb5aadc3ceb615b50d6606bd54bfe529f59247987cd1ab848d19de599a9052f1835fb0d0d44cf70183e19a68c9")};
std::optional<Bytes> out{point_evaluation_run(in)};
REQUIRE((out && out->length() == 64));
intx::uint256 fieldElementsPerBlob{intx::be::unsafe::load<intx::uint256>(out->data())};
CHECK(fieldElementsPerBlob == 4096);
intx::uint256 blsModulus{intx::be::unsafe::load<intx::uint256>(out->data() + 32)};
CHECK(blsModulus == kBlsModulus);
intx::uint256 field_elements_per_blob{intx::be::unsafe::load<intx::uint256>(out->data())};
CHECK(field_elements_per_blob == 4096);
intx::uint256 bls_modulus{intx::be::unsafe::load<intx::uint256>(out->data() + 32)};
CHECK(bls_modulus == kBlsModulus);

// change hash version
in[0] = 0x2;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/core/protocol/intrinsic_gas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ intx::uint128 intrinsic_gas(const UnsignedTransaction& txn, const evmc_revision
}

const intx::uint128 non_zero_bytes{std::ranges::count_if(txn.data, [](uint8_t c) { return c != 0; })};
const intx::uint128 nonZeroGas{rev >= EVMC_ISTANBUL ? fee::kGTxDataNonZeroIstanbul : fee::kGTxDataNonZeroFrontier};
gas += non_zero_bytes * nonZeroGas;
const intx::uint128 non_zero_gas{rev >= EVMC_ISTANBUL ? fee::kGTxDataNonZeroIstanbul : fee::kGTxDataNonZeroFrontier};
gas += non_zero_bytes * non_zero_gas;
const intx::uint128 zero_bytes{data_len - non_zero_bytes};
gas += zero_bytes * fee::kGTxDataZero;

Expand Down
4 changes: 2 additions & 2 deletions silkworm/core/types/hash_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ using namespace evmc::literals;
TEST_CASE("from_hex") {
CHECK(Hash::from_hex("foo") == std::nullopt);

const evmc::bytes32 kHashValue{0x2d690516512020171c1ec870f6ff45398cc8609250326be89915fb538e7b_bytes32};
CHECK(Hash::from_hex("0x2d690516512020171c1ec870f6ff45398cc8609250326be89915fb538e7b") == kHashValue);
const evmc::bytes32 hash_value{0x2d690516512020171c1ec870f6ff45398cc8609250326be89915fb538e7b_bytes32};
CHECK(Hash::from_hex("0x2d690516512020171c1ec870f6ff45398cc8609250326be89915fb538e7b") == hash_value);
}

} // namespace silkworm
Loading
Loading