提交 7829b7af 编写于 作者: D Daniel Larimer

cleaning up apply context

上级 68d1565c
......@@ -81,6 +81,7 @@ void apply_context::exec()
ncontext.id = id;
ncontext.processing_deadline = processing_deadline;
ncontext.published_time = published_time;
ncontext.exec();
fc::move_append( executed, move(ncontext.executed) );
total_cpu_usage += ncontext.total_cpu_usage;
......@@ -93,6 +94,7 @@ void apply_context::exec()
EOS_ASSERT( recurse_depth < config::max_recursion_depth, transaction_exception, "inline action recursion depth reached" );
apply_context ncontext( mutable_controller, _inline_actions[i], trx, recurse_depth + 1 );
ncontext.processing_deadline = processing_deadline;
ncontext.published_time = published_time;
ncontext.id = id;
ncontext.exec();
fc::move_append( executed, move(ncontext.executed) );
......@@ -219,8 +221,9 @@ void apply_context::schedule_deferred_transaction( deferred_transaction&& trx )
auto id = trx.id();
/// TODO: validate authority and delay
const auto& tr = static_cast<const transaction&>(trx);
auto trx_size = fc::raw::pack_size(trx);
auto trx_size = fc::raw::pack_size(tr);
auto& d = control.db();
d.create<generated_transaction_object>( [&]( auto& gtx ) {
......@@ -234,7 +237,7 @@ void apply_context::schedule_deferred_transaction( deferred_transaction&& trx )
gtx.packed_trx.resize( trx_size );
fc::datastream<char*> ds( gtx.packed_trx.data(), trx_size );
fc::raw::pack( ds, trx );
fc::raw::pack( ds, tr );
});
auto& rl = control.get_mutable_resource_limits_manager();
......
......@@ -302,23 +302,50 @@ struct controller_impl {
self.accepted_block( head );
}
void apply_onerror( const generated_transaction_object& gto ) {
/*
try {
signed_transaction etrx;
etrx.actions.emplace_back(vector<permission_level>{{gto.sender,config::active_name}},
contracts::onerror( gto.sender_id, gto.packed_trx.data(), gto.packed_trx.size()) );
db.remove( gto );
}
*/
}
transaction_trace_ptr push_scheduled_transaction( const generated_transaction_object& gto ) {
fc::datastream<const char*> ds( gto.packed_trx.data(), gto.packed_trx.size() );
deferred_transaction dtrx;
fc::raw::unpack(ds,dtrx);
transaction_context trx_context( self, dtrx, gto.trx_id );
trx_context.processing_deadline = fc::time_point::now() + conf.limits.max_push_transaction_us;
trx_context.net_usage = 0;
trx_context.sender = gto.sender;
trx_context.published = gto.published;
trx_context.exec();
auto& acts = pending->_actions;
fc::move_append( acts, move(trx_context.executed) );
optional<fc::exception> except;
try {
signed_transaction dtrx;
fc::raw::unpack(ds,static_cast<transaction&>(dtrx) );
transaction_context trx_context( self, dtrx, gto.trx_id );
trx_context.processing_deadline = fc::time_point::now() + conf.limits.max_push_transaction_us;
trx_context.published = gto.published;
return move(trx_context.trace);
}
/*
trx_context.exec();
auto& acts = pending->_actions;
fc::move_append( acts, move(trx_context.executed) );
db.remove( gto );
pending->_pending_block_state->block->transactions.emplace_back( gto.trx_id );
pending->_pending_block_state->block->transactions.back().kcpu_usage = trx.total_cpu_usage;
return move(trx_context.trace);
*/
} catch( const fc::exception& e ) {
except = e;
}
if( except ) {
apply_onerror( gto );
}
return transaction_trace_ptr();
} /// push_scheduled_transaction
transaction_trace_ptr push_transaction( const transaction_metadata_ptr& trx ) {
unapplied_transactions.erase( trx->signed_id );
......
......@@ -356,8 +356,7 @@ void apply_eosio_unlinkauth(apply_context& context) {
}
void apply_eosio_onerror(apply_context& context) {
FC_ASSERT(context.sender != account_name(), "onerror action cannot be called directly");
context.require_recipient(context.sender);
context.require_authorization(config::system_account_name);
}
static const abi_serializer& get_abi_serializer() {
......@@ -495,8 +494,9 @@ void apply_eosio_passrecovery(apply_context& context) {
// ensure this is only processed if it is a deferred transaction from the system account
// TODO: verify this works with any PRIVILEGED account
FC_ASSERT( context.sender == config::system_account_name );
// FC_ASSERT( context.sender == config::system_account_name );
context.require_authorization(account);
context.require_authorization(config::system_account_name);
auto maybe_recovery = get_pending_recovery(context, account);
FC_ASSERT(maybe_recovery, "No pending recovery found for account ${account}", ("account", account));
......
......@@ -578,7 +578,6 @@ class apply_context {
uint32_t recurse_depth; // how deep inline actions can recurse
fc::time_point_sec published_time;
account_name sender;
fc::time_point processing_deadline;
vector<action_receipt> executed;
......
......@@ -14,8 +14,7 @@ namespace eosio { namespace chain {
executed = 0, ///< succeed, no error handler executed
soft_fail = 1, ///< objectively failed (not executed), error handler executed
hard_fail = 2, ///< objectively failed and error handler objectively failed thus no state change
delayed = 3, ///< transaction delayed/deferred/scheduled for future execution
implicit = 4 ///< transaction that is implied or implicit with the block generation (such as on block action)
delayed = 3 ///< transaction delayed/deferred/scheduled for future execution
};
transaction_receipt_header():status(hard_fail){}
......@@ -61,7 +60,7 @@ namespace eosio { namespace chain {
} } /// eosio::chain
FC_REFLECT_ENUM( eosio::chain::transaction_receipt::status_enum,
(executed)(soft_fail)(hard_fail)(delayed)(implicit) )
(executed)(soft_fail)(hard_fail)(delayed) )
FC_REFLECT(eosio::chain::transaction_receipt_header, (status)(kcpu_usage)(net_usage_words) )
FC_REFLECT_DERIVED(eosio::chain::transaction_receipt, (eosio::chain::transaction_receipt_header), (trx) )
......
......@@ -219,8 +219,12 @@ struct unlinkauth {
}
};
struct onerror : bytes {
using bytes::bytes;
struct onerror {
uint128_t sender_id;
bytes sent_trx;
onerror( uint128_t sid, const char* data, size_t len )
:sender_id(sid),sent_trx(data,data+len){}
static account_name get_account() {
return config::system_account_name;
......@@ -304,3 +308,4 @@ FC_REFLECT( eosio::chain::postrecovery , (account)(auth)(mem
FC_REFLECT( eosio::chain::passrecovery , (account) )
FC_REFLECT( eosio::chain::vetorecovery , (account) )
FC_REFLECT( eosio::chain::canceldelay , (canceling_auth)(trx_id) )
FC_REFLECT( eosio::chain::onerror , (sender_id)(sent_trx) )
......@@ -29,6 +29,7 @@ namespace eosio { namespace chain {
transaction_receipt_header receipt;
fc::microseconds elapsed;
uint64_t cpu_usage = 0;
bool scheduled = false;
vector<action_trace> action_traces; ///< disposable
};
typedef std::shared_ptr<transaction_trace> transaction_trace_ptr;
......
......@@ -31,7 +31,6 @@ namespace eosio { namespace chain {
controller& control;
transaction_id_type id;
account_name sender;
fc::time_point published;
const signed_transaction& trx;
uint32_t net_usage = 0;
......
......@@ -41,6 +41,7 @@ namespace eosio { namespace chain {
acontext.context_free = context_free;
acontext.receiver = receiver;
acontext.processing_deadline = processing_deadline;
acontext.published_time = published;
acontext.exec();
fc::move_append(executed, move(acontext.executed) );
......
......@@ -833,10 +833,6 @@ class action_api : public context_aware_api {
return context.published_time;
}
name current_sender() {
return context.sender;
}
name current_receiver() {
return context.receiver;
}
......@@ -1546,13 +1542,10 @@ REGISTER_INTRINSICS(action_api,
(read_action_data, int(int, int) )
(action_data_size, int() )
(publication_time, int32_t() )
(current_sender, int64_t() )
(current_receiver, int64_t() )
);
REGISTER_INTRINSICS(apply_context,
// (require_write_lock, void(int64_t) )
// (require_read_lock, void(int64_t, int64_t) )
(require_recipient, void(int64_t) )
(require_authorization, void(int64_t), "require_auth", void(apply_context::*)(const account_name&))
(require_authorization, void(int64_t, int64_t), "require_auth2", void(apply_context::*)(const account_name&, const permission_name& permission))
......@@ -1560,7 +1553,6 @@ REGISTER_INTRINSICS(apply_context,
(is_account, int(int64_t) )
);
//(printdi, void(int64_t) )
REGISTER_INTRINSICS(console_api,
(prints, void(int) )
(prints_l, void(int, int) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册