eos里交易是如何执行的

来自https://blog.csdn.net/ITleaks/article/details/80557560


可以看到,交易执行的核心代码在controller.cpp里的trx_context.exec(),它调用了apply_context::exec

for( const auto& inline_action : _cfa_inline_actions ) {

      trace.inline_traces.emplace_back();

      trx_context.dispatch_action( trace.inline_traces.back(), inline_action, inline_action.account, true, recurse_depth + 1 );

  }

  for( const auto& inline_action : _inline_actions ) {

      trace.inline_traces.emplace_back();

      trx_context.dispatch_action( trace.inline_traces.back(), inline_action, inline_action.account, false, recurse_depth + 1 );

  }

这里没看到任何并行处理

https://blog.csdn.net/ITleaks/article/details/80591159

https://blog.csdn.net/zhuxiangzhidi/article/details/81090074

apply_block里的push_transaction和push_scheduled_transaction也是串行执行的

for( const auto& receipt : b->transactions ) {

            auto num_pending_receipts = pending->_pending_block_state->block->transactions.size();

            if( receipt.trx.contains() ) {

              auto& pt = receipt.trx.get();

              auto mtrx = std::make_shared(pt);

              trace = push_transaction( mtrx, fc::time_point::maximum(), receipt.cpu_usage_us, true );

            } else if( receipt.trx.contains() ) {

              trace = push_scheduled_transaction( receipt.trx.get(), fc::time_point::maximum(), receipt.cpu_usage_us, true );

            } else {

              EOS_ASSERT( false, block_validate_exception, "encountered unexpected receipt type" );

            }


EOS区块同步源码分析之见证者

http://www.cnblogs.com/hbright/p/9494789.html

cleos push transaction交易来自cleos

cleos端:

fc::variant push_transaction( signed_transaction& trx, int32_t extra_kcpu = 1000, packed_transaction::compression_type compression = packed_transaction::none ) {

nodeos接口定义

plugins/chain_api_plugin/chain_api_plugin.cpp

CHAIN_RW_CALL_ASYNC(push_transaction, chain_apis::read_write::push_transaction_results, 202),

      CHAIN_RW_CALL_ASYNC(push_transactions, chain_apis::read_write::push_transactions_results, 202)

https://blog.csdn.net/zfdabc_ok/article/details/80886203

void read_write::push_transactions(const read_write::push_transactions_params& params, next_function next) {

  try {

      EOS_ASSERT( params.size() <= 1000, too_many_tx_at_once, "Attempt to push too many transactions at once" );

      auto params_copy = std::make_shared(params.begin(), params.end());

      auto result = std::make_shared();

      result->reserve(params.size());

      push_recurse(this, 0, params_copy, result, next);

  } CATCH_AND_CALL(next);

}

static void push_recurse(read_write* rw, int index, const std::shared_ptr& params, const std::shared_ptr& results, const next_function& next) {

  auto wrapped_next = [=](const fc::static_variant& result) {

      if (result.contains()) {

        const auto& e = result.get();

        results->emplace_back( read_write::push_transaction_results{ transaction_id_type(), fc::mutable_variant_object( "error", e->to_detail_string() ) } );

      } else {

        const auto& r = result.get();

        results->emplace_back( r );

      }

      int next_index = index + 1;

      if (next_index < params->size()) {

        push_recurse(rw, next_index, params, results, next );

      } else {

        next(*results);

      }

  };

  rw->push_transaction(params->at(index), wrapped_next);

}

没有看到并行

void read_write::push_transaction(const read_write::push_transaction_params& params, next_function next) {

  try {

      auto pretty_input = std::make_shared();

      auto resolver = make_resolver(this, abi_serializer_max_time);

      try {

        abi_serializer::from_variant(params, *pretty_input, resolver, abi_serializer_max_time);

      } EOS_RETHROW_EXCEPTIONS(chain::packed_transaction_type_exception, "Invalid packed transaction")

      app().get_method()(pretty_input, true, [this, next](const fc::static_variant& result) -> void{

        if (result.contains()) {

            next(result.get());

        } else {

            auto trx_trace_ptr = result.get();

            try {

              chain::transaction_id_type id = trx_trace_ptr->id;

              fc::variant output;

              try {

                  output = db.to_variant_with_abi( *trx_trace_ptr, abi_serializer_max_time );

              } catch( chain::abi_exception& ) {

                  output = *trx_trace_ptr;

              }

              next(read_write::push_transaction_results{id, output});

            } CATCH_AND_CALL(next);

        }

      });

  } catch ( boost::interprocess::bad_alloc& ) {

      raise(SIGUSR1);

  } CATCH_AND_CALL(next);

}

也没看到任何并行

你可能感兴趣的:(eos里交易是如何执行的)