Skip to content

Commit

Permalink
code style: ++i, --i (#2394)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Oct 1, 2024
1 parent 904f1c6 commit a8adb8b
Show file tree
Hide file tree
Showing 114 changed files with 315 additions and 315 deletions.
8 changes: 4 additions & 4 deletions cmd/dev/check_log_indices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void trace(const Log& log) {
int i{0};
for (const auto& t : log.topics) {
log::Trace() << "topic[" << i << "]: " << to_hex(t);
i++;
++i;
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ int main(int argc, char* argv[]) {
}
if (reached_block_number != block_number) {
reached_block_number = block_number;
processed_block_numbers++;
++processed_block_numbers;
}

std::vector<Log> transaction_logs;
Expand All @@ -238,7 +238,7 @@ int main(int argc, char* argv[]) {
log::Info() << "block " << block_number << " tx " << tx_id << " generated log for " << log.address;
}
check_address_index(block_number, log.address, log_address_cursor.get());
processed_addresses_count++;
++processed_addresses_count;
}

if (settings.index != TargetIndex::kLogAddress) {
Expand All @@ -253,7 +253,7 @@ int main(int argc, char* argv[]) {
}
processed_logs_count += transaction_logs.size();

processed_transaction_count++;
++processed_transaction_count;
if (processed_transaction_count % 100'000 == 0) {
log::Info() << "Scanned transactions " << processed_transaction_count << " processed logs " << processed_logs_count;
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dev/check_pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int main(int argc, char* argv[]) {
StopWatch sw;
sw.start();
for (uint32_t block_num{options.block_from}; block_num <= options.block_to && !SignalHandler::signalled();
block_num++) {
++block_num) {
if (epoch_context->epoch_number != static_cast<int>(block_num / ethash::epoch_length)) {
epoch_num = (block_num / ethash::epoch_length);
log::Info() << "Initializing Light Cache for DAG epoch " << epoch_num;
Expand Down
6 changes: 3 additions & 3 deletions cmd/dev/check_senders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) {
std::vector<Transaction> transactions;
uint64_t i{0};
auto tx_data{tx_cursor->find(db::to_slice(tx_key), false)};
for (; i < body.txn_count && tx_data.done; i++, tx_data = tx_cursor->to_next(false)) {
for (; i < body.txn_count && tx_data.done; ++i, tx_data = tx_cursor->to_next(false)) {
if (!tx_data) {
log::Error() << "Block " << block_number << " tx " << i << " not found in " << db::table::kBlockTransactions.name << " table";
continue;
Expand All @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) {
log::Error() << "Block " << block_number << " tx " << i << " recovered sender " << senders[i]
<< " does not match computed sender " << *tx.sender();
}
processed_senders_count++;
++processed_senders_count;

const auto transaction_hash{keccak256(transaction_rlp)};
log::Debug() << "Tx hash: " << to_hex(transaction_hash.bytes) << " has sender: " << to_hex(senders[i].bytes);
Expand All @@ -183,7 +183,7 @@ int main(int argc, char* argv[]) {
}

// Move to next block body
expected_block_number++;
++expected_block_number;
bodies_data = bodies_cursor->to_next(false);
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/dev/check_tx_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) {
uint64_t i{0};
auto transaction_data{transactions_table.find(db::to_slice(transaction_key), false)};
for (; i < body.txn_count && transaction_data.done;
i++, transaction_data = transactions_table.to_next(false)) {
++i, transaction_data = transactions_table.to_next(false)) {
if (!transaction_data) {
log::Error() << "Block " << block_number << " transaction " << i << " not found in "
<< db::table::kBlockTransactions.name << " table";
Expand Down Expand Up @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
break;
}

expected_block_number++;
++expected_block_number;
bodies_data = bodies_table.to_next(false);
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dev/db_toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Progress {
return static_cast<uint32_t>(current_counter_ * 100 / max_counter_);
}

void step() { current_counter_++; }
void step() { ++current_counter_; }
void set_current(size_t count) { current_counter_ = std::max(count, current_counter_); }
[[nodiscard]] size_t get_current() const noexcept { return current_counter_; }
[[nodiscard]] size_t get_increment_count() const noexcept { return bar_width_ ? (max_counter_ / bar_width_) : 0u; }
Expand Down
4 changes: 2 additions & 2 deletions cmd/dev/snapshots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void decode_segment(const SnapshotSubcommandSettings& settings, int repetitions)

SILK_INFO << "Decode snapshot: " << snap_file->path();
std::chrono::time_point start{std::chrono::steady_clock::now()};
for (int i = 0; i < repetitions; i++) {
for (int i = 0; i < repetitions; ++i) {
Snapshot snapshot{*snap_file};
snapshot.reopen_segment();
}
Expand All @@ -283,7 +283,7 @@ void count_bodies(const SnapshotSubcommandSettings& settings, int repetitions) {
const auto txn_count{settings.skip_system_txs && b.txn_count >= 2 ? b.txn_count - 2 : b.txn_count};
SILK_TRACE << "Body number: " << num_bodies << " base_txn_id: " << base_txn_id << " txn_count: " << txn_count
<< " #ommers: " << b.ommers.size();
num_bodies++;
++num_bodies;
num_txns += txn_count;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/state-transition/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ void StateTransition::validate_transition(const Receipt& receipt, const Expected

if (state.state_root_hash() != expected_sub_state.stateHash) {
print_error_message(expected_state, expected_sub_state, "Failed: State root hash does not match");
failed_count_++;
++failed_count_;
} else {
Bytes encoded;
rlp::encode(encoded, receipt.logs);
if (std::bit_cast<evmc_bytes32>(keccak256(encoded)) != expected_sub_state.logsHash) {
print_error_message(expected_state, expected_sub_state, "Failed: Logs hash does not match");
failed_count_++;
++failed_count_;
} else {
print_diagnostic_message(expected_state, expected_sub_state, "OK");
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/test/backend_kv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ class AsyncCallFactory {
kv_stub_{remote::KV::NewStub(channel, grpc::StubOptions{})} {}

void start_batch(std::atomic_bool& stop, const BatchOptions& batch_options) {
for (auto i{0}; i < batch_options.batch_size && !stop; i++) {
for (auto i{0}; i < batch_options.batch_size && !stop; ++i) {
if (batch_options.is_configured(Rpc::kEtherbase)) {
auto* etherbase = new AsyncEtherbaseCall(queue_, ethbackend_stub_.get());
etherbase->start(remote::EtherbaseRequest{});
Expand Down
4 changes: 2 additions & 2 deletions cmd/test/fuzzer_diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ void print_stack_trace() {
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
[[maybe_unused]] auto _ = gsl::finally([&messages] { free(reinterpret_cast<void*>(messages)); });
std::cout << "Stack Trace:\n";
for (int i = 0; i < trace_size; i++) {
for (int i = 0; i < trace_size; ++i) {
std::cout << messages[i] << "\n";

// extract the address from the message
char* address = strchr(messages[i], '[');
if (address) {
address++;
++address;
char* end = strchr(address, ']');
if (end) {
*end = '\0';
Expand Down
4 changes: 2 additions & 2 deletions silkworm/capi/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static log::Args log_args_for_exec_progress(ExecutionProgress& progress, uint64_
}

static void update_execution_progress(ExecutionProgress& progress, const Block& block, const db::Buffer& state_buffer, size_t max_batch_size) {
progress.processed_blocks++;
++progress.processed_blocks;
progress.processed_transactions += block.transactions.size();
progress.processed_gas += block.header.gas_used;

Expand Down Expand Up @@ -253,7 +253,7 @@ SILKWORM_EXPORT int silkworm_build_recsplit_indexes(SilkwormHandle handle, struc
}

std::vector<std::shared_ptr<snapshots::IndexBuilder>> needed_indexes;
for (size_t i = 0; i < len; i++) {
for (size_t i = 0; i < len; ++i) {
struct SilkwormMemoryMappedFile* snapshot = snapshots[i];
if (!snapshot) {
return SILKWORM_INVALID_SNAPSHOT;
Expand Down
22 changes: 11 additions & 11 deletions silkworm/capi/silkworm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_ephemeral single block:
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.header.number = 11;
block.transactions[0].nonce++;
++block.transactions[0].nonce;

insert_block(env, block);

Expand Down Expand Up @@ -465,7 +465,7 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_perpetual single block:
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.header.number = 11;
block.transactions[0].nonce++;
++block.transactions[0].nonce;

insert_block(env, block);

Expand Down Expand Up @@ -537,7 +537,7 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_ephemeral multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
++block.transactions[0].nonce;
}

// Execute N blocks using an *external* txn, then commit
Expand All @@ -560,7 +560,7 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_ephemeral multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
++block.transactions[0].nonce;
}

// Execute N blocks using an *external* txn, then commit
Expand Down Expand Up @@ -637,8 +637,8 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_perpetual multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
block.transactions[0].to->bytes[19]++; // change recipient address to force batch size growth
++block.transactions[0].nonce;
++block.transactions[0].to->bytes[19]; // change recipient address to force batch size growth
}

// Execute N blocks using an *internal* txn
Expand All @@ -660,8 +660,8 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_perpetual multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
block.transactions[0].to->bytes[19]++; // change recipient address to force batch size growth
++block.transactions[0].nonce;
++block.transactions[0].to->bytes[19]; // change recipient address to force batch size growth
}

// Execute N blocks using an *internal* txn, then commit
Expand Down Expand Up @@ -732,7 +732,7 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_ephemeral multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
++block.transactions[0].nonce;
}

// Execute N blocks using an *external* txn, then commit
Expand Down Expand Up @@ -799,8 +799,8 @@ TEST_CASE_METHOD(CApiTest, "CAPI silkworm_execute_blocks_perpetual multiple bloc
insert_block(env, block);
block.transactions.erase(block.transactions.cbegin());
block.transactions.pop_back();
block.transactions[0].nonce++;
block.transactions[0].to->bytes[19]++; // change recipient address to force batch size growth
++block.transactions[0].nonce;
++block.transactions[0].to->bytes[19]; // change recipient address to force batch size growth
}

// Execute N blocks using an *internal* txn
Expand Down
2 changes: 1 addition & 1 deletion silkworm/core/common/lru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LruCache {

if (cache_items_map_.size() > max_size_) {
auto last = cache_items_list_.end();
last--;
--last;
cache_items_map_.erase(last->first);
cache_items_list_.pop_back();
}
Expand Down
2 changes: 1 addition & 1 deletion silkworm/core/common/random_number_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST_CASE("random numbers") {
uint64_t b = 3;
RandomNumber random_number(a, b);

for (int i = 0; i < 100; i++) {
for (int i = 0; i < 100; ++i) {
auto a_number = random_number.generate_one();
REQUIRE((a <= a_number && a_number <= b));
}
Expand Down
2 changes: 1 addition & 1 deletion silkworm/db/access_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void delete_transactions(RWTxn& txn, uint64_t base_id, uint64_t count) {
auto cursor = txn.rw_cursor(table::kBlockTransactions);
auto first_key = db::block_key(base_id);
auto result = cursor->find(to_slice(first_key), /* throw_notfound = */ false);
for (uint64_t i = 0; result && (i < count); result = cursor->to_next(/* throw_notfound = */ false), i++) {
for (uint64_t i = 0; result && (i < count); result = cursor->to_next(/* throw_notfound = */ false), ++i) {
cursor->erase();
}
}
Expand Down
6 changes: 3 additions & 3 deletions silkworm/db/access_layer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ TEST_CASE("Headers and bodies", "[db][access_layer]") {
height,
[&count, &height](const Block& block) {
REQUIRE(block.header.number == height);
count++;
++count;
});
REQUIRE(processed == 1);
REQUIRE(processed == count);
Expand All @@ -567,7 +567,7 @@ TEST_CASE("Headers and bodies", "[db][access_layer]") {
height,
[&count, &height](const Block& block) {
REQUIRE(block.header.number == height);
count++;
++count;
});
REQUIRE(processed == 2);
REQUIRE(processed == count);
Expand Down Expand Up @@ -852,7 +852,7 @@ TEST_CASE("read rlp encoded transactions", "[db][access_layer]") {
REQUIRE(found);
REQUIRE(rlp_transactions.size() == body.transactions.size());

for (size_t i = 0; i < rlp_transactions.size(); i++) {
for (size_t i = 0; i < rlp_transactions.size(); ++i) {
Bytes rlp_tx;
CHECK_NOTHROW(rlp::encode(rlp_tx, body.transactions[i]));
CHECK(rlp_transactions[i] == rlp_tx);
Expand Down
4 changes: 2 additions & 2 deletions silkworm/db/blocks/bodies/body_snapshot_freezer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void BodySnapshotFreezer::copy(ROTxn& txn, const FreezerCommand& command, snapsh

snapshots::BodySnapshotWriter writer{file_writer};
auto out = writer.out();
for (BlockNum i = range.start; i < range.end; i++) {
for (BlockNum i = range.start; i < range.end; ++i) {
auto value_opt = read_canonical_body_for_storage(txn, i);
if (!value_opt) throw std::runtime_error{"BodySnapshotFreezer::copy missing body for block " + std::to_string(i)};
BlockBodyForStorage& value = *value_opt;
Expand All @@ -43,7 +43,7 @@ void BodySnapshotFreezer::copy(ROTxn& txn, const FreezerCommand& command, snapsh
}

void BodySnapshotFreezer::cleanup(RWTxn& txn, BlockNumRange range) const {
for (BlockNum i = range.start, count = 1; i < range.end; i++, count++) {
for (BlockNum i = range.start, count = 1; i < range.end; ++i, ++count) {
auto hash_opt = read_canonical_header_hash(txn, i);
if (!hash_opt) continue;
auto hash = *hash_opt;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/db/blocks/headers/header_snapshot_freezer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ void HeaderSnapshotFreezer::copy(ROTxn& txn, const FreezerCommand& command, snap
BlockNumRange range = command.range;
snapshots::HeaderSnapshotWriter writer{file_writer};
auto out = writer.out();
for (BlockNum i = range.start; i < range.end; i++) {
for (BlockNum i = range.start; i < range.end; ++i) {
auto value_opt = read_canonical_header(txn, i);
if (!value_opt) throw std::runtime_error{"HeaderSnapshotFreezer::copy missing header for block " + std::to_string(i)};
*out++ = *value_opt;
}
}

void HeaderSnapshotFreezer::cleanup(RWTxn& txn, BlockNumRange range) const {
for (BlockNum i = range.start, count = 1; i < range.end; i++, count++) {
for (BlockNum i = range.start, count = 1; i < range.end; ++i, ++count) {
auto hash_opt = read_canonical_header_hash(txn, i);
if (!hash_opt) continue;
auto& hash = *hash_opt;
Expand Down
8 changes: 4 additions & 4 deletions silkworm/db/db_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ TEST_CASE("db access layer addendum") {
SECTION("header with biggest td") {
CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 1234));

header.number++;
++header.number;
CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 100'000'001'000'000));
auto expected_max_bn = header.number;
auto expected_max_hash = header.hash();

header.number++;
++header.number;
CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 34'000'000'000));

auto [max_bn, max_hash] = header_with_biggest_td(tx);
Expand All @@ -119,11 +119,11 @@ TEST_CASE("db access layer addendum") {

CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 1234));

header.number++;
++header.number;
CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 100'000'001'000'000));
bad_headers.insert(header.hash());

header.number++;
++header.number;
CHECK_NOTHROW(db::write_total_difficulty(tx, header.number, header.hash(), 34'000'000'000));
auto expected_max_bn = header.number;
auto expected_max_hash = header.hash();
Expand Down
2 changes: 1 addition & 1 deletion silkworm/db/etl_in_memory_collector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void run_collector_test(const KVLoadFunc& load_func, bool do_copy = true) {
while (data) {
auto key = db::from_slice(data.key);
auto value = db::from_slice(data.value);
found_items++;
++found_items;

// find key in set and compare value
auto it = std::find_if(set.begin(), set.end(), [&key](const Entry& entry) {
Expand Down
2 changes: 1 addition & 1 deletion silkworm/db/kv/grpc/server/kv_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void KvServer::register_kv_request_calls(agrpc::GrpcContext* grpc_context) {
//! Start server-side RPC requests as required by gRPC async model: one RPC per type is requested in advance.
void KvServer::register_request_calls() {
// Start all server-side RPC requests for each available server context
for (std::size_t i = 0; i < num_contexts(); i++) {
for (std::size_t i = 0; i < num_contexts(); ++i) {
const auto& context = next_context();
auto grpc_context = context.server_grpc_context();

Expand Down
Loading

0 comments on commit a8adb8b

Please sign in to comment.