Skip to content

Commit 5621fcb

Browse files
AlexRamRammaurermi
authored andcommitted
Address several style/documentation/aesthetic issues
Cleanup re [[fallthrough]] in switch statements (Fix #220) - src/3pc/agent/impl.cpp - src/3pc/broker/impl.cpp - src/uhs/twophase/coordinator/format.cpp src/3pc/agent/impl.cpp - do_commit(): remove unused code block in lambda callback passed to m_broker->commit() src/3pc/agent/runners/interface.hpp & src/3pc/agent/runners/lua/impl.hpp & src/3pc/agent/runners/evm/impl.hpp - runner::interface::run(): add [[nodiscard]] and comments src/3pc/agent/runners/evm/init_addresses.hpp - rename init_addresses → init_addresses_for_testing src/3pc/agent/runners/evm/serialization.hpp - fix broken doc comments src/3pc/directory/impl.cpp & src/3pc/directory/impl.hpp: - key_location(): note that using modulo operation creates a (very) small bias from a uniform distribution src/util/rpc/http/kqueue_event_handler.cpp - init(): fix if statement containing assignment tests/unit/3pc/agent/runners/evm/evm_test.cpp - Direct reader to origins of bytecode Signed-off-by: Alexander Jung <[email protected]> temp Signed-off-by: Alexander Jung <[email protected]>
1 parent 0115126 commit 5621fcb

File tree

13 files changed

+33
-39
lines changed

13 files changed

+33
-39
lines changed

src/3pc/agent/impl.cpp

+9-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace cbdc::threepc::agent {
4040
switch(m_state) {
4141
// In these states we can start again from the beginning
4242
case state::init:
43-
[[fallthrough]];
4443
case state::begin_sent:
4544
case state::begin_failed:
4645
break;
@@ -69,7 +68,6 @@ namespace cbdc::threepc::agent {
6968

7069
// Rollback first so we can start fresh
7170
case state::function_get_sent:
72-
[[fallthrough]];
7371
case state::function_get_failed:
7472
case state::function_failed:
7573
case state::function_started:
@@ -87,7 +85,6 @@ namespace cbdc::threepc::agent {
8785

8886
// End states, cannot re-run exec
8987
case state::function_get_error:
90-
[[fallthrough]];
9188
case state::commit_error:
9289
case state::function_exception:
9390
case state::finish_complete:
@@ -375,16 +372,7 @@ namespace cbdc::threepc::agent {
375372
m_ticket_number.value(),
376373
payload,
377374
[this](broker::interface::commit_return_type commit_res) {
378-
if(commit_res.has_value()) {
379-
if(std::holds_alternative<
380-
runtime_locking_shard::shard_error>(
381-
commit_res.value())) {
382-
auto err
383-
= std::get<runtime_locking_shard::shard_error>(
384-
commit_res.value());
385-
}
386-
}
387-
handle_commit(commit_res);
375+
handle_commit(std::move(commit_res));
388376
});
389377
if(!maybe_success) {
390378
m_state = state::commit_failed;
@@ -491,34 +479,40 @@ namespace cbdc::threepc::agent {
491479
// No results should be reported in these states, fatal bugs
492480
case state::init:
493481
m_log->fatal("Result reported in initial state");
482+
// System terminated by fatal()
494483
case state::begin_sent:
495484
m_log->fatal("Result reported in begin_sent state");
485+
// System terminated by fatal()
496486
case state::function_get_sent:
497487
m_log->fatal("Result reported in function_get_sent state");
488+
// System terminated by fatal()
498489
case state::commit_sent:
499490
m_log->fatal("Result reported in commit_sent state");
491+
// System terminated by fatal()
500492
case state::finish_sent:
501493
m_log->fatal("Result reported in finish_sent state");
494+
// System terminated by fatal()
502495
case state::function_started:
503496
m_log->fatal("Result reported in function_started state");
497+
// System terminated by fatal()
504498
case state::rollback_sent:
505499
m_log->fatal("Result reported in rollback_sent state");
500+
// System terminated by fatal()
506501
case state::rollback_complete:
507502
if(!std::holds_alternative<error_code>(m_result.value())
508503
|| std::get<error_code>(m_result.value())
509504
!= error_code::retry) {
510505
m_log->fatal("Result reported in rollback_complete state "
511506
"when result is not retry");
512507
}
513-
[[fallthrough]];
508+
break;
514509

515510
// Failure due to transient problems, should retry
516511
case state::begin_failed:
517512
// Couldn't get a ticket number, no need to rollback
518513
break;
519514

520515
case state::function_get_failed:
521-
[[fallthrough]];
522516
case state::function_failed:
523517
case state::commit_failed:
524518
do_rollback(false);
@@ -534,7 +528,6 @@ namespace cbdc::threepc::agent {
534528

535529
// Failure due to permanent error, abort completely
536530
case state::function_get_error:
537-
[[fallthrough]];
538531
case state::commit_error:
539532
case state::function_exception:
540533
do_rollback(true);

src/3pc/agent/runners/evm/impl.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ namespace cbdc::threepc::agent::runner {
6868
auto operator=(evm_runner&&) -> evm_runner& = delete;
6969

7070
/// Begin executing the transaction asynchronously.
71-
/// \return true if execution was initiated successfully.
72-
auto run() -> bool override;
71+
/// \return true if execution was initiated successfully
72+
/// returns false if an internal system error has occurred
73+
[[nodiscard]] auto run() -> bool override;
7374

7475
/// Initial lock type for the agent to request when retrieving the
7576
/// function key.

src/3pc/agent/runners/evm/init_addresses.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <vector>
1111

1212
namespace cbdc::threepc::agent {
13-
/// List of initial addresses to mint accounts for.
14-
const std::vector<std::string> init_addresses
13+
/// List of initial addresses to mint accounts for testing
14+
const std::vector<std::string> init_addresses_for_testing
1515
= {std::string("01a151cc5ed14d110cc0e6b64360913de9f453f1"),
1616
std::string("13333383a6c55d9b699c4d57e3b0c85759f0efca"),
1717
std::string("9269d13036f74f5e7c1560b2daad6181fb71e682"),

src/3pc/agent/runners/evm/serialization.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace cbdc::threepc::agent::runner {
3939
/// \param buf buffer containing the transaction to decode
4040
/// \param logger logger to output any parsing errors to
4141
/// \param chain_id the expected chain ID for the transaction. If the
42-
// transaction contains a different chain ID this method will return
43-
// std::nullopt
42+
/// transaction contains a different chain ID this method will return
43+
/// std::nullopt
4444
/// \return the evm_tx that was decoded or std::nullopt if no valid
4545
/// value could be decoded
4646
auto tx_decode(const cbdc::buffer& buf,
@@ -60,8 +60,8 @@ namespace cbdc::threepc::agent::runner {
6060
/// Converts a given Json::Value to an evm_tx
6161
/// \param json Json::Value containing the transaction to decode
6262
/// \param chain_id the expected chain ID for the transaction. If the
63-
// transaction contains a different chain ID this method will return
64-
// std::nullopt
63+
/// transaction contains a different chain ID this method will return
64+
/// std::nullopt
6565
/// \return the evm_tx that was decoded or std::nullopt if no valid
6666
/// value could be decoded
6767
auto tx_from_json(const Json::Value& json,
@@ -72,8 +72,8 @@ namespace cbdc::threepc::agent::runner {
7272
/// Converts a given Json::Value to an evm_dryrun_tx
7373
/// \param json Json::Value containing the transaction to decode
7474
/// \param chain_id the expected chain ID for the transaction. If the
75-
// transaction contains a different chain ID this method will return
76-
// std::nullopt
75+
/// transaction contains a different chain ID this method will return
76+
/// std::nullopt
7777
/// \return the evm_dryrun_tx that was decoded or std::nullopt if no valid
7878
/// value could be decoded
7979
auto dryrun_tx_from_json(const Json::Value& json,

src/3pc/agent/runners/evm/util.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ namespace cbdc::threepc::agent::runner {
112112

113113
auto successes = std::vector<std::future<bool>>();
114114

115-
for(const auto& init_addr_hex : cbdc::threepc::agent::init_addresses) {
115+
for(const auto& init_addr_hex :
116+
cbdc::threepc::agent::init_addresses_for_testing) {
116117
log->info("Seeding address ", init_addr_hex);
117118
auto init_addr = cbdc::buffer::from_hex(init_addr_hex).value();
118119
auto seed_success = std::make_shared<std::promise<bool>>();

src/3pc/agent/runners/interface.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ namespace cbdc::threepc::agent::runner {
113113

114114
/// Begins function execution. Retrieves the function bytecode using a
115115
/// read lock and executes it with the given parameter.
116-
/// \return true.
117-
virtual auto run() -> bool = 0;
116+
/// \return true unless a internal system error has occurred
117+
[[nodiscard]] virtual auto run() -> bool = 0;
118118

119119
friend class lua_runner;
120120
friend class evm_runner;

src/3pc/agent/runners/lua/impl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace cbdc::threepc::agent::runner {
3434

3535
/// Begins function execution. Retrieves the function bytecode using a
3636
/// read lock and executes it with the given parameter.
37-
/// \return true.
38-
auto run() -> bool override;
37+
/// \return true unless a internal system error has occurred
38+
[[nodiscard]] auto run() -> bool override;
3939

4040
/// Lock type to acquire when requesting the function code.
4141
static constexpr auto initial_lock_type = broker::lock_type::read;

src/3pc/broker/impl.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,6 @@ namespace cbdc::threepc::broker {
961961
for(auto& [sidx, t_state] : ticket->m_shard_states) {
962962
switch(t_state.m_state) {
963963
case shard_state_type::begun:
964-
[[fallthrough]];
965964
case shard_state_type::prepared:
966965
case shard_state_type::wounded:
967966
break;

src/3pc/directory/impl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace cbdc::threepc::directory {
1212
key_location_callback_type result_callback)
1313
-> bool {
1414
auto key_hash = m_siphash(key);
15+
// NOTE: using modulo creates a small bias from a true
16+
// uniform distribution
1517
auto shard = key_hash % m_n_shards;
1618
result_callback(shard);
1719
return true;

src/3pc/directory/impl.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "interface.hpp"
1010

1111
namespace cbdc::threepc::directory {
12-
/// Implementation of a directory. Uses siphash to uniformly map keys to
13-
/// shard IDs based on a fixed number of shards. Thread-safe.
12+
/// Implementation of a directory which map keys to shard IDs. Thread-safe.
1413
class impl : public interface {
1514
public:
1615
/// Constructor.

src/uhs/twophase/coordinator/format.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ namespace cbdc {
4646
// Discard, done and get don't have a payload
4747
case coordinator::state_machine::command::discard:
4848
case coordinator::state_machine::command::done:
49-
[[fallthrough]];
5049
case coordinator::state_machine::command::get: {
5150
break;
5251
}

src/util/rpc/http/kqueue_event_handler.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ namespace cbdc::rpc {
1616
}
1717

1818
auto kqueue_event_handler::init() -> bool {
19-
if((m_kq = kqueue()) == -1) {
20-
return false;
21-
}
22-
return true;
19+
m_kq = kqueue();
20+
return m_kq != -1;
2321
}
2422

2523
void kqueue_event_handler::set_timeout(long timeout_ms) {

tests/unit/3pc/agent/runners/evm/evm_test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ TEST_F(evm_test, simple_send) {
312312
}
313313

314314
TEST_F(evm_test, contract_deploy) {
315+
// See tools/bench/3pc/evm/contracts for the source Solidity contract and
316+
// other details on the generation of the following bytecode
315317
auto bytecode
316318
= cbdc::buffer::from_hex(
317319
"608060405234801561001057600080fd5b5061002d61002261003260201b602"

0 commit comments

Comments
 (0)