Skip to content

Commit

Permalink
chore: fixing lint errors and warnings; mit-dci#266
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Rockett <[email protected]>
  • Loading branch information
rockett-m committed Jul 25, 2024
1 parent f3b2d81 commit 0e4f480
Show file tree
Hide file tree
Showing 73 changed files with 218 additions and 225 deletions.
4 changes: 2 additions & 2 deletions src/parsec/agent/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace cbdc::parsec::agent {
class impl : public interface {
public:
/// States for a ticket managed by this agent.
enum class state {
enum class state : std::uint8_t {
/// Initial state.
init,
/// Begin request sent to broker.
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace cbdc::parsec::agent {
std::shared_ptr<thread_pool> m_threads;
std::optional<hash_t> m_tx_id;
bool m_wounded{false};
broker::held_locks_set_type m_requested_locks{};
broker::held_locks_set_type m_requested_locks;
bool m_restarted{false};

void handle_begin(broker::interface::ticketnum_or_errcode_type res);
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/agent/runners/evm/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ namespace cbdc::parsec::agent::runner {

return std::make_pair(
min_gas,
!(evmtx.m_gas_limit < min_gas && !is_readonly_run));
!evmtx.m_gas_limit < min_gas || is_readonly_run);
}

auto evm_runner::make_message(const evmc::address& from,
Expand Down
46 changes: 23 additions & 23 deletions src/parsec/agent/runners/evm/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace cbdc::parsec::agent::runner {
/// EVM account type
struct evm_account {
/// Balance in the account.
evmc::uint256be m_balance{};
evmc::uint256be m_balance;
/// Signature nonce.
evmc::uint256be m_nonce{};
evmc::uint256be m_nonce;

/// Set of keys modified during contract execution.
std::set<evmc::bytes32> m_modified{};
std::set<evmc::bytes32> m_modified;
/// Flag set if the account is being destructed.
bool m_destruct{false};
};
Expand All @@ -44,8 +44,8 @@ namespace cbdc::parsec::agent::runner {

/// Type for tracking storage key accesses between accounts.
struct evm_access_tuple {
evmc::address m_address{};
std::vector<evmc::bytes32> m_storage_keys{};
evmc::address m_address;
std::vector<evmc::bytes32> m_storage_keys;
auto operator==(const evm_access_tuple& rhs) const -> bool {
return m_address == rhs.m_address
&& m_storage_keys == rhs.m_storage_keys;
Expand All @@ -67,23 +67,23 @@ namespace cbdc::parsec::agent::runner {
/// Type of transaction.
evm_tx_type m_type{};
/// To address or std::nullopt if contract creation.
std::optional<evmc::address> m_to{};
std::optional<evmc::address> m_to;
/// Value to transfer.
evmc::uint256be m_value{};
evmc::uint256be m_value;
/// Nonce for from account.
evmc::uint256be m_nonce{};
evmc::uint256be m_nonce;
/// Gas price.
evmc::uint256be m_gas_price{};
evmc::uint256be m_gas_price;
/// Maximum gas for this transaction.
evmc::uint256be m_gas_limit{};
evmc::uint256be m_gas_limit;
/// Maximum tip fee.
evmc::uint256be m_gas_tip_cap{};
evmc::uint256be m_gas_tip_cap;
/// Maximum base fee.
evmc::uint256be m_gas_fee_cap{};
evmc::uint256be m_gas_fee_cap;
/// Contract input data.
std::vector<uint8_t> m_input{};
std::vector<uint8_t> m_input;
/// List of storage key accesses.
evm_access_list m_access_list{};
evm_access_list m_access_list;
/// Transaction signature.
evm_sig m_sig;
};
Expand All @@ -99,11 +99,11 @@ namespace cbdc::parsec::agent::runner {
/// EVM log output type.
struct evm_log {
/// Address for the log.
evmc::address m_addr{};
evmc::address m_addr;
/// Log data.
std::vector<uint8_t> m_data{};
std::vector<uint8_t> m_data;
/// List of log topics.
std::vector<evmc::bytes32> m_topics{};
std::vector<evmc::bytes32> m_topics;
};

/// EVM transaction receipt type.
Expand All @@ -113,11 +113,11 @@ namespace cbdc::parsec::agent::runner {
/// Created contract address, if applicable.
std::optional<evmc::address> m_create_address;
/// Gas used in transaction.
evmc::uint256be m_gas_used{};
evmc::uint256be m_gas_used;
/// List of logs emitted during transaction.
std::vector<evm_log> m_logs{};
std::vector<evm_log> m_logs;
/// EVM output data.
std::vector<uint8_t> m_output_data{};
std::vector<uint8_t> m_output_data;
/// Ticket number that ran this TX - needed to map
/// to pretend blocks
cbdc::parsec::agent::runner::interface::ticket_number_type
Expand All @@ -136,16 +136,16 @@ namespace cbdc::parsec::agent::runner {
/// Ticket number
interface::ticket_number_type m_ticket_number {};
/// Transactions executed by the ticket
std::vector<evm_tx_receipt> m_transactions{};
std::vector<evm_tx_receipt> m_transactions;
};

/// Describes the parameters of a query on EVM logs - used to transfer
/// these parameters from the getLogs API method to the runner
struct evm_log_query {
/// The addresses for which logs are queried
std::vector<evmc::address> m_addresses{};
std::vector<evmc::address> m_addresses;
/// The topics for which logs are queried
std::vector<evmc::bytes32> m_topics{};
std::vector<evmc::bytes32> m_topics;
/// The start of the block range to query logs for
cbdc::parsec::agent::runner::interface::ticket_number_type
m_from_block {};
Expand Down
9 changes: 4 additions & 5 deletions src/parsec/agent/runners/evm/rlp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace cbdc {
/// Possible types for an RLP value
enum class rlp_value_type {
enum class rlp_value_type : std::uint8_t {
/// A collection of RLP values
array,
/// A singular RLP value (byte array)
Expand Down Expand Up @@ -90,10 +90,9 @@ namespace cbdc {
/// \tparam address or byte array type.
/// \return byte array or address.
template<typename T>
[[nodiscard]] auto value() const -> typename std::enable_if_t<
std::is_same<T, evmc::bytes32>::value
|| std::is_same<T, evmc::address>::value,
T> {
requires std::is_same_v<T, evmc::bytes32>
|| std::is_same_v<T, evmc::address>
[[nodiscard]] auto value() const -> T {
auto res = T();
auto buf = cbdc::buffer();
buf.extend(sizeof(res.bytes));
Expand Down
4 changes: 2 additions & 2 deletions src/parsec/agent/runners/evm/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace cbdc::parsec::agent::runner {
auto maybe_addr = cbdc::from_buffer<evmc::address>(
maybe_addr_buf.value());
if(maybe_addr) {
return maybe_addr.value();
return maybe_addr;
}
}
}
Expand All @@ -249,7 +249,7 @@ namespace cbdc::parsec::agent::runner {
auto maybe_val
= cbdc::from_buffer<evmc::uint256be>(maybe_val_buf.value());
if(maybe_val) {
return maybe_val.value();
return maybe_val;
}
}
return std::nullopt;
Expand Down
10 changes: 3 additions & 7 deletions src/parsec/agent/runners/evm/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_UTIL_H_
#define OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_UTIL_H_

#include "messages.hpp"
#include "parsec/broker/interface.hpp"
#include "util/common/buffer.hpp"
#include "util/common/hash.hpp"
#include "util/common/keys.hpp"
#include "util/common/logging.hpp"

#include <evmc/evmc.hpp>
#include <evmc/hex.hpp>
#include <memory>
#include <optional>
#include <secp256k1.h>
#include <secp256k1_extrakeys.h>
#include <secp256k1_recovery.h>
Expand Down Expand Up @@ -51,10 +49,8 @@ namespace cbdc::parsec::agent::runner {
/// \return object containing the parsed T or std::nullopt if
/// parse failed
template<typename T>
auto from_hex(const std::string& hex) ->
typename std::enable_if_t<std::is_same<T, evmc::bytes32>::value
|| std::is_same<T, evmc::address>::value,
std::optional<T>> {
requires std::is_same_v<T, evmc::bytes32> || std::is_same_v<T, evmc::address>
auto from_hex(const std::string& hex) -> std::optional<T> {
auto maybe_bytes = cbdc::buffer::from_hex_prefixed(hex);
if(!maybe_bytes.has_value()) {
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/agent/runners/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace cbdc::parsec::agent::runner {
class interface {
public:
/// Error codes return during function execution.
enum class error_code {
enum class error_code : std::uint8_t {
/// Function did not return a string value.
result_value_type,
/// Function did not return a string key.
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/agent/server_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace cbdc::parsec::agent::rpc {
const cbdc::parsec::config& m_cfg;

mutable std::mutex m_agents_mut;
std::atomic<size_t> m_next_id{};
std::atomic<size_t> m_next_id;
std::unordered_map<size_t, std::shared_ptr<agent::impl>> m_agents;

blocking_queue<size_t> m_cleanup_queue;
Expand Down
18 changes: 9 additions & 9 deletions src/parsec/broker/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace cbdc::parsec::broker {

if(!m_directory->key_location(
key,
[=, this](std::optional<parsec::directory::interface::
[ticket_number, key, locktype, result_callback, this](std::optional<parsec::directory::interface::
key_location_return_type> res) {
handle_find_key(ticket_number,
key,
Expand Down Expand Up @@ -295,7 +295,7 @@ namespace cbdc::parsec::broker {
auto sidx = shard.first;
if(!m_shards[sidx]->commit(
ticket_number,
[=, this](const parsec::runtime_locking_shard::interface::
[commit_cb, ticket_number, sidx, this](const parsec::runtime_locking_shard::interface::
commit_return_type& comm_res) {
handle_commit(commit_cb, ticket_number, sidx, comm_res);
})) {
Expand Down Expand Up @@ -544,7 +544,7 @@ namespace cbdc::parsec::broker {
shard.second.m_state = shard_state_type::finishing;
if(!m_shards[sidx]->finish(
ticket_number,
[=, this](const parsec::runtime_locking_shard::
[result_callback, ticket_number, sidx, this](const parsec::runtime_locking_shard::
interface::finish_return_type& res) {
handle_finish(result_callback,
ticket_number,
Expand All @@ -560,7 +560,7 @@ namespace cbdc::parsec::broker {
}();

if(maybe_error.has_value()) {
result_callback(maybe_error.value());
result_callback(maybe_error);
} else if(done) {
result_callback(std::nullopt);
}
Expand Down Expand Up @@ -617,7 +617,7 @@ namespace cbdc::parsec::broker {
shard.second.m_state = shard_state_type::rolling_back;
if(!m_shards[sidx]->rollback(
ticket_number,
[=, this](const parsec::runtime_locking_shard::
[result_callback, ticket_number, sidx, this](const parsec::runtime_locking_shard::
interface::rollback_return_type& res) {
handle_rollback(result_callback,
ticket_number,
Expand Down Expand Up @@ -782,7 +782,7 @@ namespace cbdc::parsec::broker {
key,
locktype,
first_lock,
[=, this](const parsec::runtime_locking_shard::interface::
[ticket_number, key, shard_idx, result_callback, this](const parsec::runtime_locking_shard::interface::
try_lock_return_type& lock_res) {
handle_lock(ticket_number,
key,
Expand Down Expand Up @@ -873,7 +873,7 @@ namespace cbdc::parsec::broker {
}();

if(maybe_error.has_value()) {
result_callback(maybe_error.value());
result_callback(maybe_error);
} else if(callback) {
result_callback(std::nullopt);
}
Expand Down Expand Up @@ -962,7 +962,7 @@ namespace cbdc::parsec::broker {
}},
res);
if(maybe_error.has_value()) {
result_callback(maybe_error.value());
result_callback(maybe_error);
} else if(done) {
result_callback(std::nullopt);
}
Expand All @@ -972,7 +972,7 @@ namespace cbdc::parsec::broker {

auto impl::do_recovery(const recover_callback_type& result_callback)
-> std::optional<error_code> {
for(auto [ticket_number, ticket] : m_tickets) {
for(const auto& [ticket_number, ticket] : m_tickets) {
size_t committed{};
for(auto& [sidx, t_state] : ticket->m_shard_states) {
switch(t_state.m_state) {
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/runtime_locking_shard/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace cbdc::parsec::runtime_locking_shard {
key_set_type m_queued_locks;
state_update_type m_state_update;
broker_id_type m_broker_id{};
std::optional<wounded_details> m_wounded_details{};
std::optional<wounded_details> m_wounded_details;
};

struct pending_callback_element_type {
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/ticket_machine/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace cbdc::parsec::ticket_machine {

private:
std::shared_ptr<logging::log> m_log;
std::atomic<ticket_number_type> m_next_ticket_number{};
std::atomic<ticket_number_type> m_next_ticket_number;
ticket_number_type m_range;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/parsec/ticket_machine/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace cbdc::parsec::ticket_machine {

std::atomic<uint64_t> m_last_committed_idx{0};

std::unique_ptr<impl> m_ticket_machine{};
std::unique_ptr<impl> m_ticket_machine;

std::shared_ptr<logging::log> m_logger;
};
Expand Down
4 changes: 2 additions & 2 deletions src/parsec/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

namespace cbdc::parsec {
/// Type of load to generate for benchmarking
enum class load_type {
enum class load_type : std::uint8_t {
/// Base token transfer
transfer,
/// ERC20 token transfer
erc20
};

/// Execution/transaction model
enum class runner_type {
enum class runner_type : std::uint8_t {
/// Transaction semantics defined using Lua.
lua,
/// Ethereum-style transactions using EVM.
Expand Down
6 changes: 3 additions & 3 deletions src/uhs/atomizer/archiver/archiverd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ auto main(int argc, char** argv) -> int {
if(args.size() < 3) {
std::cerr << "Usage: " << args[0]
<< " <config file> <archiver id> [<max samples>]"
<< std::endl;
<< '\n';
return 0;
}

Expand All @@ -28,15 +28,15 @@ auto main(int argc, char** argv) -> int {
auto cfg_or_err = cbdc::config::load_options(args[1]);
if(std::holds_alternative<std::string>(cfg_or_err)) {
std::cerr << "Error loading config file: "
<< std::get<std::string>(cfg_or_err) << std::endl;
<< std::get<std::string>(cfg_or_err) << '\n';
return -1;
}
auto opts = std::get<cbdc::config::options>(cfg_or_err);

const auto archiver_id = std::stoull(args[2]);

if(opts.m_archiver_endpoints.size() <= archiver_id) {
std::cerr << "Archiver ID not in config file" << std::endl;
std::cerr << "Archiver ID not in config file" << '\n';
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/uhs/atomizer/archiver/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace cbdc::archiver {
= static_cast<double>(blk.m_transactions.size())
/ s_since_last_block.count();

m_tp_sample_file << tx_throughput << std::endl;
m_tp_sample_file << tx_throughput << '\n';
m_samples++;
}

Expand Down Expand Up @@ -280,7 +280,7 @@ namespace cbdc::archiver {
auto blk = from_buffer<atomizer::block>(buf);
assert(blk.has_value());
m_logger->trace("found block", height, "-", blk.value().m_height);
return blk.value();
return blk;
}

void controller::request_block(uint64_t height) {
Expand Down
Loading

0 comments on commit 0e4f480

Please sign in to comment.