Skip to content

Commit

Permalink
Improve clarity of nested callback flow by function name changes (PAr…
Browse files Browse the repository at this point in the history
…SEC)

agent::impl
    do_start() --> do_start_function()
    handle_run() —> handle_run_result()
evm_runner
    run_execute_transaction() —> start_execute_transaction()
    handle_lock_from_account() —> handle_lockfromacct_and_continue_exec()
    lock_ticket_number_key() —> lock_ticket_number_key_and_continue_exec()

Signed-off-by: Alexander Jung <[email protected]>
  • Loading branch information
AlexRamRam committed Oct 18, 2023
1 parent 2948d17 commit c813ffc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/parsec/agent/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace cbdc::parsec::agent {
m_result = std::nullopt;
m_wounded = false;
m_restarted = true;
do_start();
do_start_function();
return true;

// Re-run commit
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace cbdc::parsec::agent {
std::visit(
overloaded{[&](const ticket_machine::ticket_number_type& n) {
m_ticket_number = n;
do_start();
do_start_function();
},
[&](const broker::interface::error_code& /* e */) {
m_state = state::ticket_number_request_failed;
Expand All @@ -132,7 +132,7 @@ namespace cbdc::parsec::agent {
res);
}

void impl::do_start() {
void impl::do_start_function() {
std::unique_lock l(m_mut);
assert(m_ticket_number.has_value());
assert(m_state == state::ticket_number_request_sent
Expand All @@ -152,7 +152,7 @@ namespace cbdc::parsec::agent {
// transaction as m_param and let the runner figure it out.
handle_function(broker::value_type(get_function()));
} else {
m_log->trace("do_start ", get_function().to_hex());
m_log->trace("do_start_function ", get_function().to_hex());

auto tl_success = m_broker->try_lock(
m_ticket_number.value(),
Expand Down Expand Up @@ -329,7 +329,7 @@ namespace cbdc::parsec::agent {
get_param(),
m_is_readonly_run,
[this](const runner::interface::run_return_type& run_res) {
handle_run(run_res);
handle_run_result(run_res);
},
[this](broker::key_type key,
broker::lock_type locktype,
Expand Down Expand Up @@ -382,10 +382,12 @@ namespace cbdc::parsec::agent {
}
}

void impl::handle_run(const runner::interface::run_return_type& res) {
void
impl::handle_run_result(const runner::interface::run_return_type& res) {
std::unique_lock l(m_mut);
if(m_state != state::function_started) {
m_log->warn("handle_run while not in function_started state");
m_log->warn(
"handle_run_result while not in function_started state");
return;
}
std::visit(
Expand Down Expand Up @@ -418,7 +420,7 @@ namespace cbdc::parsec::agent {
}},
res);
m_log->trace(this,
"Agent handle_run complete for",
"Agent handle_run_result complete for",
m_ticket_number.value());
}

Expand Down
4 changes: 2 additions & 2 deletions src/parsec/agent/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ namespace cbdc::parsec::agent {
void
handle_function(const broker::interface::try_lock_return_type& res);

void handle_run(const runner::interface::run_return_type& res);
void handle_run_result(const runner::interface::run_return_type& res);

void handle_commit(broker::interface::commit_return_type res);

void do_start();
void do_start_function();

void do_result();

Expand Down
16 changes: 8 additions & 8 deletions src/parsec/agent/runners/evm/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ namespace cbdc::parsec::agent::runner {
return true;
}
auto from = maybe_from.value();
return run_execute_transaction(from, false);
return start_execute_transaction(from, false);
}

auto evm_runner::run_execute_dryrun_transaction() -> bool {
Expand All @@ -441,7 +441,7 @@ namespace cbdc::parsec::agent::runner {
auto& dryrun_tx = maybe_tx.value();
m_tx = std::move(dryrun_tx.m_tx);

return run_execute_transaction(dryrun_tx.m_from, true);
return start_execute_transaction(dryrun_tx.m_from, true);
}

auto evm_runner::check_base_gas(const evm_tx& evmtx, bool is_readonly_run)
Expand Down Expand Up @@ -519,8 +519,8 @@ namespace cbdc::parsec::agent::runner {
return tx_ctx;
}

auto evm_runner::run_execute_transaction(const evmc::address& from,
bool is_readonly_run) -> bool {
auto evm_runner::start_execute_transaction(const evmc::address& from,
bool is_readonly_run) -> bool {
auto tx_ctx = make_tx_context(from, m_tx, is_readonly_run);

m_host = std::make_unique<evm_host>(m_log,
Expand Down Expand Up @@ -549,7 +549,7 @@ namespace cbdc::parsec::agent::runner {
broker::lock_type::write,
[this](const broker::interface::try_lock_return_type& res) {
m_log->trace(m_ticket_number, "read from account");
handle_lock_from_account(res);
handle_lockfromaccount_and_continue_exec(res);
});
if(!r) {
m_log->error(
Expand Down Expand Up @@ -620,7 +620,7 @@ namespace cbdc::parsec::agent::runner {
}
}

void evm_runner::handle_lock_from_account(
void evm_runner::handle_lockfromaccount_and_continue_exec(
const broker::interface::try_lock_return_type& res) {
if(!std::holds_alternative<broker::value_type>(res)) {
m_log->debug("Failed to read account from shards");
Expand Down Expand Up @@ -684,7 +684,7 @@ namespace cbdc::parsec::agent::runner {
return;
}
m_log->trace(m_ticket_number, "locked TXID key");
lock_ticket_number_key();
lock_ticket_number_key_and_continue_exec();
});
if(!maybe_sent) {
m_log->error("Failed to send try_lock request for TX receipt");
Expand All @@ -693,7 +693,7 @@ namespace cbdc::parsec::agent::runner {
}
}

void evm_runner::lock_ticket_number_key() {
void evm_runner::lock_ticket_number_key_and_continue_exec() {
auto maybe_sent = m_try_lock_callback(
m_host->ticket_number_key(),
broker::lock_type::write,
Expand Down
8 changes: 4 additions & 4 deletions src/parsec/agent/runners/evm/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace cbdc::parsec::agent::runner {
auto run_get_account_code() -> bool;
auto run_get_transaction() -> bool;
auto run_get_transaction_receipt() -> bool;
auto run_execute_transaction(const evmc::address& from,
bool is_readonly_run) -> bool;
auto start_execute_transaction(const evmc::address& from,
bool is_readonly_run) -> bool;
auto run_get_account() -> bool;
auto run_get_block() -> bool;
auto run_get_logs() -> bool;
Expand All @@ -107,10 +107,10 @@ namespace cbdc::parsec::agent::runner {
bool is_readonly_run)
-> std::pair<evmc_message, bool>;

void handle_lock_from_account(
void handle_lockfromaccount_and_continue_exec(
const broker::interface::try_lock_return_type& res);

void lock_ticket_number_key();
void lock_ticket_number_key_and_continue_exec();
void lock_index_keys(const std::function<void()>& callback);
void schedule_exec();

Expand Down

0 comments on commit c813ffc

Please sign in to comment.