From c813ffc69eb9c452a3438ebd7fa16de86e8374e5 Mon Sep 17 00:00:00 2001 From: Alexander Jung <104335080+AlexRamRam@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:00:07 -0400 Subject: [PATCH] Improve clarity of nested callback flow by function name changes (PArSEC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 <104335080+AlexRamRam@users.noreply.github.com> --- src/parsec/agent/impl.cpp | 18 ++++++++++-------- src/parsec/agent/impl.hpp | 4 ++-- src/parsec/agent/runners/evm/impl.cpp | 16 ++++++++-------- src/parsec/agent/runners/evm/impl.hpp | 8 ++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/parsec/agent/impl.cpp b/src/parsec/agent/impl.cpp index e4bf6a021..bb7f2dfd9 100644 --- a/src/parsec/agent/impl.cpp +++ b/src/parsec/agent/impl.cpp @@ -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 @@ -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; @@ -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 @@ -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(), @@ -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, @@ -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( @@ -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()); } diff --git a/src/parsec/agent/impl.hpp b/src/parsec/agent/impl.hpp index 840c37ca6..818954267 100644 --- a/src/parsec/agent/impl.hpp +++ b/src/parsec/agent/impl.hpp @@ -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(); diff --git a/src/parsec/agent/runners/evm/impl.cpp b/src/parsec/agent/runners/evm/impl.cpp index aa4c6827a..3669ea219 100644 --- a/src/parsec/agent/runners/evm/impl.cpp +++ b/src/parsec/agent/runners/evm/impl.cpp @@ -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 { @@ -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) @@ -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(m_log, @@ -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( @@ -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(res)) { m_log->debug("Failed to read account from shards"); @@ -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"); @@ -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, diff --git a/src/parsec/agent/runners/evm/impl.hpp b/src/parsec/agent/runners/evm/impl.hpp index 16c0a6cc8..c75ea463b 100644 --- a/src/parsec/agent/runners/evm/impl.hpp +++ b/src/parsec/agent/runners/evm/impl.hpp @@ -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; @@ -107,10 +107,10 @@ namespace cbdc::parsec::agent::runner { bool is_readonly_run) -> std::pair; - 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& callback); void schedule_exec();