提交 1bbe9db7 编写于 作者: D Daniel Larimer

progress

上级 ab83927a
......@@ -163,6 +163,7 @@ struct controller_impl {
}
/**
* This method will backup all tranasctions in the current pending block,
* undo the pending block, call f(), and then push the pending transactions
......@@ -203,6 +204,73 @@ struct controller_impl {
});
}
transaction_trace_ptr push_transaction( const transaction_metadata_ptr& trx ) {
return db.with_write_lock( [&](){
return apply_transaction( trx );
});
}
void record_transaction( const transaction_metadata_ptr& trx ) {
try {
_db.create<transaction_object>([&](transaction_object& transaction) {
transaction.trx_id = trx->id;
transaction.expiration = trx->trx.expiration;
});
} catch ( ... ) {
EOS_ASSERT( false, transaction_exception,
"duplicate transaction ${id}",
("id", trx.id() ) );
}
}
void start_transaction( const transaction_metadata_ptr& trx ) {
record_transaction( trx );
}
transaction_trace_ptr apply_transaction( const transaction_metadata_ptr& trx, bool implicit = false ) {
auto trx_session = db.start_undo_session();
// TODO: notify pre transaction
start_transaction( trx );
for( const auto& act : trx->trx.context_free_actions ) {
apply_action( act, ... );
/*
apply_context context( self, db, act, trx );
context.context_free = true;
context.exec();
receipt.kcpu_usage += context.kcpu_usage
*/
}
for( const auto& act : trx->trx.actions ) {
auto act_session = db.start_undo_session();
// TODO: notify pre action
/*
apply_context context( self, db, act, trx );
context.exec();
receipt.kcpu_usage += context.kcpu_usage
*/
// TODO: notify post action
act_session.squash();
}
finalize_transaction();
// TODO: notify post transaction
trx_session.squash();
push_transaction_receipt( trx, type );
}
block_state_ptr push_block_impl( const signed_block_ptr& b ) {
#if 0
......@@ -268,6 +336,20 @@ struct controller_impl {
} /// validate_net_usage
*/
transaction_trace_ptr apply_transaction( const transaction_metadata_ptr& trx ) {
auto trx_trace = std::make_shared<transaction_trace>();
trx_trace->action_traces.reserve( trx->trx.actions.size() );
trx_trace->action_receipts.reserve( trx->trx.actions.size() );
for( const auto& act : trx->trx.actions ) {
// trx_trace->action_receipts.emplace_back( apply_action( act
}
return trx_trace;
}
void finalize_block( const block_trace& trace )
{ try {
......@@ -437,15 +519,18 @@ void controller::start_block( block_timestamp_type when ) {
FC_ASSERT( !my->pending );
my->pending = my->db.start_undo_session(true);
my->pending->_pending_block_state = std::make_shared<block_state>( *my->head, when );
auto t = my->get_on_block_transaction();
// apply_transaction(
// idump((t));
}
void controller::finalize_block() {
auto p = my->pending->_pending_block_state;
/// set trx mroot and act mroot
my->pending->_pending_block_state->id = my->pending->_pending_block_state->header.id();
/// set trx mroot and act mroot on pending.header and pending.block (which also has copy of header)
// my->pending->_pending_block_state->id = my->pending->_pending_block_state->header.id();
}
void controller::sign_block( std::function<signature_type( const digest_type& )> signer_callback ) {
......@@ -474,7 +559,7 @@ void controller::push_block( const signed_block_ptr& b ) {
}
transaction_trace_ptr controller::push_transaction( const transaction_metadata_ptr& trx ) {
return my->push_transaction();
}
transaction_trace_ptr controller::push_transaction() {
......
......@@ -11,12 +11,10 @@ namespace eosio { namespace chain {
struct action_receipt {
account_name receiver;
action act;
uint32_t block_sequence;
uint32_t sender_sequence;
fc::sha256 transaction_id_type; /// the trx that started this action
uint16_t trx_action_dispatch_seq; ///< the relative order for implied trx
uint16_t trx_action_creator_seq; ///< the dispatch seq of the action that created this dispatch
uint16_t trx_action_dispatch_count; ///< the total number of actions dispatched by transaction when this action was dispatched
uint32_t block_sequence; /// block num
uint32_t sender_sequence;
transaction_id_type trx_id; /// the trx that started this action
uint16_t trx_action_dispatch_seq; ///< the relative order for implied trx
/// TODO: add code/scope/rw sequence numbers
};
......@@ -36,9 +34,9 @@ namespace eosio { namespace chain {
typedef std::shared_ptr<transaction_trace> transaction_trace_ptr;
struct block_trace {
fc::microseconds ellapsed;
uint64_t cpu_usage;
vector<transaction_trace> trx_traces;
fc::microseconds ellapsed;
uint64_t cpu_usage;
vector<transaction_trace_ptr> trx_traces;
};
typedef std::shared_ptr<block_trace> block_trace_ptr;
......
......@@ -9,19 +9,7 @@ int main( int argc, char** argv ) {
controller c( {} );
controller c2( {.shared_memory_dir = "c2dir", .block_log_dir = "c2dir" } );
c.start_block();
c.finalize_block();
c.sign_block( []( digest_type d ) {
auto priv = fc::variant("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3").as<private_key_type>();
return priv.sign(d);
});
c.commit_block();
c2.push_block( c.head_block_state()->block );
for( uint32_t i = 0; i < 4; ++i ) {
ilog("============================================================\n");
c.start_block();
c.finalize_block();
c.sign_block( []( digest_type d ) {
......@@ -29,9 +17,10 @@ for( uint32_t i = 0; i < 4; ++i ) {
return priv.sign(d);
});
c.commit_block();
c2.push_block( c.head_block_state()->block );
idump((c.head_block_num())(c2.head_block_state()->dpos_last_irreversible_blocknum));
idump((c2.head_block_num())(c2.head_block_state()->dpos_last_irreversible_blocknum));
idump((c.head_block_state()->header));
idump((c2.head_block_state()->header));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册