diff --git a/libraries/blockchain/asset_operations.cpp b/libraries/blockchain/asset_operations.cpp index 3ba734636..c8278d7d2 100644 --- a/libraries/blockchain/asset_operations.cpp +++ b/libraries/blockchain/asset_operations.cpp @@ -72,6 +72,9 @@ void create_asset_operation::evaluate( transaction_evaluation_state& eval_state if ( !issuer_game_record.valid() ) FC_CAPTURE_AND_THROW(unknown_game_id, (issuer_id) ); + // workaround: to triger reinstall_game_engine in storing game record + eval_state.pending_state()->store_game_record(*issuer_game_record); + authority_account_record = eval_state.pending_state()->get_account_record( issuer_game_record->owner_account_id ); if( !authority_account_record.valid() ) diff --git a/libraries/blockchain/genesis_xts.json b/libraries/blockchain/genesis_xts.json index c0cd23dc3..c7e6ae22d 100644 --- a/libraries/blockchain/genesis_xts.json +++ b/libraries/blockchain/genesis_xts.json @@ -1,7 +1,7 @@ { - "timestamp" : "2015-09-21T18:00:00", + "timestamp" : "2016-01-21T18:00:00", "sharedrop_balances": { - "start_time": "2015-09-20T00:00:00", + "start_time": "2016-01-20T00:00:00", "duration_days": 365, "vesting_balances": [ { diff --git a/libraries/blockchain/include/bts/blockchain/game_record.hpp b/libraries/blockchain/include/bts/blockchain/game_record.hpp index 9d24ebb8a..5bf97df56 100644 --- a/libraries/blockchain/include/bts/blockchain/game_record.hpp +++ b/libraries/blockchain/include/bts/blockchain/game_record.hpp @@ -115,7 +115,8 @@ namespace bts { namespace blockchain { bool is_null()const { return !last_error.valid(); } - game_id_type game_id; + game_id_type game_id; + uint32_t block_number; optional last_error; }; typedef optional ogame_status; @@ -141,4 +142,4 @@ FC_REFLECT_TYPENAME( std::vector ) FC_REFLECT( bts::blockchain::game_result_transaction, (game_id)(data) ) -FC_REFLECT( bts::blockchain::game_status, (game_id)(last_error) ) +FC_REFLECT( bts::blockchain::game_status, (game_id)(block_number)(last_error) ) diff --git a/libraries/game/client.cpp b/libraries/game/client.cpp index 1e212d124..68a70e338 100644 --- a/libraries/game/client.cpp +++ b/libraries/game/client.cpp @@ -123,8 +123,9 @@ namespace bts { namespace game { create_params.array_buffer_allocator = _allocator; ResourceConstraints rc; - rc.set_max_old_space_size(40); //MB - rc.set_max_executable_size(40); //MB + rc.set_max_semi_space_size(40); + rc.set_max_old_space_size(60); //MB + rc.set_max_executable_size(60); //MB static const int stack_breathing_room = 1024 * 1024; //uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); rc.set_stack_limit(reinterpret_cast((char*)&rc - stack_breathing_room)); diff --git a/libraries/game/include/bts/game/v8_api.hpp b/libraries/game/include/bts/game/v8_api.hpp index 058f7d90e..5533ea136 100644 --- a/libraries/game/include/bts/game/v8_api.hpp +++ b/libraries/game/include/bts/game/v8_api.hpp @@ -62,7 +62,7 @@ namespace bts { namespace game { public: v8_blockchain(chain_database_ptr blockchain, int block_num):_blockchain(blockchain), _block_num(block_num){} - static Local New(v8::Isolate* isolate, chain_database_ptr blockchain, uint32_t block_num); + static Local New(v8::Isolate* isolate, v8_blockchain* local_v8_blockchain); static void Get_Block_Number(Local property, const v8::PropertyCallbackInfo& info); @@ -97,7 +97,7 @@ namespace bts { namespace game { public: v8_wallet(wallet_ptr wallet):_wallet(wallet){} - static Local New(v8::Isolate* isolate, wallet_ptr wallet); + static Local New(v8::Isolate* isolate, v8_wallet* local_v8_wallet); static void Get_Transaction_Fee(const v8::FunctionCallbackInfo& args); @@ -120,7 +120,7 @@ namespace bts { namespace game { chain_interface_ptr _chain_state; - static Local New(v8::Isolate* isolate, const pending_chain_state_ptr& pending_state); + static Local New(v8::Isolate* isolate, v8_chainstate* v8_pendingstate); static void Get_Blance_Record(const v8::FunctionCallbackInfo& args); @@ -148,7 +148,7 @@ namespace bts { namespace game { transaction_evaluation_state* _eval_state; - static Local New(v8::Isolate* isolate, transaction_evaluation_state* eval_state); + static Local New(v8::Isolate* isolate, v8_evalstate* local_v8_evalstate); /** * @brief Method for v8_evalstate diff --git a/libraries/game/v8_api.cpp b/libraries/game/v8_api.cpp index 7ae15a784..864a7c0ef 100644 --- a/libraries/game/v8_api.cpp +++ b/libraries/game/v8_api.cpp @@ -177,11 +177,10 @@ namespace bts { namespace game { args.GetReturnValue().Set( External::New(args.GetIsolate(), &addr) ); } - Local v8_blockchain::New(v8::Isolate* isolate, chain_database_ptr blockchain, uint32_t block_num) + Local v8_blockchain::New(v8::Isolate* isolate, v8_blockchain* local_v8_blockchain) { EscapableHandleScope handle_scope(isolate); - // FIXME TODO: Delete this. - v8_blockchain* local_v8_blockchain = new v8_blockchain(blockchain, block_num); + //get class template Handle templ = Local::New(isolate, v8_api::blockchain_templ); Handle blockchain_ctor = templ->GetFunction(); @@ -378,11 +377,10 @@ namespace bts { namespace game { } } - Local v8_wallet::New(v8::Isolate* isolate, wallet_ptr wallet) + Local v8_wallet::New(v8::Isolate* isolate, v8_wallet* local_v8_wallet) { EscapableHandleScope handle_scope(isolate); - // FIXME TODO: Delete this. - v8_wallet* local_v8_wallet = new v8_wallet(wallet); + //get class template Handle templ = Local::New(isolate, v8_api::wallet_templ); Handle wallet_ctor = templ->GetFunction(); @@ -455,12 +453,12 @@ namespace bts { namespace game { static_cast(ptr)->_wallet->store_transaction( trx_data ); } - Local v8_chainstate::New(v8::Isolate* isolate, const pending_chain_state_ptr& pending_state) + Local v8_chainstate::New(v8::Isolate* isolate, v8_chainstate* v8_pendingstate) { EscapableHandleScope handle_scope(isolate); - v8_chainstate* v8_pendingstate = new v8_chainstate(pending_state); + Handle templ = Local::New(isolate, v8_api::pendingstate_templ); @@ -646,12 +644,10 @@ namespace bts { namespace game { static_cast(ptr)->_chain_state->store_game_data_record(wrapper_type->Int32Value(), wrapper_id->Int32Value(), v8_helper::json_to_cpp(args.GetIsolate(), wrap_game_data ) ); } - Local v8_evalstate::New(v8::Isolate* isolate, transaction_evaluation_state* eval_state_ptr) + Local v8_evalstate::New(v8::Isolate* isolate, v8_evalstate* local_v8_evalstate) { EscapableHandleScope handle_scope(isolate); - v8_evalstate* local_v8_evalstate = new v8_evalstate(eval_state_ptr); - Handle templ = Local::New(isolate, v8_api::eval_state_templ); Handle evalstate_ctor = templ->GetFunction(); Local g_evalstate = evalstate_ctor->NewInstance(); diff --git a/libraries/game/v8_game.cpp b/libraries/game/v8_game.cpp index 13441493b..264d2532b 100644 --- a/libraries/game/v8_game.cpp +++ b/libraries/game/v8_game.cpp @@ -170,9 +170,13 @@ namespace bts { namespace game { if(!evaluate->IsFunction()) { FC_CAPTURE_AND_THROW( failed_compile_script ); } else { + v8_chainstate v8_pendingstate(eval_state.pending_state()->shared_from_this()); + + v8_evalstate local_v8_evalstate(&eval_state); + evaluate_func = Handle::Cast(evaluate); - argv[0] = v8_evalstate::New( isolate, &eval_state ); - argv[1] = v8_chainstate::New( isolate, eval_state.pending_state()->shared_from_this() ); + argv[0] = v8_evalstate::New( isolate, &local_v8_evalstate ); + argv[1] = v8_chainstate::New( isolate, &v8_pendingstate ); auto _input = var; // TODO: convert/parse it to a v8 javascript object argv[2] = v8_helper::cpp_to_json(isolate, _input); @@ -325,8 +329,12 @@ namespace bts { namespace game { FC_CAPTURE_AND_THROW( failed_compile_script ); } else { play_func = Handle::Cast(play_f); - argv[0] = v8_blockchain::New(isolate, blockchain, blockchain->get_head_block_num()); - argv[1] = v8_wallet::New(isolate, w); + v8_blockchain local_v8_blockchain(blockchain, blockchain->get_head_block_num()); + + v8_wallet local_v8_wallet(w); + + argv[0] = v8_blockchain::New(isolate, &local_v8_blockchain); + argv[1] = v8_wallet::New(isolate, &local_v8_wallet); auto _input = var; // TODO: convert/parse it to a v8 javascript object argv[2] = v8_helper::cpp_to_json(isolate, _input); @@ -449,9 +457,12 @@ namespace bts { namespace game { FC_CAPTURE_AND_THROW( failed_compile_script ); } else { scan_ledger_func = Handle::Cast(scan_ledger); - argv[0] = v8_blockchain::New(my->GetIsolate(), blockchain, blockchain->get_head_block_num()); + v8_blockchain local_v8_blockchain(blockchain, blockchain->get_head_block_num()); + v8_wallet local_v8_wallet(w); + + argv[0] = v8_blockchain::New(my->GetIsolate(), &local_v8_blockchain); argv[1] = v8_helper::cpp_to_json(isolate, trx_rec); - argv[2] = v8_wallet::New(isolate, w); + argv[2] = v8_wallet::New(isolate, &local_v8_wallet); auto _input = var; // TODO: convert/parse it to a v8 javascript object argv[3] = v8_helper::cpp_to_json(isolate, _input); @@ -505,12 +516,14 @@ namespace bts { namespace game { if(!scan_result->IsFunction()) { FC_CAPTURE_AND_THROW( failed_compile_script ); } else { + v8_wallet local_v8_wallet(w); + scan_result_func = Handle::Cast(scan_result); argv[0] = v8_helper::cpp_to_json(isolate, rtrx); argv[1] = Integer::New(my->GetIsolate(), block_num); argv[2] = String::NewFromUtf8(my->GetIsolate(), fc::variant(block_time).as_string().c_str() ); argv[3] = Integer::New(my->GetIsolate(), trx_index); - argv[4] = v8_wallet::New(isolate, w); + argv[4] = v8_wallet::New(isolate, &local_v8_wallet); Local result = scan_result_func->Call(context->Global(), 5, argv); @@ -551,9 +564,12 @@ namespace bts { namespace game { } else { execute_func = Handle::Cast(execute); - argv[0] = v8_blockchain::New(my->GetIsolate(), blockchain, block_num); + v8_blockchain local_v8_blockchain(blockchain, block_num); + v8_chainstate v8_pendingstate(pending_state); + + argv[0] = v8_blockchain::New(my->GetIsolate(), &local_v8_blockchain); argv[1] = Integer::New(my->GetIsolate(), block_num); - argv[2] = v8_chainstate::New(my->GetIsolate(), pending_state); + argv[2] = v8_chainstate::New(my->GetIsolate(), &v8_pendingstate); // Run the script to get the result. // wlog("Run the script to get the result..."); @@ -582,17 +598,26 @@ namespace bts { namespace game { auto diff_supply = v.get_object()["diff_supply"]; FC_ASSERT( execute_results.is_array() ); - vector game_result_transactions; - game_result_transactions.resize( execute_results.get_array().size() ); - for ( auto result : execute_results.get_array() ) + + if (execute_results.get_array().size()) { - game_result_transaction g_trx; - g_trx.game_id = game_id; - g_trx.data = result; - game_result_transactions.push_back( std::move( g_trx ) ); + vector game_result_transactions; + + game_result_transactions.reserve(execute_results.get_array().size()); + for (auto result : execute_results.get_array()) + { + game_result_transaction g_trx; + g_trx.game_id = game_id; + g_trx.data = result; + game_result_transactions.push_back(std::move(g_trx)); + } + + // execute() could be re-enterred for mutiple games execution in one block + // so here we need to append the game transactions instend of re-set + pending_state->game_result_transactions.insert(pending_state->game_result_transactions.end(), + game_result_transactions.begin(), game_result_transactions.end()); } - - pending_state->set_game_result_transactions( std::move( game_result_transactions ) ); + FC_ASSERT( game_datas.is_array() ); for ( auto d : game_datas.get_array() ) { @@ -676,6 +701,7 @@ namespace bts { namespace game { ogame_status game_stat = pending_state->get_game_status( game_id ); if( !game_stat.valid() ) game_stat = game_status( game_id ); + game_stat->block_number = block_num; game_stat->last_error = e; pending_state->store_game_status( *game_stat ); } diff --git a/programs/qt_wallet b/programs/qt_wallet index a63493c2f..7c47cec59 160000 --- a/programs/qt_wallet +++ b/programs/qt_wallet @@ -1 +1 @@ -Subproject commit a63493c2f258cefeb0a5ee896d83968984965dd1 +Subproject commit 7c47cec59f6787396905f56f7ce3bcd190154501 diff --git a/programs/web_wallet b/programs/web_wallet index 401610adf..72934d29b 160000 --- a/programs/web_wallet +++ b/programs/web_wallet @@ -1 +1 @@ -Subproject commit 401610adfa52558eb8d50d19077eed14bd6494e5 +Subproject commit 72934d29b3e4013d20a1fe64ffd2c5621396cf8d diff --git a/vendor b/vendor index bf8c9dbb9..ec8b08a10 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit bf8c9dbb9af3f7bf44b6d6b08abf895e4d548c25 +Subproject commit ec8b08a10ef22980c0ac32fdb7336a3c3be5360f